mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 13:44:58 +00:00
refactor: dedupe channel and gateway surfaces
This commit is contained in:
@@ -22,6 +22,20 @@ function configureTerminalIO(params: {
|
||||
(process.stdin as { isPaused?: () => boolean }).isPaused = params.isPaused;
|
||||
}
|
||||
|
||||
function setupPausedTTYStdin() {
|
||||
const setRawMode = vi.fn();
|
||||
const resume = vi.fn();
|
||||
const isPaused = vi.fn(() => true);
|
||||
configureTerminalIO({
|
||||
stdinIsTTY: true,
|
||||
stdoutIsTTY: false,
|
||||
setRawMode,
|
||||
resume,
|
||||
isPaused,
|
||||
});
|
||||
return { setRawMode, resume };
|
||||
}
|
||||
|
||||
describe("restoreTerminalState", () => {
|
||||
const originalStdinIsTTY = process.stdin.isTTY;
|
||||
const originalStdoutIsTTY = process.stdout.isTTY;
|
||||
@@ -45,17 +59,7 @@ describe("restoreTerminalState", () => {
|
||||
});
|
||||
|
||||
it("does not resume paused stdin by default", () => {
|
||||
const setRawMode = vi.fn();
|
||||
const resume = vi.fn();
|
||||
const isPaused = vi.fn(() => true);
|
||||
|
||||
configureTerminalIO({
|
||||
stdinIsTTY: true,
|
||||
stdoutIsTTY: false,
|
||||
setRawMode,
|
||||
resume,
|
||||
isPaused,
|
||||
});
|
||||
const { setRawMode, resume } = setupPausedTTYStdin();
|
||||
|
||||
restoreTerminalState("test");
|
||||
|
||||
@@ -64,17 +68,7 @@ describe("restoreTerminalState", () => {
|
||||
});
|
||||
|
||||
it("resumes paused stdin when resumeStdin is true", () => {
|
||||
const setRawMode = vi.fn();
|
||||
const resume = vi.fn();
|
||||
const isPaused = vi.fn(() => true);
|
||||
|
||||
configureTerminalIO({
|
||||
stdinIsTTY: true,
|
||||
stdoutIsTTY: false,
|
||||
setRawMode,
|
||||
resume,
|
||||
isPaused,
|
||||
});
|
||||
const { setRawMode, resume } = setupPausedTTYStdin();
|
||||
|
||||
restoreTerminalState("test", { resumeStdinIfPaused: true });
|
||||
|
||||
|
||||
@@ -48,44 +48,13 @@ describe("renderTable", () => {
|
||||
],
|
||||
});
|
||||
|
||||
const ESC = "\u001b";
|
||||
for (let i = 0; i < out.length; i += 1) {
|
||||
if (out[i] !== ESC) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// SGR: ESC [ ... m
|
||||
if (out[i + 1] === "[") {
|
||||
let j = i + 2;
|
||||
while (j < out.length) {
|
||||
const ch = out[j];
|
||||
if (ch === "m") {
|
||||
break;
|
||||
}
|
||||
if (ch && ch >= "0" && ch <= "9") {
|
||||
j += 1;
|
||||
continue;
|
||||
}
|
||||
if (ch === ";") {
|
||||
j += 1;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
expect(out[j]).toBe("m");
|
||||
i = j;
|
||||
continue;
|
||||
}
|
||||
|
||||
// OSC-8: ESC ] 8 ; ; ... ST (ST = ESC \)
|
||||
if (out[i + 1] === "]" && out.slice(i + 2, i + 5) === "8;;") {
|
||||
const st = out.indexOf(`${ESC}\\`, i + 5);
|
||||
expect(st).toBeGreaterThanOrEqual(0);
|
||||
i = st + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new Error(`Unexpected escape sequence at index ${i}`);
|
||||
const ansiToken = new RegExp(String.raw`\u001b\[[0-9;]*m|\u001b\]8;;.*?\u001b\\`, "gs");
|
||||
let escapeIndex = out.indexOf("\u001b");
|
||||
while (escapeIndex >= 0) {
|
||||
ansiToken.lastIndex = escapeIndex;
|
||||
const match = ansiToken.exec(out);
|
||||
expect(match?.index).toBe(escapeIndex);
|
||||
escapeIndex = out.indexOf("\u001b", escapeIndex + 1);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user