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 8d7aa5adab718e2182298250f6d7f9ba23f4a386
Author: Boris Faure <[email protected]>
AuthorDate: Sat Nov 14 22:41:47 2026 +0000
termptyesc: answer the kitty keyboard query
Answer CSI ? u with the current flags, masked to the implemented ones,
so that a client can detect the protocol and fall back on what is
missing: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#detection
---
src/bin/termpty.c | 25 ++++++++++++++++++-------
src/bin/termptyesc.c | 13 ++++++++++++-
src/bin/tytest.c | 2 +-
src/bin/unit_tests.h | 2 +-
tests/kitty-kbd-altscreen.sh | 15 +++++++++++++++
tests/kitty-kbd-malformed.sh | 6 ++++++
tests/kitty-kbd-query.sh | 18 ++++++++++++++++++
tests/kitty-kbd-reset.sh | 10 ++++++++++
tests/kitty-kbd-stack.sh | 24 ++++++++++++++++++++++++
tests/kitty-kbd-unsupported.sh | 6 ++++++
tests/tests.results | 6 ++++++
11 files changed, 117 insertions(+), 10 deletions(-)
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 589ca18a..fd7ca271 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -3418,19 +3418,30 @@ tytest_color_scheme_notify(void)
return 0;
}
-/* Unanswered kitty sequences are how a client keeps to legacy encoding */
+/* The kitty keyboard query answers the stored, masked flags */
int
-tytest_kitty_keyboard_ignored(void)
+tytest_kitty_kbd_query(void)
{
Termpty ty;
_ty_test_init(&ty, 80, 24);
- _ty_feed(&ty, "\x1b[?u"); /* query */
- _ty_feed(&ty, "\x1b[?0u"); /* query */
- _ty_feed(&ty, "\x1b[>1u"); /* push */
- _ty_feed(&ty, "\x1b[<1u"); /* pop */
- _ty_feed(&ty, "\x1b[=1;1u"); /* set */
+ _ty_feed(&ty, "\x1b[?u"); /* query */
+ _ty_reply_is(&ty, "\x1b[?0u");
+
+ /* a parameter is ignored */
+ _ty_feed(&ty, "\x1b[?0u");
+ _ty_reply_is(&ty, "\x1b[?0u");
+
+ /* only implemented flags are stored and answered */
+ _ty_feed(&ty, "\x1b[>5u"); /* push */
+ _ty_feed(&ty, "\x1b[?u");
+ _ty_reply_is(&ty, "\x1b[?1u");
+ _ty_feed(&ty, "\x1b[<u"); /* pop */
+ _ty_feed(&ty, "\x1b[=5;1u"); /* set */
+ _ty_feed(&ty, "\x1b[?u");
+ _ty_reply_is(&ty, "\x1b[?1u");
+ _ty_feed(&ty, "\x1b[=0;1u"); /* set */
assert(ty.write_buffer.len == 0);
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 0e174b32..4b7a9629 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -3748,6 +3748,17 @@ _seq_incomplete(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *cc)
}
/* https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement */
+static void
+_kitty_kbd_reply(Termpty *ty)
+{
+ char bf[16];
+ int len;
+
+ len = snprintf(bf, sizeof(bf), "\033[?%uu",
+ termpty_kitty_kbd_flags_get(ty));
+ termpty_write(ty, bf, len);
+}
+
static void
_handle_esc_csi_kitty_kbd(Termpty *ty, Eina_Unicode **ptr)
{
@@ -3758,7 +3769,7 @@ _handle_esc_csi_kitty_kbd(Termpty *ty, Eina_Unicode **ptr)
switch (cmd)
{
case '?':
- DBG("ignoring kitty keyboard query");
+ _kitty_kbd_reply(ty);
break;
case '>':
flags = _csi_arg_get(ty, &b);
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index 1ae32f36..302e4807 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -99,7 +99,7 @@ static struct {
{ "decrqm", tytest_decrqm},
{ "kam", tytest_kam},
{ "color_scheme_notify", tytest_color_scheme_notify},
- { "kitty_keyboard_ignored", tytest_kitty_keyboard_ignored},
+ { "kitty_kbd_query", tytest_kitty_kbd_query},
{ "kitty_kbd_stack", tytest_kitty_kbd_stack},
{ "keyin_legacy", tytest_keyin_legacy},
{ "keyin_modify_other_keys", tytest_keyin_modify_other_keys},
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index 05a3aba8..05b2395c 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -72,7 +72,7 @@ int tytest_decrqss_settings(void);
int tytest_decrqm(void);
int tytest_kam(void);
int tytest_color_scheme_notify(void);
-int tytest_kitty_keyboard_ignored(void);
+int tytest_kitty_kbd_query(void);
int tytest_kitty_kbd_stack(void);
int tytest_vs16_regression_no_scroll(void);
int tytest_vs16_bare_narrow(void);
diff --git a/tests/kitty-kbd-altscreen.sh b/tests/kitty-kbd-altscreen.sh
new file mode 100644
index 00000000..1614cec9
--- /dev/null
+++ b/tests/kitty-kbd-altscreen.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+# kitty keyboard protocol: one stack per screen, kept across switches
+printf '\033[>1u'
+# 1049: the alternate screen starts with its own empty stack
+printf '\033[?1049h\033[?u'
+printf '\033[>1u\033[?u'
+# back on main: still 1
+printf '\033[?1049l\033[?u'
+# the alternate stack survived the switch
+printf '\033[?1049h\033[?u\033[<u\033[?1049l'
+# 47 and 1047 select the same stacks
+printf '\033[?47h\033[?u\033[?47l'
+printf '\033[?1047h\033[>1u\033[?1047l\033[?u'
+printf '\033[?1047h\033[?u\033[<u\033[?1047l'
+printf '\033[<u\033[?u'
diff --git a/tests/kitty-kbd-malformed.sh b/tests/kitty-kbd-malformed.sh
new file mode 100644
index 00000000..297ed45d
--- /dev/null
+++ b/tests/kitty-kbd-malformed.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+# kitty keyboard protocol: oversized parameters must not crash or push
+printf '\033[>99999999999u\033[?u'
+printf '\033[<99999999999u\033[?u'
+printf '\033[=1;99999999999u\033[?u'
+printf '\033[=1;0u\033[?u'
diff --git a/tests/kitty-kbd-query.sh b/tests/kitty-kbd-query.sh
new file mode 100644
index 00000000..1408e9d3
--- /dev/null
+++ b/tests/kitty-kbd-query.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+# kitty keyboard protocol: query, set modes and missing parameters
+# default flags are 0
+printf '\033[?u'
+# CSI = flags u, mode defaults to 1 (assign)
+printf '\033[=1u\033[?u'
+# mode 3 clears, mode 2 ORs
+printf '\033[=1;3u\033[?u'
+printf '\033[=1;2u\033[?u'
+# unknown mode is ignored
+printf '\033[=0;4u\033[?u'
+# missing flags means 0
+printf '\033[=u\033[?u'
+# the query ignores a parameter
+printf '\033[=1u\033[?0u'
+printf '\033[=0u'
+# CSI u without parameter is still SCORC
+printf '\033[5;7Hx\033[s\033[1;1H\033[uy'
diff --git a/tests/kitty-kbd-reset.sh b/tests/kitty-kbd-reset.sh
new file mode 100644
index 00000000..c3cc2dff
--- /dev/null
+++ b/tests/kitty-kbd-reset.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+# kitty keyboard protocol: RIS and DECSTR clear both stacks
+printf '\033[>1u\033[?1049h\033[>1u'
+# DECSTR
+printf '\033[!p\033[?u'
+printf '\033[?1049l\033[?u'
+printf '\033[>1u\033[?1049h\033[>1u\033[?1049l'
+# RIS
+printf '\033c\033[?u'
+printf '\033[?1049h\033[?u\033[?1049l'
diff --git a/tests/kitty-kbd-stack.sh b/tests/kitty-kbd-stack.sh
new file mode 100644
index 00000000..3ffb78a0
--- /dev/null
+++ b/tests/kitty-kbd-stack.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+# kitty keyboard protocol: push, pop, eviction and over-pop
+# push without parameter pushes 0
+printf '\033[>1u\033[>u\033[?u'
+# pop without parameter pops 1
+printf '\033[<u\033[?u'
+# pop more than the depth resets to 0
+printf '\033[<10u\033[?u'
+# CSI < 0 u pops nothing
+printf '\033[>1u\033[<0u\033[?u'
+printf '\033[<u'
+# 9 pushes into a stack of 8 evict the oldest:
+# base 0 then 1,0,1,0,1,0,1 fills the 8 slots,
+# the 8th push (0) evicts the base, the 9th (1) evicts the leading 1,
+# leaving 0,1,0,1,0,1,0,1
+printf '\033[>1u\033[>0u\033[>1u\033[>0u\033[>1u'
+printf '\033[>0u\033[>1u\033[>0u\033[>1u'
+# pop 7: the remaining entry is the second push, 0
+printf '\033[<7u\033[?u'
+# one more pop empties the stack
+printf '\033[<u\033[?u'
+# set on an empty stack, then push and pop return to it
+printf '\033[=1u\033[>0u\033[?u\033[<u\033[?u'
+printf '\033[<u\033[?u'
diff --git a/tests/kitty-kbd-unsupported.sh b/tests/kitty-kbd-unsupported.sh
new file mode 100644
index 00000000..5c46d596
--- /dev/null
+++ b/tests/kitty-kbd-unsupported.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+# kitty keyboard protocol: only implemented flags are stored and reported
+printf '\033[>31u\033[?u'
+printf '\033[=127u\033[?u'
+printf '\033[=0u\033[=4;2u\033[?u'
+printf '\033[<u'
diff --git a/tests/tests.results b/tests/tests.results
index bff12af4..fe98f3e2 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -242,3 +242,9 @@ scroll-region-counts.sh 342c990e76a9bcc7a6be7a939685d841
zero-width-wrapnext.sh 24fc65e89f6438b48ee2882e2cf2bb21
wide-unicode-18.sh 720a9c33382672f78d2045722b69d610
zero-width.sh 13feb72c327f04b5891b256de112d1d9
+kitty-kbd-query.sh 2aeecb0992989a62a9b4cf5ce687852f
+kitty-kbd-stack.sh 1940619ffdbe765b2495edbce9cf22cc
+kitty-kbd-altscreen.sh df9913f9d85f856c75dd525a806da4f6
+kitty-kbd-reset.sh bd10ee95b6b71d150fbe1a11c7b6ac94
+kitty-kbd-unsupported.sh e1de2502f1ec6c40e2bee6f0f2f54bf3
+kitty-kbd-malformed.sh bd10ee95b6b71d150fbe1a11c7b6ac94
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.