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:
@@ -11,6 +11,10 @@
|
||||
import { FEATURES, type FeatureId } from "$lib/features/catalog";
|
||||
import { featureSwitches, setFeature } from "$lib/features/state";
|
||||
import { featureErrors } from "$lib/features/loader";
|
||||
import { TERMINAL_SHORTCUTS } from "$lib/features/terminalKeys";
|
||||
import TerminalSettings from "$lib/features/TerminalSettings.svelte";
|
||||
import { invoke, isTauri } from "@tauri-apps/api/core";
|
||||
import { confirm } from "@tauri-apps/plugin-dialog";
|
||||
import { onMount, untrack, type Snippet } from "svelte";
|
||||
import Icon from "$lib/ui/Icon.svelte";
|
||||
import IconButton, { type IconName } from "$lib/ui/IconButton.svelte";
|
||||
@@ -19,13 +23,16 @@
|
||||
import { appVersion as version } from "../appVersion";
|
||||
import { COMMAND_LABELS, OTHER_SHORTCUTS, commandShortcut, shortcutKeys, type WorkbenchCommand } from "./workbenchKeys";
|
||||
import { isMac } from "$lib/ui/shortcuts";
|
||||
// Help lists every shortcut: the workbench commands, then the editor and file tree shortcuts.
|
||||
const shortcutSections = (() => {
|
||||
const general = (Object.keys(COMMAND_LABELS) as WorkbenchCommand[]).map(command => ({ label: COMMAND_LABELS[command], keys: commandShortcut(command) })).filter(item => item.keys);
|
||||
// Help lists every shortcut: the workbench commands, then the editor and file tree shortcuts, then Terminal while it is on.
|
||||
const shortcutSections = $derived.by(() => {
|
||||
const terminal = $featureSwitches.terminal;
|
||||
const general = (Object.keys(COMMAND_LABELS) as WorkbenchCommand[]).filter(command => terminal || command !== "toggle-terminal")
|
||||
.map(command => ({ label: COMMAND_LABELS[command], keys: commandShortcut(command) })).filter(item => item.keys);
|
||||
const others = new Map<string, { label: string; keys: string }[]>();
|
||||
for (const item of OTHER_SHORTCUTS) others.set(item.section, [...(others.get(item.section) ?? []), { label: item.label, keys: shortcutKeys(isMac() && item.macKeys ? item.macKeys : item.keys) }]);
|
||||
if (terminal) others.set("Terminal", TERMINAL_SHORTCUTS.map(item => ({ label: item.label, keys: shortcutKeys(item.keys) })));
|
||||
return [{ name: "General", items: general }, ...[...others].map(([name, items]) => ({ name, items }))];
|
||||
})();
|
||||
});
|
||||
|
||||
let { settings, help = false, standalone = false, windowError = "", windowControls, onSave, onClose }: {
|
||||
settings: AppSettings;
|
||||
@@ -69,7 +76,8 @@
|
||||
label: tool.title, icon: "settings" as const,
|
||||
keywords: `${$installedPlugins.plugins.find(row => row.manifest.id === tool.owner)?.manifest.name ?? tool.owner} settings configuration`,
|
||||
})));
|
||||
const matches = $derived([...sections, ...(browserEnabled ? [{ id: "browser" as const, label: $t("Browser"), icon: "globe" as const, keywords: "browser profiles search cookies cache web privacy" }] : []), ...pluginSections].filter(item => `${item.label} ${item.keywords}`.toLowerCase().includes(query.trim().toLowerCase())));
|
||||
const terminalSection = $derived($featureSwitches.terminal ? [{ id: "terminal" as const, label: $t("Terminal"), icon: "terminal" as const, keywords: "terminal shell profile default font size scrollback lines cursor blink powershell bash cmd" }] : []);
|
||||
const matches = $derived([...sections, ...(browserEnabled ? [{ id: "browser" as const, label: $t("Browser"), icon: "globe" as const, keywords: "browser profiles search cookies cache web privacy" }] : []), ...terminalSection, ...pluginSections].filter(item => `${item.label} ${item.keywords}`.toLowerCase().includes(query.trim().toLowerCase())));
|
||||
const selected = $derived(matches.find(item => item.id === section) ?? matches[0]);
|
||||
const selectedPlugin = $derived(pluginSections.find(item => item.id === selected?.id));
|
||||
|
||||
@@ -99,8 +107,22 @@
|
||||
apply({ ...settings, autosaveSeconds: seconds });
|
||||
}
|
||||
|
||||
function changeFeature(id: FeatureId, on: boolean) {
|
||||
/** True when a window runs a shell. The host counts the sessions of all windows. */
|
||||
async function shellsRunning(): Promise<boolean> {
|
||||
if (!isTauri()) return false;
|
||||
try { return await invoke<number>("pty_running") > 0; }
|
||||
catch { return false; }
|
||||
}
|
||||
|
||||
async function changeFeature(id: FeatureId, on: boolean, input: HTMLInputElement) {
|
||||
error = "";
|
||||
// Terminal off ends the shells of every window, so ask first, with the words of the close guard of the workbench.
|
||||
if (id === "terminal" && !on && await shellsRunning()) {
|
||||
let accepted = false;
|
||||
try { accepted = await confirm(`${$t("Terminal sessions will end.")}\n${$t("Turn off Terminal?")}`, { title: $t("Turn off Terminal"), kind: "warning" }); }
|
||||
catch (reason) { error = String(reason); }
|
||||
if (!accepted) { input.checked = true; return; }
|
||||
}
|
||||
setFeature(id, on).then(() => { message = $t("Changes saved."); })
|
||||
.catch(() => { error = $t("Could not save these settings. Your previous settings still apply. Try again."); message = ""; });
|
||||
}
|
||||
@@ -201,7 +223,7 @@
|
||||
<p id={`feature-${feature.id}-description`}>{$t(feature.description)}</p>
|
||||
{#if $featureErrors[feature.id]}<p class="error" role="alert">{$t("{name} could not load: {error}", { name: $t(feature.name), error: $featureErrors[feature.id] ?? "" })}</p>{/if}
|
||||
</div>
|
||||
<input id={`feature-${feature.id}`} class="rs-switch" type="checkbox" role="switch" aria-describedby={`feature-${feature.id}-description`} checked={$featureSwitches[feature.id]} onchange={event => changeFeature(feature.id, event.currentTarget.checked)} />
|
||||
<input id={`feature-${feature.id}`} class="rs-switch" type="checkbox" role="switch" aria-describedby={`feature-${feature.id}-description`} checked={$featureSwitches[feature.id]} onchange={event => void changeFeature(feature.id, event.currentTarget.checked, event.currentTarget)} />
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -211,6 +233,8 @@
|
||||
<PluginManager />
|
||||
{:else if selected.id === "browser"}
|
||||
<BrowserSlot kind="settings" />
|
||||
{:else if selected.id === "terminal"}
|
||||
<TerminalSettings />
|
||||
{:else if selectedPlugin}
|
||||
{#key selectedPlugin.id}<PluginSettings owner={selectedPlugin.owner} id={selectedPlugin.view} />{/key}
|
||||
{:else}
|
||||
|
||||
@@ -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} />
|
||||
|
||||
Reference in New Issue
Block a user