Bläddra i källkod

[prompt] Replace shell_banner() with a generic prompt() function

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 år sedan
förälder
incheckning
c4b6c244b0
5 ändrade filer med 64 tillägg och 37 borttagningar
  1. 17
    1
      src/core/main.c
  2. 1
    0
      src/include/ipxe/errfile.h
  3. 0
    14
      src/include/ipxe/shell_banner.h
  4. 14
    0
      src/include/usr/prompt.h
  5. 32
    22
      src/usr/prompt.c

+ 17
- 1
src/core/main.c Visa fil

@@ -18,8 +18,9 @@ FILE_LICENCE ( GPL2_OR_LATER );
18 18
 #include <ipxe/init.h>
19 19
 #include <ipxe/features.h>
20 20
 #include <ipxe/shell.h>
21
-#include <ipxe/shell_banner.h>
22 21
 #include <ipxe/image.h>
22
+#include <ipxe/keys.h>
23
+#include <usr/prompt.h>
23 24
 #include <usr/autoboot.h>
24 25
 #include <config/general.h>
25 26
 
@@ -27,6 +28,21 @@ FILE_LICENCE ( GPL2_OR_LATER );
27 28
 #define BOLD	"\033[1m"
28 29
 #define CYAN	"\033[36m"
29 30
 
31
+/**
32
+ * Prompt for shell entry
33
+ *
34
+ * @ret	enter_shell		User wants to enter shell
35
+ */
36
+static int shell_banner ( void ) {
37
+
38
+	/* Skip prompt if timeout is zero */
39
+	if ( BANNER_TIMEOUT <= 0 )
40
+		return 0;
41
+
42
+	return ( prompt ( "\nPress Ctrl-B for the iPXE command line...",
43
+			  ( BANNER_TIMEOUT * 100 ), CTRL_B ) == 0 );
44
+}
45
+
30 46
 /**
31 47
  * Main entry point
32 48
  *

+ 1
- 0
src/include/ipxe/errfile.h Visa fil

@@ -237,6 +237,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
237 237
 #define ERRFILE_gdbstub_cmd	      ( ERRFILE_OTHER | 0x001f0000 )
238 238
 #define ERRFILE_sanboot_cmd	      ( ERRFILE_OTHER | 0x00200000 )
239 239
 #define ERRFILE_bofm		      ( ERRFILE_OTHER | 0x00210000 )
240
+#define ERRFILE_prompt		      ( ERRFILE_OTHER | 0x00220000 )
240 241
 
241 242
 /** @} */
242 243
 

+ 0
- 14
src/include/ipxe/shell_banner.h Visa fil

@@ -1,14 +0,0 @@
1
-#ifndef _IPXE_SHELL_BANNER_H
2
-#define _IPXE_SHELL_BANNER_H
3
-
4
-/** @file
5
- *
6
- * Shell startup banner
7
- *
8
- */
9
-
10
-FILE_LICENCE ( GPL2_OR_LATER );
11
-
12
-extern int shell_banner ( void );
13
-
14
-#endif /* _IPXE_SHELL_BANNER_H */

+ 14
- 0
src/include/usr/prompt.h Visa fil

@@ -0,0 +1,14 @@
1
+#ifndef _USR_PROMPT_H
2
+#define _USR_PROMPT_H
3
+
4
+/** @file
5
+ *
6
+ * Prompt for keypress
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+extern int prompt ( const char *text, unsigned int wait_ms, int key );
13
+
14
+#endif /* _USR_PROMPT_H */

src/hci/shell_banner.c → src/usr/prompt.c Visa fil

@@ -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
 }

Laddar…
Avbryt
Spara