summaryrefslogtreecommitdiffstats
path: root/debian/grub-extras/disabled/gpxe/src/include/gpxe/ansiesc.h
blob: 85f7a9f329eaba572c9de09bbba5f9b48aaf56bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef _GPXE_ANSIESC_H
#define _GPXE_ANSIESC_H

/** @file
 *
 * ANSI escape sequences
 *
 * ANSI X3.64 (aka ECMA-48 or ISO/IEC 6429, available from
 * http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf)
 * defines escape sequences consisting of:
 *
 *     A Control Sequence Introducer (CSI)
 *
 *     Zero or more Parameter Bytes (P)
 *
 *     Zero or more Intermediate Bytes (I)
 *
 *     A Final Byte (F)
 *
 * The CSI consists of ESC (0x1b) followed by "[" (0x5b).  The
 * Parameter Bytes, for a standardised (i.e. not private or
 * experimental) sequence, consist of a list of ASCII decimal integers
 * separated by semicolons.  The Intermediate Bytes (in the range 0x20
 * to 0x2f) and the Final Byte (in the range 0x40 to 0x4f) determine
 * the control function.
 * 
 */

FILE_LICENCE ( GPL2_OR_LATER );

/** A handler for an escape sequence */
struct ansiesc_handler {
	/** The control function identifier
	 *
	 * The control function identifier consists of the
	 * Intermediate Bytes (if any) and the Final Byte.  In
	 * practice, no more than one immediate byte is ever used, so
	 * the byte combination can be efficiently expressed as a
	 * single integer, in the obvious way (with the Final Byte
	 * being the least significant byte).
	 */
	unsigned int function;
	/** Handle escape sequence
	 *
	 * @v count		Parameter count
	 * @v params		Parameter list
	 *
	 * A negative parameter value indicates that the parameter was
	 * omitted and that the default value for this control
	 * function should be used.
	 *
	 * Since all parameters are optional, there is no way to
	 * distinguish between "zero parameters" and "single parameter
	 * omitted".  Consequently, the parameter list will always
	 * contain at least one item.
	 */
	void ( * handle ) ( unsigned int count, int params[] );
};

/** Maximum number of parameters within a single escape sequence */
#define ANSIESC_MAX_PARAMS 4

/**
 * ANSI escape sequence context
 *
 * This provides temporary storage for processing escape sequences,
 * and points to the list of escape sequence handlers.
 */
struct ansiesc_context {
	/** Array of handlers
	 *
	 * Must be terminated by a handler with @c function set to
	 * zero.
	 */
	struct ansiesc_handler *handlers;
	/** Parameter count
	 *
	 * Will be zero when not currently in an escape sequence.
	 */
	unsigned int count;
	/** Parameter list */ 
	int params[ANSIESC_MAX_PARAMS];
	/** Control function identifier */
	unsigned int function;
};

/** Escape character */
#define ESC 0x1b

/** Control Sequence Introducer */
#define CSI "\033["

/**
 * @defgroup ansifuncs ANSI escape sequence function identifiers
 * @{
 */

/** Cursor position */
#define ANSIESC_CUP 'H'

/** Erase in page */
#define ANSIESC_ED 'J'

/** Erase from cursor to end of page */
#define ANSIESC_ED_TO_END 0

/** Erase from start of page to cursor */
#define ANSIESC_ED_FROM_START 1

/** Erase whole page */
#define ANSIESC_ED_ALL 2

/** Select graphic rendition */
#define ANSIESC_SGR 'm'

/** @} */

extern int ansiesc_process ( struct ansiesc_context *ctx, int c );

#endif /* _GPXE_ANSIESC_H */