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