Terminals in a drawer below the conversation with a tab each; a tabbed right column; the message editor in the composer's place
This commit is contained in:
1 parent
c2696328fe
commit
0d7a5cc051
6 files changed
+529
-103
No files matched your search
+145
-23
@@ -1,6 +1,11 @@
|
||||
import { afterEach, describe, expect, test } from "bun:test";
|
||||
import { mkdtempSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { fakeSession, renderApp, v2ThreadId } from "./harness.tsx";
|
||||
import { loadLayout } from "../../src/layout.ts";
|
||||
import { withReply } from "./fixtures.ts";
|
||||
import { fakeSession, renderApp, v2ShellSnapshot, v2ThreadId } from "./harness.tsx";
|
||||
|
||||
let app: Awaited<ReturnType<typeof renderApp>> | null = null;
|
||||
const open = async (...args: Parameters<typeof renderApp>) => (app = await renderApp(...args));
|
||||
@@ -11,16 +16,21 @@ afterEach(() => {
|
||||
|
||||
const terminal = { threadId: v2ThreadId, terminalId: "term-1", cwd: "/workspace/project", worktreePath: null, status: "running", pid: 42, exitCode: null, exitSignal: null, hasRunningSubprocess: false, label: "", updatedAt: "2026-06-20T00:00:00.000Z" };
|
||||
const snapshot = { type: "snapshot", threadId: v2ThreadId, terminalId: "term-1", createdAt: "2026-06-20T00:00:00.000Z", snapshot: { history: "earlier output\r\nuser@host:~$ " } };
|
||||
const withTerminal = (events: readonly unknown[] = [snapshot]) => fakeSession({ terminals: [terminal], terminalEvents: events });
|
||||
const withTerminal = (events: readonly unknown[] = [snapshot]) => fakeSession({ terminals: [terminal], terminalEvents: events, projection: withReply("The reply above the drawer.", false) });
|
||||
|
||||
describe("terminal pane", () => {
|
||||
test("ctrl+j opens the thread's terminal in the pane, with its scrollback, and takes every key", async () => {
|
||||
describe("terminal drawer", () => {
|
||||
test("ctrl+j opens the thread's terminal in a drawer below the conversation, with its scrollback, and it takes every key", async () => {
|
||||
const app = await open({ session: withTerminal() });
|
||||
await app.press("j", { ctrl: true });
|
||||
expect(app.frame()).toContain("Terminal · Terminal 1");
|
||||
expect(app.frame()).toContain("Terminal 1 +");
|
||||
expect(app.frame()).toContain("user@host:~$");
|
||||
expect(app.calls("attachTerminal")).toHaveLength(1);
|
||||
expect(app.hints()).toBe("ctrl+\\ leave pane");
|
||||
// Between the conversation and the composer, the conversation's full width.
|
||||
const tab = app.find("Terminal 1 +");
|
||||
expect(tab.y).toBeGreaterThan(app.find("The reply above").y);
|
||||
expect(tab.y).toBeLessThan(app.find("Press i to type").y);
|
||||
expect(tab.x).toBeLessThan(app.find("Press i to type").x);
|
||||
await app.press("q");
|
||||
await app.press("escape");
|
||||
expect(app.calls("writeTerminal").map((call) => call.args[2])).toEqual(["q", "\x1b"]);
|
||||
@@ -28,7 +38,7 @@ describe("terminal pane", () => {
|
||||
expect(app.frame()).toContain("user@host:~$");
|
||||
});
|
||||
|
||||
test("ctrl+\\ leaves the pane and comes back to it; a click focuses it too", async () => {
|
||||
test("ctrl+\\ leaves the drawer and comes back to it; a click focuses it too", async () => {
|
||||
const app = await open({ session: withTerminal() });
|
||||
await app.press("j", { ctrl: true });
|
||||
await app.press("\\", { ctrl: true });
|
||||
@@ -43,32 +53,108 @@ describe("terminal pane", () => {
|
||||
expect(app.hints()).toBe("ctrl+\\ leave pane");
|
||||
});
|
||||
|
||||
test("it takes the details column's place, and the conversation's when the window is narrow", async () => {
|
||||
const wide = await open({ width: 200, session: withTerminal() });
|
||||
await wide.press("j", { ctrl: true });
|
||||
const title = wide.find("Terminal · Terminal 1");
|
||||
expect(title.x).toBeGreaterThan(200 - 38 - 1);
|
||||
expect(wide.frame()).not.toContain("/workspace/project ·");
|
||||
wide.destroy();
|
||||
const narrow = await open({ width: 100, session: withTerminal() });
|
||||
await narrow.press("j", { ctrl: true });
|
||||
expect(narrow.find("Terminal · Terminal 1").x).toBeLessThan(50);
|
||||
test("ctrl+j hides the drawer again, from it or from the conversation, and brings back the same terminal", async () => {
|
||||
const app = await open({ session: withTerminal() });
|
||||
await app.press("j", { ctrl: true });
|
||||
await app.press("j", { ctrl: true });
|
||||
expect(app.frame()).not.toContain("user@host");
|
||||
expect(app.hints()).toStartWith("j/k threads");
|
||||
await app.press("j", { ctrl: true });
|
||||
expect(app.frame()).toContain("user@host");
|
||||
await app.press("\\", { ctrl: true });
|
||||
await app.press("j", { ctrl: true });
|
||||
expect(app.frame()).not.toContain("user@host");
|
||||
expect(app.calls("writeTerminal")).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("the pane closes when the terminal does", async () => {
|
||||
const app = await open({ session: withTerminal([snapshot, { type: "closed", threadId: v2ThreadId, terminalId: "term-1", createdAt: "2026-06-20T00:00:00.000Z" }]) });
|
||||
test("each terminal is a tab: a click, alt+1…9, or the T picker switches; + opens another", async () => {
|
||||
const second = { ...terminal, terminalId: "term-2" };
|
||||
const app = await open({ session: fakeSession({ terminals: [terminal, second], terminalEvents: [snapshot] }) });
|
||||
await app.press("j", { ctrl: true });
|
||||
expect(app.frame()).not.toContain("Terminal · Terminal 1");
|
||||
expect(app.frame()).toContain("Terminal 1 Terminal 2 +");
|
||||
const attached = () => app.calls("attachTerminal").map((call) => (call.args[0] as { terminalId: string }).terminalId);
|
||||
expect(attached()).toEqual(["term-1"]);
|
||||
await app.press("2", { meta: true });
|
||||
expect(attached()).toEqual(["term-1", "term-2"]);
|
||||
// From the conversation too, while the drawer shows.
|
||||
await app.press("\\", { ctrl: true });
|
||||
await app.press("1", { meta: true });
|
||||
expect(attached()).toEqual(["term-1", "term-2", "term-1"]);
|
||||
const tab = app.find("Terminal 2");
|
||||
await app.click(tab.x, tab.y);
|
||||
expect(attached()).toEqual(["term-1", "term-2", "term-1", "term-2"]);
|
||||
await app.press("T");
|
||||
await app.press("return");
|
||||
expect(attached().at(-1)).toBe("term-1");
|
||||
const plus = app.find("Terminal 2 +");
|
||||
await app.click(plus.x + "Terminal 2 ".length, plus.y);
|
||||
expect(app.calls("openTerminal")).toHaveLength(1);
|
||||
expect(app.frame()).toContain("Terminal 1 Terminal 2 Terminal 3 +");
|
||||
expect(attached().at(-1)).toBe("term-3");
|
||||
});
|
||||
|
||||
test("a terminal that closes takes its tab away, and the last one the drawer", async () => {
|
||||
const closed = { type: "closed", threadId: v2ThreadId, terminalId: "term-1", createdAt: "2026-06-20T00:00:00.000Z" };
|
||||
const app = await open({ session: withTerminal([snapshot, closed]) });
|
||||
await app.press("j", { ctrl: true });
|
||||
expect(app.frame()).not.toContain("Terminal 1 +");
|
||||
expect(app.hints()).toBe("Terminal closed");
|
||||
});
|
||||
|
||||
test("dragging the drawer's edge resizes it and keeps the height; right-click resets it", async () => {
|
||||
const app = await open({ session: withTerminal() });
|
||||
await app.press("j", { ctrl: true });
|
||||
await app.press("\\", { ctrl: true });
|
||||
const tabs = () => app.find("Terminal 1 +").y;
|
||||
const before = tabs();
|
||||
const edge = app.find("━");
|
||||
await app.mockMouse.drag(edge.x + 5, edge.y, edge.x + 5, edge.y - 4);
|
||||
await app.settle(100);
|
||||
expect(tabs()).toBe(before - 4);
|
||||
expect((await loadLayout()).drawerHeight).toBeGreaterThan(0);
|
||||
await app.click(edge.x + 5, edge.y - 4, 2);
|
||||
expect(tabs()).toBe(before);
|
||||
expect((await loadLayout()).drawerHeight).toBeNull();
|
||||
});
|
||||
|
||||
test("on a short window the drawer takes the conversation's place", async () => {
|
||||
const app = await open({ height: 22, session: withTerminal() });
|
||||
expect(app.frame()).toContain("The reply above");
|
||||
await app.press("j", { ctrl: true });
|
||||
expect(app.frame()).toContain("user@host:~$");
|
||||
expect(app.frame()).not.toContain("The reply above");
|
||||
expect(app.frame()).toContain("Press i to type");
|
||||
});
|
||||
|
||||
test("Move terminal to the side puts terminals in the right column's Terminal tab, and stays", async () => {
|
||||
const app = await open({ width: 200, session: withTerminal() });
|
||||
await app.press("k", { ctrl: true });
|
||||
await app.type("move terminal to the side");
|
||||
await app.press("return");
|
||||
expect((await loadLayout()).terminalPlacement).toBe("side");
|
||||
await app.press("j", { ctrl: true });
|
||||
expect(app.frame()).toContain("Details Terminal");
|
||||
const tab = app.find("Terminal 1 +");
|
||||
expect(tab.x).toBeGreaterThan(200 - 38 - 1);
|
||||
expect(app.hints()).toBe("ctrl+\\ leave pane");
|
||||
// { and } step through the column's tabs from the conversation.
|
||||
await app.press("\\", { ctrl: true });
|
||||
await app.press("{");
|
||||
expect(app.frame()).not.toContain("user@host");
|
||||
expect(app.frame()).toContain("/workspace/project");
|
||||
await app.press("}");
|
||||
expect(app.frame()).toContain("user@host");
|
||||
await app.press("j", { ctrl: true });
|
||||
expect(app.frame()).not.toContain("Details Terminal");
|
||||
});
|
||||
|
||||
test("the T picker can still attach full screen", async () => {
|
||||
const app = await open({ session: withTerminal() });
|
||||
await app.press("T");
|
||||
expect(app.frame()).toContain("Attach full screen");
|
||||
});
|
||||
|
||||
test("ctrl+g writes the message in $EDITOR in the pane, and what's saved comes back", async () => {
|
||||
test("ctrl+g writes the message in $EDITOR in the composer's place, and what's saved comes back", async () => {
|
||||
const previous = { visual: process.env.VISUAL, editor: process.env.EDITOR };
|
||||
delete process.env.VISUAL;
|
||||
// Run as `$EDITOR "$1"`: this one waits a moment, overwrites the file and exits.
|
||||
@@ -77,21 +163,28 @@ describe("terminal pane", () => {
|
||||
const app = await open();
|
||||
await app.press("i");
|
||||
await app.type("draft");
|
||||
const composer = app.find("draft");
|
||||
await app.press("g", { ctrl: true });
|
||||
expect(app.frame()).toContain("Message · save and quit");
|
||||
expect(app.frame()).not.toContain("draft");
|
||||
expect(app.find("Message · save and quit").x).toBeLessThan(composer.x);
|
||||
expect(app.hints()).toBe("ctrl+\\ leave pane");
|
||||
for (let tries = 0; tries < 40 && app.frame().includes("Message · save and quit"); tries++) await app.settle(50);
|
||||
expect(app.frame()).not.toContain("Message · save and quit");
|
||||
expect(app.frame()).toContain("from the editor");
|
||||
expect(app.hints()).toStartWith("enter send");
|
||||
} finally {
|
||||
if (previous.visual !== undefined) process.env.VISUAL = previous.visual;
|
||||
if (previous.editor === undefined) delete process.env.EDITOR;
|
||||
else process.env.EDITOR = previous.editor;
|
||||
restoreEditor(previous);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const restoreEditor = (previous: { visual: string | undefined; editor: string | undefined }) => {
|
||||
if (previous.visual !== undefined) process.env.VISUAL = previous.visual;
|
||||
if (previous.editor === undefined) delete process.env.EDITOR;
|
||||
else process.env.EDITOR = previous.editor;
|
||||
};
|
||||
|
||||
describe("editing a changed file", () => {
|
||||
const vcs = {
|
||||
status: "live",
|
||||
@@ -108,4 +201,33 @@ describe("editing a changed file", () => {
|
||||
// The fixture's workspace isn't on this machine.
|
||||
expect(app.hints()).toBe("README.md isn't on this machine.");
|
||||
});
|
||||
|
||||
test("a file on this machine opens in the column's Editor tab, which closes when the editor does", async () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "t3tui-edit-"));
|
||||
writeFileSync(join(root, "README.md"), "hello\n");
|
||||
const project = { ...v2ShellSnapshot.projects[0]!, workspaceRoot: root };
|
||||
const previous = { visual: process.env.VISUAL, editor: process.env.EDITOR };
|
||||
delete process.env.VISUAL;
|
||||
process.env.EDITOR = "sleep 0.6; true";
|
||||
try {
|
||||
const app = await open({ width: 200, session: fakeSession({ vcs, snapshot: { ...v2ShellSnapshot, projects: [project] } }) });
|
||||
await app.press("l");
|
||||
await app.press("o");
|
||||
expect(app.frame()).toContain("Details Editor");
|
||||
expect(app.frame()).toContain("Editing README.md");
|
||||
expect(app.find("Details Editor").x).toBeGreaterThan(200 - 38 - 1);
|
||||
expect(app.hints()).toBe("ctrl+\\ leave pane");
|
||||
// Back to Details and to the editor again, with it still running.
|
||||
await app.press("\\", { ctrl: true });
|
||||
await app.press("}");
|
||||
expect(app.frame()).not.toContain("Editing README.md");
|
||||
await app.click(app.find("Editor").x, app.find("Editor").y);
|
||||
expect(app.frame()).toContain("Editing README.md");
|
||||
for (let tries = 0; tries < 40 && app.frame().includes("Details Editor"); tries++) await app.settle(50);
|
||||
expect(app.frame()).not.toContain("Details Editor");
|
||||
expect(app.frame()).toContain("Changes");
|
||||
} finally {
|
||||
restoreEditor(previous);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user