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 
31 struct ansiesc_context;
32 
33 /** A handler for an escape sequence */
35  /** The control function identifier
36  *
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).
43  */
44  unsigned int function;
45  /** Handle escape sequence
46  *
47  * @v ctx ANSI escape context
48  * @v count Parameter count
49  * @v params Parameter list
50  *
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.
54  *
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.
59  */
60  void ( * handle ) ( struct ansiesc_context *ctx, unsigned int count,
61  int params[] );
62 };
63 
64 /** Maximum number of parameters within a single escape sequence */
65 #define ANSIESC_MAX_PARAMS 5
66 
67 /**
68  * ANSI escape sequence context
69  *
70  * This provides temporary storage for processing escape sequences,
71  * and points to the list of escape sequence handlers.
72  */
74  /** Array of handlers
75  *
76  * Must be terminated by a handler with @c function set to
77  * zero.
78  */
80  /** Parameter count
81  *
82  * Will be zero when not currently in an escape sequence.
83  */
84  unsigned int count;
85  /** Parameter list */
87  /** Control function identifier */
88  unsigned int function;
89 };
90 
91 /** Escape character */
92 #define ESC 0x1b
93 
94 /** Control Sequence Introducer */
95 #define CSI "\033["
96 
97 /**
98  * @defgroup ansifuncs ANSI escape sequence function identifiers
99  * @{
100  */
101 
102 /** Cursor position */
103 #define ANSIESC_CUP 'H'
104 
105 /** Erase in page */
106 #define ANSIESC_ED 'J'
107 
108 /** Erase from cursor to end of page */
109 #define ANSIESC_ED_TO_END 0
110 
111 /** Erase from start of page to cursor */
112 #define ANSIESC_ED_FROM_START 1
113 
114 /** Erase whole page */
115 #define ANSIESC_ED_ALL 2
116 
117 /** Select graphic rendition */
118 #define ANSIESC_SGR 'm'
119 
120 /** Explicit log message priority
121  *
122  * This is an iPXE private sequence identifier. (The range 'p' to '~'
123  * is reserved for private sequences.)
124  */
125 #define ANSIESC_LOG_PRIORITY 'p'
126 
127 /** Show cursor */
128 #define ANSIESC_DECTCEM_SET ( ( '?' << 8 ) | 'h' )
129 
130 /** Hide cursor */
131 #define ANSIESC_DECTCEM_RESET ( ( '?' << 8 ) | 'l' )
132 
133 /** @} */
134 
135 extern int ansiesc_process ( struct ansiesc_context *ctx, int c );
136 
137 #endif /* _IPXE_ANSIESC_H */
#define ANSIESC_MAX_PARAMS
Maximum number of parameters within a single escape sequence.
Definition: ansiesc.h:65
A handler for an escape sequence.
Definition: ansiesc.h:34
struct ansiesc_handler * handlers
Array of handlers.
Definition: ansiesc.h:79
int params[ANSIESC_MAX_PARAMS]
Parameter list.
Definition: ansiesc.h:86
void(* handle)(struct ansiesc_context *ctx, unsigned int count, int params[])
Handle escape sequence.
Definition: ansiesc.h:60
unsigned int count
Parameter count.
Definition: ansiesc.h:84
ANSI escape sequence context.
Definition: ansiesc.h:73
static __always_inline void off_t int c
Definition: efi_uaccess.h:87
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:74
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
uint16_t count
Number of entries.
Definition: ena.h:22