5 FILE_LICENCE ( GPL2_OR_LATER
);
7 static void ansiscr_reset(struct _curses_screen
*scr
) __nonnull
;
8 static void ansiscr_movetoyx(struct _curses_screen
*scr
,
9 unsigned int y
, unsigned int x
) __nonnull
;
10 static void ansiscr_putc(struct _curses_screen
*scr
, chtype c
) __nonnull
;
12 unsigned short _COLS
= 80;
13 unsigned short _LINES
= 24;
15 static void ansiscr_reset ( struct _curses_screen
*scr
) {
16 /* Reset terminal attributes and clear screen */
23 static void ansiscr_movetoyx ( struct _curses_screen
*scr
,
24 unsigned int y
, unsigned int x
) {
25 if ( ( x
!= scr
->curs_x
) || ( y
!= scr
->curs_y
) ) {
26 /* ANSI escape sequence to update cursor position */
27 printf ( "\033[%d;%dH", ( y
+ 1 ), ( x
+ 1 ) );
33 static void ansiscr_putc ( struct _curses_screen
*scr
, chtype c
) {
34 unsigned int character
= ( c
& A_CHARTEXT
);
35 attr_t attrs
= ( c
& ( A_ATTRIBUTES
| A_COLOR
) );
36 int bold
= ( attrs
& A_BOLD
);
37 attr_t cpair
= PAIR_NUMBER ( attrs
);
41 /* Update attributes if changed */
42 if ( attrs
!= scr
->attrs
) {
44 pair_content ( cpair
, &fcol
, &bcol
);
45 /* ANSI escape sequence to update character attributes */
46 printf ( "\033[0;%d;3%d;4%dm", ( bold
? 1 : 22 ), fcol
, bcol
);
49 /* Print the actual character */
50 putchar ( character
);
52 /* Update expected cursor position */
53 if ( ++(scr
->curs_x
) == _COLS
) {
59 static int ansiscr_getc ( struct _curses_screen
*scr __unused
) {
63 static bool ansiscr_peek ( struct _curses_screen
*scr __unused
) {
67 SCREEN _ansi_screen
= {
68 .init
= ansiscr_reset
,
69 .exit
= ansiscr_reset
,
70 .movetoyx
= ansiscr_movetoyx
,