Browse Source

[console] Allow consoles to update the recorded console size

Provide a mechanism for consoles to update the recorded console width
and height, and use this width and height to provide the curses COLS
and LINES variables.

We choose not to use ANSI escape sequences to obtain the width and
height, for two reasons:

- iPXE's model is that all output is sent to all consoles; we could
  therefore end up with multiple consoles reporting conflicting widths
  and heights

- when a serial console is in use, we probably don't want to resize
  the output shown on the BIOS console to match the size of the serial
  console, since it's likely that the serial console is in use only
  for debugging.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 years ago
parent
commit
03401f9d21
4 changed files with 33 additions and 8 deletions
  1. 9
    0
      src/core/console.c
  2. 1
    4
      src/hci/mucurses/ansi_screen.c
  3. 3
    4
      src/include/curses.h
  4. 20
    0
      src/include/ipxe/console.h

+ 9
- 0
src/core/console.c View File

@@ -10,6 +10,12 @@ FILE_LICENCE ( GPL2_OR_LATER );
10 10
 /** Current console usage */
11 11
 int console_usage = CONSOLE_USAGE_STDOUT;
12 12
 
13
+/** Console width */
14
+unsigned int console_width = CONSOLE_DEFAULT_WIDTH;
15
+
16
+/** Console height */
17
+unsigned int console_height = CONSOLE_DEFAULT_HEIGHT;
18
+
13 19
 /**
14 20
  * Write a single character to each console device
15 21
  *
@@ -138,6 +144,9 @@ int console_configure ( struct console_configuration *config ) {
138 144
 	struct console_driver *console;
139 145
 	int rc;
140 146
 
147
+	/* Reset console width and height */
148
+	console_set_size ( CONSOLE_DEFAULT_WIDTH, CONSOLE_DEFAULT_HEIGHT );
149
+
141 150
 	/* Try to configure each console */
142 151
 	for_each_table_entry ( console, CONSOLES ) {
143 152
 		if ( ( console->configure ) &&

+ 1
- 4
src/hci/mucurses/ansi_screen.c View File

@@ -9,9 +9,6 @@ static void ansiscr_movetoyx(struct _curses_screen *scr,
9 9
                                unsigned int y, unsigned int x) __nonnull;
10 10
 static void ansiscr_putc(struct _curses_screen *scr, chtype c) __nonnull;
11 11
 
12
-unsigned short _COLS = 80;
13
-unsigned short _LINES = 24;
14
-
15 12
 static unsigned int saved_usage;
16 13
 
17 14
 static void ansiscr_attrs ( struct _curses_screen *scr, attr_t attrs ) {
@@ -72,7 +69,7 @@ static void ansiscr_putc ( struct _curses_screen *scr, chtype c ) {
72 69
 	putchar ( character );
73 70
 
74 71
 	/* Update expected cursor position */
75
-	if ( ++(scr->curs_x) == _COLS ) {
72
+	if ( ++(scr->curs_x) == COLS ) {
76 73
 		scr->curs_x = 0;
77 74
 		++scr->curs_y;
78 75
 	}

+ 3
- 4
src/include/curses.h View File

@@ -3,6 +3,7 @@
3 3
 
4 4
 #include <stdint.h>
5 5
 #include <stdarg.h>
6
+#include <ipxe/console.h>
6 7
 
7 8
 /** @file
8 9
  *
@@ -105,12 +106,10 @@ typedef struct _curses_window {
105 106
 } WINDOW;
106 107
 
107 108
 extern WINDOW _stdscr;
108
-extern unsigned short _COLS;
109
-extern unsigned short _LINES;
110 109
 
111 110
 #define stdscr ( &_stdscr )
112
-#define COLS _COLS
113
-#define LINES _LINES
111
+#define COLS console_width
112
+#define LINES console_height
114 113
 
115 114
 #define MUCURSES_BITS( mask, shift ) (( mask ) << (shift))
116 115
 #define CPAIR_SHIFT	8

+ 20
- 0
src/include/ipxe/console.h View File

@@ -159,7 +159,15 @@ struct console_driver {
159 159
  */
160 160
 #define CONSOLE_EXPLICIT( console ) ( ( 2 * console + 1 ) != 2 )
161 161
 
162
+/** Default console width */
163
+#define CONSOLE_DEFAULT_WIDTH 80
164
+
165
+/** Default console height */
166
+#define CONSOLE_DEFAULT_HEIGHT 25
167
+
162 168
 extern int console_usage;
169
+extern unsigned int console_width;
170
+extern unsigned int console_height;
163 171
 
164 172
 /**
165 173
  * Set console usage
@@ -175,6 +183,18 @@ console_set_usage ( int usage ) {
175 183
 	return old_usage;
176 184
 }
177 185
 
186
+/**
187
+ * Set console size
188
+ *
189
+ * @v width		Width, in characters
190
+ * @v height		Height, in characters
191
+ */
192
+static inline __attribute__ (( always_inline )) void
193
+console_set_size ( unsigned int width, unsigned int height ) {
194
+	console_width = width;
195
+	console_height = height;
196
+}
197
+
178 198
 extern int iskey ( void );
179 199
 extern int getkey ( unsigned long timeout );
180 200
 extern int console_configure ( struct console_configuration *config );

Loading…
Cancel
Save