Files
RuneStone/src/lib/features/terminalKeys.ts
T
Knotty Wyvern 833f793244 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.
2026-10-29 19:02:58 -07:00

46 lines
2.6 KiB
TypeScript

// The shortcuts of the Terminal feature. This file is in the main bundle, because the workbench routes the keys
// and Help lists them while the feature code is not loaded yet.
import { message } from "../i18n/index.ts";
/** The actions of a terminal shortcut. "toggle" shows or hides the terminal panel. */
export type TerminalAction = "toggle" | "new" | "window" | "split" | "previous" | "next" | "commands" | "directories";
export type TerminalKeyEvent = Pick<KeyboardEvent, "ctrlKey" | "metaKey" | "altKey" | "shiftKey" | "code" | "key">;
/** The terminal action of a key event, or null. Backquote and Digit5 match the physical key on each keyboard layout. */
export function terminalShortcut(event: TerminalKeyEvent): TerminalAction | null {
if (!event.ctrlKey && !event.metaKey) return null;
if (event.code === "Backquote" || event.key === "`") return event.shiftKey ? event.altKey ? "window" : "new" : "toggle";
if (event.shiftKey && event.code === "Digit5" && !event.altKey) return "split";
if (!event.shiftKey && !event.altKey && event.key.toLowerCase() === "j") return "toggle";
if (!event.shiftKey && !event.altKey && event.key === "ArrowUp") return "previous";
if (!event.shiftKey && !event.altKey && event.key === "ArrowDown") return "next";
if (!event.shiftKey && event.altKey && event.key.toLowerCase() === "r") return "commands";
if (!event.shiftKey && !event.altKey && event.key.toLowerCase() === "g") return "directories";
return null;
}
/** The written combination of each action, for menus and Help. `keys()` in `src/lib/ui/shortcuts.ts` gives the label. */
export const TERMINAL_KEYS = {
toggle: "Mod+J",
new: "Mod+Shift+`",
window: "Mod+Shift+Alt+`",
split: "Mod+Shift+5",
previous: "Mod+ArrowUp",
next: "Mod+ArrowDown",
commands: "Mod+Alt+R",
directories: "Mod+G",
} as const satisfies Record<TerminalAction, string>;
/** The Terminal rows of Help. They show only while Terminal is on. */
export const TERMINAL_SHORTCUTS: readonly { label: string; keys: string }[] = [
{ label: message("Show or hide the terminal"), keys: TERMINAL_KEYS.toggle },
{ label: message("New terminal"), keys: TERMINAL_KEYS.new },
{ label: message("New terminal window"), keys: TERMINAL_KEYS.window },
{ label: message("Split terminal"), keys: TERMINAL_KEYS.split },
{ label: message("Scroll to the previous command"), keys: TERMINAL_KEYS.previous },
{ label: message("Scroll to the next command"), keys: TERMINAL_KEYS.next },
{ label: message("Run a recent command"), keys: TERMINAL_KEYS.commands },
{ label: message("Go to a recent folder"), keys: TERMINAL_KEYS.directories },
{ label: message("Copy the selected output"), keys: "Mod+Shift+C" },
];