]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[prompt] Replace shell_banner() with a generic prompt() function
authorMichael Brown <mcb30@ipxe.org>
Mon, 7 Mar 2011 17:42:06 +0000 (17:42 +0000)
committerMichael Brown <mcb30@ipxe.org>
Mon, 7 Mar 2011 19:53:53 +0000 (19:53 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/main.c
src/include/ipxe/errfile.h
src/include/ipxe/shell_banner.h [deleted file]
src/include/usr/prompt.h [new file with mode: 0644]
src/usr/prompt.c [moved from src/hci/shell_banner.c with 51% similarity]

index e2b4e3e2e7bb96a9d89f9d60b149886a520942b6..35f31c2c10ccf428dbe11b596fc81851f70abd4b 100644 (file)
@@ -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>
 
@@ -27,6 +28,21 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #define BOLD   "\033[1m"
 #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
  *
index 01de5600eb7adf93f0601e0c121da70e18dd764d..7968c4f517cccdafdf3648386184dcc3be65e5d7 100644 (file)
@@ -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 (file)
index d03fcba..0000000
+++ /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 (file)
index 0000000..fc1946c
--- /dev/null
@@ -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 */
similarity index 51%
rename from src/hci/shell_banner.c
rename to src/usr/prompt.c
index 6f225d789e52a0dd2c631f8d66bfe5ddb28dfbd4..7f9a94484c335f6cb9974b1ddff71e7d21d9133b 100644 (file)
@@ -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
 
 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;
 }