Adding debian version 3.70~pre8+dfsg-1.
[syslinux-debian/hramrach.git] / gpxe / src / hci / mucurses / ansi_screen.c
blob0742a7d41d83365652e319204477954c99f07e9a
1 #include <stdio.h>
2 #include <curses.h>
3 #include <console.h>
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 */
15 scr->attrs = 0;
16 scr->curs_x = 0;
17 scr->curs_y = 0;
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 ) );
26 scr->curs_x = x;
27 scr->curs_y = y;
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 );
36 short fcol;
37 short bcol;
39 /* Update attributes if changed */
40 if ( attrs != scr->attrs ) {
41 scr->attrs = 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 ) {
52 scr->curs_x = 0;
53 ++scr->curs_y;
57 static int ansiscr_getc ( struct _curses_screen *scr __unused ) {
58 return getchar();
61 static bool ansiscr_peek ( struct _curses_screen *scr __unused ) {
62 return iskey();
65 SCREEN _ansi_screen = {
66 .init = ansiscr_reset,
67 .exit = ansiscr_reset,
68 .movetoyx = ansiscr_movetoyx,
69 .putc = ansiscr_putc,
70 .getc = ansiscr_getc,
71 .peek = ansiscr_peek,