Skip to content

Commit

Permalink
[console] Pass escape sequence context to ANSI escape sequence handlers
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Nov 27, 2013
1 parent 3102866 commit 02a63c6
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 14 deletions.
12 changes: 9 additions & 3 deletions src/arch/i386/firmware/pcbios/bios_console.c
Expand Up @@ -62,11 +62,13 @@ static unsigned int bios_attr = ATTR_DEFAULT;
/**
* Handle ANSI CUP (cursor position)
*
* @v ctx ANSI escape sequence context
* @v count Parameter count
* @v params[0] Row (1 is top)
* @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 cy = ( params[0] - 1 );

Expand All @@ -85,10 +87,12 @@ static void bios_handle_cup ( unsigned int count __unused, int params[] ) {
/**
* Handle ANSI ED (erase in page)
*
* @v ctx ANSI escape sequence context
* @v count Parameter count
* @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 ) {
/* We assume that we always clear the whole screen */
assert ( params[0] == ANSIESC_ED_ALL );
Expand All @@ -103,10 +107,12 @@ static void bios_handle_ed ( unsigned int count __unused,
/**
* Handle ANSI SGR (set graphics rendition)
*
* @v ctx ANSI escape sequence context
* @v count Parameter count
* @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] = {
ATTR_FCOL_BLACK, ATTR_FCOL_RED, ATTR_FCOL_GREEN,
ATTR_FCOL_YELLOW, ATTR_FCOL_BLUE, ATTR_FCOL_MAGENTA,
Expand Down
10 changes: 6 additions & 4 deletions src/core/ansiesc.c
Expand Up @@ -32,19 +32,20 @@ FILE_LICENCE ( GPL2_OR_LATER );
/**
* Call ANSI escape sequence handler
*
* @v handlers List of escape sequence handlers
* @v ctx ANSI escape sequence context
* @v function Control function identifier
* @v count Parameter count
* @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,
int params[] ) {
struct ansiesc_handler *handlers = ctx->handlers;
struct ansiesc_handler *handler;

for ( handler = handlers ; handler->function ; handler++ ) {
if ( handler->function == function ) {
handler->handle ( count, params );
handler->handle ( ctx, count, params );
break;
}
}
Expand All @@ -67,6 +68,7 @@ static void ansiesc_call_handler ( struct ansiesc_handler *handlers,
* sequences we are prepared to accept as valid.
*/
int ansiesc_process ( struct ansiesc_context *ctx, int c ) {

if ( ctx->count == 0 ) {
if ( c == ESC ) {
/* First byte of CSI : begin escape sequence */
Expand Down Expand Up @@ -109,7 +111,7 @@ int ansiesc_process ( struct ansiesc_context *ctx, int c ) {
ctx->count = 0;
ctx->function <<= 8;
ctx->function |= c;
ansiesc_call_handler ( ctx->handlers, ctx->function,
ansiesc_call_handler ( ctx, ctx->function,
count, ctx->params );
}
return -1;
Expand Down
6 changes: 5 additions & 1 deletion src/include/ipxe/ansiesc.h
Expand Up @@ -28,6 +28,8 @@

FILE_LICENCE ( GPL2_OR_LATER );

struct ansiesc_context;

/** A handler for an escape sequence */
struct ansiesc_handler {
/** The control function identifier
Expand All @@ -42,6 +44,7 @@ struct ansiesc_handler {
unsigned int function;
/** Handle escape sequence
*
* @v ctx ANSI escape context
* @v count Parameter count
* @v params Parameter list
*
Expand All @@ -54,7 +57,8 @@ struct ansiesc_handler {
* omitted". Consequently, the parameter list will always
* 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 */
Expand Down
14 changes: 10 additions & 4 deletions src/interface/efi/efi_console.c
Expand Up @@ -64,11 +64,13 @@ static unsigned int efi_attr = ATTR_DEFAULT;
/**
* Handle ANSI CUP (cursor position)
*
* @v ctx ANSI escape sequence context
* @v count Parameter count
* @v params[0] Row (1 is top)
* @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;
int cx = ( params[1] - 1 );
int cy = ( params[0] - 1 );
Expand All @@ -84,11 +86,13 @@ static void efi_handle_cup ( unsigned int count __unused, int params[] ) {
/**
* Handle ANSI ED (erase in page)
*
* @v ctx ANSI escape sequence context
* @v count Parameter count
* @v params[0] Region to erase
*/
static void efi_handle_ed ( unsigned int count __unused,
int params[] __unused ) {
static void efi_handle_ed ( struct ansiesc_context *ctx __unused,
unsigned int count __unused,
int params[] __unused ) {
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;

/* We assume that we always clear the whole screen */
Expand All @@ -100,10 +104,12 @@ static void efi_handle_ed ( unsigned int count __unused,
/**
* Handle ANSI SGR (set graphics rendition)
*
* @v ctx ANSI escape sequence context
* @v count Parameter count
* @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;
static const uint8_t efi_attr_fcols[10] = {
ATTR_FCOL_BLACK, ATTR_FCOL_RED, ATTR_FCOL_GREEN,
Expand Down
4 changes: 3 additions & 1 deletion src/net/tcp/syslogs.c
Expand Up @@ -113,10 +113,12 @@ static unsigned int syslogs_severity = SYSLOG_DEFAULT_SEVERITY;
/**
* Handle ANSI set encrypted syslog priority (private sequence)
*
* @v ctx ANSI escape sequence context
* @v count Parameter count
* @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[] ) {
if ( params[0] >= 0 ) {
syslogs_severity = params[0];
Expand Down
4 changes: 3 additions & 1 deletion src/net/udp/syslog.c
Expand Up @@ -111,10 +111,12 @@ static unsigned int syslog_severity = SYSLOG_DEFAULT_SEVERITY;
/**
* Handle ANSI set syslog priority (private sequence)
*
* @v ctx ANSI escape sequence context
* @v count Parameter count
* @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[] ) {
if ( params[0] >= 0 ) {
syslog_severity = params[0];
Expand Down

0 comments on commit 02a63c6

Please sign in to comment.