M3.6: integrated terminal with PTY sessions and xterm.js sub-tabs
- crates/terminal: portable-pty sessions (ConPTY on Windows) with reader, writer and waiter threads, UTF-8 chunking, a 1 MiB output buffer with backpressure, a non-blocking input queue, resize, kill and exit codes; default shell pwsh -> powershell -> cmd on Windows, $SHELL or /bin/sh. - Engine: terminal.create/input/resize/close, terminalOutput (capped per terminal and per pump, round-robin) and terminalExited through the pump; terminals close with the project and on app.quit. - UI: Terminal tab in the bottom panel (tabs next to Find), xterm.js with the fit addon, sub-tabs, copy/paste, a focus rule that leaves plain Ctrl keys to the shell, terminal.open (Mod+Shift+T), --lt-terminal-* ANSI tokens in both themes (text colours AA) and a 4.5:1 minimum contrast. - Tests: real-shell crate tests (UTF-8, backpressure), engine and TCP control tests, Vitest with a mocked xterm; live check on port 7936; docs and parity rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5fa7f0c8b3
commit
a8daf269fb
45 changed files with 3935 additions and 49 deletions
|
|
@ -4,7 +4,10 @@
|
|||
* UI draws text with reaches AA: 4.5:1 for body text, 3:1 for non-text
|
||||
* marks (cursor, modified dot, settings switch knob; WCAG 1.4.11). Every
|
||||
* syntax colour (`--lt-syntax-*`) reaches 4.5:1 on the editor background
|
||||
* and on the active line. The themes come from
|
||||
* and on the active line. The terminal's text, cursor and every ANSI colour
|
||||
* that shows as text reach AA on the terminal background (M3.6); the colour
|
||||
* meant to vanish into it is exempt per theme (`TERMINAL_EXEMPT`). The
|
||||
* themes come from
|
||||
* `themes.json`, a snapshot that the Rust test `ui_snapshot_is_current`
|
||||
* keeps equal to `lutra_engine::theme`.
|
||||
*/
|
||||
|
|
@ -65,6 +68,35 @@ const SYNTAX_PAIRS: [string, string, number][] = SYNTAX.flatMap((name): [string,
|
|||
[`syntax-${name}`, "editor-active-line-bg", TEXT],
|
||||
]);
|
||||
|
||||
/** ANSI colour names, as in `TERMINAL_TOKENS` in `theme.rs`. */
|
||||
const ANSI = ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"] as const;
|
||||
|
||||
/** ANSI tokens that may blend into the background, per theme id. */
|
||||
const TERMINAL_EXEMPT: Record<string, readonly string[]> = {
|
||||
"lutra-dark": ["terminal-ansi-black"],
|
||||
"lutra-light": ["terminal-ansi-white", "terminal-ansi-bright-white"],
|
||||
};
|
||||
|
||||
/**
|
||||
* The terminal's pairs for one theme: text and selection, the cursor, and
|
||||
* every ANSI colour (normal and bright) that is not exempt.
|
||||
*
|
||||
* @param id - the theme id.
|
||||
* @returns foreground token, background token and minimum ratio.
|
||||
*/
|
||||
function terminalPairs(id: string): [string, string, number][] {
|
||||
const exempt = TERMINAL_EXEMPT[id] ?? [];
|
||||
const ansi = ANSI.flatMap((name) => [`terminal-ansi-${name}`, `terminal-ansi-bright-${name}`]).filter(
|
||||
(name) => !exempt.includes(name),
|
||||
);
|
||||
return [
|
||||
["terminal-fg", "terminal-bg", TEXT],
|
||||
["terminal-fg", "terminal-selection-bg", TEXT],
|
||||
["terminal-cursor", "terminal-bg", LARGE],
|
||||
...ansi.map((name): [string, string, number] => [name, "terminal-bg", TEXT]),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Relative luminance of a `#rrggbb` colour (WCAG 2.1 definition).
|
||||
*
|
||||
|
|
@ -121,7 +153,12 @@ describe.each(themes)("theme $id", (theme) => {
|
|||
expect(defined).toEqual([...SYNTAX].sort());
|
||||
});
|
||||
|
||||
it.each([...PAIRS, ...SYNTAX_PAIRS])("%s on %s reaches %d:1", (fg, bg, min) => {
|
||||
it("checks every terminal ANSI token it defines", () => {
|
||||
const defined = Object.keys(tokens).filter((name) => name.startsWith("--lt-terminal-ansi-"));
|
||||
expect(defined).toHaveLength(ANSI.length * 2);
|
||||
});
|
||||
|
||||
it.each([...PAIRS, ...SYNTAX_PAIRS, ...terminalPairs(theme.id)])("%s on %s reaches %d:1", (fg, bg, min) => {
|
||||
expect(contrast(token(fg), token(bg))).toBeGreaterThanOrEqual(min);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue