Browse Source

[mucurses] Use "<ESC>[2J" ANSI escape sequence to clear screen

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
7271b50890
3 changed files with 40 additions and 16 deletions
  1. 22
    11
      src/hci/mucurses/ansi_screen.c
  2. 10
    0
      src/hci/mucurses/clear.c
  3. 8
    5
      src/include/curses.h

+ 22
- 11
src/hci/mucurses/ansi_screen.c View File

@@ -14,12 +14,26 @@ unsigned short _LINES = 24;
14 14
 
15 15
 static unsigned int saved_usage;
16 16
 
17
+static void ansiscr_attrs ( struct _curses_screen *scr, attr_t attrs ) {
18
+	int bold = ( attrs & A_BOLD );
19
+	attr_t cpair = PAIR_NUMBER ( attrs );
20
+	short fcol;
21
+	short bcol;
22
+
23
+	if ( scr->attrs != attrs ) {
24
+		scr->attrs = attrs;
25
+		pair_content ( cpair, &fcol, &bcol );
26
+		/* ANSI escape sequence to update character attributes */
27
+		printf ( "\033[0;%d;3%d;4%dm", ( bold ? 1 : 22 ), fcol, bcol );
28
+	}
29
+}
30
+
17 31
 static void ansiscr_reset ( struct _curses_screen *scr ) {
18 32
 	/* Reset terminal attributes and clear screen */
19 33
 	scr->attrs = 0;
20 34
 	scr->curs_x = 0;
21 35
 	scr->curs_y = 0;
22
-	printf ( "\033[0m" );
36
+	printf ( "\033[0m\033[2J" );
23 37
 }
24 38
 
25 39
 static void ansiscr_init ( struct _curses_screen *scr ) {
@@ -32,6 +46,11 @@ static void ansiscr_exit ( struct _curses_screen *scr ) {
32 46
 	console_set_usage ( saved_usage );
33 47
 }
34 48
 
49
+static void ansiscr_erase ( struct _curses_screen *scr, attr_t attrs ) {
50
+	ansiscr_attrs ( scr, attrs );
51
+	printf ( "\033[2J" );
52
+}
53
+
35 54
 static void ansiscr_movetoyx ( struct _curses_screen *scr,
36 55
 			       unsigned int y, unsigned int x ) {
37 56
 	if ( ( x != scr->curs_x ) || ( y != scr->curs_y ) ) {
@@ -45,18 +64,9 @@ static void ansiscr_movetoyx ( struct _curses_screen *scr,
45 64
 static void ansiscr_putc ( struct _curses_screen *scr, chtype c ) {
46 65
 	unsigned int character = ( c & A_CHARTEXT );
47 66
 	attr_t attrs = ( c & ( A_ATTRIBUTES | A_COLOR ) );
48
-	int bold = ( attrs & A_BOLD );
49
-	attr_t cpair = PAIR_NUMBER ( attrs );
50
-	short fcol;
51
-	short bcol;
52 67
 
53 68
 	/* Update attributes if changed */
54
-	if ( attrs != scr->attrs ) {
55
-		scr->attrs = attrs;
56
-		pair_content ( cpair, &fcol, &bcol );
57
-		/* ANSI escape sequence to update character attributes */
58
-		printf ( "\033[0;%d;3%d;4%dm", ( bold ? 1 : 22 ), fcol, bcol );
59
-	}
69
+	ansiscr_attrs ( scr, attrs );
60 70
 
61 71
 	/* Print the actual character */
62 72
 	putchar ( character );
@@ -79,6 +89,7 @@ static bool ansiscr_peek ( struct _curses_screen *scr __unused ) {
79 89
 SCREEN _ansi_screen = {
80 90
 	.init		= ansiscr_init,
81 91
 	.exit		= ansiscr_exit,
92
+	.erase		= ansiscr_erase,
82 93
 	.movetoyx	= ansiscr_movetoyx,
83 94
 	.putc		= ansiscr_putc,
84 95
 	.getc		= ansiscr_getc,

+ 10
- 0
src/hci/mucurses/clear.c View File

@@ -88,3 +88,13 @@ int werase ( WINDOW *win ) {
88 88
 	wclrtobot( win );
89 89
 	return OK;
90 90
 }
91
+
92
+/**
93
+ * Completely clear the screen
94
+ *
95
+ * @ret rc	return status code
96
+ */
97
+int erase ( void ) {
98
+	stdscr->scr->erase( stdscr->scr, stdscr->attrs );
99
+	return OK;
100
+}

+ 8
- 5
src/include/curses.h View File

@@ -37,6 +37,13 @@ typedef struct _curses_screen {
37 37
 
38 38
 	void ( *init ) ( struct _curses_screen *scr );
39 39
 	void ( *exit ) ( struct _curses_screen *scr );
40
+	/**
41
+	 * Erase screen
42
+	 *
43
+	 * @v scr	screen on which to operate
44
+	 * @v attrs	attributes
45
+	 */
46
+	void ( * erase ) ( struct _curses_screen *scr, attr_t attrs );
40 47
 	/**
41 48
 	 * Move cursor to position specified by x,y coords
42 49
 	 *
@@ -242,7 +249,7 @@ extern int echo ( void );
242 249
 extern int echochar ( const chtype );
243 250
 extern int endwin ( void );
244 251
 extern char erasechar ( void );
245
-//extern int erase ( void );
252
+extern int erase ( void );
246 253
 extern void filter ( void );
247 254
 extern int flash ( void );
248 255
 extern int flushinp ( void );
@@ -552,10 +559,6 @@ static inline int deleteln ( void ) {
552 559
 	return wdeleteln( stdscr );
553 560
 }
554 561
 
555
-static inline int erase ( void ) {
556
-	return werase ( stdscr );
557
-}
558
-
559 562
 static inline int getch ( void ) {
560 563
 	return wgetch ( stdscr );
561 564
 }

Loading…
Cancel
Save