From 1d772d17174cdfcf3763089b42976829474ae19c Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Wed, 31 May 2023 06:24:19 +0200 Subject: [PATCH] Handle non-printable characters when ctrl is pressed This extends the list of characters we convert to non-printable characters when control is pressed by adding `backslash`, `left_bracket`, `right_bracket` to the list. This is based on the "Legacy `ctrl` mapping of ASCII keys" section in the Kitty documentation [0]. That page also links to the VT100 documentation [1] that contains Table 3-5, which shows the same mappings at the Kitty documentation. I started out wanting to add only `left_bracket` because I very often use ctrl+[ to escape insert mode in Vim (it maps to escape), but then added `backslash`, `right_bracket` too because they're next in the list and having `ctrl+right_bracket` mapped also makes it work in Vim as the default go-to-def combination. Why not complete the whole table? Some keys aren't yet handled in `input.zig`, such as `circumflex` (not defined), and mitchellh said that it'd require more elaborate handling of different keyboard layouts. So instead of adding something that might be wrong, I tried to add what I knew (and tested) to work. [0]: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#legacy-ctrl-mapping-of-ascii-keys [1]: https://vt100.net/docs/vt100-ug/chapter3.html --- src/Surface.zig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Surface.zig b/src/Surface.zig index 2701919c4..0d621f758 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -1148,6 +1148,9 @@ pub fn keyCallback( // we convert to a non-printable. if (mods_int == ctrl_only) { const val: u8 = switch (key) { + .left_bracket => 0x1B, + .backslash => 0x1C, + .right_bracket => 0x1D, .a => 0x01, .b => 0x02, .c => 0x03,