Browse Source

[console] Add a timeout parameter to getkey()

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

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

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

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

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

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

47
 	printf ( "\nPress Ctrl-B for the iPXE command line..." );
47
 	printf ( "\nPress Ctrl-B for the iPXE command line..." );
48
 
48
 
49
 	/* Wait for key */
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
 	/* Clear the "Press Ctrl-B" line */
52
 	/* Clear the "Press Ctrl-B" line */
53
 	printf ( "\r                                         \r" );
53
 	printf ( "\r                                         \r" );

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

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

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

401
 		draw_setting ( &widget );
401
 		draw_setting ( &widget );
402
 		color_set ( CPAIR_NORMAL, NULL );
402
 		color_set ( CPAIR_NORMAL, NULL );
403
 
403
 
404
-		key = getkey();
404
+		key = getkey ( 0 );
405
 		if ( widget.editing ) {
405
 		if ( widget.editing ) {
406
 			key = edit_setting ( &widget, key );
406
 			key = edit_setting ( &widget, key );
407
 			switch ( key ) {
407
 			switch ( key ) {

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

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

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

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

Loading…
Cancel
Save