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}
|
||||
|
||||
Reference in New Issue
Block a user