5 unsigned short _COLS
= 80;
6 unsigned short _LINES
= 24;
8 static void ansiscr_reset ( struct _curses_screen
*scr
) {
9 /* Reset terminal attributes and clear screen */
13 printf ( "\033[0m\033[2J\033[1;1H" );
16 static void ansiscr_movetoyx ( struct _curses_screen
*scr
,
17 unsigned int y
, unsigned int x
) {
18 if ( ( x
!= scr
->curs_x
) || ( y
!= scr
->curs_y
) ) {
19 /* ANSI escape sequence to update cursor position */
20 printf ( "\033[%d;%dH", ( y
+ 1 ), ( x
+ 1 ) );
26 static void ansiscr_putc ( struct _curses_screen
*scr
, chtype c
) {
27 unsigned int character
= ( c
& A_CHARTEXT
);
28 attr_t attrs
= ( c
& ( A_ATTRIBUTES
| A_COLOR
) );
29 int bold
= ( attrs
& A_BOLD
);
30 attr_t cpair
= PAIR_NUMBER ( attrs
);
34 /* Update attributes if changed */
35 if ( attrs
!= scr
->attrs
) {
37 pair_content ( cpair
, &fcol
, &bcol
);
38 /* ANSI escape sequence to update character attributes */
39 printf ( "\033[0;%d;3%d;4%dm", ( bold
? 1 : 22 ), fcol
, bcol
);
42 /* Print the actual character */
43 putchar ( character
);
45 /* Update expected cursor position */
46 if ( ++(scr
->curs_x
) == _COLS
) {
52 static int ansiscr_getc ( struct _curses_screen
*scr __unused
) {
56 static bool ansiscr_peek ( struct _curses_screen
*scr __unused
) {
60 SCREEN _ansi_screen
= {
61 .init
= ansiscr_reset
,
62 .exit
= ansiscr_reset
,
63 .movetoyx
= ansiscr_movetoyx
,