Files
loki/scripts/test/terminal-expand.ts
CatoandClaude Opus 5.5 75c870da2d fix(terminal): PTY follows the grid, expandable full-width pane, one composer (#887)
* fix(terminal): resize the PTY to the grid on screen, not only when typing

The resize was published only from an interactive (Type + live keys) view,
so Prompt mode, Voice mode and every phone fitted xterm locally and never
told the PTY. Measured: 79-col grid drawing a 120-col PTY on desktop Prompt
mode, 86 vs 120 on a 390px phone — torn words and stray columns at the
right edge. Fit + publish now run on mount, on every host resize, on a font
step, and re-assert on window focus.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(terminal): one composer for chat and inject; expandable, full-width pane

- components/composer/Composer is THE composer (text, attach, voice, model,
  Send/Stop, optional modes). Loki chat (LokiComposer), the terminal's
  Ask/Inject rail, the Prompt-mode box / phone dock and Control's quick send
  all render it. TerminalLokiComposer (bare textarea, no attach/voice) is
  deleted; Control's one-line ⌘Enter input is gone.
- The rail's Inject is the prompt composer while the rail is beside the
  session, so the page no longer shows two inject boxes at once.
- Terminal pane: rail is a fixed width (lg+) instead of 40% of the row, can be
  closed (remembered), is a sheet below lg; Expand works at every width and
  Esc leaves it, except when typed into the xterm or handled by a dialog.
- Tests: one-composer (logic, per-call-site render, no private textareas),
  terminal-expand (Esc rules).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 15:55:43 -07:00

47 lines
1.6 KiB
TypeScript

// Esc leaves the expanded terminal — but never takes Esc from the session
// itself, where it is how you interrupt an agent (src/lib/terminal-expand.ts).
// Run: npx tsx scripts/test/terminal-expand.ts
import { shouldLeaveExpandedOnKey } from "@/lib/terminal-expand";
let pass = 0;
let fail = 0;
function eq(actual: unknown, expected: unknown, label: string) {
if (actual === expected) pass++;
else {
fail++;
console.error(`✗ ${label}: expected ${expected}, got ${actual}`);
}
}
/** An element whose ancestors match the given selectors. */
const inside = (...selectors: string[]) => ({
closest: (sel: string) => (selectors.includes(sel) ? {} : null),
});
eq(shouldLeaveExpandedOnKey({ key: "Escape", target: inside() }), true, "Esc on the page leaves");
eq(shouldLeaveExpandedOnKey({ key: "Escape" }), true, "Esc with no target leaves");
eq(shouldLeaveExpandedOnKey({ key: "Enter", target: inside() }), false, "other keys do nothing");
eq(
shouldLeaveExpandedOnKey({ key: "Escape", target: inside(".xterm") }),
false,
"Esc typed into the session stays with the agent",
);
eq(
shouldLeaveExpandedOnKey({ key: "Escape", target: inside('[role="dialog"]') }),
false,
"Esc in a sheet closes the sheet, not the full screen",
);
eq(
shouldLeaveExpandedOnKey({ key: "Escape", defaultPrevented: true, target: inside() }),
false,
"a control that already handled Esc (a picker) wins",
);
eq(
shouldLeaveExpandedOnKey({ key: "Escape", isComposing: true, target: inside() }),
false,
"Esc cancelling an IME composition is not a layout command",
);
console.log(`terminal-expand: ${pass} passed, ${fail} failed`);
if (fail > 0) process.exit(1);