Browse Source

[console] Pass escape sequence context to ANSI escape sequence handlers

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
02a63c6dec

+ 9
- 3
src/arch/i386/firmware/pcbios/bios_console.c View File

62
 /**
62
 /**
63
  * Handle ANSI CUP (cursor position)
63
  * Handle ANSI CUP (cursor position)
64
  *
64
  *
65
+ * @v ctx		ANSI escape sequence context
65
  * @v count		Parameter count
66
  * @v count		Parameter count
66
  * @v params[0]		Row (1 is top)
67
  * @v params[0]		Row (1 is top)
67
  * @v params[1]		Column (1 is left)
68
  * @v params[1]		Column (1 is left)
68
  */
69
  */
69
-static void bios_handle_cup ( unsigned int count __unused, int params[] ) {
70
+static void bios_handle_cup ( struct ansiesc_context *ctx __unused,
71
+			      unsigned int count __unused, int params[] ) {
70
 	int cx = ( params[1] - 1 );
72
 	int cx = ( params[1] - 1 );
71
 	int cy = ( params[0] - 1 );
73
 	int cy = ( params[0] - 1 );
72
 
74
 
85
 /**
87
 /**
86
  * Handle ANSI ED (erase in page)
88
  * Handle ANSI ED (erase in page)
87
  *
89
  *
90
+ * @v ctx		ANSI escape sequence context
88
  * @v count		Parameter count
91
  * @v count		Parameter count
89
  * @v params[0]		Region to erase
92
  * @v params[0]		Region to erase
90
  */
93
  */
91
-static void bios_handle_ed ( unsigned int count __unused,
94
+static void bios_handle_ed ( struct ansiesc_context *ctx __unused,
95
+			     unsigned int count __unused,
92
 			     int params[] __unused ) {
96
 			     int params[] __unused ) {
93
 	/* We assume that we always clear the whole screen */
97
 	/* We assume that we always clear the whole screen */
94
 	assert ( params[0] == ANSIESC_ED_ALL );
98
 	assert ( params[0] == ANSIESC_ED_ALL );
103
 /**
107
 /**
104
  * Handle ANSI SGR (set graphics rendition)
108
  * Handle ANSI SGR (set graphics rendition)
105
  *
109
  *
110
+ * @v ctx		ANSI escape sequence context
106
  * @v count		Parameter count
111
  * @v count		Parameter count
107
  * @v params		List of graphic rendition aspects
112
  * @v params		List of graphic rendition aspects
108
  */
113
  */
109
-static void bios_handle_sgr ( unsigned int count, int params[] ) {
114
+static void bios_handle_sgr ( struct ansiesc_context *ctx __unused,
115
+			      unsigned int count, int params[] ) {
110
 	static const uint8_t bios_attr_fcols[10] = {
116
 	static const uint8_t bios_attr_fcols[10] = {
111
 		ATTR_FCOL_BLACK, ATTR_FCOL_RED, ATTR_FCOL_GREEN,
117
 		ATTR_FCOL_BLACK, ATTR_FCOL_RED, ATTR_FCOL_GREEN,
112
 		ATTR_FCOL_YELLOW, ATTR_FCOL_BLUE, ATTR_FCOL_MAGENTA,
118
 		ATTR_FCOL_YELLOW, ATTR_FCOL_BLUE, ATTR_FCOL_MAGENTA,

+ 6
- 4
src/core/ansiesc.c View File

32
 /**
32
 /**
33
  * Call ANSI escape sequence handler
33
  * Call ANSI escape sequence handler
34
  *
34
  *
35
- * @v handlers		List of escape sequence handlers
35
+ * @v ctx		ANSI escape sequence context
36
  * @v function		Control function identifier
36
  * @v function		Control function identifier
37
  * @v count		Parameter count
37
  * @v count		Parameter count
38
  * @v params		Parameter list
38
  * @v params		Parameter list
39
  */
39
  */
40
-static void ansiesc_call_handler ( struct ansiesc_handler *handlers,
40
+static void ansiesc_call_handler ( struct ansiesc_context *ctx,
41
 				   unsigned int function, int count,
41
 				   unsigned int function, int count,
42
 				   int params[] ) {
42
 				   int params[] ) {
43
+	struct ansiesc_handler *handlers = ctx->handlers;
43
 	struct ansiesc_handler *handler;
44
 	struct ansiesc_handler *handler;
44
 
45
 
45
 	for ( handler = handlers ; handler->function ; handler++ ) {
46
 	for ( handler = handlers ; handler->function ; handler++ ) {
46
 		if ( handler->function == function ) {
47
 		if ( handler->function == function ) {
47
-			handler->handle ( count, params );
48
+			handler->handle ( ctx, count, params );
48
 			break;
49
 			break;
49
 		}
50
 		}
50
 	}
51
 	}
67
  * sequences we are prepared to accept as valid.
68
  * sequences we are prepared to accept as valid.
68
  */
69
  */
69
 int ansiesc_process ( struct ansiesc_context *ctx, int c ) {
70
 int ansiesc_process ( struct ansiesc_context *ctx, int c ) {
71
+
70
 	if ( ctx->count == 0 ) {
72
 	if ( ctx->count == 0 ) {
71
 		if ( c == ESC ) {
73
 		if ( c == ESC ) {
72
 			/* First byte of CSI : begin escape sequence */
74
 			/* First byte of CSI : begin escape sequence */
109
 			ctx->count = 0;
111
 			ctx->count = 0;
110
 			ctx->function <<= 8;
112
 			ctx->function <<= 8;
111
 			ctx->function |= c;
113
 			ctx->function |= c;
112
-			ansiesc_call_handler ( ctx->handlers, ctx->function,
114
+			ansiesc_call_handler ( ctx, ctx->function,
113
 					       count, ctx->params );
115
 					       count, ctx->params );
114
 		}
116
 		}
115
 		return -1;
117
 		return -1;

+ 5
- 1
src/include/ipxe/ansiesc.h View File

28
 
28
 
29
 FILE_LICENCE ( GPL2_OR_LATER );
29
 FILE_LICENCE ( GPL2_OR_LATER );
30
 
30
 
31
+struct ansiesc_context;
32
+
31
 /** A handler for an escape sequence */
33
 /** A handler for an escape sequence */
32
 struct ansiesc_handler {
34
 struct ansiesc_handler {
33
 	/** The control function identifier
35
 	/** The control function identifier
42
 	unsigned int function;
44
 	unsigned int function;
43
 	/** Handle escape sequence
45
 	/** Handle escape sequence
44
 	 *
46
 	 *
47
+	 * @v ctx		ANSI escape context
45
 	 * @v count		Parameter count
48
 	 * @v count		Parameter count
46
 	 * @v params		Parameter list
49
 	 * @v params		Parameter list
47
 	 *
50
 	 *
54
 	 * omitted".  Consequently, the parameter list will always
57
 	 * omitted".  Consequently, the parameter list will always
55
 	 * contain at least one item.
58
 	 * contain at least one item.
56
 	 */
59
 	 */
57
-	void ( * handle ) ( unsigned int count, int params[] );
60
+	void ( * handle ) ( struct ansiesc_context *ctx, unsigned int count,
61
+			    int params[] );
58
 };
62
 };
59
 
63
 
60
 /** Maximum number of parameters within a single escape sequence */
64
 /** Maximum number of parameters within a single escape sequence */

+ 10
- 4
src/interface/efi/efi_console.c View File

64
 /**
64
 /**
65
  * Handle ANSI CUP (cursor position)
65
  * Handle ANSI CUP (cursor position)
66
  *
66
  *
67
+ * @v ctx		ANSI escape sequence context
67
  * @v count		Parameter count
68
  * @v count		Parameter count
68
  * @v params[0]		Row (1 is top)
69
  * @v params[0]		Row (1 is top)
69
  * @v params[1]		Column (1 is left)
70
  * @v params[1]		Column (1 is left)
70
  */
71
  */
71
-static void efi_handle_cup ( unsigned int count __unused, int params[] ) {
72
+static void efi_handle_cup ( struct ansiesc_context *ctx __unused,
73
+			     unsigned int count __unused, int params[] ) {
72
 	EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
74
 	EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
73
 	int cx = ( params[1] - 1 );
75
 	int cx = ( params[1] - 1 );
74
 	int cy = ( params[0] - 1 );
76
 	int cy = ( params[0] - 1 );
84
 /**
86
 /**
85
  * Handle ANSI ED (erase in page)
87
  * Handle ANSI ED (erase in page)
86
  *
88
  *
89
+ * @v ctx		ANSI escape sequence context
87
  * @v count		Parameter count
90
  * @v count		Parameter count
88
  * @v params[0]		Region to erase
91
  * @v params[0]		Region to erase
89
  */
92
  */
90
-static void efi_handle_ed ( unsigned int count __unused,
91
-			     int params[] __unused ) {
93
+static void efi_handle_ed ( struct ansiesc_context *ctx __unused,
94
+			    unsigned int count __unused,
95
+			    int params[] __unused ) {
92
 	EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
96
 	EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
93
 
97
 
94
 	/* We assume that we always clear the whole screen */
98
 	/* We assume that we always clear the whole screen */
100
 /**
104
 /**
101
  * Handle ANSI SGR (set graphics rendition)
105
  * Handle ANSI SGR (set graphics rendition)
102
  *
106
  *
107
+ * @v ctx		ANSI escape sequence context
103
  * @v count		Parameter count
108
  * @v count		Parameter count
104
  * @v params		List of graphic rendition aspects
109
  * @v params		List of graphic rendition aspects
105
  */
110
  */
106
-static void efi_handle_sgr ( unsigned int count, int params[] ) {
111
+static void efi_handle_sgr ( struct ansiesc_context *ctx __unused,
112
+			     unsigned int count, int params[] ) {
107
 	EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
113
 	EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
108
 	static const uint8_t efi_attr_fcols[10] = {
114
 	static const uint8_t efi_attr_fcols[10] = {
109
 		ATTR_FCOL_BLACK, ATTR_FCOL_RED, ATTR_FCOL_GREEN,
115
 		ATTR_FCOL_BLACK, ATTR_FCOL_RED, ATTR_FCOL_GREEN,

+ 3
- 1
src/net/tcp/syslogs.c View File

113
 /**
113
 /**
114
  * Handle ANSI set encrypted syslog priority (private sequence)
114
  * Handle ANSI set encrypted syslog priority (private sequence)
115
  *
115
  *
116
+ * @v ctx		ANSI escape sequence context
116
  * @v count		Parameter count
117
  * @v count		Parameter count
117
  * @v params		List of graphic rendition aspects
118
  * @v params		List of graphic rendition aspects
118
  */
119
  */
119
-static void syslogs_handle_priority ( unsigned int count __unused,
120
+static void syslogs_handle_priority ( struct ansiesc_context *ctx __unused,
121
+				      unsigned int count __unused,
120
 				      int params[] ) {
122
 				      int params[] ) {
121
 	if ( params[0] >= 0 ) {
123
 	if ( params[0] >= 0 ) {
122
 		syslogs_severity = params[0];
124
 		syslogs_severity = params[0];

+ 3
- 1
src/net/udp/syslog.c View File

111
 /**
111
 /**
112
  * Handle ANSI set syslog priority (private sequence)
112
  * Handle ANSI set syslog priority (private sequence)
113
  *
113
  *
114
+ * @v ctx		ANSI escape sequence context
114
  * @v count		Parameter count
115
  * @v count		Parameter count
115
  * @v params		List of graphic rendition aspects
116
  * @v params		List of graphic rendition aspects
116
  */
117
  */
117
-static void syslog_handle_priority ( unsigned int count __unused,
118
+static void syslog_handle_priority ( struct ansiesc_context *ctx __unused,
119
+				     unsigned int count __unused,
118
 				     int params[] ) {
120
 				     int params[] ) {
119
 	if ( params[0] >= 0 ) {
121
 	if ( params[0] >= 0 ) {
120
 		syslog_severity = params[0];
122
 		syslog_severity = params[0];

Loading…
Cancel
Save