Files
Netcatty/components/terminal/runtime/nativeKittyKeyboard.test.ts
T
a03d41ebf5 fix(terminal): migrate saved Shift+Enter newline and honor xterm CSI u (#3775)
* fix(terminal): migrate the saved Shift+Enter newline once

Existing installs kept the pre-#3770 "\\n" default, so Shift+Enter still
submitted in TUI CLIs. Rewrite only that stored value to ESC+CR, and let
xterm's native CSI u own the chord when an app has opted in.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* fix(terminal): keep the Shift+Enter migration local

The one-time rewrite of a saved "\n" does not need a sync flag or a
three-way merge. An imported or synced old newline can stay as stored.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* fix(terminal): keep native kitty Shift+Enter on broadcast peers

When a target has negotiated xterm kitty keyboard and the custom
protocol setting is off, resolve the broadcast chord as CSI 13;2u
instead of the ESC+CR fallback.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>
2026-10-20 13:53:52 +08:00

69 lines
1.9 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import xterm from "@xterm/xterm";
import {
nativeKittyKeyboardPreservesShiftEnter,
readNativeKittyKeyboardFlags,
SHIFT_ENTER_CSI_U_SEQUENCE,
} from "./shiftEnterText.ts";
const { Terminal } = xterm;
type KittyProbe = {
flags: number;
shiftEnter: string | undefined;
};
const probeShiftEnter = (setup: string): Promise<KittyProbe> => {
const term = new Terminal({
cols: 80,
rows: 24,
allowProposedApi: true,
vtExtensions: { kittyKeyboard: true },
});
return new Promise((resolve) => {
term.write(setup, () => {
const event = {
type: "keydown",
key: "Enter",
code: "Enter",
shiftKey: true,
altKey: false,
ctrlKey: false,
metaKey: false,
repeat: false,
keyCode: 13,
};
const core = (term as unknown as {
_core: {
_keyboardService: {
evaluateKeyDown: (ev: object) => { key?: string };
};
};
})._core;
resolve({
flags: readNativeKittyKeyboardFlags(term),
shiftEnter: core._keyboardService.evaluateKeyDown(event).key,
});
});
});
};
test("xterm kitty keyboard encodes opted-in Shift+Enter as CSI 13;2u", async () => {
const idle = await probeShiftEnter("");
assert.equal(idle.flags, 0);
assert.equal(idle.shiftEnter, "\r");
assert.equal(nativeKittyKeyboardPreservesShiftEnter(idle.flags), false);
const disambiguate = await probeShiftEnter("\u001b[=1u");
assert.equal(disambiguate.flags, 1);
assert.equal(disambiguate.shiftEnter, SHIFT_ENTER_CSI_U_SEQUENCE);
assert.equal(nativeKittyKeyboardPreservesShiftEnter(disambiguate.flags), true);
const alternateOnly = await probeShiftEnter("\u001b[=4u");
assert.equal(alternateOnly.flags, 4);
assert.equal(alternateOnly.shiftEnter, "\r");
assert.equal(nativeKittyKeyboardPreservesShiftEnter(alternateOnly.flags), false);
});