00001 #ifndef _GPXE_ANSIESC_H 00002 #define _GPXE_ANSIESC_H 00003 00004 /** @file 00005 * 00006 * ANSI escape sequences 00007 * 00008 * ANSI X3.64 (aka ECMA-48 or ISO/IEC 6429, available from 00009 * http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf) 00010 * defines escape sequences consisting of: 00011 * 00012 * A Control Sequence Introducer (CSI) 00013 * 00014 * Zero or more Parameter Bytes (P) 00015 * 00016 * Zero or more Intermediate Bytes (I) 00017 * 00018 * A Final Byte (F) 00019 * 00020 * The CSI consists of ESC (0x1b) followed by "[" (0x5b). The 00021 * Parameter Bytes, for a standardised (i.e. not private or 00022 * experimental) sequence, consist of a list of ASCII decimal integers 00023 * separated by semicolons. The Intermediate Bytes (in the range 0x20 00024 * to 0x2f) and the Final Byte (in the range 0x40 to 0x4f) determine 00025 * the control function. 00026 * 00027 */ 00028 00029 FILE_LICENCE ( GPL2_OR_LATER ); 00030 00031 /** A handler for an escape sequence */ 00032 struct ansiesc_handler { 00033 /** The control function identifier 00034 * 00035 * The control function identifier consists of the 00036 * Intermediate Bytes (if any) and the Final Byte. In 00037 * practice, no more than one immediate byte is ever used, so 00038 * the byte combination can be efficiently expressed as a 00039 * single integer, in the obvious way (with the Final Byte 00040 * being the least significant byte). 00041 */ 00042 unsigned int function; 00043 /** Handle escape sequence 00044 * 00045 * @v count Parameter count 00046 * @v params Parameter list 00047 * 00048 * A negative parameter value indicates that the parameter was 00049 * omitted and that the default value for this control 00050 * function should be used. 00051 * 00052 * Since all parameters are optional, there is no way to 00053 * distinguish between "zero parameters" and "single parameter 00054 * omitted". Consequently, the parameter list will always 00055 * contain at least one item. 00056 */ 00057 void ( * handle ) ( unsigned int count, int params[] ); 00058 }; 00059 00060 /** Maximum number of parameters within a single escape sequence */ 00061 #define ANSIESC_MAX_PARAMS 4 00062 00063 /** 00064 * ANSI escape sequence context 00065 * 00066 * This provides temporary storage for processing escape sequences, 00067 * and points to the list of escape sequence handlers. 00068 */ 00069 struct ansiesc_context { 00070 /** Array of handlers 00071 * 00072 * Must be terminated by a handler with @c function set to 00073 * zero. 00074 */ 00075 struct ansiesc_handler *handlers; 00076 /** Parameter count 00077 * 00078 * Will be zero when not currently in an escape sequence. 00079 */ 00080 unsigned int count; 00081 /** Parameter list */ 00082 int params[ANSIESC_MAX_PARAMS]; 00083 /** Control function identifier */ 00084 unsigned int function; 00085 }; 00086 00087 /** Escape character */ 00088 #define ESC 0x1b 00089 00090 /** Control Sequence Introducer */ 00091 #define CSI "\033[" 00092 00093 /** 00094 * @defgroup ansifuncs ANSI escape sequence function identifiers 00095 * @{ 00096 */ 00097 00098 /** Cursor position */ 00099 #define ANSIESC_CUP 'H' 00100 00101 /** Erase in page */ 00102 #define ANSIESC_ED 'J' 00103 00104 /** Erase from cursor to end of page */ 00105 #define ANSIESC_ED_TO_END 0 00106 00107 /** Erase from start of page to cursor */ 00108 #define ANSIESC_ED_FROM_START 1 00109 00110 /** Erase whole page */ 00111 #define ANSIESC_ED_ALL 2 00112 00113 /** Select graphic rendition */ 00114 #define ANSIESC_SGR 'm' 00115 00116 /** @} */ 00117 00118 extern int ansiesc_process ( struct ansiesc_context *ctx, int c ); 00119 00120 #endif /* _GPXE_ANSIESC_H */
1.5.7.1