1 #ifndef _IPXE_ANSIESC_H
2 #define _IPXE_ANSIESC_H
6 * ANSI escape sequences
8 * ANSI X3.64 (aka ECMA-48 or ISO/IEC 6429, available from
9 * http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf)
10 * defines escape sequences consisting of:
12 * A Control Sequence Introducer (CSI)
14 * Zero or more Parameter Bytes (P)
16 * Zero or more Intermediate Bytes (I)
20 * The CSI consists of ESC (0x1b) followed by "[" (0x5b). The
21 * Parameter Bytes, for a standardised (i.e. not private or
22 * experimental) sequence, consist of a list of ASCII decimal integers
23 * separated by semicolons. The Intermediate Bytes (in the range 0x20
24 * to 0x2f) and the Final Byte (in the range 0x40 to 0x4f) determine
25 * the control function.
29 FILE_LICENCE ( GPL2_OR_LATER );
31 struct ansiesc_context;
33 /** A handler for an escape sequence */
34 struct ansiesc_handler {
35 /** The control function identifier
37 * The control function identifier consists of the
38 * Intermediate Bytes (if any) and the Final Byte. In
39 * practice, no more than one immediate byte is ever used, so
40 * the byte combination can be efficiently expressed as a
41 * single integer, in the obvious way (with the Final Byte
42 * being the least significant byte).
44 unsigned int function;
45 /** Handle escape sequence
47 * @v ctx ANSI escape context
48 * @v count Parameter count
49 * @v params Parameter list
51 * A negative parameter value indicates that the parameter was
52 * omitted and that the default value for this control
53 * function should be used.
55 * Since all parameters are optional, there is no way to
56 * distinguish between "zero parameters" and "single parameter
57 * omitted". Consequently, the parameter list will always
58 * contain at least one item.
60 void ( * handle ) ( struct ansiesc_context *ctx, unsigned int count,
64 /** Maximum number of parameters within a single escape sequence */
65 #define ANSIESC_MAX_PARAMS 5
68 * ANSI escape sequence context
70 * This provides temporary storage for processing escape sequences,
71 * and points to the list of escape sequence handlers.
73 struct ansiesc_context {
76 * Must be terminated by a handler with @c function set to
79 struct ansiesc_handler *handlers;
82 * Will be zero when not currently in an escape sequence.
86 int params[ANSIESC_MAX_PARAMS];
87 /** Control function identifier */
88 unsigned int function;
91 /** Escape character */
94 /** Control Sequence Introducer */
98 * @defgroup ansifuncs ANSI escape sequence function identifiers
102 /** Cursor position */
103 #define ANSIESC_CUP 'H'
106 #define ANSIESC_ED 'J'
108 /** Erase from cursor to end of page */
109 #define ANSIESC_ED_TO_END 0
111 /** Erase from start of page to cursor */
112 #define ANSIESC_ED_FROM_START 1
114 /** Erase whole page */
115 #define ANSIESC_ED_ALL 2
117 /** Select graphic rendition */
118 #define ANSIESC_SGR 'm'
120 /** Explicit log message priority
122 * This is an iPXE private sequence identifier. (The range 'p' to '~'
123 * is reserved for private sequences.)
125 #define ANSIESC_LOG_PRIORITY 'p'
128 #define ANSIESC_DECTCEM_SET ( ( '?' << 8 ) | 'h' )
131 #define ANSIESC_DECTCEM_RESET ( ( '?' << 8 ) | 'l' )
135 extern int ansiesc_process ( struct ansiesc_context *ctx, int c );
137 #endif /* _IPXE_ANSIESC_H */