[contrib] Allow Network Protocol header to display in rom-o-matic
[gpxe.git] / src / include / gpxe / ansiesc.h
blob85f7a9f329eaba572c9de09bbba5f9b48aaf56bf
1 #ifndef _GPXE_ANSIESC_H
2 #define _GPXE_ANSIESC_H
4 /** @file
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)
18 * A Final Byte (F)
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 /** A handler for an escape sequence */
32 struct ansiesc_handler {
33 /** The control function identifier
35 * The control function identifier consists of the
36 * Intermediate Bytes (if any) and the Final Byte. In
37 * practice, no more than one immediate byte is ever used, so
38 * the byte combination can be efficiently expressed as a
39 * single integer, in the obvious way (with the Final Byte
40 * being the least significant byte).
42 unsigned int function;
43 /** Handle escape sequence
45 * @v count Parameter count
46 * @v params Parameter list
48 * A negative parameter value indicates that the parameter was
49 * omitted and that the default value for this control
50 * function should be used.
52 * Since all parameters are optional, there is no way to
53 * distinguish between "zero parameters" and "single parameter
54 * omitted". Consequently, the parameter list will always
55 * contain at least one item.
57 void ( * handle ) ( unsigned int count, int params[] );
60 /** Maximum number of parameters within a single escape sequence */
61 #define ANSIESC_MAX_PARAMS 4
63 /**
64 * ANSI escape sequence context
66 * This provides temporary storage for processing escape sequences,
67 * and points to the list of escape sequence handlers.
69 struct ansiesc_context {
70 /** Array of handlers
72 * Must be terminated by a handler with @c function set to
73 * zero.
75 struct ansiesc_handler *handlers;
76 /** Parameter count
78 * Will be zero when not currently in an escape sequence.
80 unsigned int count;
81 /** Parameter list */
82 int params[ANSIESC_MAX_PARAMS];
83 /** Control function identifier */
84 unsigned int function;
87 /** Escape character */
88 #define ESC 0x1b
90 /** Control Sequence Introducer */
91 #define CSI "\033["
93 /**
94 * @defgroup ansifuncs ANSI escape sequence function identifiers
95 * @{
98 /** Cursor position */
99 #define ANSIESC_CUP 'H'
101 /** Erase in page */
102 #define ANSIESC_ED 'J'
104 /** Erase from cursor to end of page */
105 #define ANSIESC_ED_TO_END 0
107 /** Erase from start of page to cursor */
108 #define ANSIESC_ED_FROM_START 1
110 /** Erase whole page */
111 #define ANSIESC_ED_ALL 2
113 /** Select graphic rendition */
114 #define ANSIESC_SGR 'm'
116 /** @} */
118 extern int ansiesc_process ( struct ansiesc_context *ctx, int c );
120 #endif /* _GPXE_ANSIESC_H */