Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(shared): skip printable spans in command output scanning #28924

Closedhieu-lee(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/28924/headopened View on GitHub

Showing 2 changed files with 42 additions and 4 deletions.

x
0 of 2 viewed, 2 left
35 additions and 0 deletionspackages/shared/src/terminalOutput.test.tsModified
View file
@@ -42,9 +42,35 @@
it("holds an escape sequence split across chunks until it finishes", () => {
const first = appendTerminalOutput(EMPTY_TERMINAL_OUTPUT, "red: \u001b[3");
expect(first.text).toBe("red: ");
+ expect(first.pending).toBe("\u001b[3");
expect(feed(["red: \u001b[3", "1mR\u001b[0m"]).text).toBe("red: \u001b[0;31mR\u001b[0m");
});
​
+ it("preserves tabs and Unicode while ignoring non-cursor C0, DEL and C1 controls", () => {
+ const ignored = Array.from({ length: 160 }, (_, code) => code)
+ .filter((code) => code < 32 || code >= 127)
+ .filter((code) => ![8, 9, 10, 13, 27].includes(code));
+ for (const code of ignored) {
+ const state = feed([`a\t界é😀${String.fromCharCode(code)}z`]);
+ expect(state.text).toBe("a\t界é😀z");
+ expect(state.pending).toBe("");
+ expect(state.screen.col).toBe(8);
+ }
+ expect(feed(["a\t界é\ud83d", "\ude00z"]).text).toBe("a\t界é😀z");
+ expect(feed(["ab\bc\rd\ne"]).text).toBe("dc\ne");
+ });
+​
+ it("keeps pending escapes and control scanning independent between interleaved feeds", () => {
+ const first = appendTerminalOutput(EMPTY_TERMINAL_OUTPUT, "alpha\u001b[3");
+ const second = appendTerminalOutput(EMPTY_TERMINAL_OUTPUT, "\rB\t界😀\u009f");
+ const completed = appendTerminalOutput(first, "1mR\u001b[0m\bX");
+ expect(completed.text).toBe("alphaX");
+ expect(completed.pending).toBe("");
+ expect(appendTerminalOutput(second, "\rC").text).toBe("C\t界😀");
+ expect(first.pending).toBe("\u001b[3");