forked from alexfru/dflat20
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunikey.h
201 lines (176 loc) · 4.25 KB
/
unikey.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#ifndef __UNIKEY__H
#define __UNIKEY__H
/*
* ANSI to Unicode keyboard mapping
*/
enum ttyflags {
MouseTracking = 1, /* mouse button tracking */
FullMouseTracking = 2, /* track mouse position events */
CatchISig = 4, /* catch SIGINT and exit by default */
Utf8 = 8, /* set termios IUTF8 */
ExitLastLine = 16, /* on exit, cursor position to bottom */
FullBuffer /* fully buffered output */
};
/* tty.c - tty termios and mouse management */
int tty_init(enum ttyflags flags);
void tty_enable_unikey(void);
void tty_restore(void);
void tty_fullbuffer(void);
void tty_linebuffer(void);
int tty_getsize(int *cols, int *rows);
extern int iselksconsole;
/* tty-cp437.c - display cp437 characters */
char *tty_allocate_screen(int cols, int lines);
void tty_output_screen(int flush);
void tty_setfgpalette(const int *pal16, const int *pal256);
#ifndef COSMO
extern unsigned short kCp437[256];
#endif
/* unikey.c - recognize ANSI input */
/* check and convert from ANSI keyboard sequence to unicode key value */
int ansi_to_unikey(char *buf, int n);
/* check and convert from ANSI mouse sequence to unicode mouse value */
int ansi_to_unimouse(char *buf, int n, int *x, int *y, int *modkeys, int *status);
const char *describemouseevent(int e);
extern int kDoubleClickTime;
/* Check and respond to ANSI DSR (device status report). */
int ansi_dsr(char *buf, int n, int *cols, int *rows);
/* return keyname */
char *unikeyname(int k);
/* state machine conversion of UTF-8 byte sequence to Rune */
int stream_to_rune(unsigned int ch);
#ifndef COSMO
/* Reads single keystroke or control sequence from character device */
int readansi(int fd, char *p, int n);
#endif
#define bsr(x) ((x)? (__builtin_clz(x) ^ ((sizeof(int) * 8) -1)): 0)
#if 0
int bsr(int n)
{
if (n == 0) return 0; /* avoid incorrect result of 31 returned! */
return (__builtin_clz(n) ^ ((sizeof(int) * 8) - 1));
}
#endif
/* defines from Cosmopolitan - see copyright in unikey.c */
#define ThomPikeCont(x) (0200 == (0300 & (x)))
#define ThomPikeByte(x) ((x) & (((1 << ThomPikeMsb(x)) - 1) | 3))
#define ThomPikeLen(x) (7 - ThomPikeMsb(x))
#define ThomPikeMsb(x) ((255 & (x)) < 252 ? bsr(255 & ~(x)) : 1)
#define ThomPikeMerge(x, y) ((x) << 6 | (077 & (y)))
/* when adding key values, add to unikeyname[] in unikey.c also */
typedef enum {
/* ASCII range */
kBackSpace = 8,
kTab = 9,
kEscKey = 27,
kDel = 127,
/* Unicode private use range 0xF000 - 0xF1FF */
/* max key group size is 32 (0x20) */
#define kKeyFirst ((unsigned)kUpArrow)
kUpArrow = 0xF000,
kDownArrow,
kLeftArrow,
kRightArrow,
kInsert,
kDelete,
kHome,
kEnd,
kPageUp,
kPageDown,
/* leave out keypad keys for now */
kMouseLeftDown,
kMouseMiddleDown,
kMouseRightDown,
kMouseLeftUp,
kMouseMiddleUp,
kMouseRightUp,
kMouseLeftDrag,
kMouseMiddleDrag,
kMouseRightDrag,
kMouseWheelUp,
kMouseWheelDown,
kMouseMotion,
kMouseLeftDoubleClick,
kF1 = 0xF020,
kF2,
kF3,
kF4,
kF5,
kF6,
kF7,
kF8,
kF9,
kF10,
kF11,
kF12,
kCtrl = 0x0080,
kCtrlF1 = kF1 + kCtrl, /* = 0xF0A0 */
kCtrlF2,
kCtrlF3,
kCtrlF4,
kCtrlF5,
kCtrlF6,
kCtrlF7,
kCtrlF8,
kCtrlF9,
kCtrlF10,
kCtrlF11,
kCtrlF12,
/* TODO: entries for Alt-kUpArrow */
kAlt = 0x0100,
kAltF1 = kF1 + kAlt, /* = 0xF120 */
kAltF2,
kAltF3,
kAltF4,
kAltF5,
kAltF6,
kAltF7,
kAltF8,
kAltF9,
kAltF10,
kAltF11,
kAltF12,
kAltA = kF1 + kAlt + 0x20, /* = 0xF140 */
kAltB,
kAltC,
kAltD,
kAltE,
kAltF,
kAltG,
kAltH,
kAltI,
kAltJ,
kAltK,
kAltL,
kAltM,
kAltN,
kAltO,
kAltP,
kAltQ,
kAltR,
kAltS,
kAltT,
kAltU,
kAltV,
kAltW,
kAltX,
kAltY,
kAltZ,
kAlt0,
kAlt1,
kAlt2,
kAlt3,
kAlt4,
kAlt5,
kAlt6,
kAlt7,
kAlt8,
kAlt9,
kShift = 0x0200 /* bit value only, not ORed into private use range */
} unikey;
struct unikeyname {
unikey key;
char * name;
};
extern struct unikeyname unikeynames[];
#endif