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 11 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
 /** Current console usage */
10
 /** Current console usage */
11
 int console_usage = CONSOLE_USAGE_STDOUT;
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
  * Write a single character to each console device
20
  * Write a single character to each console device
15
  *
21
  *
138
 	struct console_driver *console;
144
 	struct console_driver *console;
139
 	int rc;
145
 	int rc;
140
 
146
 
147
+	/* Reset console width and height */
148
+	console_set_size ( CONSOLE_DEFAULT_WIDTH, CONSOLE_DEFAULT_HEIGHT );
149
+
141
 	/* Try to configure each console */
150
 	/* Try to configure each console */
142
 	for_each_table_entry ( console, CONSOLES ) {
151
 	for_each_table_entry ( console, CONSOLES ) {
143
 		if ( ( console->configure ) &&
152
 		if ( ( console->configure ) &&

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

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

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

3
 
3
 
4
 #include <stdint.h>
4
 #include <stdint.h>
5
 #include <stdarg.h>
5
 #include <stdarg.h>
6
+#include <ipxe/console.h>
6
 
7
 
7
 /** @file
8
 /** @file
8
  *
9
  *
105
 } WINDOW;
106
 } WINDOW;
106
 
107
 
107
 extern WINDOW _stdscr;
108
 extern WINDOW _stdscr;
108
-extern unsigned short _COLS;
109
-extern unsigned short _LINES;
110
 
109
 
111
 #define stdscr ( &_stdscr )
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
 #define MUCURSES_BITS( mask, shift ) (( mask ) << (shift))
114
 #define MUCURSES_BITS( mask, shift ) (( mask ) << (shift))
116
 #define CPAIR_SHIFT	8
115
 #define CPAIR_SHIFT	8

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

159
  */
159
  */
160
 #define CONSOLE_EXPLICIT( console ) ( ( 2 * console + 1 ) != 2 )
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
 extern int console_usage;
168
 extern int console_usage;
169
+extern unsigned int console_width;
170
+extern unsigned int console_height;
163
 
171
 
164
 /**
172
 /**
165
  * Set console usage
173
  * Set console usage
175
 	return old_usage;
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
 extern int iskey ( void );
198
 extern int iskey ( void );
179
 extern int getkey ( unsigned long timeout );
199
 extern int getkey ( unsigned long timeout );
180
 extern int console_configure ( struct console_configuration *config );
200
 extern int console_configure ( struct console_configuration *config );

Loading…
Cancel
Save