|
@@ -1,5 +1,5 @@
|
1
|
1
|
/*
|
2
|
|
- * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
|
|
2
|
+ * Copyright (C) 2011 Michael Brown <mbrown@fensystems.co.uk>.
|
3
|
3
|
*
|
4
|
4
|
* This program is free software; you can redistribute it and/or
|
5
|
5
|
* modify it under the terms of the GNU General Public License as
|
|
@@ -18,39 +18,49 @@
|
18
|
18
|
|
19
|
19
|
FILE_LICENCE ( GPL2_OR_LATER );
|
20
|
20
|
|
21
|
|
-#include <stdio.h>
|
22
|
|
-#include <console.h>
|
23
|
|
-#include <config/general.h>
|
24
|
|
-#include <ipxe/keys.h>
|
25
|
|
-#include <ipxe/timer.h>
|
26
|
|
-#include <ipxe/shell_banner.h>
|
27
|
|
-
|
28
|
21
|
/** @file
|
29
|
22
|
*
|
30
|
|
- * Shell startup banner
|
|
23
|
+ * Prompt for keypress
|
31
|
24
|
*
|
32
|
25
|
*/
|
33
|
26
|
|
|
27
|
+#include <errno.h>
|
|
28
|
+#include <stdio.h>
|
|
29
|
+#include <console.h>
|
|
30
|
+#include <ipxe/timer.h>
|
|
31
|
+#include <usr/prompt.h>
|
|
32
|
+
|
34
|
33
|
/**
|
35
|
|
- * Print shell banner and prompt for shell entry
|
|
34
|
+ * Prompt for keypress
|
|
35
|
+ *
|
|
36
|
+ * @v text Prompt string
|
|
37
|
+ * @v wait_ms Time to wait, in milliseconds (0=indefinite)
|
|
38
|
+ * @v key Key to wait for (0=any key)
|
|
39
|
+ * @ret rc Return status code
|
36
|
40
|
*
|
37
|
|
- * @ret enter_shell User wants to enter shell
|
|
41
|
+ * Returns success if the specified key was pressed within the
|
|
42
|
+ * specified timeout period.
|
38
|
43
|
*/
|
39
|
|
-int shell_banner ( void ) {
|
40
|
|
- int key;
|
41
|
|
-
|
42
|
|
- /* Skip prompt if timeout is zero */
|
43
|
|
- if ( BANNER_TIMEOUT <= 0 )
|
44
|
|
- return 0;
|
|
44
|
+int prompt ( const char *text, unsigned int wait_ms, int key ) {
|
|
45
|
+ int key_pressed;
|
45
|
46
|
|
46
|
47
|
/* Display prompt */
|
47
|
|
- printf ( "\nPress Ctrl-B for the iPXE command line..." );
|
|
48
|
+ printf ( "%s", text );
|
48
|
49
|
|
49
|
50
|
/* Wait for key */
|
50
|
|
- key = getkey ( ( BANNER_TIMEOUT * TICKS_PER_SEC ) / 10 );
|
|
51
|
+ key_pressed = getkey ( ( wait_ms * TICKS_PER_SEC ) / 1000 );
|
|
52
|
+
|
|
53
|
+ /* Clear the prompt line */
|
|
54
|
+ while ( *(text++) )
|
|
55
|
+ printf ( "\b \b" );
|
|
56
|
+
|
|
57
|
+ /* Check for timeout */
|
|
58
|
+ if ( key_pressed < 0 )
|
|
59
|
+ return -ETIMEDOUT;
|
51
|
60
|
|
52
|
|
- /* Clear the "Press Ctrl-B" line */
|
53
|
|
- printf ( "\r \r" );
|
|
61
|
+ /* Check for correct key pressed */
|
|
62
|
+ if ( key && ( key_pressed != key ) )
|
|
63
|
+ return -ECANCELED;
|
54
|
64
|
|
55
|
|
- return ( key == CTRL_B );
|
|
65
|
+ return 0;
|
56
|
66
|
}
|