Warnings purge: src/{crypto,hci,net}
[gpxe.git] / src / hci / mucurses / ansi_screen.c
blobe77fcdc6f170c632cc1246a9f562cf649f1adc4d
1 #include <stdio.h>
2 #include <curses.h>
3 #include <console.h>
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 */
10 scr->attrs = 0;
11 scr->curs_x = 0;
12 scr->curs_y = 0;
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 ) );
21 scr->curs_x = x;
22 scr->curs_y = y;
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 );
31 short fcol;
32 short bcol;
34 /* Update attributes if changed */
35 if ( attrs != scr->attrs ) {
36 scr->attrs = 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 ) {
47 scr->curs_x = 0;
48 ++scr->curs_y;
52 static int ansiscr_getc ( struct _curses_screen *scr __unused ) {
53 return getchar();
56 static bool ansiscr_peek ( struct _curses_screen *scr __unused ) {
57 return iskey();
60 SCREEN _ansi_screen = {
61 .init = ansiscr_reset,
62 .exit = ansiscr_reset,
63 .movetoyx = ansiscr_movetoyx,
64 .putc = ansiscr_putc,
65 .getc = ansiscr_getc,
66 .peek = ansiscr_peek,