mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-20 15:19:16 +00:00
* fix(terminal): forward xterm onBinary for legacy mouse (#3811) Legacy DEC mouse (ttymouse=xterm2) is emitted via onBinary; only onData was wired. Preserve 0-255 through the write path with a binary/latin1 Buffer so high coordinate bytes are not UTF-8-corrupted. * chore: retrigger CI after lint-and-test runner shutdown (exit 143) * chore: retrigger CI after lint-and-test runner shutdown (2) --------- Co-authored-by: binaricat <binaricat@users.noreply.github.com>
41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import test from "node:test";
|
|
import { runInNewContext } from "node:vm";
|
|
|
|
const source = readFileSync(new URL("./createXTermRuntime.ts", import.meta.url), "utf8");
|
|
const start = source.indexOf(" term.onBinary((data) => {");
|
|
const end = source.indexOf(" const handleKittyKeyboardBroadcast =", start);
|
|
assert.ok(start >= 0 && end > start, "runtime must subscribe to xterm onBinary");
|
|
|
|
test("onBinary forwards unchanged bytes only to the current session without text handling", () => {
|
|
const writes: Array<{ id: string; data: string; binary: boolean }> = [];
|
|
const sessionRef: { current: string | null } = { current: "first" };
|
|
let receive!: (data: string) => void;
|
|
runInNewContext(source.slice(start, end), {
|
|
term: { onBinary(callback: typeof receive) { receive = callback; } },
|
|
ctx: {
|
|
sessionRef,
|
|
terminalBackend: {
|
|
writeToSession(id: string, data: string, options: { binary: boolean }) {
|
|
writes.push({ id, data, binary: options.binary });
|
|
},
|
|
},
|
|
},
|
|
handleTerminalInputData: () => assert.fail("binary reports must bypass text handling"),
|
|
});
|
|
|
|
const mouse = String.fromCharCode(0x1b, 0x5b, 0x4d, 0x20, 0x21, 0xc0);
|
|
receive(mouse);
|
|
sessionRef.current = "replacement";
|
|
const allBytes = String.fromCharCode(...Array.from({ length: 256 }, (_, i) => i));
|
|
receive(allBytes);
|
|
sessionRef.current = null;
|
|
receive(mouse);
|
|
|
|
assert.deepEqual(writes, [
|
|
{ id: "first", data: mouse, binary: true },
|
|
{ id: "replacement", data: allBytes, binary: true },
|
|
]);
|
|
});
|