Browse Source

[console] Allow KEY_xxx constants to cover F8 function key

F8 is represented by the ANSI escape sequence "^[[19~", which is not
representable as a KEY_xxx constant using the current encoding scheme.
Adapt the encoding scheme to allow F8 to be represented, since PXE
requires that we may need to prompt the user to press F8.
tags/v0.9.7
Michael Brown 16 years ago
parent
commit
ce9690ca39
2 changed files with 21 additions and 22 deletions
  1. 8
    6
      src/core/getkey.c
  2. 13
    16
      src/include/gpxe/keys.h

+ 8
- 6
src/core/getkey.c View File

@@ -16,6 +16,7 @@
16 16
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
  */
18 18
 
19
+#include <ctype.h>
19 20
 #include <console.h>
20 21
 #include <gpxe/process.h>
21 22
 #include <gpxe/keys.h>
@@ -59,21 +60,22 @@ static int getchar_timeout ( unsigned long timeout ) {
59 60
  */
60 61
 int getkey ( void ) {
61 62
 	int character;
62
-	int key;
63
+	unsigned int n = 0;
63 64
 
64 65
 	character = getchar();
65 66
 	if ( character != ESC )
66 67
 		return character;
67 68
 
68
-	key = 0;
69 69
 	while ( ( character = getchar_timeout ( GETKEY_TIMEOUT ) ) >= 0 ) {
70 70
 		if ( character == '[' )
71 71
 			continue;
72
-		if ( ! key )
73
-			key = KEY_ANSI ( character );
72
+		if ( isdigit ( character ) ) {
73
+			n = ( ( n * 10 ) + ( character - '0' ) );
74
+			continue;
75
+		}
74 76
 		if ( character >= 0x40 )
75
-			break;
77
+			return KEY_ANSI ( n, character );
76 78
 	}
77 79
 
78
-	return ( key ? key : ESC );
80
+	return ESC;
79 81
 }

+ 13
- 16
src/include/gpxe/keys.h View File

@@ -52,26 +52,23 @@
52 52
  *
53 53
  * The names are chosen to match those used by curses.  The values are
54 54
  * chosen to facilitate easy conversion from a received ANSI escape
55
- * sequence to a KEY_XXX constant.  The KEY_XXX constant is simply
56
- * 0x100 plus the first byte following CSI in the ANSI escape
57
- * sequence.  For example, KEY_LEFT is 0x144, since a left cursor key
58
- * is transmitted as the ANSI sequence "^[[D".
55
+ * sequence to a KEY_XXX constant.
59 56
  */
60 57
 
61
-#define KEY_ANSI( character ) ( 0x100 + (character) )
58
+#define KEY_ANSI( n, terminator ) ( 0x100 * ( (n) + 1 ) + (terminator) )
62 59
 
63 60
 #define KEY_MIN		0x101
64
-#define KEY_UP		KEY_ANSI ( 'A' )	/**< Up arrow */
65
-#define KEY_DOWN	KEY_ANSI ( 'B' )	/**< Down arrow */
66
-#define KEY_RIGHT	KEY_ANSI ( 'C' )	/**< Right arrow */
67
-#define KEY_LEFT	KEY_ANSI ( 'D' )	/**< Left arrow */
68
-#define KEY_END		KEY_ANSI ( 'F' )	/**< End */
69
-#define KEY_HOME	KEY_ANSI ( 'H' )	/**< Home */
70
-#define KEY_IC		KEY_ANSI ( '2' )	/**< Insert */
71
-#define KEY_DC		KEY_ANSI ( '3' )	/**< Delete */
72
-#define KEY_PPAGE	KEY_ANSI ( '5' )	/**< Page up */
73
-#define KEY_NPAGE	KEY_ANSI ( '6' )	/**< Page down */
74
-#define KEY_MAX		0x1ff
61
+#define KEY_UP		KEY_ANSI ( 0, 'A' )	/**< Up arrow */
62
+#define KEY_DOWN	KEY_ANSI ( 0, 'B' )	/**< Down arrow */
63
+#define KEY_RIGHT	KEY_ANSI ( 0, 'C' )	/**< Right arrow */
64
+#define KEY_LEFT	KEY_ANSI ( 0, 'D' )	/**< Left arrow */
65
+#define KEY_END		KEY_ANSI ( 0, 'F' )	/**< End */
66
+#define KEY_HOME	KEY_ANSI ( 0, 'H' )	/**< Home */
67
+#define KEY_IC		KEY_ANSI ( 2, '~' )	/**< Insert */
68
+#define KEY_DC		KEY_ANSI ( 3, '~' )	/**< Delete */
69
+#define KEY_PPAGE	KEY_ANSI ( 5, '~' )	/**< Page up */
70
+#define KEY_NPAGE	KEY_ANSI ( 6, '~' )	/**< Page down */
71
+#define KEY_F8		KEY_ANSI ( 19, '~' )	/**< F8 (for PXE) */
75 72
 
76 73
 /* Not in the [KEY_MIN,KEY_MAX] range; terminals seem to send these as
77 74
  * normal ASCII values.

Loading…
Cancel
Save