Browse Source

Avoid cursor move on every single character

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
e85bf52446
2 changed files with 22 additions and 4 deletions
  1. 20
    4
      src/hci/mucurses/ansi_screen.c
  2. 2
    0
      src/include/curses.h

+ 20
- 4
src/hci/mucurses/ansi_screen.c View File

@@ -4,18 +4,25 @@
4 4
 unsigned short _COLS = 80;
5 5
 unsigned short _LINES = 25;
6 6
 
7
-static void ansiscr_init ( struct _curses_screen *scr __unused ) {
7
+static void ansiscr_init ( struct _curses_screen *scr ) {
8 8
 	/* Reset terminal attributes and clear screen */
9
+	scr->attrs = 0;
10
+	scr->curs_x = 0;
11
+	scr->curs_y = 0;
9 12
 	printf ( "\033[0m\033[2J" );
10 13
 }
11 14
 
12 15
 static void ansiscr_exit ( struct _curses_screen *scr __unused ) {
13 16
 }
14 17
 
15
-static void ansiscr_movetoyx ( struct _curses_screen *scr __unused,
18
+static void ansiscr_movetoyx ( struct _curses_screen *scr,
16 19
 			       unsigned int y, unsigned int x ) {
17
-	/* ANSI escape sequence to update cursor position */
18
-	printf ( "\033[%d;%dH", ( y + 1 ), ( x + 1 ) );
20
+	if ( ( x != scr->curs_x ) || ( y != scr->curs_y ) ) {
21
+		/* ANSI escape sequence to update cursor position */
22
+		printf ( "\033[%d;%dH", ( y + 1 ), ( x + 1 ) );
23
+		scr->curs_x = x;
24
+		scr->curs_y = y;
25
+	}
19 26
 }
20 27
 
21 28
 static void ansiscr_putc ( struct _curses_screen *scr, chtype c ) {
@@ -26,13 +33,22 @@ static void ansiscr_putc ( struct _curses_screen *scr, chtype c ) {
26 33
 	short fcol;
27 34
 	short bcol;
28 35
 
36
+	/* Update attributes if changed */
29 37
 	if ( attrs != scr->attrs ) {
30 38
 		scr->attrs = attrs;
31 39
 		pair_content ( cpair, &fcol, &bcol );
32 40
 		/* ANSI escape sequence to update character attributes */
33 41
 		printf ( "\033[0;%d;3%d;4%dm", ( bold ? 1 : 22 ), fcol, bcol );
34 42
 	}
43
+
44
+	/* Print the actual character */
35 45
 	putchar ( character );
46
+
47
+	/* Update expected cursor position */
48
+	if ( ++(scr->curs_x) == _COLS ) {
49
+		scr->curs_x = 0;
50
+		++scr->curs_y;
51
+	}
36 52
 }
37 53
 
38 54
 static int ansiscr_getc ( struct _curses_screen *scr __unused ) {

+ 2
- 0
src/include/curses.h View File

@@ -28,6 +28,8 @@ typedef uint32_t attr_t;
28 28
 
29 29
 /** Curses SCREEN object */
30 30
 typedef struct _curses_screen {
31
+	/** Current cursor position */
32
+	unsigned int curs_x, curs_y;
31 33
 	/** Current attribute */
32 34
 	attr_t attrs;
33 35
 

Loading…
Cancel
Save