|
@@ -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,
|