#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>
#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
*
/*
- * 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;
}