iPXE
Functions | Variables
ansi_screen.c File Reference
#include <stdio.h>
#include <curses.h>
#include <ipxe/ansicol.h>
#include <ipxe/console.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static void ansiscr_reset (struct _curses_screen *scr) __nonnull
static void ansiscr_movetoyx (struct _curses_screen *scr, unsigned int y, unsigned int x) __nonnull
static void ansiscr_putc (struct _curses_screen *scr, chtype c) __nonnull
static void ansiscr_attrs (struct _curses_screen *scr, attr_t attrs)
static void ansiscr_init (struct _curses_screen *scr)
static void ansiscr_exit (struct _curses_screen *scr)
static void ansiscr_erase (struct _curses_screen *scr, attr_t attrs)
static int ansiscr_getc (struct _curses_screen *scr __unused)
static bool ansiscr_peek (struct _curses_screen *scr __unused)
static void ansiscr_cursor (struct _curses_screen *scr __unused, int visibility)

Variables

static unsigned int saved_usage
SCREEN _ansi_screen

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static void ansiscr_reset ( struct _curses_screen scr) [static]

Definition at line 28 of file ansi_screen.c.

References ansicol_set_pair(), _curses_screen::attrs, CPAIR_DEFAULT, _curses_screen::curs_x, _curses_screen::curs_y, and printf().

Referenced by ansiscr_exit(), and ansiscr_init().

                                                         {
        /* Reset terminal attributes and clear screen */
        scr->attrs = 0;
        scr->curs_x = 0;
        scr->curs_y = 0;
        printf ( "\0330m" );
        ansicol_set_pair ( CPAIR_DEFAULT );
        printf ( "\033[2J" );
}
static void ansiscr_movetoyx ( struct _curses_screen scr,
unsigned int  y,
unsigned int  x 
) [static]

Definition at line 53 of file ansi_screen.c.

References _curses_screen::curs_x, _curses_screen::curs_y, and printf().

                                                                {
        if ( ( x != scr->curs_x ) || ( y != scr->curs_y ) ) {
                /* ANSI escape sequence to update cursor position */
                printf ( "\033[%d;%dH", ( y + 1 ), ( x + 1 ) );
                scr->curs_x = x;
                scr->curs_y = y;
        }
}
static void ansiscr_putc ( struct _curses_screen scr,
chtype  c 
) [static]

Definition at line 63 of file ansi_screen.c.

References A_ATTRIBUTES, A_CHARTEXT, A_COLOR, ansiscr_attrs(), attrs, COLS, _curses_screen::curs_x, _curses_screen::curs_y, and putchar().

                                                                  {
        unsigned int character = ( c & A_CHARTEXT );
        attr_t attrs = ( c & ( A_ATTRIBUTES | A_COLOR ) );

        /* Update attributes if changed */
        ansiscr_attrs ( scr, attrs );

        /* Print the actual character */
        putchar ( character );

        /* Update expected cursor position */
        if ( ++(scr->curs_x) == COLS ) {
                scr->curs_x = 0;
                ++scr->curs_y;
        }
}
static void ansiscr_attrs ( struct _curses_screen scr,
attr_t  attrs 
) [static]

Definition at line 15 of file ansi_screen.c.

References A_BOLD, ansicol_set_pair(), _curses_screen::attrs, attrs, PAIR_NUMBER, and printf().

Referenced by ansiscr_erase(), and ansiscr_putc().

                                                                       {
        int bold = ( attrs & A_BOLD );
        attr_t cpair = PAIR_NUMBER ( attrs );

        if ( scr->attrs != attrs ) {
                scr->attrs = attrs;
                /* Reset attributes and set/clear bold as appropriate */
                printf ( "\033[0;%dm", ( bold ? 1 : 22 ) );
                /* Set foreground and background colours */
                ansicol_set_pair ( cpair );
        }
}
static void ansiscr_init ( struct _curses_screen scr) [static]
static void ansiscr_exit ( struct _curses_screen scr) [static]

Definition at line 43 of file ansi_screen.c.

References ansiscr_reset(), console_set_usage(), and saved_usage.

static void ansiscr_erase ( struct _curses_screen scr,
attr_t  attrs 
) [static]

Definition at line 48 of file ansi_screen.c.

References ansiscr_attrs(), and printf().

                                                                       {
        ansiscr_attrs ( scr, attrs );
        printf ( "\033[2J" );
}
static int ansiscr_getc ( struct _curses_screen *scr  __unused) [static]

Definition at line 80 of file ansi_screen.c.

References getchar().

                                                                {
        return getchar();
}
static bool ansiscr_peek ( struct _curses_screen *scr  __unused) [static]

Definition at line 84 of file ansi_screen.c.

References iskey().

                                                                 {
        return iskey();
}
static void ansiscr_cursor ( struct _curses_screen *scr  __unused,
int  visibility 
) [static]

Definition at line 88 of file ansi_screen.c.

References printf().

                                              {
        printf ( "\033[?25%c", ( visibility ? 'h' : 'l' ) );
}

Variable Documentation

unsigned int saved_usage [static]

Definition at line 13 of file ansi_screen.c.

Referenced by ansiscr_exit(), ansiscr_init(), dbg_printf(), and log_vprintf().

Initial value:
 {
        .init           = ansiscr_init,
        .exit           = ansiscr_exit,
        .erase          = ansiscr_erase,
        .movetoyx       = ansiscr_movetoyx,
        .putc           = ansiscr_putc,
        .getc           = ansiscr_getc,
        .peek           = ansiscr_peek,
        .cursor         = ansiscr_cursor,
}

Definition at line 93 of file ansi_screen.c.