summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brown2011-03-07 20:33:50 +0100
committerMichael Brown2011-03-07 20:37:30 +0100
commit9d633bdc7113f0050a0b35df5245dee2b819a273 (patch)
tree637c56a790d95598026387b05ed086dbc606470c /src
parent[console] Avoid timer wraparound problems in getchar_timeout() (diff)
downloadipxe-9d633bdc7113f0050a0b35df5245dee2b819a273.tar.gz
ipxe-9d633bdc7113f0050a0b35df5245dee2b819a273.tar.xz
ipxe-9d633bdc7113f0050a0b35df5245dee2b819a273.zip
[console] Add a timeout parameter to getkey()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src')
-rw-r--r--src/core/getkey.c11
-rw-r--r--src/hci/readline.c2
-rw-r--r--src/hci/shell_banner.c2
-rw-r--r--src/hci/tui/login_ui.c2
-rw-r--r--src/hci/tui/settings_ui.c2
-rw-r--r--src/include/console.h3
-rw-r--r--src/usr/pxemenu.c7
7 files changed, 13 insertions, 16 deletions
diff --git a/src/core/getkey.c b/src/core/getkey.c
index 5710f190..b8e6af78 100644
--- a/src/core/getkey.c
+++ b/src/core/getkey.c
@@ -35,13 +35,13 @@ FILE_LICENCE ( GPL2_OR_LATER );
/**
* Read character from console if available within timeout period
*
- * @v timeout Timeout period, in ticks
+ * @v timeout Timeout period, in ticks (0=indefinite)
* @ret character Character read from console
*/
-int getchar_timeout ( unsigned long timeout ) {
+static int getchar_timeout ( unsigned long timeout ) {
unsigned long start = currticks();
- while ( ( currticks() - start ) < timeout ) {
+ while ( ( timeout == 0 ) || ( ( currticks() - start ) < timeout ) ) {
step();
if ( iskey() )
return getchar();
@@ -53,6 +53,7 @@ int getchar_timeout ( unsigned long timeout ) {
/**
* Get single keypress
*
+ * @v timeout Timeout period, in ticks (0=indefinite)
* @ret key Key pressed
*
* The returned key will be an ASCII value or a KEY_XXX special
@@ -60,11 +61,11 @@ int getchar_timeout ( unsigned long timeout ) {
* will return "special" keys (e.g. cursor keys) as a series of
* characters forming an ANSI escape sequence.
*/
-int getkey ( void ) {
+int getkey ( unsigned long timeout ) {
int character;
unsigned int n = 0;
- character = getchar();
+ character = getchar_timeout ( timeout );
if ( character != ESC )
return character;
diff --git a/src/hci/readline.c b/src/hci/readline.c
index ee252a19..6a7af9db 100644
--- a/src/hci/readline.c
+++ b/src/hci/readline.c
@@ -98,7 +98,7 @@ char * readline ( const char *prompt ) {
buf[0] = '\0';
while ( 1 ) {
- key = edit_string ( &string, getkey() );
+ key = edit_string ( &string, getkey ( 0 ) );
sync_console ( &string );
switch ( key ) {
case CR:
diff --git a/src/hci/shell_banner.c b/src/hci/shell_banner.c
index dbfa8edf..6f225d78 100644
--- a/src/hci/shell_banner.c
+++ b/src/hci/shell_banner.c
@@ -47,7 +47,7 @@ int shell_banner ( void ) {
printf ( "\nPress Ctrl-B for the iPXE command line..." );
/* Wait for key */
- key = getchar_timeout ( ( BANNER_TIMEOUT * TICKS_PER_SEC ) / 10 );
+ key = getkey ( ( BANNER_TIMEOUT * TICKS_PER_SEC ) / 10 );
/* Clear the "Press Ctrl-B" line */
printf ( "\r \r" );
diff --git a/src/hci/tui/login_ui.c b/src/hci/tui/login_ui.c
index bcfd09cb..954bde50 100644
--- a/src/hci/tui/login_ui.c
+++ b/src/hci/tui/login_ui.c
@@ -88,7 +88,7 @@ int login_ui ( void ) {
draw_editbox ( current_box );
- key = getkey();
+ key = getkey ( 0 );
switch ( key ) {
case KEY_DOWN:
current_box = &password_box;
diff --git a/src/hci/tui/settings_ui.c b/src/hci/tui/settings_ui.c
index b8fe207f..176fbd3e 100644
--- a/src/hci/tui/settings_ui.c
+++ b/src/hci/tui/settings_ui.c
@@ -401,7 +401,7 @@ static int main_loop ( struct settings *settings ) {
draw_setting ( &widget );
color_set ( CPAIR_NORMAL, NULL );
- key = getkey();
+ key = getkey ( 0 );
if ( widget.editing ) {
key = edit_setting ( &widget, key );
switch ( key ) {
diff --git a/src/include/console.h b/src/include/console.h
index 271b4f36..df9e8092 100644
--- a/src/include/console.h
+++ b/src/include/console.h
@@ -102,8 +102,7 @@ struct console_driver {
extern void putchar ( int character );
extern int getchar ( void );
-extern int getchar_timeout ( unsigned long timeout );
extern int iskey ( void );
-extern int getkey ( void );
+extern int getkey ( unsigned long timeout );
#endif /* CONSOLE_H */
diff --git a/src/usr/pxemenu.c b/src/usr/pxemenu.c
index a9ea1f04..b3105162 100644
--- a/src/usr/pxemenu.c
+++ b/src/usr/pxemenu.c
@@ -30,7 +30,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/dhcp.h>
#include <ipxe/keys.h>
#include <ipxe/timer.h>
-#include <ipxe/process.h>
#include <ipxe/uri.h>
#include <usr/dhcpmgmt.h>
#include <usr/autoboot.h>
@@ -239,9 +238,7 @@ static int pxe_menu_select ( struct pxe_menu *menu ) {
pxe_menu_draw_item ( menu, menu->selection, 1 );
/* Wait for keyboard input */
- while ( ! iskey() )
- step();
- key = getkey();
+ key = getkey ( 0 );
/* Unhighlight currently selected item */
pxe_menu_draw_item ( menu, menu->selection, 0 );
@@ -304,7 +301,7 @@ static int pxe_menu_prompt_and_select ( struct pxe_menu *menu ) {
if ( ! len )
len = printf ( " (%d)", menu->timeout );
if ( iskey() ) {
- key = getkey();
+ key = getkey ( 0 );
if ( key == KEY_F8 ) {
/* Display menu */
printf ( "\n" );