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:
danny 2026-10-18 11:25:30 +02:00
parent 5fa7f0c8b3
commit a8daf269fb
45 changed files with 3935 additions and 49 deletions

View file

@ -15,10 +15,14 @@
* `view.toggleStructure` (`Mod+2`): each shows its tool window, or hides
* the left window when that tool window is already shown.
*
* The bottom panel ({@link BottomPanel}) holds the Find tool window. It
* appears with the UI command `find.open` (`Mod+Alt+F`, supplied here so it
* works before the panel exists), collapses to its header and closes from
* its header; the Find store keeps the results while it is closed.
* The bottom panel ({@link BottomPanel}) holds the Find and Terminal tool
* windows, as tabs in its header while both are shown. Find appears with
* the UI command `find.open` (`Mod+Alt+F`), Terminal with `terminal.open`
* (`Mod+Shift+T`, M3.6); both are supplied here so they work before the
* panel exists, and each makes its tool window the active tab. The panel
* collapses to its header; closing it hides the active tool window (the
* other one, if shown, becomes active). The Find store keeps the results
* and the Terminal store the running terminals while they are hidden.
*
* A slim header bar along the top (M3.9) holds the app menu
* ({@link AppMenu}); its `header` slot can replace it.
@ -28,7 +32,9 @@ import { computed, onBeforeUnmount, onMounted, ref } from "vue";
import { useCommandsStore } from "../../commands/store";
import { t } from "../../i18n";
import { useFindStore } from "../../stores/find";
import { useTerminalStore } from "../../stores/terminal";
import FindToolWindow from "../find/FindToolWindow.vue";
import TerminalToolWindow from "../terminal/TerminalToolWindow.vue";
import ProjectToolWindow from "../project/ProjectToolWindow.vue";
import StatusBar from "../StatusBar.vue";
import StructureToolWindow from "../structure/StructureToolWindow.vue";
@ -72,19 +78,81 @@ function toggleLeft(tool: LeftTool): void {
const commands = useCommandsStore();
const find = useFindStore();
const terminal = useTerminalStore();
/** Tool windows of the bottom panel. */
type BottomTool = "find" | "terminal";
/** The bottom tool window last chosen. */
const bottomTool = ref<BottomTool>("find");
/** Bottom tool windows that are shown, in tab order. */
const bottomTools = computed(() => {
const tools: { id: BottomTool; title: string }[] = [];
if (find.visible) tools.push({ id: "find", title: t("find.toolWindow.title") });
if (terminal.visible) tools.push({ id: "terminal", title: t("terminal.toolWindow.title") });
return tools;
});
/** The active bottom tool window: the chosen one if shown, else the first. */
const bottomActive = computed<BottomTool | null>(() => {
const tools = bottomTools.value;
return tools.some((tool) => tool.id === bottomTool.value) ? bottomTool.value : (tools[0]?.id ?? null);
});
/** Expansion of the panel, kept per tool window by its store. */
const bottomOpen = computed({
get: () => (bottomActive.value === "terminal" ? terminal.expanded : find.expanded),
set: (open: boolean) => {
if (bottomActive.value === "terminal") {
terminal.expanded = open;
} else {
find.expanded = open;
}
},
});
/**
* Makes a bottom tool window the active tab.
*
* @param id - the tool window id from the panel.
*/
function chooseBottom(id: string): void {
if (id === "find" || id === "terminal") {
bottomTool.value = id;
}
}
/** Hides the active bottom tool window. */
function closeBottom(): void {
if (bottomActive.value === "terminal") {
terminal.hide();
} else {
find.hide();
}
}
/** Withdraws the command handlers; filled while mounted. */
let withdraw: (() => void)[] = [];
onMounted(() => {
find.start();
terminal.start();
withdraw = [
commands.provide("view.toggleProjectTree", {
run: () => {
toggleLeft("project");
},
}),
commands.provide("find.open", { run: (params) => find.open(params) }),
commands.provide("find.open", {
run: (params) => {
bottomTool.value = "find";
return find.open(params);
},
}),
commands.provide("terminal.open", {
run: (params) => {
bottomTool.value = "terminal";
return terminal.open(params);
},
enabled: () => commands.isEnabled("terminal.create"),
}),
commands.provide("view.toggleStructure", {
run: () => {
toggleLeft("structure");
@ -99,6 +167,7 @@ onBeforeUnmount(() => {
}
withdraw = [];
find.stop();
terminal.stop();
});
</script>
@ -156,13 +225,20 @@ onBeforeUnmount(() => {
</main>
</div>
<BottomPanel
v-if="find.visible"
v-if="bottomActive !== null"
v-model:height="bottomHeight"
v-model:open="find.expanded"
:title="t('find.toolWindow.title')"
@close="find.hide()"
v-model:open="bottomOpen"
:title="bottomTools.find((tool) => tool.id === bottomActive)?.title ?? ''"
:tabs="bottomTools.length > 1 ? bottomTools : []"
:active="bottomActive"
@update:active="chooseBottom"
@close="closeBottom"
>
<FindToolWindow />
<FindToolWindow v-show="bottomActive === 'find'" />
<TerminalToolWindow
v-if="terminal.visible"
v-show="bottomActive === 'terminal'"
/>
</BottomPanel>
<StatusBar />
</div>