Go to the source code of this file.
Data Structures | |
| struct | ansiesc_handler |
| A handler for an escape sequence. More... | |
| struct | ansiesc_context |
| ANSI escape sequence context. More... | |
Defines | |
| #define | ANSIESC_MAX_PARAMS 4 |
| Maximum number of parameters within a single escape sequence. | |
| #define | ESC 0x1b |
| Escape character. | |
| #define | CSI "\033[" |
| Control Sequence Introducer. | |
| #define | ANSIESC_CUP 'H' |
| Cursor position. | |
| #define | ANSIESC_ED 'J' |
| Erase in page. | |
| #define | ANSIESC_ED_TO_END 0 |
| Erase from cursor to end of page. | |
| #define | ANSIESC_ED_FROM_START 1 |
| Erase from start of page to cursor. | |
| #define | ANSIESC_ED_ALL 2 |
| Erase whole page. | |
| #define | ANSIESC_SGR 'm' |
| Select graphic rendition. | |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| int | ansiesc_process (struct ansiesc_context *ctx, int c) |
| Process character that may be part of ANSI escape sequence. | |
ANSI X3.64 (aka ECMA-48 or ISO/IEC 6429, available from http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf) defines escape sequences consisting of:
A Control Sequence Introducer (CSI)
Zero or more Parameter Bytes (P)
Zero or more Intermediate Bytes (I)
A Final Byte (F)
The CSI consists of ESC (0x1b) followed by "[" (0x5b). The Parameter Bytes, for a standardised (i.e. not private or experimental) sequence, consist of a list of ASCII decimal integers separated by semicolons. The Intermediate Bytes (in the range 0x20 to 0x2f) and the Final Byte (in the range 0x40 to 0x4f) determine the control function.
Definition in file ansiesc.h.
| #define ANSIESC_MAX_PARAMS 4 |
| #define ESC 0x1b |
Escape character.
Definition at line 88 of file ansiesc.h.
Referenced by ansiesc_process(), getkey(), login_ui(), pxe_menu_prompt_and_select(), and pxe_menu_select().
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| int ansiesc_process | ( | struct ansiesc_context * | ctx, | |
| int | c | |||
| ) |
Process character that may be part of ANSI escape sequence.
| ctx | ANSI escape sequence context | |
| c | Character |
| c | Original character if not part of escape sequence | |
| <0 | Character was part of escape sequence |
In the interests of code size, we are rather liberal about the sequences we are prepared to accept as valid.
Definition at line 68 of file ansiesc.c.
References ansiesc_call_handler(), ansiesc_context::count, DBG, ESC, ansiesc_context::function, ansiesc_context::handlers, memset(), and ansiesc_context::params.
Referenced by bios_putchar(), and efi_putchar().
00068 { 00069 if ( ctx->count == 0 ) { 00070 if ( c == ESC ) { 00071 /* First byte of CSI : begin escape sequence */ 00072 ctx->count = 1; 00073 memset ( ctx->params, 0xff, sizeof ( ctx->params ) ); 00074 ctx->function = 0; 00075 return -1; 00076 } else { 00077 /* Normal character */ 00078 return c; 00079 } 00080 } else { 00081 if ( c == '[' ) { 00082 /* Second byte of CSI : do nothing */ 00083 } else if ( ( c >= '0' ) && ( c <= '9' ) ) { 00084 /* Parameter Byte : part of a parameter value */ 00085 int *param = &ctx->params[ctx->count - 1]; 00086 if ( *param < 0 ) 00087 *param = 0; 00088 *param = ( ( *param * 10 ) + ( c - '0' ) ); 00089 } else if ( c == ';' ) { 00090 /* Parameter Byte : parameter delimiter */ 00091 ctx->count++; 00092 if ( ctx->count > ( sizeof ( ctx->params ) / 00093 sizeof ( ctx->params[0] ) ) ) { 00094 /* Excessive parameters : abort sequence */ 00095 ctx->count = 0; 00096 DBG ( "Too many parameters in ANSI escape " 00097 "sequence\n" ); 00098 } 00099 } else if ( ( c >= 0x20 ) && ( c <= 0x2f ) ) { 00100 /* Intermediate Byte */ 00101 ctx->function <<= 8; 00102 ctx->function |= c; 00103 } else { 00104 /* Treat as Final Byte. Zero ctx->count before 00105 * calling handler to avoid potential infinite loops. 00106 */ 00107 int count = ctx->count; 00108 ctx->count = 0; 00109 ctx->function <<= 8; 00110 ctx->function |= c; 00111 ansiesc_call_handler ( ctx->handlers, ctx->function, 00112 count, ctx->params ); 00113 } 00114 return -1; 00115 } 00116 }
1.5.7.1