diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/main.c | 18 | ||||
-rw-r--r-- | src/include/ipxe/errfile.h | 1 | ||||
-rw-r--r-- | src/include/ipxe/shell_banner.h | 14 | ||||
-rw-r--r-- | src/include/usr/prompt.h | 14 | ||||
-rw-r--r-- | src/usr/prompt.c (renamed from src/hci/shell_banner.c) | 54 |
5 files changed, 64 insertions, 37 deletions
diff --git a/src/core/main.c b/src/core/main.c index e2b4e3e2e..35f31c2c1 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -18,8 +18,9 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <ipxe/init.h> #include <ipxe/features.h> #include <ipxe/shell.h> -#include <ipxe/shell_banner.h> #include <ipxe/image.h> +#include <ipxe/keys.h> +#include <usr/prompt.h> #include <usr/autoboot.h> #include <config/general.h> @@ -28,6 +29,21 @@ FILE_LICENCE ( GPL2_OR_LATER ); #define CYAN "\033[36m" /** + * Prompt for shell entry + * + * @ret enter_shell User wants to enter shell + */ +static int shell_banner ( void ) { + + /* Skip prompt if timeout is zero */ + if ( BANNER_TIMEOUT <= 0 ) + return 0; + + return ( prompt ( "\nPress Ctrl-B for the iPXE command line...", + ( BANNER_TIMEOUT * 100 ), CTRL_B ) == 0 ); +} + +/** * Main entry point * * @ret rc Return status code diff --git a/src/include/ipxe/errfile.h b/src/include/ipxe/errfile.h index 01de5600e..7968c4f51 100644 --- a/src/include/ipxe/errfile.h +++ b/src/include/ipxe/errfile.h @@ -237,6 +237,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #define ERRFILE_gdbstub_cmd ( ERRFILE_OTHER | 0x001f0000 ) #define ERRFILE_sanboot_cmd ( ERRFILE_OTHER | 0x00200000 ) #define ERRFILE_bofm ( ERRFILE_OTHER | 0x00210000 ) +#define ERRFILE_prompt ( ERRFILE_OTHER | 0x00220000 ) /** @} */ diff --git a/src/include/ipxe/shell_banner.h b/src/include/ipxe/shell_banner.h deleted file mode 100644 index d03fcbace..000000000 --- a/src/include/ipxe/shell_banner.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _IPXE_SHELL_BANNER_H -#define _IPXE_SHELL_BANNER_H - -/** @file - * - * Shell startup banner - * - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -extern int shell_banner ( void ); - -#endif /* _IPXE_SHELL_BANNER_H */ diff --git a/src/include/usr/prompt.h b/src/include/usr/prompt.h new file mode 100644 index 000000000..fc1946c7a --- /dev/null +++ b/src/include/usr/prompt.h @@ -0,0 +1,14 @@ +#ifndef _USR_PROMPT_H +#define _USR_PROMPT_H + +/** @file + * + * Prompt for keypress + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +extern int prompt ( const char *text, unsigned int wait_ms, int key ); + +#endif /* _USR_PROMPT_H */ diff --git a/src/hci/shell_banner.c b/src/usr/prompt.c index 6f225d789..7f9a94484 100644 --- a/src/hci/shell_banner.c +++ b/src/usr/prompt.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>. + * Copyright (C) 2011 Michael Brown <mbrown@fensystems.co.uk>. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -18,39 +18,49 @@ FILE_LICENCE ( GPL2_OR_LATER ); -#include <stdio.h> -#include <console.h> -#include <config/general.h> -#include <ipxe/keys.h> -#include <ipxe/timer.h> -#include <ipxe/shell_banner.h> - /** @file * - * Shell startup banner + * Prompt for keypress * */ +#include <errno.h> +#include <stdio.h> +#include <console.h> +#include <ipxe/timer.h> +#include <usr/prompt.h> + /** - * Print shell banner and prompt for shell entry + * Prompt for keypress + * + * @v text Prompt string + * @v wait_ms Time to wait, in milliseconds (0=indefinite) + * @v key Key to wait for (0=any key) + * @ret rc Return status code * - * @ret enter_shell User wants to enter shell + * Returns success if the specified key was pressed within the + * specified timeout period. */ -int shell_banner ( void ) { - int key; - - /* Skip prompt if timeout is zero */ - if ( BANNER_TIMEOUT <= 0 ) - return 0; +int prompt ( const char *text, unsigned int wait_ms, int key ) { + int key_pressed; /* Display prompt */ - printf ( "\nPress Ctrl-B for the iPXE command line..." ); + printf ( "%s", text ); /* Wait for key */ - key = getkey ( ( BANNER_TIMEOUT * TICKS_PER_SEC ) / 10 ); + key_pressed = getkey ( ( wait_ms * TICKS_PER_SEC ) / 1000 ); + + /* Clear the prompt line */ + while ( *(text++) ) + printf ( "\b \b" ); + + /* Check for timeout */ + if ( key_pressed < 0 ) + return -ETIMEDOUT; - /* Clear the "Press Ctrl-B" line */ - printf ( "\r \r" ); + /* Check for correct key pressed */ + if ( key && ( key_pressed != key ) ) + return -ECANCELED; - return ( key == CTRL_B ); + return 0; } |