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
 unsigned short _COLS = 80;
4
 unsigned short _COLS = 80;
5
 unsigned short _LINES = 25;
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
 	/* Reset terminal attributes and clear screen */
8
 	/* Reset terminal attributes and clear screen */
9
+	scr->attrs = 0;
10
+	scr->curs_x = 0;
11
+	scr->curs_y = 0;
9
 	printf ( "\033[0m\033[2J" );
12
 	printf ( "\033[0m\033[2J" );
10
 }
13
 }
11
 
14
 
12
 static void ansiscr_exit ( struct _curses_screen *scr __unused ) {
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
 			       unsigned int y, unsigned int x ) {
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
 static void ansiscr_putc ( struct _curses_screen *scr, chtype c ) {
28
 static void ansiscr_putc ( struct _curses_screen *scr, chtype c ) {
26
 	short fcol;
33
 	short fcol;
27
 	short bcol;
34
 	short bcol;
28
 
35
 
36
+	/* Update attributes if changed */
29
 	if ( attrs != scr->attrs ) {
37
 	if ( attrs != scr->attrs ) {
30
 		scr->attrs = attrs;
38
 		scr->attrs = attrs;
31
 		pair_content ( cpair, &fcol, &bcol );
39
 		pair_content ( cpair, &fcol, &bcol );
32
 		/* ANSI escape sequence to update character attributes */
40
 		/* ANSI escape sequence to update character attributes */
33
 		printf ( "\033[0;%d;3%d;4%dm", ( bold ? 1 : 22 ), fcol, bcol );
41
 		printf ( "\033[0;%d;3%d;4%dm", ( bold ? 1 : 22 ), fcol, bcol );
34
 	}
42
 	}
43
+
44
+	/* Print the actual character */
35
 	putchar ( character );
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
 static int ansiscr_getc ( struct _curses_screen *scr __unused ) {
54
 static int ansiscr_getc ( struct _curses_screen *scr __unused ) {

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

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

Loading…
Cancel
Save