about summary refs log tree commit diff stats
path: root/termbox/input.inl
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-08-09 20:01:42 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-08-09 20:01:42 -0700
commite709c65e67f873541b958ba43e425b08f3e073e3 (patch)
tree37d7203b4f2874e41e178938f1f00917dae949c8 /termbox/input.inl
parent6fef33fd0872ffcb5141a926d1dae5b0eded3071 (diff)
downloadmu-e709c65e67f873541b958ba43e425b08f3e073e3.tar.gz
1964 - don't mess up paste
It took me a long time to fix termbox because the escape codes it was
seeing seemed all wrong. Had to stop calling tb_shutdown/printf and put
in the extra 3 lines to log to a file. Then everything cleared up.
Weird.
Diffstat (limited to 'termbox/input.inl')
-rw-r--r--termbox/input.inl35
1 files changed, 35 insertions, 0 deletions
diff --git a/termbox/input.inl b/termbox/input.inl
index 618e0b28..4cbba0a5 100644
--- a/termbox/input.inl
+++ b/termbox/input.inl
@@ -12,9 +12,20 @@ static bool starts_with(const char *s1, int len, const char *s2)
   return *s2 == 0;
 }
 
+#define FOO(...) { \
+  FILE* f = fopen("log", "a+"); \
+  fprintf(f, __VA_ARGS__); \
+  fclose(f); \
+}
+
 // convert escape sequence to event, and return consumed bytes on success (failure == 0)
 static int parse_escape_seq(struct tb_event *event, const char *buf, int len)
 {
+//?   int x = 0;
+//?   FOO("-- %d\n", len);
+//?   for (x = 0; x < len; ++x) {
+//?     FOO("%d\n", (unsigned char)buf[x]);
+//?   }
   if (len >= 6 && starts_with(buf, len, "\033[M")) {
 
     switch (buf[3] & 3) {
@@ -58,6 +69,18 @@ static int parse_escape_seq(struct tb_event *event, const char *buf, int len)
       return strlen(keys[i]);
     }
   }
+
+  if (starts_with(buf, len, "\033[200~")) {
+    event->ch = 0;
+    event->key = TB_KEY_START_PASTE;
+    return strlen("\033[200~");
+  }
+  if (starts_with(buf, len, "\033[201~")) {
+    event->ch = 0;
+    event->key = TB_KEY_END_PASTE;
+    return strlen("\033[201~");
+  }
+
   return 0;
 }
 
@@ -68,8 +91,15 @@ static bool extract_event(struct tb_event *event, struct bytebuffer *inbuf)
   if (len == 0)
     return false;
 
+//?   int x = 0;
+//?   FOO("== %d\n", len);
+//?   for (x = 0; x < len; ++x) {
+//?     FOO("%x\n", (unsigned char)buf[x]);
+//?   }
   if (buf[0] == '\033') {
+//?     FOO("AAA\n");
     int n = parse_escape_seq(event, buf, len);
+//?     FOO("AAA: %u %u %u %u\n", n, (unsigned int)event->type, (unsigned int)event->key, event->ch);
     if (n != 0) {
       bool success = true;
       if (n < 0) {
@@ -79,6 +109,7 @@ static bool extract_event(struct tb_event *event, struct bytebuffer *inbuf)
       bytebuffer_truncate(inbuf, n);
       return success;
     } else {
+//?       FOO("escape sequence\n");
       // it's not escape sequence; assume it's esc
       event->ch = 0;
       event->key = TB_KEY_ESC;
@@ -94,6 +125,7 @@ static bool extract_event(struct tb_event *event, struct bytebuffer *inbuf)
   if ((unsigned char)buf[0] <= TB_KEY_SPACE ||
       (unsigned char)buf[0] == TB_KEY_BACKSPACE2)
   {
+//?     FOO("BBB\n");
     // fill event, pop buffer, return success */
     event->ch = 0;
     event->key = (uint16_t)buf[0];
@@ -105,8 +137,10 @@ static bool extract_event(struct tb_event *event, struct bytebuffer *inbuf)
 
   // check if there is all bytes
   if (len >= tb_utf8_char_length(buf[0])) {
+//?     FOO("CCC\n");
     /* everything ok, fill event, pop buffer, return success */
     tb_utf8_char_to_unicode(&event->ch, buf);
+//?     FOO("CCC: %d\n", event->ch);
     event->key = 0;
     bytebuffer_truncate(inbuf, tb_utf8_char_length(buf[0]));
     return true;
@@ -114,5 +148,6 @@ static bool extract_event(struct tb_event *event, struct bytebuffer *inbuf)
 
   // event isn't recognized, perhaps there is not enough bytes in utf8
   // sequence
+//?   FOO("ZZZ\n");
   return false;
 }