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()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ ansiscr_reset()

static void ansiscr_reset ( struct _curses_screen scr)
static

Definition at line 28 of file ansi_screen.c.

28  {
29  /* Reset terminal attributes and clear screen */
30  scr->attrs = 0;
31  scr->curs_x = 0;
32  scr->curs_y = 0;
33  printf ( "\0330m" );
35  printf ( "\033[2J" );
36 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
void ansicol_set_pair(unsigned int cpair)
Set ANSI foreground and background colour.
Definition: ansicol.c:89
unsigned int curs_x
Current cursor position.
Definition: curses.h:35
#define CPAIR_DEFAULT
Default colour pair.
Definition: ansicol.h:37
attr_t attrs
Current attribute.
Definition: curses.h:37
unsigned int curs_y
Definition: curses.h:35

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().

◆ ansiscr_movetoyx()

static void ansiscr_movetoyx ( struct _curses_screen scr,
unsigned int  y,
unsigned int  x 
)
static

Definition at line 53 of file ansi_screen.c.

54  {
55  if ( ( x != scr->curs_x ) || ( y != scr->curs_y ) ) {
56  /* ANSI escape sequence to update cursor position */
57  printf ( "\033[%d;%dH", ( y + 1 ), ( x + 1 ) );
58  scr->curs_x = x;
59  scr->curs_y = y;
60  }
61 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
unsigned int curs_x
Current cursor position.
Definition: curses.h:35
unsigned int curs_y
Definition: curses.h:35

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

◆ ansiscr_putc()

static void ansiscr_putc ( struct _curses_screen scr,
chtype  c 
)
static

Definition at line 63 of file ansi_screen.c.

63  {
64  unsigned int character = ( c & A_CHARTEXT );
65  attr_t attrs = ( c & ( A_ATTRIBUTES | A_COLOR ) );
66 
67  /* Update attributes if changed */
68  ansiscr_attrs ( scr, attrs );
69 
70  /* Print the actual character */
71  putchar ( character );
72 
73  /* Update expected cursor position */
74  if ( ++(scr->curs_x) == COLS ) {
75  scr->curs_x = 0;
76  ++scr->curs_y;
77  }
78 }
#define A_ATTRIBUTES
Definition: curses.h:146
void putchar(int character)
Write a single character to each console device.
Definition: console.c:27
static __always_inline void off_t int c
Definition: efi_uaccess.h:87
uint32_t attr_t
Definition: curses.h:30
uint32_t attrs
Extended attributes (optional)
Definition: memmap.c:32
unsigned int curs_x
Current cursor position.
Definition: curses.h:35
#define COLS
Definition: curses.h:111
#define A_COLOR
Definition: curses.h:149
unsigned int curs_y
Definition: curses.h:35
#define A_CHARTEXT
Definition: curses.h:147
static void ansiscr_attrs(struct _curses_screen *scr, attr_t attrs)
Definition: ansi_screen.c:15

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

◆ ansiscr_attrs()

static void ansiscr_attrs ( struct _curses_screen scr,
attr_t  attrs 
)
static

Definition at line 15 of file ansi_screen.c.

15  {
16  int bold = ( attrs & A_BOLD );
17  attr_t cpair = PAIR_NUMBER ( attrs );
18 
19  if ( scr->attrs != attrs ) {
20  scr->attrs = attrs;
21  /* Reset attributes and set/clear bold as appropriate */
22  printf ( "\033[0;%dm", ( bold ? 1 : 22 ) );
23  /* Set foreground and background colours */
24  ansicol_set_pair ( cpair );
25  }
26 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
void ansicol_set_pair(unsigned int cpair)
Set ANSI foreground and background colour.
Definition: ansicol.c:89
uint32_t attr_t
Definition: curses.h:30
uint32_t attrs
Extended attributes (optional)
Definition: memmap.c:32
attr_t attrs
Current attribute.
Definition: curses.h:37
#define A_BOLD
Definition: curses.h:138
#define PAIR_NUMBER(attrs)
Definition: curses.h:153

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

Referenced by ansiscr_erase(), and ansiscr_putc().

◆ ansiscr_init()

static void ansiscr_init ( struct _curses_screen scr)
static

Definition at line 38 of file ansi_screen.c.

38  {
40  ansiscr_reset ( scr );
41 }
#define CONSOLE_USAGE_TUI
Text-based user interface.
Definition: console.h:147
static void ansiscr_reset(struct _curses_screen *scr) __nonnull
Definition: ansi_screen.c:28
static int console_set_usage(int usage)
Set console usage.
Definition: console.h:187
static unsigned int saved_usage
Definition: ansi_screen.c:13

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

◆ ansiscr_exit()

static void ansiscr_exit ( struct _curses_screen scr)
static

Definition at line 43 of file ansi_screen.c.

43  {
44  ansiscr_reset ( scr );
46 }
static void ansiscr_reset(struct _curses_screen *scr) __nonnull
Definition: ansi_screen.c:28
static int console_set_usage(int usage)
Set console usage.
Definition: console.h:187
static unsigned int saved_usage
Definition: ansi_screen.c:13

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

◆ ansiscr_erase()

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

Definition at line 48 of file ansi_screen.c.

48  {
49  ansiscr_attrs ( scr, attrs );
50  printf ( "\033[2J" );
51 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
uint32_t attrs
Extended attributes (optional)
Definition: memmap.c:32
static void ansiscr_attrs(struct _curses_screen *scr, attr_t attrs)
Definition: ansi_screen.c:15

References ansiscr_attrs(), attrs, and printf().

◆ ansiscr_getc()

static int ansiscr_getc ( struct _curses_screen *scr  __unused)
static

Definition at line 80 of file ansi_screen.c.

80  {
81  return getchar();
82 }
int getchar(void)
Read a single character from any console.
Definition: console.c:82

References getchar().

◆ ansiscr_peek()

static bool ansiscr_peek ( struct _curses_screen *scr  __unused)
static

Definition at line 84 of file ansi_screen.c.

84  {
85  return iskey();
86 }
int iskey(void)
Check for available input on any console.
Definition: console.c:127

References iskey().

◆ ansiscr_cursor()

static void ansiscr_cursor ( struct _curses_screen *scr  __unused,
int  visibility 
)
static

Definition at line 88 of file ansi_screen.c.

89  {
90  printf ( "\033[?25%c", ( visibility ? 'h' : 'l' ) );
91 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464

References printf().

Variable Documentation

◆ saved_usage

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().

◆ _ansi_screen

SCREEN _ansi_screen
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,
}
static void ansiscr_exit(struct _curses_screen *scr)
Definition: ansi_screen.c:43
static int ansiscr_getc(struct _curses_screen *scr __unused)
Definition: ansi_screen.c:80
static void ansiscr_cursor(struct _curses_screen *scr __unused, int visibility)
Definition: ansi_screen.c:88
static bool ansiscr_peek(struct _curses_screen *scr __unused)
Definition: ansi_screen.c:84
static void ansiscr_erase(struct _curses_screen *scr, attr_t attrs)
Definition: ansi_screen.c:48
static void ansiscr_movetoyx(struct _curses_screen *scr, unsigned int y, unsigned int x) __nonnull
Definition: ansi_screen.c:53
static void ansiscr_init(struct _curses_screen *scr)
Definition: ansi_screen.c:38
static void ansiscr_putc(struct _curses_screen *scr, chtype c) __nonnull
Definition: ansi_screen.c:63

Definition at line 93 of file ansi_screen.c.