Browse Source

[console] Add a timeout parameter to getkey()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
9d633bdc71

+ 6
- 5
src/core/getkey.c View File

@@ -35,13 +35,13 @@ FILE_LICENCE ( GPL2_OR_LATER );
35 35
 /**
36 36
  * Read character from console if available within timeout period
37 37
  *
38
- * @v timeout		Timeout period, in ticks
38
+ * @v timeout		Timeout period, in ticks (0=indefinite)
39 39
  * @ret character	Character read from console
40 40
  */
41
-int getchar_timeout ( unsigned long timeout ) {
41
+static int getchar_timeout ( unsigned long timeout ) {
42 42
 	unsigned long start = currticks();
43 43
 
44
-	while ( ( currticks() - start ) < timeout ) {
44
+	while ( ( timeout == 0 ) || ( ( currticks() - start ) < timeout ) ) {
45 45
 		step();
46 46
 		if ( iskey() )
47 47
 			return getchar();
@@ -53,6 +53,7 @@ int getchar_timeout ( unsigned long timeout ) {
53 53
 /**
54 54
  * Get single keypress
55 55
  *
56
+ * @v timeout		Timeout period, in ticks (0=indefinite)
56 57
  * @ret key		Key pressed
57 58
  *
58 59
  * The returned key will be an ASCII value or a KEY_XXX special
@@ -60,11 +61,11 @@ int getchar_timeout ( unsigned long timeout ) {
60 61
  * will return "special" keys (e.g. cursor keys) as a series of
61 62
  * characters forming an ANSI escape sequence.
62 63
  */
63
-int getkey ( void ) {
64
+int getkey ( unsigned long timeout ) {
64 65
 	int character;
65 66
 	unsigned int n = 0;
66 67
 
67
-	character = getchar();
68
+	character = getchar_timeout ( timeout );
68 69
 	if ( character != ESC )
69 70
 		return character;
70 71
 

+ 1
- 1
src/hci/readline.c View File

@@ -98,7 +98,7 @@ char * readline ( const char *prompt ) {
98 98
 	buf[0] = '\0';
99 99
 
100 100
 	while ( 1 ) {
101
-		key = edit_string ( &string, getkey() );
101
+		key = edit_string ( &string, getkey ( 0 ) );
102 102
 		sync_console ( &string );
103 103
 		switch ( key ) {
104 104
 		case CR:

+ 1
- 1
src/hci/shell_banner.c View File

@@ -47,7 +47,7 @@ int shell_banner ( void ) {
47 47
 	printf ( "\nPress Ctrl-B for the iPXE command line..." );
48 48
 
49 49
 	/* Wait for key */
50
-	key = getchar_timeout ( ( BANNER_TIMEOUT * TICKS_PER_SEC ) / 10 );
50
+	key = getkey ( ( BANNER_TIMEOUT * TICKS_PER_SEC ) / 10 );
51 51
 
52 52
 	/* Clear the "Press Ctrl-B" line */
53 53
 	printf ( "\r                                         \r" );

+ 1
- 1
src/hci/tui/login_ui.c View File

@@ -88,7 +88,7 @@ int login_ui ( void ) {
88 88
 
89 89
 		draw_editbox ( current_box );
90 90
 
91
-		key = getkey();
91
+		key = getkey ( 0 );
92 92
 		switch ( key ) {
93 93
 		case KEY_DOWN:
94 94
 			current_box = &password_box;

+ 1
- 1
src/hci/tui/settings_ui.c View File

@@ -401,7 +401,7 @@ static int main_loop ( struct settings *settings ) {
401 401
 		draw_setting ( &widget );
402 402
 		color_set ( CPAIR_NORMAL, NULL );
403 403
 
404
-		key = getkey();
404
+		key = getkey ( 0 );
405 405
 		if ( widget.editing ) {
406 406
 			key = edit_setting ( &widget, key );
407 407
 			switch ( key ) {

+ 1
- 2
src/include/console.h View File

@@ -102,8 +102,7 @@ struct console_driver {
102 102
 
103 103
 extern void putchar ( int character );
104 104
 extern int getchar ( void );
105
-extern int getchar_timeout ( unsigned long timeout );
106 105
 extern int iskey ( void );
107
-extern int getkey ( void );
106
+extern int getkey ( unsigned long timeout );
108 107
 
109 108
 #endif /* CONSOLE_H */

+ 2
- 5
src/usr/pxemenu.c View File

@@ -30,7 +30,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
30 30
 #include <ipxe/dhcp.h>
31 31
 #include <ipxe/keys.h>
32 32
 #include <ipxe/timer.h>
33
-#include <ipxe/process.h>
34 33
 #include <ipxe/uri.h>
35 34
 #include <usr/dhcpmgmt.h>
36 35
 #include <usr/autoboot.h>
@@ -239,9 +238,7 @@ static int pxe_menu_select ( struct pxe_menu *menu ) {
239 238
 		pxe_menu_draw_item ( menu, menu->selection, 1 );
240 239
 
241 240
 		/* Wait for keyboard input */
242
-		while ( ! iskey() )
243
-			step();
244
-		key = getkey();
241
+		key = getkey ( 0 );
245 242
 
246 243
 		/* Unhighlight currently selected item */
247 244
 		pxe_menu_draw_item ( menu, menu->selection, 0 );
@@ -304,7 +301,7 @@ static int pxe_menu_prompt_and_select ( struct pxe_menu *menu ) {
304 301
 		if ( ! len )
305 302
 			len = printf ( " (%d)", menu->timeout );
306 303
 		if ( iskey() ) {
307
-			key = getkey();
304
+			key = getkey ( 0 );
308 305
 			if ( key == KEY_F8 ) {
309 306
 				/* Display menu */
310 307
 				printf ( "\n" );

Loading…
Cancel
Save