mirror of https://github.com/ipxe/ipxe.git
[console] Pass escape sequence context to ANSI escape sequence handlers
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/17/head
parent
3102866a7f
commit
02a63c6dec
|
@ -62,11 +62,13 @@ static unsigned int bios_attr = ATTR_DEFAULT;
|
||||||
/**
|
/**
|
||||||
* Handle ANSI CUP (cursor position)
|
* Handle ANSI CUP (cursor position)
|
||||||
*
|
*
|
||||||
|
* @v ctx ANSI escape sequence context
|
||||||
* @v count Parameter count
|
* @v count Parameter count
|
||||||
* @v params[0] Row (1 is top)
|
* @v params[0] Row (1 is top)
|
||||||
* @v params[1] Column (1 is left)
|
* @v params[1] Column (1 is left)
|
||||||
*/
|
*/
|
||||||
static void bios_handle_cup ( unsigned int count __unused, int params[] ) {
|
static void bios_handle_cup ( struct ansiesc_context *ctx __unused,
|
||||||
|
unsigned int count __unused, int params[] ) {
|
||||||
int cx = ( params[1] - 1 );
|
int cx = ( params[1] - 1 );
|
||||||
int cy = ( params[0] - 1 );
|
int cy = ( params[0] - 1 );
|
||||||
|
|
||||||
|
@ -85,10 +87,12 @@ static void bios_handle_cup ( unsigned int count __unused, int params[] ) {
|
||||||
/**
|
/**
|
||||||
* Handle ANSI ED (erase in page)
|
* Handle ANSI ED (erase in page)
|
||||||
*
|
*
|
||||||
|
* @v ctx ANSI escape sequence context
|
||||||
* @v count Parameter count
|
* @v count Parameter count
|
||||||
* @v params[0] Region to erase
|
* @v params[0] Region to erase
|
||||||
*/
|
*/
|
||||||
static void bios_handle_ed ( unsigned int count __unused,
|
static void bios_handle_ed ( struct ansiesc_context *ctx __unused,
|
||||||
|
unsigned int count __unused,
|
||||||
int params[] __unused ) {
|
int params[] __unused ) {
|
||||||
/* We assume that we always clear the whole screen */
|
/* We assume that we always clear the whole screen */
|
||||||
assert ( params[0] == ANSIESC_ED_ALL );
|
assert ( params[0] == ANSIESC_ED_ALL );
|
||||||
|
@ -103,10 +107,12 @@ static void bios_handle_ed ( unsigned int count __unused,
|
||||||
/**
|
/**
|
||||||
* Handle ANSI SGR (set graphics rendition)
|
* Handle ANSI SGR (set graphics rendition)
|
||||||
*
|
*
|
||||||
|
* @v ctx ANSI escape sequence context
|
||||||
* @v count Parameter count
|
* @v count Parameter count
|
||||||
* @v params List of graphic rendition aspects
|
* @v params List of graphic rendition aspects
|
||||||
*/
|
*/
|
||||||
static void bios_handle_sgr ( unsigned int count, int params[] ) {
|
static void bios_handle_sgr ( struct ansiesc_context *ctx __unused,
|
||||||
|
unsigned int count, int params[] ) {
|
||||||
static const uint8_t bios_attr_fcols[10] = {
|
static const uint8_t bios_attr_fcols[10] = {
|
||||||
ATTR_FCOL_BLACK, ATTR_FCOL_RED, ATTR_FCOL_GREEN,
|
ATTR_FCOL_BLACK, ATTR_FCOL_RED, ATTR_FCOL_GREEN,
|
||||||
ATTR_FCOL_YELLOW, ATTR_FCOL_BLUE, ATTR_FCOL_MAGENTA,
|
ATTR_FCOL_YELLOW, ATTR_FCOL_BLUE, ATTR_FCOL_MAGENTA,
|
||||||
|
|
|
@ -32,19 +32,20 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
/**
|
/**
|
||||||
* Call ANSI escape sequence handler
|
* Call ANSI escape sequence handler
|
||||||
*
|
*
|
||||||
* @v handlers List of escape sequence handlers
|
* @v ctx ANSI escape sequence context
|
||||||
* @v function Control function identifier
|
* @v function Control function identifier
|
||||||
* @v count Parameter count
|
* @v count Parameter count
|
||||||
* @v params Parameter list
|
* @v params Parameter list
|
||||||
*/
|
*/
|
||||||
static void ansiesc_call_handler ( struct ansiesc_handler *handlers,
|
static void ansiesc_call_handler ( struct ansiesc_context *ctx,
|
||||||
unsigned int function, int count,
|
unsigned int function, int count,
|
||||||
int params[] ) {
|
int params[] ) {
|
||||||
|
struct ansiesc_handler *handlers = ctx->handlers;
|
||||||
struct ansiesc_handler *handler;
|
struct ansiesc_handler *handler;
|
||||||
|
|
||||||
for ( handler = handlers ; handler->function ; handler++ ) {
|
for ( handler = handlers ; handler->function ; handler++ ) {
|
||||||
if ( handler->function == function ) {
|
if ( handler->function == function ) {
|
||||||
handler->handle ( count, params );
|
handler->handle ( ctx, count, params );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,6 +68,7 @@ static void ansiesc_call_handler ( struct ansiesc_handler *handlers,
|
||||||
* sequences we are prepared to accept as valid.
|
* sequences we are prepared to accept as valid.
|
||||||
*/
|
*/
|
||||||
int ansiesc_process ( struct ansiesc_context *ctx, int c ) {
|
int ansiesc_process ( struct ansiesc_context *ctx, int c ) {
|
||||||
|
|
||||||
if ( ctx->count == 0 ) {
|
if ( ctx->count == 0 ) {
|
||||||
if ( c == ESC ) {
|
if ( c == ESC ) {
|
||||||
/* First byte of CSI : begin escape sequence */
|
/* First byte of CSI : begin escape sequence */
|
||||||
|
@ -109,7 +111,7 @@ int ansiesc_process ( struct ansiesc_context *ctx, int c ) {
|
||||||
ctx->count = 0;
|
ctx->count = 0;
|
||||||
ctx->function <<= 8;
|
ctx->function <<= 8;
|
||||||
ctx->function |= c;
|
ctx->function |= c;
|
||||||
ansiesc_call_handler ( ctx->handlers, ctx->function,
|
ansiesc_call_handler ( ctx, ctx->function,
|
||||||
count, ctx->params );
|
count, ctx->params );
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
|
|
||||||
FILE_LICENCE ( GPL2_OR_LATER );
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
|
struct ansiesc_context;
|
||||||
|
|
||||||
/** A handler for an escape sequence */
|
/** A handler for an escape sequence */
|
||||||
struct ansiesc_handler {
|
struct ansiesc_handler {
|
||||||
/** The control function identifier
|
/** The control function identifier
|
||||||
|
@ -42,6 +44,7 @@ struct ansiesc_handler {
|
||||||
unsigned int function;
|
unsigned int function;
|
||||||
/** Handle escape sequence
|
/** Handle escape sequence
|
||||||
*
|
*
|
||||||
|
* @v ctx ANSI escape context
|
||||||
* @v count Parameter count
|
* @v count Parameter count
|
||||||
* @v params Parameter list
|
* @v params Parameter list
|
||||||
*
|
*
|
||||||
|
@ -54,7 +57,8 @@ struct ansiesc_handler {
|
||||||
* omitted". Consequently, the parameter list will always
|
* omitted". Consequently, the parameter list will always
|
||||||
* contain at least one item.
|
* contain at least one item.
|
||||||
*/
|
*/
|
||||||
void ( * handle ) ( unsigned int count, int params[] );
|
void ( * handle ) ( struct ansiesc_context *ctx, unsigned int count,
|
||||||
|
int params[] );
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Maximum number of parameters within a single escape sequence */
|
/** Maximum number of parameters within a single escape sequence */
|
||||||
|
|
|
@ -64,11 +64,13 @@ static unsigned int efi_attr = ATTR_DEFAULT;
|
||||||
/**
|
/**
|
||||||
* Handle ANSI CUP (cursor position)
|
* Handle ANSI CUP (cursor position)
|
||||||
*
|
*
|
||||||
|
* @v ctx ANSI escape sequence context
|
||||||
* @v count Parameter count
|
* @v count Parameter count
|
||||||
* @v params[0] Row (1 is top)
|
* @v params[0] Row (1 is top)
|
||||||
* @v params[1] Column (1 is left)
|
* @v params[1] Column (1 is left)
|
||||||
*/
|
*/
|
||||||
static void efi_handle_cup ( unsigned int count __unused, int params[] ) {
|
static void efi_handle_cup ( struct ansiesc_context *ctx __unused,
|
||||||
|
unsigned int count __unused, int params[] ) {
|
||||||
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
|
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
|
||||||
int cx = ( params[1] - 1 );
|
int cx = ( params[1] - 1 );
|
||||||
int cy = ( params[0] - 1 );
|
int cy = ( params[0] - 1 );
|
||||||
|
@ -84,10 +86,12 @@ static void efi_handle_cup ( unsigned int count __unused, int params[] ) {
|
||||||
/**
|
/**
|
||||||
* Handle ANSI ED (erase in page)
|
* Handle ANSI ED (erase in page)
|
||||||
*
|
*
|
||||||
|
* @v ctx ANSI escape sequence context
|
||||||
* @v count Parameter count
|
* @v count Parameter count
|
||||||
* @v params[0] Region to erase
|
* @v params[0] Region to erase
|
||||||
*/
|
*/
|
||||||
static void efi_handle_ed ( unsigned int count __unused,
|
static void efi_handle_ed ( struct ansiesc_context *ctx __unused,
|
||||||
|
unsigned int count __unused,
|
||||||
int params[] __unused ) {
|
int params[] __unused ) {
|
||||||
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
|
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
|
||||||
|
|
||||||
|
@ -100,10 +104,12 @@ static void efi_handle_ed ( unsigned int count __unused,
|
||||||
/**
|
/**
|
||||||
* Handle ANSI SGR (set graphics rendition)
|
* Handle ANSI SGR (set graphics rendition)
|
||||||
*
|
*
|
||||||
|
* @v ctx ANSI escape sequence context
|
||||||
* @v count Parameter count
|
* @v count Parameter count
|
||||||
* @v params List of graphic rendition aspects
|
* @v params List of graphic rendition aspects
|
||||||
*/
|
*/
|
||||||
static void efi_handle_sgr ( unsigned int count, int params[] ) {
|
static void efi_handle_sgr ( struct ansiesc_context *ctx __unused,
|
||||||
|
unsigned int count, int params[] ) {
|
||||||
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
|
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
|
||||||
static const uint8_t efi_attr_fcols[10] = {
|
static const uint8_t efi_attr_fcols[10] = {
|
||||||
ATTR_FCOL_BLACK, ATTR_FCOL_RED, ATTR_FCOL_GREEN,
|
ATTR_FCOL_BLACK, ATTR_FCOL_RED, ATTR_FCOL_GREEN,
|
||||||
|
|
|
@ -113,10 +113,12 @@ static unsigned int syslogs_severity = SYSLOG_DEFAULT_SEVERITY;
|
||||||
/**
|
/**
|
||||||
* Handle ANSI set encrypted syslog priority (private sequence)
|
* Handle ANSI set encrypted syslog priority (private sequence)
|
||||||
*
|
*
|
||||||
|
* @v ctx ANSI escape sequence context
|
||||||
* @v count Parameter count
|
* @v count Parameter count
|
||||||
* @v params List of graphic rendition aspects
|
* @v params List of graphic rendition aspects
|
||||||
*/
|
*/
|
||||||
static void syslogs_handle_priority ( unsigned int count __unused,
|
static void syslogs_handle_priority ( struct ansiesc_context *ctx __unused,
|
||||||
|
unsigned int count __unused,
|
||||||
int params[] ) {
|
int params[] ) {
|
||||||
if ( params[0] >= 0 ) {
|
if ( params[0] >= 0 ) {
|
||||||
syslogs_severity = params[0];
|
syslogs_severity = params[0];
|
||||||
|
|
|
@ -111,10 +111,12 @@ static unsigned int syslog_severity = SYSLOG_DEFAULT_SEVERITY;
|
||||||
/**
|
/**
|
||||||
* Handle ANSI set syslog priority (private sequence)
|
* Handle ANSI set syslog priority (private sequence)
|
||||||
*
|
*
|
||||||
|
* @v ctx ANSI escape sequence context
|
||||||
* @v count Parameter count
|
* @v count Parameter count
|
||||||
* @v params List of graphic rendition aspects
|
* @v params List of graphic rendition aspects
|
||||||
*/
|
*/
|
||||||
static void syslog_handle_priority ( unsigned int count __unused,
|
static void syslog_handle_priority ( struct ansiesc_context *ctx __unused,
|
||||||
|
unsigned int count __unused,
|
||||||
int params[] ) {
|
int params[] ) {
|
||||||
if ( params[0] >= 0 ) {
|
if ( params[0] >= 0 ) {
|
||||||
syslog_severity = params[0];
|
syslog_severity = params[0];
|
||||||
|
|
Loading…
Reference in New Issue