This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch tymux-10-quiet-head
in repository terminology.

View the commit online.

commit 654e02738d4f2bb5922b4c0e4221da13c517d3fc
Author: Boris Faure <[email protected]>
AuthorDate: Sat Nov 14 22:39:07 2026 +0000

    keyin: encode keys with the kitty disambiguate flag
    
    Implement the disambiguate flag (1) of the kitty keyboard protocol:
    https://sw.kovidgoyal.net/kitty/keyboard-protocol/#disambiguate
    
    Return, Tab and BackSpace keep their legacy bytes when no real modifier
    is held, as the spec requires, and those bytes still come from
    erase_is_del, send_bs and LNM: a shell left behind by a client that
    enabled the protocol and died stays usable.
---
 src/bin/keyin_encode.c |   8 ++
 src/bin/keyin_kitty.c  | 358 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/bin/keyin_kitty.h  |  12 ++
 src/bin/meson.build    |   2 +
 src/bin/tytest.c       |   1 +
 src/bin/tytest_keyin.c | 171 +++++++++++++++++++++++
 src/bin/unit_tests.h   |   1 +
 7 files changed, 553 insertions(+)

diff --git a/src/bin/keyin_encode.c b/src/bin/keyin_encode.c
index 18da073a..27533ef3 100644
--- a/src/bin/keyin_encode.c
+++ b/src/bin/keyin_encode.c
@@ -2,7 +2,9 @@
 
 #include <Elementary.h>
 #include "termpty.h"
+#include "termptyops.h"
 #include "keyin_encode.h"
+#include "keyin_kitty.h"
 
 typedef struct tag_Tty_Key Tty_Key;
 typedef struct tag_Key_Values Key_Values;
@@ -342,8 +344,14 @@ _encode_legacy(Termpty *ty, const Keyin_Event *kev)
 void
 keyin_encode_event(Termpty *ty, const Keyin_Event *kev)
 {
+   unsigned int flags;
+
    if (!kev->key)
      return;
 
+   flags = termpty_kitty_kbd_flags_get(ty);
+   if (flags && keyin_kitty_encode(ty, kev, flags))
+     return;
+
    _encode_legacy(ty, kev);
 }
diff --git a/src/bin/keyin_kitty.c b/src/bin/keyin_kitty.c
new file mode 100644
index 00000000..46efc6cd
--- /dev/null
+++ b/src/bin/keyin_kitty.c
@@ -0,0 +1,358 @@
+#include "private.h"
+
+#include <Elementary.h>
+#include <stdio.h>
+#include <string.h>
+#include <wctype.h>
+
+#include "termpty.h"
+#include "keyin_encode.h"
+#include "keyin_kitty.h"
+
+/* https://sw.kovidgoyal.net/kitty/keyboard-protocol/#functional */
+
+typedef struct tag_Kitty_Functional_Key
+{
+   const char *name;
+   unsigned short number;
+   char final;
+   unsigned char is_modifier : 1;
+} Kitty_Functional_Key;
+
+/* sorted by name for bsearch */
+static const Kitty_Functional_Key kitty_functional_keys[] = {
+     { "Alt_L", 57443, 'u', 1 },
+     { "Alt_R", 57449, 'u', 1 },
+     { "BackSpace", 127, 'u', 0 },
+     { "Caps_Lock", 57358, 'u', 1 },
+     { "Control_L", 57442, 'u', 1 },
+     { "Control_R", 57448, 'u', 1 },
+     { "Delete", 3, '~', 0 },
+     { "Down", 1, 'B', 0 },
+     { "End", 1, 'F', 0 },
+     { "Escape", 27, 'u', 0 },
+     { "F1", 1, 'P', 0 },
+     { "F10", 21, '~', 0 },
+     { "F11", 23, '~', 0 },
+     { "F12", 24, '~', 0 },
+     { "F13", 57376, 'u', 0 },
+     { "F14", 57377, 'u', 0 },
+     { "F15", 57378, 'u', 0 },
+     { "F16", 57379, 'u', 0 },
+     { "F17", 57380, 'u', 0 },
+     { "F18", 57381, 'u', 0 },
+     { "F19", 57382, 'u', 0 },
+     { "F2", 1, 'Q', 0 },
+     { "F20", 57383, 'u', 0 },
+     { "F21", 57384, 'u', 0 },
+     { "F22", 57385, 'u', 0 },
+     { "F23", 57386, 'u', 0 },
+     { "F24", 57387, 'u', 0 },
+     { "F25", 57388, 'u', 0 },
+     { "F26", 57389, 'u', 0 },
+     { "F27", 57390, 'u', 0 },
+     { "F28", 57391, 'u', 0 },
+     { "F29", 57392, 'u', 0 },
+     { "F3", 13, '~', 0 },
+     { "F30", 57393, 'u', 0 },
+     { "F31", 57394, 'u', 0 },
+     { "F32", 57395, 'u', 0 },
+     { "F33", 57396, 'u', 0 },
+     { "F34", 57397, 'u', 0 },
+     { "F35", 57398, 'u', 0 },
+     { "F4", 1, 'S', 0 },
+     { "F5", 15, '~', 0 },
+     { "F6", 17, '~', 0 },
+     { "F7", 18, '~', 0 },
+     { "F8", 19, '~', 0 },
+     { "F9", 20, '~', 0 },
+     { "Home", 1, 'H', 0 },
+     { "Hyper_L", 57445, 'u', 1 },
+     { "Hyper_R", 57451, 'u', 1 },
+     { "ISO_Left_Tab", 9, 'u', 0 },
+     { "ISO_Level3_Shift", 57453, 'u', 1 },
+     { "ISO_Level5_Shift", 57454, 'u', 1 },
+     { "Insert", 2, '~', 0 },
+     { "KP_0", 57399, 'u', 0 },
+     { "KP_1", 57400, 'u', 0 },
+     { "KP_2", 57401, 'u', 0 },
+     { "KP_3", 57402, 'u', 0 },
+     { "KP_4", 57403, 'u', 0 },
+     { "KP_5", 57404, 'u', 0 },
+     { "KP_6", 57405, 'u', 0 },
+     { "KP_7", 57406, 'u', 0 },
+     { "KP_8", 57407, 'u', 0 },
+     { "KP_9", 57408, 'u', 0 },
+     { "KP_Add", 57413, 'u', 0 },
+     { "KP_Begin", 1, 'E', 0 },
+     { "KP_Decimal", 57409, 'u', 0 },
+     { "KP_Delete", 57426, 'u', 0 },
+     { "KP_Divide", 57410, 'u', 0 },
+     { "KP_Down", 57420, 'u', 0 },
+     { "KP_End", 57424, 'u', 0 },
+     { "KP_Enter", 57414, 'u', 0 },
+     { "KP_Equal", 57415, 'u', 0 },
+     { "KP_Home", 57423, 'u', 0 },
+     { "KP_Insert", 57425, 'u', 0 },
+     { "KP_Left", 57417, 'u', 0 },
+     { "KP_Multiply", 57411, 'u', 0 },
+     { "KP_Next", 57422, 'u', 0 },
+     { "KP_Prior", 57421, 'u', 0 },
+     { "KP_Right", 57418, 'u', 0 },
+     { "KP_Separator", 57416, 'u', 0 },
+     { "KP_Subtract", 57412, 'u', 0 },
+     { "KP_Up", 57419, 'u', 0 },
+     { "Left", 1, 'D', 0 },
+     { "Menu", 57363, 'u', 0 },
+     { "Meta_L", 57446, 'u', 1 },
+     { "Meta_R", 57452, 'u', 1 },
+     { "Next", 6, '~', 0 },
+     { "Num_Lock", 57360, 'u', 1 },
+     { "Pause", 57362, 'u', 0 },
+     { "Print", 57361, 'u', 0 },
+     { "Prior", 5, '~', 0 },
+     { "Return", 13, 'u', 0 },
+     { "Right", 1, 'C', 0 },
+     { "Scroll_Lock", 57359, 'u', 1 },
+     { "Shift_L", 57441, 'u', 1 },
+     { "Shift_R", 57447, 'u', 1 },
+     { "Super_L", 57444, 'u', 1 },
+     { "Super_R", 57450, 'u', 1 },
+     { "Tab", 9, 'u', 0 },
+     { "Up", 1, 'A', 0 },
+     { "XF86AudioForward", 57433, 'u', 0 },
+     { "XF86AudioLowerVolume", 57438, 'u', 0 },
+     { "XF86AudioMute", 57440, 'u', 0 },
+     { "XF86AudioNext", 57435, 'u', 0 },
+     { "XF86AudioPause", 57429, 'u', 0 },
+     { "XF86AudioPlay", 57428, 'u', 0 },
+     { "XF86AudioPrev", 57436, 'u', 0 },
+     { "XF86AudioRaiseVolume", 57439, 'u', 0 },
+     { "XF86AudioRecord", 57437, 'u', 0 },
+     { "XF86AudioRewind", 57434, 'u', 0 },
+     { "XF86AudioStop", 57432, 'u', 0 },
+};
+
+static int
+_kitty_functional_key_cmp(const void *name, const void *elem)
+{
+   return strcmp(name, ((const Kitty_Functional_Key *)elem)->name);
+}
+
+static const Kitty_Functional_Key *
+_kitty_functional_key_find(const char *name)
+{
+   return bsearch(name, kitty_functional_keys,
+                  sizeof(kitty_functional_keys) / sizeof(kitty_functional_keys[0]),
+                  sizeof(kitty_functional_keys[0]),
+                  _kitty_functional_key_cmp);
+}
+
+/* the spec's text: no C0, DEL or C1, and none with Ctrl, Alt or Super */
+static Eina_Bool
+_kitty_text_ok(const Keyin_Event *kev)
+{
+   const char *s = kev->string;
+   int idx = 0;
+
+   if (!s || !s[0])
+     return EINA_FALSE;
+   if (kev->action == KEYIN_ACTION_RELEASE)
+     return EINA_FALSE;
+   if (kev->mods & (KEYIN_MOD_CTRL | KEYIN_MOD_ALT | KEYIN_MOD_SUPER))
+     return EINA_FALSE;
+   while (s[idx])
+     {
+        Eina_Unicode cp = eina_unicode_utf8_next_get(s, &idx);
+
+        if (cp < 0x20)
+          return EINA_FALSE;
+        if (cp == 0x7f)
+          return EINA_FALSE;
+        if (cp >= 0x80 && cp < 0xa0)
+          return EINA_FALSE;
+     }
+   return EINA_TRUE;
+}
+
+/* the lowercased codepoint, or the unshifted key's with Shift held */
+static Eina_Unicode
+_kitty_key_code(const Keyin_Event *kev)
+{
+   Eina_Unicode cp = keyin_keysym_codepoint(kev->key);
+   Eina_Unicode lower;
+
+   if (!cp)
+     return 0;
+   lower = towlower((wint_t)cp);
+   if (lower != cp)
+     return lower;
+   if (kev->mods & KEYIN_MOD_SHIFT)
+     {
+        Eina_Unicode base = keyin_keysym_codepoint(kev->keyname);
+
+        if (base)
+          return base;
+     }
+   return cp;
+}
+
+/* CSI number[:shifted[:base]|::base][;mods+1[:action]][;text] final */
+typedef struct tag_Kitty_Sequence
+{
+   unsigned int number;       /* omitted when 1 and nothing follows it */
+   char final;
+   Eina_Unicode shifted;      /* 0 when not reported */
+   Eina_Unicode base;         /* 0 when not reported */
+   unsigned int mods;
+   int action;                /* Keyin_Action, 0 when not reported */
+   const char *text;          /* UTF-8, NULL when not reported */
+} Kitty_Sequence;
+
+/* Appends the codepoints of text, ;cp:cp…; truncated before it overflows size */
+static int
+_kitty_text_codepoints_append(char *buf, int size, const char *text)
+{
+   int len = 0;
+   int idx = 0;
+
+   while (text[idx])
+     {
+        char tmp[16];
+        Eina_Unicode cp = eina_unicode_utf8_next_get(text, &idx);
+        int written = snprintf(tmp, sizeof(tmp), len == 0 ? ";%u" : ":%u", cp);
+
+        if (written > size)
+          break;
+        memcpy(buf + len, tmp, written);
+        len += written;
+        size -= written;
+     }
+   return len;
+}
+
+static void
+_kitty_serialize(Termpty *ty, const Kitty_Sequence *seq)
+{
+   char buf[128];
+   int len;
+   Eina_Bool has_tail;
+
+   has_tail = seq->mods != 0 || seq->action != 0 || seq->text != NULL;
+
+   memcpy(buf, "\033[", 2);
+   len = 2;
+   if (seq->number != 1 || has_tail || seq->shifted != 0 || seq->base != 0)
+     len += snprintf(buf + len, sizeof(buf) - len, "%u", seq->number);
+   if (seq->shifted != 0)
+     len += snprintf(buf + len, sizeof(buf) - len, ":%u", seq->shifted);
+   if (seq->base != 0)
+     {
+        if (seq->shifted != 0)
+          len += snprintf(buf + len, sizeof(buf) - len, ":%u", seq->base);
+        else
+          len += snprintf(buf + len, sizeof(buf) - len, "::%u", seq->base);
+     }
+   if (has_tail)
+     {
+        buf[len++] = ';';
+        if (seq->mods != 0 || seq->action != 0)
+          len += snprintf(buf + len, sizeof(buf) - len, "%u", seq->mods + 1);
+        if (seq->action != 0)
+          len += snprintf(buf + len, sizeof(buf) - len, ":%d", seq->action);
+        if (seq->text != NULL)
+          len += _kitty_text_codepoints_append(buf + len, sizeof(buf) - len - 1,
+                                               seq->text);
+     }
+   buf[len] = seq->final;
+   len++;
+   termpty_write(ty, buf, len);
+}
+
+/* leaves these keys to erase_is_del, send_bs and crlf */
+static Eina_Bool
+_kitty_legacy_exception(const Keyin_Event *kev)
+{
+   if (kev->mods & ~KEYIN_MOD_LOCKS)
+     return EINA_FALSE;
+   if (strcmp(kev->key, "Return") == 0 ||
+       strcmp(kev->key, "Tab") == 0 ||
+       strcmp(kev->key, "BackSpace") == 0)
+     return EINA_TRUE;
+   /* evas may report Shift+Tab as ISO_Left_Tab without the Shift bit */
+   if (strcmp(kev->key, "ISO_Left_Tab") == 0 &&
+       !(kev->mods & KEYIN_MOD_SHIFT))
+     return EINA_TRUE;
+   return EINA_FALSE;
+}
+
+Eina_Bool
+keyin_kitty_encode(Termpty *ty, const Keyin_Event *kev, unsigned int flags)
+{
+   const Kitty_Functional_Key *fk = _kitty_functional_key_find(kev->key);
+   Kitty_Sequence seq =
+     {
+        .final = 'u',
+     };
+   Eina_Bool text_ok;
+
+   /* modifier keys send nothing unless all keys are reported */
+   if (fk && fk->is_modifier && !(flags & TERMPTY_KITTY_KBD_REPORT_ALL))
+     return EINA_TRUE;
+
+   /* releases send nothing unless event types are reported */
+   if (kev->action == KEYIN_ACTION_RELEASE &&
+       !(flags & TERMPTY_KITTY_KBD_REPORT_EVENTS))
+     return EINA_TRUE;
+
+   text_ok = _kitty_text_ok(kev);
+
+   /* legacy presses keep DECCKM, DECKPAM and modifyOtherKeys */
+   if (!(flags & (TERMPTY_KITTY_KBD_DISAMBIGUATE |
+                  TERMPTY_KITTY_KBD_REPORT_ALL)) &&
+       kev->action != KEYIN_ACTION_RELEASE)
+     return EINA_FALSE;
+
+   if (!(flags & TERMPTY_KITTY_KBD_REPORT_ALL))
+     {
+        if (text_ok)
+          {
+             termpty_write(ty, kev->string, strlen(kev->string));
+             return EINA_TRUE;
+          }
+        if (_kitty_legacy_exception(kev))
+          {
+             if (kev->action == KEYIN_ACTION_RELEASE)
+               return EINA_TRUE;
+             return EINA_FALSE;
+          }
+     }
+
+   if (fk)
+     {
+        seq.number = fk->number;
+        seq.final = fk->final;
+     }
+   else
+     {
+        seq.number = _kitty_key_code(kev);
+        if (seq.number == 0)
+          {
+             /* the text is all this key has to report */
+             if ((flags & TERMPTY_KITTY_KBD_REPORT_ALL) && text_ok)
+               termpty_write(ty, kev->string, strlen(kev->string));
+             return EINA_TRUE;
+          }
+     }
+
+   seq.mods = kev->mods;
+   if ((flags & TERMPTY_KITTY_KBD_REPORT_EVENTS) &&
+       kev->action != KEYIN_ACTION_PRESS)
+     seq.action = ""
+   if ((flags & TERMPTY_KITTY_KBD_REPORT_TEXT) &&
+       (flags & TERMPTY_KITTY_KBD_REPORT_ALL) && text_ok)
+     seq.text = kev->string;
+
+   _kitty_serialize(ty, &seq);
+   return EINA_TRUE;
+}
diff --git a/src/bin/keyin_kitty.h b/src/bin/keyin_kitty.h
new file mode 100644
index 00000000..000d4c45
--- /dev/null
+++ b/src/bin/keyin_kitty.h
@@ -0,0 +1,12 @@
+#ifndef TERMINOLOGY_KEYIN_KITTY_H_
+#define TERMINOLOGY_KEYIN_KITTY_H_ 1
+
+/* https://sw.kovidgoyal.net/kitty/keyboard-protocol/ */
+
+#include "keyin_encode.h"
+
+/* Returns EINA_FALSE when the caller must use the legacy encoding. */
+Eina_Bool
+keyin_kitty_encode(Termpty *ty, const Keyin_Event *kev, unsigned int flags);
+
+#endif
diff --git a/src/bin/meson.build b/src/bin/meson.build
index 4af06f46..ee86ff22 100644
--- a/src/bin/meson.build
+++ b/src/bin/meson.build
@@ -30,6 +30,7 @@ terminology_sources = ['private.h',
                        'keyin_encode.c', 'keyin_encode.h',
                        keyin_keysyms,
                        'keyin_keysyms.c', 'keyin_keysyms.h',
+                       'keyin_kitty.c', 'keyin_kitty.h',
                        'main.c', 'main.h',
                        'media.c', 'media.h',
                        'options.c', 'options.h',
@@ -130,6 +131,7 @@ tytest_sources = [color_names,
                   'keyin_encode.c', 'keyin_encode.h',
                   keyin_keysyms,
                   'keyin_keysyms.c', 'keyin_keysyms.h',
+                  'keyin_kitty.c', 'keyin_kitty.h',
                   'tty_keys.h', 'tytest_keyin.c',
                   'tytest.c', 'tytest.h']
 tybench_sources = [color_names,
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index 05d384e4..1ae32f36 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -107,6 +107,7 @@ static struct {
        { "keyin_backspace", tytest_keyin_backspace},
        { "keyin_keypad", tytest_keyin_keypad},
        { "keyin_keysyms", tytest_keyin_keysyms},
+       { "keyin_kitty_disambiguate", tytest_keyin_kitty_disambiguate},
        { "config_erase_is_del_upgrade", tytest_config_erase_is_del_upgrade},
        { "config_selection_read_upgrade", tytest_config_selection_read_upgrade},
        { "config_cursor_blink_timeout_upgrade", tytest_config_cursor_blink_timeout_upgrade},
diff --git a/src/bin/tytest_keyin.c b/src/bin/tytest_keyin.c
index e0e27d83..04c6a38e 100644
--- a/src/bin/tytest_keyin.c
+++ b/src/bin/tytest_keyin.c
@@ -5,10 +5,12 @@
 #include <Elementary.h>
 #include <Ecore_Input.h>
 #include <assert.h>
+#include <locale.h>
 #include <stdio.h>
 #include <string.h>
 
 #include "termpty.h"
+#include "termptyops.h"
 #include "keyin_encode.h"
 #include "unit_tests.h"
 
@@ -395,6 +397,175 @@ tytest_keyin_keypad(void)
 #undef PRESS_S
 #undef PRESS_KP
 
+/* Flag 1, disambiguate escape codes:
+ * https://sw.kovidgoyal.net/kitty/keyboard-protocol/ */
+typedef struct tag_Kitty_Case
+{
+   unsigned int flags;
+   const char *key;
+   const char *keyname;
+   const char *string;
+   unsigned int mods;
+   Keyin_Action action;
+   const char *expected;   /* "" means nothing is written */
+} Kitty_Case;
+
+#define S  KEYIN_MOD_SHIFT
+#define A  KEYIN_MOD_ALT
+#define C  KEYIN_MOD_CTRL
+#define CL KEYIN_MOD_CAPS_LOCK
+#define NL KEYIN_MOD_NUM_LOCK
+#define P  KEYIN_ACTION_PRESS
+#define R  KEYIN_ACTION_REPEAT
+#define U  KEYIN_ACTION_RELEASE
+
+static int
+_kitty_case_is(const Kitty_Case *c)
+{
+   struct ty_sb *sb = &_ty->write_buffer;
+   Keyin_Event kev = {
+      .key = c->key,
+      .keyname = c->keyname,
+      .string = c->string,
+      .mods = c->mods,
+      .action = ""
+   };
+   size_t expected_len = strlen(c->expected);
+   int bad = 0;
+
+   termpty_kitty_kbd_set(_ty, c->flags, 1);
+   ty_sb_free(sb);
+   keyin_encode_event(_ty, &kev);
+
+   /* an empty buffer has no storage: memcmp() must not see its NULL */
+   if ((sb->len != expected_len) ||
+       ((expected_len > 0) &&
+        (memcmp(sb->buf + sb->gap, c->expected, expected_len) != 0)))
+     {
+        fprintf(stderr, "\n  %s (mods %#x, action %d): got '",
+                c->key, c->mods, c->action);
+        _show(sb->buf + sb->gap, sb->len);
+        fprintf(stderr, "' want '");
+        _show(c->expected, expected_len);
+        fprintf(stderr, "'");
+        bad = 1;
+     }
+   ty_sb_free(sb);
+   return bad;
+}
+
+int
+tytest_keyin_kitty_disambiguate(void)
+{
+   static const Kitty_Case cases[] = {
+        /* flags key             keyname  string   mods    action expected */
+        { 1, "a",                "a",     "a",     0,      P,     "a" },
+        { 1, "A",                "a",     "A",     S,      P,     "A" },
+        { 1, "A",                "a",     "A",     CL,     P,     "A" },
+        { 1, "a",                "a",     "\001",  C,      P,     "\033[97;5u" },
+        { 1, "a",                "a",     "a",     A,      P,     "\033[97;3u" },
+        { 1, "A",                "a",     "A",     C|S,    P,     "\033[97;6u" },
+        { 1, "A",                "a",     "A",     A|S,    P,     "\033[97;4u" },
+        { 1, "a",                "a",     "\001",  C|CL,   P,     "\033[97;69u" },
+        { 1, "i",                "i",     "\t",    C,      P,     "\033[105;5u" },
+        { 1, "Escape",           "Escape","\033",   0,      P,     "\033[27u" },
+        { 1, "Escape",           "Escape","\033",   S,      P,     "\033[27;2u" },
+        { 1, "Return",           "Return","\r",    0,      P,     "\r" },
+        { 1, "Return",           "Return","\r",    NL,     P,     "\r" },
+        { 1, "Return",           "Return","\r",    S,      P,     "\033[13;2u" },
+        { 1, "Return",           "Return","\r",    C,      P,     "\033[13;5u" },
+        { 1, "Tab",              "Tab",   "\t",    0,      P,     "\t" },
+        { 1, "ISO_Left_Tab",     "Tab",   NULL,    S,      P,     "\033[9;2u" },
+        { 1, "BackSpace",        "BackSpace", "\b", 0,     P,     "\b" },
+        { 1, "BackSpace",        "BackSpace", "\b", C,     P,     "\033[127;5u" },
+        { 1, "BackSpace",        "BackSpace", "\b", A,     P,     "\033[127;3u" },
+        { 1, "Left",             "Left",  NULL,    0,      P,     "\033[D" },
+        { 1, "Left",             "Left",  NULL,    C,      P,     "\033[1;5D" },
+        { 1, "F1",               "F1",    NULL,    0,      P,     "\033[P" },
+        { 1, "F3",               "F3",    NULL,    S,      P,     "\033[13;2~" },
+        { 1, "F5",               "F5",    NULL,    0,      P,     "\033[15~" },
+        { 1, "Delete",           "Delete","\177",  0,      P,     "\033[3~" },
+        { 1, "Prior",            "Prior", NULL,    A,      P,     "\033[5;3~" },
+        { 1, "F13",              "F13",   NULL,    0,      P,     "\033[57376u" },
+        { 1, "KP_1",             "KP_End","1",     NL,     P,     "1" },
+        { 1, "KP_End",           "KP_End", NULL,   0,      P,     "\033[57424u" },
+        { 1, "KP_Enter",         "KP_Enter", "\r", NL,     P,     "\033[57414;129u" },
+        { 1, "KP_Begin",         "KP_Begin", NULL, 0,      P,     "\033[E" },
+        { 1, "Shift_L",          "Shift_L", NULL,  0,      P,     "" },
+        { 1, "a",                "a",     NULL,    0,      U,     "" },
+        { 1, "space",            "space", NULL,    C,      P,     "\033[32;5u" },
+        { 1, "Cyrillic_es",      "c",     "\003",  C,      P,     "\033[1089;5u" },
+        { 1, "exclam",           "1",     "!",     S,      P,     "!" },
+        { 1, "exclam",           "1",     "!",     C|S,    P,     "\033[49;6u" },
+        { 1, "at",               "q",     "@",     0,      P,     "@" },
+        { 1, "XF86AudioMute",    "XF86AudioMute", NULL, 0, P,     "\033[57440u" },
+        { 1, "a",                "a",     "a",     0,      R,     "a" },
+        { 1, "eacute",           "eacute","\xc3\xa9", C,   P,     "\033[233;5u" },
+   };
+   char *saved_locale;
+   size_t i;
+   int bad = 0;
+
+   /* towlower() needs a UTF-8 locale; the real terminal gets one from
+    * elm_init(), the harness does not */
+   saved_locale = strdup(setlocale(LC_CTYPE, NULL));
+   assert(saved_locale);
+   if (!setlocale(LC_CTYPE, "C.UTF-8"))
+     {
+        fprintf(stderr, "\n  no C.UTF-8 locale, skipping");
+        free(saved_locale);
+        return 0;
+     }
+
+   _init();
+   for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
+     bad += _kitty_case_is(&cases[i]);
+
+   /* DECCKM stays legacy: the protocol has no application cursor keys */
+   {
+      const Kitty_Case c = { 1, "Left", "Left", NULL, 0, P, "\033[D" };
+
+      _ty->termstate.appcursor = EINA_TRUE;
+      bad += _kitty_case_is(&c);
+      _ty->termstate.appcursor = EINA_FALSE;
+   }
+
+   /* erase_is_del still decides what a legacy BackSpace sends */
+   {
+      const Kitty_Case c = { 1, "BackSpace", "BackSpace", "\b", 0, P, "\177" };
+
+      _cfg.erase_is_del = EINA_TRUE;
+      bad += _kitty_case_is(&c);
+      _cfg.erase_is_del = EINA_FALSE;
+   }
+
+   /* LNM still decides what a legacy Return sends */
+   {
+      const Kitty_Case c = { 1, "Return", "Return", "\r", 0, P, "\r\n" };
+
+      _ty->termstate.crlf = 1;
+      bad += _kitty_case_is(&c);
+      _ty->termstate.crlf = 0;
+   }
+
+   _shutdown();
+   setlocale(LC_CTYPE, saved_locale);
+   free(saved_locale);
+
+   if (bad)
+     fprintf(stderr, "\n  %d wrong encoding%s", bad, bad == 1 ? "" : "s");
+   return bad;
+}
+
+#undef S
+#undef A
+#undef C
+#undef CL
+#undef NL
+#undef P
+#undef R
+#undef U
+
 static int
 _keysym_is(const char *name, Eina_Unicode want)
 {
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index aa66ca96..05a3aba8 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -107,6 +107,7 @@ int tytest_keyin_modify_other_keys_level1(void);
 int tytest_keyin_backspace(void);
 int tytest_keyin_keypad(void);
 int tytest_keyin_keysyms(void);
+int tytest_keyin_kitty_disambiguate(void);
 int tytest_config_erase_is_del_upgrade(void);
 int tytest_config_selection_read_upgrade(void);
 int tytest_config_cursor_blink_timeout_upgrade(void);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to