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:
@@ -1,44 +1,30 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { pluginRepo } from "./index.mjs";
|
||||
// Installed plugin packages for the smoke tests: the `plugins_*` commands of src-tauri/src/plugins.rs, without plugin code.
|
||||
|
||||
/** An installed package of the old Table Formulas plugin. RuneStone now includes the feature and must not load this code. */
|
||||
export const oldTableFormulasRow = {
|
||||
manifest: { schemaVersion: 1, id: "runestone.table-formulas", name: "Table Formulas", author: "RuneStone Team", description: "Calculate formulas in Markdown tables.", version: "0.1.3", apiVersion: 1, entry: "main.js", access: "full-app" },
|
||||
hash: "old-hash", enabled: true, path: "C:\\AppData\\RuneStone\\plugins\\runestone.table-formulas", error: null, removal: false,
|
||||
hash: "old-hash", enabled: true, path: "C:\AppData\RuneStone\plugins\runestone.table-formulas", error: null, removal: false,
|
||||
};
|
||||
|
||||
/**
|
||||
* Load the compiled Terminal package through the production Blob module loader.
|
||||
* `extraRows` adds installed rows without code, for example `oldTableFormulasRow`.
|
||||
* Serve `rows` as the installed packages. All pages of a context share them through localStorage, and a change sends
|
||||
* `plugins-changed`. Enable, disable, and remove work. `plugins_load` fails, because the rows have no code.
|
||||
* Call it after `mockTauri`, because it wraps the IPC mock.
|
||||
*/
|
||||
export async function mockFeaturePlugins(surface, extraRows = []) {
|
||||
// The runner checks the same folder for "@requires plugin:terminal".
|
||||
const root = pathToFileURL(resolve(process.env.RUNESTONE_TERMINAL_DIST || pluginRepo("RuneStone_Terminal/dist")) + "/");
|
||||
const packages = [{
|
||||
manifest: JSON.parse(await readFile(new URL("plugin.json", root), "utf8")),
|
||||
code: await readFile(new URL("main.js", root), "utf8"),
|
||||
css: await readFile(new URL("style.css", root), "base64"),
|
||||
}];
|
||||
await surface.addInitScript(({ packages, extraRows }) => {
|
||||
export async function mockInstalledPlugins(surface, rows = []) {
|
||||
await surface.addInitScript(rows => {
|
||||
const key = "test.installed-plugins";
|
||||
const root = "C:\\AppData\\RuneStone\\plugins";
|
||||
const defaults = [...packages.map(item => ({ manifest: item.manifest, hash: "test-hash", enabled: true, path: root + "\\" + item.manifest.id, error: null, removal: false })), ...extraRows];
|
||||
const read = () => JSON.parse(localStorage.getItem(key) || JSON.stringify(defaults));
|
||||
const write = rows => { localStorage.setItem(key, JSON.stringify(rows)); window.__TEST__?.emit("plugins-changed", {}); };
|
||||
if (!localStorage.getItem(key)) localStorage.setItem(key, JSON.stringify(defaults));
|
||||
const root = "C:\AppData\RuneStone\plugins";
|
||||
const read = () => JSON.parse(localStorage.getItem(key) || JSON.stringify(rows));
|
||||
const write = next => { localStorage.setItem(key, JSON.stringify(next)); window.__TEST__?.emit("plugins-changed", {}); };
|
||||
if (!localStorage.getItem(key)) localStorage.setItem(key, JSON.stringify(rows));
|
||||
window.addEventListener("storage", event => { if (event.key === key) window.__TEST__?.emit("plugins-changed", {}); });
|
||||
const original = window.__TAURI_INTERNALS__.invoke;
|
||||
window.__TAURI_INTERNALS__.invoke = async (command, args = {}) => {
|
||||
if (!command.startsWith("plugins_")) return original(command, args);
|
||||
window.__TEST__?.calls.push({ command, args });
|
||||
if (command === "plugins_snapshot") return { root, plugins: read() };
|
||||
if (command === "plugins_load" || command === "plugins_asset") {
|
||||
const item = packages.find(item => item.manifest.id === args.id);
|
||||
if (!item) throw new Error(`No code for ${args.id}`);
|
||||
return command === "plugins_load" ? item.code : item.css;
|
||||
}
|
||||
if (command === "plugins_load" || command === "plugins_asset") throw new Error(`No code for ${args.id}`);
|
||||
if (command === "plugins_set_enabled") { write(read().map(item => item.manifest.id === args.id ? { ...item, enabled: args.enabled } : item)); return; }
|
||||
if (command === "plugins_prepare_remove") return { token: args.id, plugin: read().find(item => item.manifest.id === args.id) };
|
||||
if (command === "plugins_remove") { write(read().filter(item => item.manifest.id !== args.token)); return; }
|
||||
@@ -46,5 +32,5 @@ export async function mockFeaturePlugins(surface, extraRows = []) {
|
||||
if (["plugins_release", "plugins_cancel", "plugins_reveal"].includes(command)) return;
|
||||
throw new Error(`Unhandled plugin IPC: ${command}`);
|
||||
};
|
||||
}, { packages, extraRows });
|
||||
}, rows);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user