source: bootcd/isolinux/syslinux-6.03/gpxe/src/hci/mucurses/ansi_screen.c

Last change on this file was e16e8f2, checked in by Edwin Eefting <edwin@datux.nl>, 3 years ago

bootstuff

  • Property mode set to 100644
File size: 1.9 KB
Line 
1#include <stdio.h>
2#include <curses.h>
3#include <console.h>
4
5FILE_LICENCE ( GPL2_OR_LATER );
6
7static void ansiscr_reset(struct _curses_screen *scr) __nonnull;
8static void ansiscr_movetoyx(struct _curses_screen *scr,
9                               unsigned int y, unsigned int x) __nonnull;
10static void ansiscr_putc(struct _curses_screen *scr, chtype c) __nonnull;
11
12unsigned short _COLS = 80;
13unsigned short _LINES = 24;
14
15static void ansiscr_reset ( struct _curses_screen *scr ) {
16        /* Reset terminal attributes and clear screen */
17        scr->attrs = 0;
18        scr->curs_x = 0;
19        scr->curs_y = 0;
20        printf ( "\033[0m" );
21}
22
23static 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 ) );
28                scr->curs_x = x;
29                scr->curs_y = y;
30        }
31}
32
33static 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 );
38        short fcol;
39        short bcol;
40
41        /* Update attributes if changed */
42        if ( attrs != scr->attrs ) {
43                scr->attrs = 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 );
47        }
48
49        /* Print the actual character */
50        putchar ( character );
51
52        /* Update expected cursor position */
53        if ( ++(scr->curs_x) == _COLS ) {
54                scr->curs_x = 0;
55                ++scr->curs_y;
56        }
57}
58
59static int ansiscr_getc ( struct _curses_screen *scr __unused ) {
60        return getchar();
61}
62
63static bool ansiscr_peek ( struct _curses_screen *scr __unused ) {
64        return iskey();
65}
66
67SCREEN _ansi_screen = {
68        .init           = ansiscr_reset,
69        .exit           = ansiscr_reset,
70        .movetoyx       = ansiscr_movetoyx,
71        .putc           = ansiscr_putc,
72        .getc           = ansiscr_getc,
73        .peek           = ansiscr_peek,
74};
Note: See TracBrowser for help on using the repository browser.