|
@@ -0,0 +1,77 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
|
|
3
|
+ *
|
|
4
|
+ * This program is free software; you can redistribute it and/or
|
|
5
|
+ * modify it under the terms of the GNU General Public License as
|
|
6
|
+ * published by the Free Software Foundation; either version 2 of the
|
|
7
|
+ * License, or any later version.
|
|
8
|
+ *
|
|
9
|
+ * This program is distributed in the hope that it will be useful, but
|
|
10
|
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+ * General Public License for more details.
|
|
13
|
+ *
|
|
14
|
+ * You should have received a copy of the GNU General Public License
|
|
15
|
+ * along with this program; if not, write to the Free Software
|
|
16
|
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
17
|
+ */
|
|
18
|
+
|
|
19
|
+#include <console.h>
|
|
20
|
+#include <latch.h>
|
|
21
|
+#include <gpxe/keys.h>
|
|
22
|
+
|
|
23
|
+/** @file
|
|
24
|
+ *
|
|
25
|
+ * Special key interpretation
|
|
26
|
+ *
|
|
27
|
+ */
|
|
28
|
+
|
|
29
|
+#define GETKEY_TIMEOUT ( TICKS_PER_SEC / 4 )
|
|
30
|
+
|
|
31
|
+/**
|
|
32
|
+ * Read character from console if available within timeout period
|
|
33
|
+ *
|
|
34
|
+ * @v timeout Timeout period, in ticks
|
|
35
|
+ * @ret character Character read from console
|
|
36
|
+ */
|
|
37
|
+static int getchar_timeout ( unsigned long timeout ) {
|
|
38
|
+ unsigned long expiry = ( currticks() + timeout );
|
|
39
|
+
|
|
40
|
+ while ( currticks() < expiry ) {
|
|
41
|
+ if ( iskey() )
|
|
42
|
+ return getchar();
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ return -1;
|
|
46
|
+}
|
|
47
|
+
|
|
48
|
+/**
|
|
49
|
+ * Get single keypress
|
|
50
|
+ *
|
|
51
|
+ * @ret key Key pressed
|
|
52
|
+ *
|
|
53
|
+ * The returned key will be an ASCII value or a KEY_XXX special
|
|
54
|
+ * constant. This function differs from getchar() in that getchar()
|
|
55
|
+ * will return "special" keys (e.g. cursor keys) as a series of
|
|
56
|
+ * characters forming an ANSI escape sequence.
|
|
57
|
+ */
|
|
58
|
+int getkey ( void ) {
|
|
59
|
+ int character;
|
|
60
|
+ int key;
|
|
61
|
+
|
|
62
|
+ character = getchar();
|
|
63
|
+ if ( character != ESC )
|
|
64
|
+ return character;
|
|
65
|
+
|
|
66
|
+ key = 0;
|
|
67
|
+ while ( ( character = getchar_timeout ( GETKEY_TIMEOUT ) ) >= 0 ) {
|
|
68
|
+ if ( character == '[' )
|
|
69
|
+ continue;
|
|
70
|
+ if ( ! key )
|
|
71
|
+ key = KEY_ANSI ( character );
|
|
72
|
+ if ( ( character >= 0x40 ) && ( character <= 0x4f ) )
|
|
73
|
+ break;
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ return ( key ? key : ESC );
|
|
77
|
+}
|