mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 17:00:45 +00:00
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import assert from "node:assert";
|
|
import { describe, it } from "node:test";
|
|
import { type Component, TUI } from "../src/tui.js";
|
|
import { VirtualTerminal } from "./virtual-terminal.js";
|
|
|
|
class TestComponent implements Component {
|
|
lines: string[] = [];
|
|
render(_width: number): string[] {
|
|
return this.lines;
|
|
}
|
|
invalidate(): void {}
|
|
}
|
|
|
|
describe("TUI differential rendering", () => {
|
|
it("tracks cursor correctly when content shrinks with unchanged remaining lines", async () => {
|
|
const terminal = new VirtualTerminal(40, 10);
|
|
const tui = new TUI(terminal);
|
|
const component = new TestComponent();
|
|
tui.addChild(component);
|
|
|
|
// Initial render: 5 identical lines
|
|
component.lines = ["Line 0", "Line 1", "Line 2", "Line 3", "Line 4"];
|
|
tui.start();
|
|
await terminal.flush();
|
|
|
|
// Shrink to 3 lines, all identical to before (no content changes in remaining lines)
|
|
component.lines = ["Line 0", "Line 1", "Line 2"];
|
|
tui.requestRender();
|
|
await terminal.flush();
|
|
|
|
// cursorRow should be 2 (last line of new content)
|
|
// Verify by doing another render with a change on line 1
|
|
component.lines = ["Line 0", "CHANGED", "Line 2"];
|
|
tui.requestRender();
|
|
await terminal.flush();
|
|
|
|
const viewport = terminal.getViewport();
|
|
// Line 1 should show "CHANGED", proving cursor tracking was correct
|
|
assert.ok(viewport[1]?.includes("CHANGED"), `Expected "CHANGED" on line 1, got: ${viewport[1]}`);
|
|
|
|
tui.stop();
|
|
});
|
|
});
|