about summary refs log tree commit diff stats
path: root/cpp/termbox
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-04-22 20:39:43 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-04-22 20:43:59 -0700
commit8e7827dfcf15ccbbade3e5d58c340dd5f72b7208 (patch)
tree3dcc48c2aa05041e4c2816810fe2dd92d4e9caef /cpp/termbox
parentf674c4a51d760722867070defed638f246d79205 (diff)
downloadmu-8e7827dfcf15ccbbade3e5d58c340dd5f72b7208.tar.gz
1144 - dump termbox's support for modifier keys
Diffstat (limited to 'cpp/termbox')
-rw-r--r--cpp/termbox/input.inl43
-rw-r--r--cpp/termbox/termbox.c22
-rw-r--r--cpp/termbox/termbox.h4
3 files changed, 9 insertions, 60 deletions
diff --git a/cpp/termbox/input.inl b/cpp/termbox/input.inl
index 8a4a14de..6493273c 100644
--- a/cpp/termbox/input.inl
+++ b/cpp/termbox/input.inl
@@ -1,20 +1,3 @@
-/* Sets the termbox input mode. Termbox has two input modes:
- * 1. Esc input mode.
- *    When ESC sequence is in the buffer and it doesn't match any known
- *    ESC sequence => ESC means TB_KEY_ESC.
- * 2. Alt input mode.
- *    When ESC sequence is in the buffer and it doesn't match any known
- *    sequence => ESC enables TB_MOD_ALT modifier for the next keyboard event.
- *
- * If 'mode' is TB_INPUT_CURRENT, it returns the current input mode.
- */
-int tb_select_input_mode(int mode);
-/* Possible values for mode. */
-#define TB_INPUT_CURRENT 0x0
-#define TB_INPUT_ESC     0x1
-#define TB_INPUT_ALT     0x2
-#define TB_INPUT_MOUSE   0x4
-
 // if s1 starts with s2 returns true, else false
 // len is the length of s1
 // s2 should be null-terminated
@@ -78,7 +61,7 @@ static int parse_escape_seq(struct tb_event *event, const char *buf, int len)
   return 0;
 }
 
-static bool extract_event(struct tb_event *event, struct bytebuffer *inbuf, int inputmode)
+static bool extract_event(struct tb_event *event, struct bytebuffer *inbuf)
 {
   const char *buf = inbuf->buf;
   const int len = inbuf->len;
@@ -96,25 +79,11 @@ static bool extract_event(struct tb_event *event, struct bytebuffer *inbuf, int
       bytebuffer_truncate(inbuf, n);
       return success;
     } else {
-      // it's not escape sequence, then it's ALT or ESC,
-      // check inputmode
-      if (inputmode&TB_INPUT_ESC) {
-        // if we're in escape mode, fill ESC event, pop
-        // buffer, return success
-        event->ch = 0;
-        event->key = TB_KEY_ESC;
-        event->mod = 0;
-        bytebuffer_truncate(inbuf, 1);
-        return true;
-      }
-      if (inputmode&TB_INPUT_ALT) {
-        // if we're in alt mode, set ALT modifier to
-        // event and redo parsing
-        event->mod = TB_MOD_ALT;
-        bytebuffer_truncate(inbuf, 1);
-        return extract_event(event, inbuf, inputmode);
-      }
-      assert(!"never got here");
+      // it's not escape sequence; assume it's esc
+      event->ch = 0;
+      event->key = TB_KEY_ESC;
+      bytebuffer_truncate(inbuf, 1);
+      return true;
     }
   }
 
diff --git a/cpp/termbox/termbox.c b/cpp/termbox/termbox.c
index 616a2539..3ecc0b4b 100644
--- a/cpp/termbox/termbox.c
+++ b/cpp/termbox/termbox.c
@@ -40,7 +40,6 @@ static struct bytebuffer input_buffer;
 static int termw = -1;
 static int termh = -1;
 
-static int inputmode = TB_INPUT_ESC;
 static int outputmode = TB_OUTPUT_NORMAL;
 
 static int inout;
@@ -269,21 +268,6 @@ void tb_clear(void)
   cellbuf_clear(&back_buffer);
 }
 
-int tb_select_input_mode(int mode)
-{
-  if (mode) {
-    inputmode = mode;
-    if (mode&TB_INPUT_MOUSE) {
-      bytebuffer_puts(&output_buffer, funcs[T_ENTER_MOUSE]);
-      bytebuffer_flush(&output_buffer, inout);
-    } else {
-      bytebuffer_puts(&output_buffer, funcs[T_EXIT_MOUSE]);
-      bytebuffer_flush(&output_buffer, inout);
-    }
-  }
-  return inputmode;
-}
-
 int tb_select_output_mode(int mode)
 {
   if (mode)
@@ -597,7 +581,7 @@ static int wait_fill_event(struct tb_event *event, struct timeval *timeout)
 
   // try to extract event from input buffer, return on success
   event->type = TB_EVENT_KEY;
-  if (extract_event(event, &input_buffer, inputmode))
+  if (extract_event(event, &input_buffer))
     return event->type;
 
   // it looks like input buffer is incomplete, let's try the short path,
@@ -605,7 +589,7 @@ static int wait_fill_event(struct tb_event *event, struct timeval *timeout)
   int n = read_up_to(ENOUGH_DATA_FOR_PARSING);
   if (n < 0)
     return -1;
-  if (n > 0 && extract_event(event, &input_buffer, inputmode))
+  if (n > 0 && extract_event(event, &input_buffer))
     return event->type;
 
   // 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)
       if (n == 0)
         continue;
 
-      if (extract_event(event, &input_buffer, inputmode))
+      if (extract_event(event, &input_buffer))
         return event->type;
     }
     if (FD_ISSET(winch_fds[0], &events)) {
diff --git a/cpp/termbox/termbox.h b/cpp/termbox/termbox.h
index 73ee53b6..3e2228de 100644
--- a/cpp/termbox/termbox.h
+++ b/cpp/termbox/termbox.h
@@ -83,7 +83,6 @@ void tb_change_cell(int x, int y, uint32_t ch, uint16_t fg, uint16_t bg);
 struct tb_event {
   uint8_t type;
   /* fields for type TB_EVENT_KEY */
-  uint8_t mod;
   uint16_t key;
   uint32_t ch;
   /* fields for type TB_EVENT_RESIZE */
@@ -99,9 +98,6 @@ struct tb_event {
 #define TB_EVENT_RESIZE 2
 #define TB_EVENT_MOUSE  3
 
-/* Possible values for tb_event.mod. */
-#define TB_MOD_ALT 0x01
-
 /* Possible values for tb_event.key.
  *
  * These are a safe subset of terminfo keys, which exist on all popular