5 static void ansiscr_reset(struct _curses_screen
*scr
) __nonnull
;
6 static void ansiscr_movetoyx(struct _curses_screen
*scr
,
7 unsigned int y
, unsigned int x
) __nonnull
;
8 static void ansiscr_putc(struct _curses_screen
*scr
, chtype c
) __nonnull
;
10 unsigned short _COLS
= 80;
11 unsigned short _LINES
= 24;
13 static void ansiscr_reset ( struct _curses_screen
*scr
) {
14 /* Reset terminal attributes and clear screen */
18 printf ( "\033[0m\033[2J\033[1;1H" );
21 static void ansiscr_movetoyx ( struct _curses_screen
*scr
,
22 unsigned int y
, unsigned int x
) {
23 if ( ( x
!= scr
->curs_x
) || ( y
!= scr
->curs_y
) ) {
24 /* ANSI escape sequence to update cursor position */
25 printf ( "\033[%d;%dH", ( y
+ 1 ), ( x
+ 1 ) );
31 static void ansiscr_putc ( struct _curses_screen
*scr
, chtype c
) {
32 unsigned int character
= ( c
& A_CHARTEXT
);
33 attr_t attrs
= ( c
& ( A_ATTRIBUTES
| A_COLOR
) );
34 int bold
= ( attrs
& A_BOLD
);
35 attr_t cpair
= PAIR_NUMBER ( attrs
);
39 /* Update attributes if changed */
40 if ( attrs
!= scr
->attrs
) {
42 pair_content ( cpair
, &fcol
, &bcol
);
43 /* ANSI escape sequence to update character attributes */
44 printf ( "\033[0;%d;3%d;4%dm", ( bold
? 1 : 22 ), fcol
, bcol
);
47 /* Print the actual character */
48 putchar ( character
);
50 /* Update expected cursor position */
51 if ( ++(scr
->curs_x
) == _COLS
) {
57 static int ansiscr_getc ( struct _curses_screen
*scr __unused
) {
61 static bool ansiscr_peek ( struct _curses_screen
*scr __unused
) {
65 SCREEN _ansi_screen
= {
66 .init
= ansiscr_reset
,
67 .exit
= ansiscr_reset
,
68 .movetoyx
= ansiscr_movetoyx
,