szn

Bug 352 — Kitty functional-key encoding wrong in writeKeyToPty

352. Wrong kitty codepoints + Enter-as-LF inconsistency

File: src/server/server.zig:1155-1166 (arrows), src/server/server.zig:1178-1181 (Enter) Severity: MEDIUM Status: ✅ FIXED

Correction on filing

The “kitty Enter forwarded as LF” half of this entry was wrong: CSI 13u decodes to char code 13 (0x0D = CR), which the raw <0x20 branch already forwards byte-exact as \r. Only the codepoint table was broken.

Fix (applied)

writeKeyToPty now maps the spec functional-key table: ESCAPE=57344→\e, ENTER=57345→\r, TAB=57346→\t, BACKSPACE=57347→\x7f, and arrows LEFT/RIGHT/UP/DOWN=57350-57353 → SS3 sequences. The old table sent Escape as Up-arrow etc.

Test: writeKeyToPty maps kitty functional codepoints per spec — bug #352 (all eight codepoints forwarded over a fake pty pipe).

Problem

Two defects in the kitty-key forwarding path:

  1. Wrong codepoint table.
    // Kitty private-use arrow codepoints (57344-57347)
    if (ch.code >= 57344 and ch.code <= 57347) {
        const seq: []const u8 = switch (ch.code) {
            57344 => "\x1bOA", // ← spec: ESCAPE
            57345 => "\x1bOB", // ← spec: ENTER
            57347 => "\x1bOC", // ← spec: BACKSPACE
            57346 => "\x1bOD", // ← spec: TAB
    

    Per the kitty keyboard protocol functional-key table: 57344=ESCAPE, 57345=ENTER, 57346=TAB, 57347=BACKSPACE, INSERT=57348, DELETE=57349, LEFT=57350, RIGHT=57351, UP=57352, DOWN=57353. If a CSI-u sequence carrying these codepoints ever decodes (e.g. szn run under a terminal that reports all keys), Escape would be delivered as Up-arrow etc.

  2. Kitty Enter inconsistency. CSI 13u parses as char.code == 13, which misses the Tab special-case (only code 9 is handled) and falls into the ch.code < 0x20 branch, forwarding raw 0x0A (LF) — whereas normal Enter forwards \r (bug 349 territory: readline distinguishes C-j/C-m).

Fix (proposed)

Correct the table to spec values (57350-57353 → arrows, plus ESCAPE/ENTER/TAB/BACKSPACE mappings), special-case ch.code == 13 to emit \r like .enter, and route 57345 through it. Currently latent (szn never requests kitty mode on the outer tty) but wrong and load-bearing once enabled.