-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.cpp
71 lines (52 loc) · 1.83 KB
/
ui.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "ui.h"
/* Struct to hold keycode/keyname information */
struct keydesc {
int code;
char name[20];
};
/* Returns a string describing a character passed to it */
char * intprtkey(int ch) {
/* Define a selection of keys we will handle */
static struct keydesc keys[] = { { KEY_UP, "Up arrow" },
{ KEY_DOWN, "Down arrow" },
{ KEY_LEFT, "Left arrow" },
{ KEY_RIGHT, "Right arrow" },
{ KEY_HOME, "Home" },
{ KEY_END, "End" },
{ KEY_BACKSPACE, "Backspace" },
{ KEY_IC, "Insert" },
{ KEY_DC, "Delete" },
{ KEY_NPAGE, "Page down" },
{ KEY_PPAGE, "Page up" },
{ KEY_F(1), "Function key 1" },
{ KEY_F(2), "Function key 2" },
{ KEY_F(3), "Function key 3" },
{ KEY_F(4), "Function key 4" },
{ KEY_F(5), "Function key 5" },
{ KEY_F(6), "Function key 6" },
{ KEY_F(7), "Function key 7" },
{ KEY_F(8), "Function key 8" },
{ KEY_F(9), "Function key 9" },
{ KEY_F(10), "Function key 10" },
{ KEY_F(11), "Function key 11" },
{ KEY_F(12), "Function key 12" },
{ -1, "<unsupported>" }
};
static char keych[2] = {0};
if ( isprint(ch) && !(ch & KEY_CODE_YES)) {
/* If a printable character */
keych[0] = ch;
return keych;
}
else {
/* Non-printable, so loop through our array of structs */
int n = 0;
do {
if ( keys[n].code == ch )
return keys[n].name;
n++;
} while ( keys[n].code != -1 );
return keys[n].name;
}
return NULL; /* We shouldn't get here */
}