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:
@@ -0,0 +1,36 @@
|
||||
// The Terminal feature. `loader.ts` imports this module at the first use of a terminal panel:
|
||||
// the Terminal button, a terminal shortcut, or a terminal window. Settings → Terminal does not load it.
|
||||
// It starts shells through the `pty_*` commands of src-tauri/src/pty.rs (`transport.ts`).
|
||||
import { flushSync, mount, unmount } from "svelte";
|
||||
import { tr } from "../../i18n/index.ts";
|
||||
import type { TerminalInstance, TerminalMount } from "../terminalHost.ts";
|
||||
import type { FeatureContext } from "../types.ts";
|
||||
import { TerminalSessions } from "./sessions.ts";
|
||||
import { desktopTransport } from "./transport.ts";
|
||||
import TerminalBridge from "./TerminalBridge.svelte";
|
||||
// The xterm styles load with the feature chunk.
|
||||
import "@xterm/xterm/css/xterm.css";
|
||||
|
||||
export function start(_context: FeatureContext): TerminalInstance {
|
||||
const sessions = new TerminalSessions(desktopTransport);
|
||||
const docks = new Set<() => Promise<void>>();
|
||||
return {
|
||||
mount() { throw new Error(tr("This view is unavailable.")); },
|
||||
mountDock(element, props): TerminalMount {
|
||||
if (sessions.stopped) throw new Error(tr("This feature is off."));
|
||||
const instance = mount(TerminalBridge, { target: element, props: { initial: props, sessions } });
|
||||
flushSync();
|
||||
let stopping: Promise<void> | undefined;
|
||||
const dispose = () => stopping ??= unmount(instance).then(() => { docks.delete(dispose); });
|
||||
docks.add(dispose);
|
||||
return { update: value => instance.update(value), command: action => instance.command(action), dispose };
|
||||
},
|
||||
/** Remove the panels, then stop the shells that are left. Panels close their own sessions when they unmount. */
|
||||
async dispose() {
|
||||
const results = await Promise.allSettled([...docks].map(dispose => dispose()));
|
||||
await sessions.closeAll();
|
||||
const errors = results.filter(result => result.status === "rejected");
|
||||
if (errors.length) throw new Error(errors.map(result => String(result.reason)).join("\n"));
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user