iPXE
ansiesc.h
Go to the documentation of this file.
1 #ifndef _IPXE_ANSIESC_H
2 #define _IPXE_ANSIESC_H
3 
4 /** @file
5  *
6  * ANSI escape sequences
7  *
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:
11  *
12  * A Control Sequence Introducer (CSI)
13  *
14  * Zero or more Parameter Bytes (P)
15  *
16  * Zero or more Intermediate Bytes (I)
17  *
18  * A Final Byte (F)
19  *
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.
26  *
27  */
28 
29 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
30 FILE_SECBOOT ( PERMITTED );
31 
32 struct ansiesc_context;
33 
34 /** A handler for an escape sequence */
36  /** The control function identifier
37  *
38  * The control function identifier consists of the
39  * Intermediate Bytes (if any) and the Final Byte. In
40  * practice, no more than one immediate byte is ever used, so
41  * the byte combination can be efficiently expressed as a
42  * single integer, in the obvious way (with the Final Byte
43  * being the least significant byte).
44  */
45  unsigned int function;
46  /** Handle escape sequence
47  *
48  * @v ctx ANSI escape context
49  * @v count Parameter count
50  * @v params Parameter list
51  *
52  * A negative parameter value indicates that the parameter was
53  * omitted and that the default value for this control
54  * function should be used.
55  *
56  * Since all parameters are optional, there is no way to
57  * distinguish between "zero parameters" and "single parameter
58  * omitted". Consequently, the parameter list will always
59  * contain at least one item.
60  */
61  void ( * handle ) ( struct ansiesc_context *ctx, unsigned int count,
62  int params[] );
63 };
64 
65 /** Maximum number of parameters within a single escape sequence */
66 #define ANSIESC_MAX_PARAMS 5
67 
68 /**
69  * ANSI escape sequence context
70  *
71  * This provides temporary storage for processing escape sequences,
72  * and points to the list of escape sequence handlers.
73  */
75  /** Array of handlers
76  *
77  * Must be terminated by a handler with @c function set to
78  * zero.
79  */
81  /** Parameter count
82  *
83  * Will be zero when not currently in an escape sequence.
84  */
85  unsigned int count;
86  /** Parameter list */
88  /** Control function identifier */
89  unsigned int function;
90 };
91 
92 /** Escape character */
93 #define ESC 0x1b
94 
95 /** Control Sequence Introducer */
96 #define CSI "\033["
97 
98 /**
99  * @defgroup ansifuncs ANSI escape sequence function identifiers
100  * @{
101  */
102 
103 /** Cursor position */
104 #define ANSIESC_CUP 'H'
105 
106 /** Erase in page */
107 #define ANSIESC_ED 'J'
108 
109 /** Erase from cursor to end of page */
110 #define ANSIESC_ED_TO_END 0
111 
112 /** Erase from start of page to cursor */
113 #define ANSIESC_ED_FROM_START 1
114 
115 /** Erase whole page */
116 #define ANSIESC_ED_ALL 2
117 
118 /** Select graphic rendition */
119 #define ANSIESC_SGR 'm'
120 
121 /** Explicit log message priority
122  *
123  * This is an iPXE private sequence identifier. (The range 'p' to '~'
124  * is reserved for private sequences.)
125  */
126 #define ANSIESC_LOG_PRIORITY 'p'
127 
128 /** Show cursor */
129 #define ANSIESC_DECTCEM_SET ( ( '?' << 8 ) | 'h' )
130 
131 /** Hide cursor */
132 #define ANSIESC_DECTCEM_RESET ( ( '?' << 8 ) | 'l' )
133 
134 /** @} */
135 
136 extern int ansiesc_process ( struct ansiesc_context *ctx, int c );
137 
138 #endif /* _IPXE_ANSIESC_H */
#define ANSIESC_MAX_PARAMS
Maximum number of parameters within a single escape sequence.
Definition: ansiesc.h:66
A handler for an escape sequence.
Definition: ansiesc.h:35
struct ansiesc_handler * handlers
Array of handlers.
Definition: ansiesc.h:80
int params[ANSIESC_MAX_PARAMS]
Parameter list.
Definition: ansiesc.h:87
void(* handle)(struct ansiesc_context *ctx, unsigned int count, int params[])
Handle escape sequence.
Definition: ansiesc.h:61
unsigned int count
Parameter count.
Definition: ansiesc.h:85
ANSI escape sequence context.
Definition: ansiesc.h:74
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
int ansiesc_process(struct ansiesc_context *ctx, int c)
Process character that may be part of ANSI escape sequence.
Definition: ansiesc.c:75
static unsigned int count
Number of entries.
Definition: dwmac.h:225
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
FILE_SECBOOT(PERMITTED)