Make Terminal a native feature

- Move the Terminal plugin into src/lib/features/terminal/ on the host Svelte runtime, with xterm 6.0.0 and addon-fit 0.11.0.
- Buttons, shortcuts, Help rows, and the close guard follow the Terminal switch. The first use loads the module.
- Add Settings → Terminal and the terminal settings section. The first start copies the old runestone.terminal key.
- The 16 ANSI colors come from the --rs-ansi-* tokens.
- Off asks first when a shell runs in any window (pty_running).
- Rust: no pty-data or pty-exit events, an owner check for write, resize, and close, output joined up to 64 KiB or 8 ms, and the sessions of a reloaded page close.
- Remove api.pty, the terminal contribution, TerminalSlot, and the plugin loader of the smoke harness.
- Check only the tested switches in the Background smoke test.
- Update the tests, the menu inventory, the docs, and UI-058.
This commit is contained in:
Knotty Wyvern
2026-10-29 19:02:58 -07:00
parent 53b9cea7f0
commit 833f793244
78 changed files with 2971 additions and 659 deletions
+12 -10
View File
@@ -1,6 +1,8 @@
<script lang="ts">
import { t } from "$lib/i18n";
import TerminalSlot from "$lib/plugins/TerminalSlot.svelte";
import TerminalHost from "$lib/features/TerminalHost.svelte";
import { featureSwitches } from "$lib/features/state";
import { terminalShortcut, type TerminalAction } from "$lib/features/terminalKeys";
import type PluginEditor from "$lib/plugins/PluginEditor.svelte";
import { featureOfOwner } from "$lib/features/catalog";
import { pluginSplits, pinPluginEditor, pluginTabActions, pluginTabState, restorePluginTab, pluginTabDragData, dropPluginTab, waitForPluginStartup, pluginTools, installedPlugins, runPluginCommand } from "$lib/plugins/external";
@@ -14,7 +16,6 @@
import type { ViewMode } from "./ViewModes.svelte";
import { selectedEditorText } from "$lib/editor/selection";
import { pluginHost } from "$lib/plugins/registry";
import type { Contributions } from "$lib/plugins/contracts";
import { invoke, isTauri } from "@tauri-apps/api/core";
import { getCurrentWindow } from "@tauri-apps/api/window";
import { confirm, message as dialogMessage } from "@tauri-apps/plugin-dialog";
@@ -173,9 +174,9 @@
let templateManager = $state(false);
let terminalStarted = $state(false);
let terminalMaximized = $state(false);
let terminalDock: TerminalSlot | undefined = $state();
const terminalContribution = $derived.by(() => { void $pluginHost; return pluginHost.get("terminal"); });
const terminalEnabled = $derived(!!terminalContribution);
let terminalDock: TerminalHost | undefined = $state();
// The Terminal buttons, shortcuts, and command work from the switch alone. The first use loads the feature.
const terminalEnabled = $derived($featureSwitches.terminal);
const sidebarNavigation = $derived($pluginNavigation.filter(item => item.placement === "sidebar"));
const ribbonNavigation = $derived($pluginNavigation.filter(item => item.placement !== "sidebar" && !item.toolbar));
const browserContribution = $derived.by(() => { void $pluginHost; return pluginHost.get("browser"); });
@@ -429,7 +430,7 @@
if (terminalOpen && bottomHeight < 220) bottomHeight = 260;
}
async function terminalAction(action: Exclude<ReturnType<Contributions["terminal"]["shortcut"]>, null | "toggle">) {
async function terminalAction(action: Exclude<TerminalAction, "toggle">) {
if (!terminalEnabled) return;
if (!workspace) { error = $t("Open a workspace to start a terminal."); return; }
const started = terminalStarted;
@@ -965,7 +966,7 @@
void pluginPaneComponents[$pluginView.key]?.openFind();
return;
}
const action = pluginHost.get("terminal")?.shortcut(event);
const action = terminalEnabled ? terminalShortcut(event) : null;
const terminalTarget = event.target instanceof Element && !!event.target.closest(".dock");
if (action && (["toggle", "new", "split", "window"].includes(action) || terminalTarget)) {
event.preventDefault();
@@ -1248,7 +1249,7 @@
if (closing) return;
closing = true;
try {
const message = [hasDirty ? "Unsaved edits will be discarded." : "", terminalStarted ? "Terminal sessions will end." : ""].filter(Boolean).join("\n");
const message = [hasDirty ? $t("Unsaved edits will be discarded.") : "", terminalStarted ? $t("Terminal sessions will end.") : ""].filter(Boolean).join("\n");
if (await confirm(`${message}\n${$t("Close RuneStone?")}`, { title: $t("Close workspace"), kind: "warning" })) {
saveDocumentTabs();
await getCurrentWindow().destroy();
@@ -1392,7 +1393,7 @@
onCursor={(pane, line, column) => { if (pane.id === documentPanes.active) cursor = { line, column }; }}
onOpenLink={(pane, kind, target) => void openLink(kind, target, pane.buffer?.relPath ?? "", pane.id)}
/>
{#if terminalContribution && terminalStarted}
{#if terminalEnabled && terminalStarted}
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions (A focusable separator is the splitter pattern.) -->
<div
class="gutter gutter-h" class:terminal-hidden={!terminalOpen}
@@ -1408,7 +1409,8 @@
<section class="bottom" class:terminal-hidden={!terminalOpen}>
{#if workspace}
{#key workspace.root}
<TerminalSlot contribution={terminalContribution} bind:this={terminalDock} cwd={workspace.root} visible={terminalOpen} onClose={() => { terminalOpen = false; terminalStarted = false; terminalMaximized = false; }}
<TerminalHost bind:this={terminalDock} cwd={workspace.root} visible={terminalOpen} onClose={() => { terminalOpen = false; terminalStarted = false; terminalMaximized = false; }}
onOpenSettings={() => void openSettings()}
maximized={terminalMaximized} onMaximize={() => terminalMaximized = !terminalMaximized}
activeFile={buffer?.kind === "text" && !reading} onRunFile={terminalFile}
getSelection={() => selectedEditorText(buffer?.id)} onConfigureTasks={configureTasks} />