]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[console] Add a timeout parameter to getkey()
authorMichael Brown <mcb30@ipxe.org>
Mon, 7 Mar 2011 19:33:50 +0000 (19:33 +0000)
committerMichael Brown <mcb30@ipxe.org>
Mon, 7 Mar 2011 19:37:30 +0000 (19:37 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/getkey.c
src/hci/readline.c
src/hci/shell_banner.c
src/hci/tui/login_ui.c
src/hci/tui/settings_ui.c
src/include/console.h
src/usr/pxemenu.c

index 5710f190002dfd99f4d7d3fc9eb80fd183f6104b..b8e6af78606ea17478c92754ed2d92e61beefa98 100644 (file)
@@ -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;
 
index ee252a199266d67fe0cf21296679d55be10ddd03..6a7af9db6ffd9c81d2e044aa98fe09c7cacc4bc0 100644 (file)
@@ -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:
index dbfa8edfeb1e49ba095614f0b767dc70e840a74c..6f225d789e52a0dd2c631f8d66bfe5ddb28dfbd4 100644 (file)
@@ -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" );
index bcfd09cb6d014f38bb564747381f34e24d8e2025..954bde50934d958e8897ed71fd304f277bc1dfeb 100644 (file)
@@ -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;
index b8fe207fb992614006340bcca28b145367a46227..176fbd3ed3f8e30b60d9abb9b1215fe4cb8aab13 100644 (file)
@@ -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 ) {
index 271b4f365519bb97f30b696277b2821fa8342cfe..df9e8092f63c2180f909d1c721c997b6bd7429f8 100644 (file)
@@ -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 */
index a9ea1f044c015cdefe5b35dcc7272b8cfd88a0ff..b310516294e1beb3368814c3b9bc6e0559801b8a 100644 (file)
@@ -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" );