4 unsigned short _COLS = 80;
5 unsigned short _LINES = 24;
7 static void ansiscr_init ( struct _curses_screen *scr ) {
8 /* Reset terminal attributes and clear screen */
12 printf ( "\033[0m\033[2J" );
15 static void ansiscr_exit ( struct _curses_screen *scr __unused ) {
18 static void ansiscr_movetoyx ( struct _curses_screen *scr,
19 unsigned int y, unsigned int x ) {
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 ) );
28 static void ansiscr_putc ( struct _curses_screen *scr, chtype c ) {
29 unsigned int character = ( c & A_CHARTEXT );
30 attr_t attrs = ( c & ( A_ATTRIBUTES | A_COLOR ) );
31 int bold = ( attrs & A_BOLD );
32 attr_t cpair = PAIR_NUMBER ( attrs );
36 /* Update attributes if changed */
37 if ( attrs != scr->attrs ) {
39 pair_content ( cpair, &fcol, &bcol );
40 /* ANSI escape sequence to update character attributes */
41 printf ( "\033[0;%d;3%d;4%dm", ( bold ? 1 : 22 ), fcol, bcol );
44 /* Print the actual character */
45 putchar ( character );
47 /* Update expected cursor position */
48 if ( ++(scr->curs_x) == _COLS ) {
54 static int ansiscr_getc ( struct _curses_screen *scr __unused ) {
58 static bool ansiscr_peek ( struct _curses_screen *scr __unused ) {
62 SCREEN _ansi_screen = {
65 .movetoyx = ansiscr_movetoyx,