mirror of
https://github.com/ipxe/ipxe
synced 2026-02-14 02:31:26 +03:00
[mucurses] Use "<ESC>[2J" ANSI escape sequence to clear screen
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -14,12 +14,26 @@ unsigned short _LINES = 24;
|
|||||||
|
|
||||||
static unsigned int saved_usage;
|
static unsigned int saved_usage;
|
||||||
|
|
||||||
|
static void ansiscr_attrs ( struct _curses_screen *scr, attr_t attrs ) {
|
||||||
|
int bold = ( attrs & A_BOLD );
|
||||||
|
attr_t cpair = PAIR_NUMBER ( attrs );
|
||||||
|
short fcol;
|
||||||
|
short bcol;
|
||||||
|
|
||||||
|
if ( scr->attrs != attrs ) {
|
||||||
|
scr->attrs = attrs;
|
||||||
|
pair_content ( cpair, &fcol, &bcol );
|
||||||
|
/* ANSI escape sequence to update character attributes */
|
||||||
|
printf ( "\033[0;%d;3%d;4%dm", ( bold ? 1 : 22 ), fcol, bcol );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void ansiscr_reset ( struct _curses_screen *scr ) {
|
static void ansiscr_reset ( struct _curses_screen *scr ) {
|
||||||
/* Reset terminal attributes and clear screen */
|
/* Reset terminal attributes and clear screen */
|
||||||
scr->attrs = 0;
|
scr->attrs = 0;
|
||||||
scr->curs_x = 0;
|
scr->curs_x = 0;
|
||||||
scr->curs_y = 0;
|
scr->curs_y = 0;
|
||||||
printf ( "\033[0m" );
|
printf ( "\033[0m\033[2J" );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ansiscr_init ( struct _curses_screen *scr ) {
|
static void ansiscr_init ( struct _curses_screen *scr ) {
|
||||||
@@ -32,6 +46,11 @@ static void ansiscr_exit ( struct _curses_screen *scr ) {
|
|||||||
console_set_usage ( saved_usage );
|
console_set_usage ( saved_usage );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ansiscr_erase ( struct _curses_screen *scr, attr_t attrs ) {
|
||||||
|
ansiscr_attrs ( scr, attrs );
|
||||||
|
printf ( "\033[2J" );
|
||||||
|
}
|
||||||
|
|
||||||
static void ansiscr_movetoyx ( struct _curses_screen *scr,
|
static void ansiscr_movetoyx ( struct _curses_screen *scr,
|
||||||
unsigned int y, unsigned int x ) {
|
unsigned int y, unsigned int x ) {
|
||||||
if ( ( x != scr->curs_x ) || ( y != scr->curs_y ) ) {
|
if ( ( x != scr->curs_x ) || ( y != scr->curs_y ) ) {
|
||||||
@@ -45,18 +64,9 @@ static void ansiscr_movetoyx ( struct _curses_screen *scr,
|
|||||||
static void ansiscr_putc ( struct _curses_screen *scr, chtype c ) {
|
static void ansiscr_putc ( struct _curses_screen *scr, chtype c ) {
|
||||||
unsigned int character = ( c & A_CHARTEXT );
|
unsigned int character = ( c & A_CHARTEXT );
|
||||||
attr_t attrs = ( c & ( A_ATTRIBUTES | A_COLOR ) );
|
attr_t attrs = ( c & ( A_ATTRIBUTES | A_COLOR ) );
|
||||||
int bold = ( attrs & A_BOLD );
|
|
||||||
attr_t cpair = PAIR_NUMBER ( attrs );
|
|
||||||
short fcol;
|
|
||||||
short bcol;
|
|
||||||
|
|
||||||
/* Update attributes if changed */
|
/* Update attributes if changed */
|
||||||
if ( attrs != scr->attrs ) {
|
ansiscr_attrs ( scr, attrs );
|
||||||
scr->attrs = attrs;
|
|
||||||
pair_content ( cpair, &fcol, &bcol );
|
|
||||||
/* ANSI escape sequence to update character attributes */
|
|
||||||
printf ( "\033[0;%d;3%d;4%dm", ( bold ? 1 : 22 ), fcol, bcol );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Print the actual character */
|
/* Print the actual character */
|
||||||
putchar ( character );
|
putchar ( character );
|
||||||
@@ -79,6 +89,7 @@ static bool ansiscr_peek ( struct _curses_screen *scr __unused ) {
|
|||||||
SCREEN _ansi_screen = {
|
SCREEN _ansi_screen = {
|
||||||
.init = ansiscr_init,
|
.init = ansiscr_init,
|
||||||
.exit = ansiscr_exit,
|
.exit = ansiscr_exit,
|
||||||
|
.erase = ansiscr_erase,
|
||||||
.movetoyx = ansiscr_movetoyx,
|
.movetoyx = ansiscr_movetoyx,
|
||||||
.putc = ansiscr_putc,
|
.putc = ansiscr_putc,
|
||||||
.getc = ansiscr_getc,
|
.getc = ansiscr_getc,
|
||||||
|
|||||||
@@ -88,3 +88,13 @@ int werase ( WINDOW *win ) {
|
|||||||
wclrtobot( win );
|
wclrtobot( win );
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Completely clear the screen
|
||||||
|
*
|
||||||
|
* @ret rc return status code
|
||||||
|
*/
|
||||||
|
int erase ( void ) {
|
||||||
|
stdscr->scr->erase( stdscr->scr, stdscr->attrs );
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|||||||
@@ -37,6 +37,13 @@ typedef struct _curses_screen {
|
|||||||
|
|
||||||
void ( *init ) ( struct _curses_screen *scr );
|
void ( *init ) ( struct _curses_screen *scr );
|
||||||
void ( *exit ) ( struct _curses_screen *scr );
|
void ( *exit ) ( struct _curses_screen *scr );
|
||||||
|
/**
|
||||||
|
* Erase screen
|
||||||
|
*
|
||||||
|
* @v scr screen on which to operate
|
||||||
|
* @v attrs attributes
|
||||||
|
*/
|
||||||
|
void ( * erase ) ( struct _curses_screen *scr, attr_t attrs );
|
||||||
/**
|
/**
|
||||||
* Move cursor to position specified by x,y coords
|
* Move cursor to position specified by x,y coords
|
||||||
*
|
*
|
||||||
@@ -242,7 +249,7 @@ extern int echo ( void );
|
|||||||
extern int echochar ( const chtype );
|
extern int echochar ( const chtype );
|
||||||
extern int endwin ( void );
|
extern int endwin ( void );
|
||||||
extern char erasechar ( void );
|
extern char erasechar ( void );
|
||||||
//extern int erase ( void );
|
extern int erase ( void );
|
||||||
extern void filter ( void );
|
extern void filter ( void );
|
||||||
extern int flash ( void );
|
extern int flash ( void );
|
||||||
extern int flushinp ( void );
|
extern int flushinp ( void );
|
||||||
@@ -552,10 +559,6 @@ static inline int deleteln ( void ) {
|
|||||||
return wdeleteln( stdscr );
|
return wdeleteln( stdscr );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int erase ( void ) {
|
|
||||||
return werase ( stdscr );
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int getch ( void ) {
|
static inline int getch ( void ) {
|
||||||
return wgetch ( stdscr );
|
return wgetch ( stdscr );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user