Skip to content

Commit 8e7827d

Browse files
committed
1144 - dump termbox's support for modifier keys
1 parent f674c4a commit 8e7827d

File tree

3 files changed

+9
-60
lines changed

3 files changed

+9
-60
lines changed

cpp/termbox/input.inl

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
/* Sets the termbox input mode. Termbox has two input modes:
2-
* 1. Esc input mode.
3-
* When ESC sequence is in the buffer and it doesn't match any known
4-
* ESC sequence => ESC means TB_KEY_ESC.
5-
* 2. Alt input mode.
6-
* When ESC sequence is in the buffer and it doesn't match any known
7-
* sequence => ESC enables TB_MOD_ALT modifier for the next keyboard event.
8-
*
9-
* If 'mode' is TB_INPUT_CURRENT, it returns the current input mode.
10-
*/
11-
int tb_select_input_mode(int mode);
12-
/* Possible values for mode. */
13-
#define TB_INPUT_CURRENT 0x0
14-
#define TB_INPUT_ESC 0x1
15-
#define TB_INPUT_ALT 0x2
16-
#define TB_INPUT_MOUSE 0x4
17-
181
// if s1 starts with s2 returns true, else false
192
// len is the length of s1
203
// s2 should be null-terminated
@@ -78,7 +61,7 @@ static int parse_escape_seq(struct tb_event *event, const char *buf, int len)
7861
return 0;
7962
}
8063

81-
static bool extract_event(struct tb_event *event, struct bytebuffer *inbuf, int inputmode)
64+
static bool extract_event(struct tb_event *event, struct bytebuffer *inbuf)
8265
{
8366
const char *buf = inbuf->buf;
8467
const int len = inbuf->len;
@@ -96,25 +79,11 @@ static bool extract_event(struct tb_event *event, struct bytebuffer *inbuf, int
9679
bytebuffer_truncate(inbuf, n);
9780
return success;
9881
} else {
99-
// it's not escape sequence, then it's ALT or ESC,
100-
// check inputmode
101-
if (inputmode&TB_INPUT_ESC) {
102-
// if we're in escape mode, fill ESC event, pop
103-
// buffer, return success
104-
event->ch = 0;
105-
event->key = TB_KEY_ESC;
106-
event->mod = 0;
107-
bytebuffer_truncate(inbuf, 1);
108-
return true;
109-
}
110-
if (inputmode&TB_INPUT_ALT) {
111-
// if we're in alt mode, set ALT modifier to
112-
// event and redo parsing
113-
event->mod = TB_MOD_ALT;
114-
bytebuffer_truncate(inbuf, 1);
115-
return extract_event(event, inbuf, inputmode);
116-
}
117-
assert(!"never got here");
82+
// it's not escape sequence; assume it's esc
83+
event->ch = 0;
84+
event->key = TB_KEY_ESC;
85+
bytebuffer_truncate(inbuf, 1);
86+
return true;
11887
}
11988
}
12089

cpp/termbox/termbox.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ static struct bytebuffer input_buffer;
4040
static int termw = -1;
4141
static int termh = -1;
4242

43-
static int inputmode = TB_INPUT_ESC;
4443
static int outputmode = TB_OUTPUT_NORMAL;
4544

4645
static int inout;
@@ -269,21 +268,6 @@ void tb_clear(void)
269268
cellbuf_clear(&back_buffer);
270269
}
271270

272-
int tb_select_input_mode(int mode)
273-
{
274-
if (mode) {
275-
inputmode = mode;
276-
if (mode&TB_INPUT_MOUSE) {
277-
bytebuffer_puts(&output_buffer, funcs[T_ENTER_MOUSE]);
278-
bytebuffer_flush(&output_buffer, inout);
279-
} else {
280-
bytebuffer_puts(&output_buffer, funcs[T_EXIT_MOUSE]);
281-
bytebuffer_flush(&output_buffer, inout);
282-
}
283-
}
284-
return inputmode;
285-
}
286-
287271
int tb_select_output_mode(int mode)
288272
{
289273
if (mode)
@@ -597,15 +581,15 @@ static int wait_fill_event(struct tb_event *event, struct timeval *timeout)
597581

598582
// try to extract event from input buffer, return on success
599583
event->type = TB_EVENT_KEY;
600-
if (extract_event(event, &input_buffer, inputmode))
584+
if (extract_event(event, &input_buffer))
601585
return event->type;
602586

603587
// it looks like input buffer is incomplete, let's try the short path,
604588
// but first make sure there is enough space
605589
int n = read_up_to(ENOUGH_DATA_FOR_PARSING);
606590
if (n < 0)
607591
return -1;
608-
if (n > 0 && extract_event(event, &input_buffer, inputmode))
592+
if (n > 0 && extract_event(event, &input_buffer))
609593
return event->type;
610594

611595
// n == 0, or not enough data, let's go to select
@@ -627,7 +611,7 @@ static int wait_fill_event(struct tb_event *event, struct timeval *timeout)
627611
if (n == 0)
628612
continue;
629613

630-
if (extract_event(event, &input_buffer, inputmode))
614+
if (extract_event(event, &input_buffer))
631615
return event->type;
632616
}
633617
if (FD_ISSET(winch_fds[0], &events)) {

cpp/termbox/termbox.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ void tb_change_cell(int x, int y, uint32_t ch, uint16_t fg, uint16_t bg);
8383
struct tb_event {
8484
uint8_t type;
8585
/* fields for type TB_EVENT_KEY */
86-
uint8_t mod;
8786
uint16_t key;
8887
uint32_t ch;
8988
/* fields for type TB_EVENT_RESIZE */
@@ -99,9 +98,6 @@ struct tb_event {
9998
#define TB_EVENT_RESIZE 2
10099
#define TB_EVENT_MOUSE 3
101100

102-
/* Possible values for tb_event.mod. */
103-
#define TB_MOD_ALT 0x01
104-
105101
/* Possible values for tb_event.key.
106102
*
107103
* These are a safe subset of terminfo keys, which exist on all popular

0 commit comments

Comments
 (0)