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:
+14
-52
@@ -11,7 +11,6 @@ This reference gives the package contract, the build procedure, and the API for
|
||||
- [Versions and releases](#versions-and-releases)
|
||||
- [Plugin API](#plugin-api)
|
||||
- [Use the SDK instead of native calls](#use-the-sdk-instead-of-native-calls)
|
||||
- [Terminal API](#terminal-api)
|
||||
- [Folder grants](#folder-grants)
|
||||
- [Plugin services](#plugin-services)
|
||||
- [Background API](#background-api)
|
||||
@@ -146,22 +145,21 @@ In user instructions, do not tell users to load JSON, select a build folder, ren
|
||||
Each example is specific to one plugin. Read the package scripts of a plugin before you build it.
|
||||
For the RuneStone source setup, see [Run from source](development.md#run-from-source).
|
||||
|
||||
### Example: Terminal
|
||||
### Example: CSV Viewer
|
||||
|
||||
Source: [Terminal repository](https://git.knottywyvern.com/kwyvern/RuneStone_Terminal), its `package.json`, and its `scripts/build.mjs`.
|
||||
Source: [CSV Viewer repository](https://git.knottywyvern.com/kwyvern/RuneStone_CSV_Viewer), its `package.json`, `plugin.json`, `scripts/build.mjs`, and `README.md`.
|
||||
|
||||
| Item | Value |
|
||||
| --- | --- |
|
||||
| Prerequisites | Node.js 24 and pnpm 10. Run `pnpm install --frozen-lockfile` in the Terminal folder. |
|
||||
| Working folder | The Terminal repository root |
|
||||
| Prerequisites | Node.js 24 or later and pnpm. Run `pnpm install --frozen-lockfile` in the CSV Viewer folder. Put the RuneStone source checkout beside it, in a folder with the name `RuneStone`. The source imports shared interface files from `../../RuneStone/src/lib/ui/`. |
|
||||
| Working folder | The CSV Viewer repository root |
|
||||
| Command | `pnpm build` |
|
||||
| Output | `releases/runestone.terminal-<version>.zip` in the Terminal folder |
|
||||
| Output | `releases/runestone.csv-viewer-<version>.zip` in the CSV Viewer folder. `<version>` is the `version` of `plugin.json`, for example `0.1.3`. |
|
||||
|
||||
The build compiles the Svelte interface and its dependencies into `dist/` (`main.js`, `style.css`, `plugin.json`, and `README.md`). Then it makes the ZIP.
|
||||
The build stops when the versions in `package.json` and `plugin.json` are different.
|
||||
To compile into `dist/` without a ZIP, run `node scripts/build.mjs --no-package`.
|
||||
RuneStone supplies the native terminal sessions. The plugin supplies the interface, shortcuts, and session controls.
|
||||
For use of the terminal, see the [Terminal guide](guides/terminal.md).
|
||||
The build compiles `src/index.js` with esbuild into a readable `dist/main.js`. It copies `plugin.json` and `README.md` into `dist/` and writes `dist/build.json`.
|
||||
Then it runs `scripts/packagePlugin.mjs` of the RuneStone checkout on `dist/`. Set `RUNESTONE_ROOT` to use another RuneStone checkout for this step.
|
||||
The build stops when the versions in `package.json` and `plugin.json` are different. It also stops when the release ZIP of the version exists. Set the next version in both files first.
|
||||
To compile into `dist/` without a ZIP, run `pnpm compile`.
|
||||
|
||||
### Example: Workspace overview
|
||||
|
||||
@@ -216,8 +214,8 @@ The SDK feature checks do this. Their error names each missing feature and tells
|
||||
```ts
|
||||
import { hasFeature, requireFeature, requireFeatures } from "@runestone/plugin-sdk";
|
||||
|
||||
requireFeatures(api, ["pty", "workspace.readBytes"]);
|
||||
const pty = requireFeature(api, "pty");
|
||||
requireFeatures(api, ["files", "workspace.readBytes"]);
|
||||
const files = requireFeature(api, "files");
|
||||
if (hasFeature(api, "settings.subscribe")) watchSettings();
|
||||
```
|
||||
|
||||
@@ -264,7 +262,6 @@ Older hosts ignore unknown fields in objects that you pass to the host, such as
|
||||
| `assets.read(path)` | | Read a package file as a `Uint8Array`. |
|
||||
| `ui.showActionMenu(options)` | yes | Open the shared RuneStone action menu. See [Menus](#menus). |
|
||||
| `completion` | yes | Autocomplete fields and providers. See the [completion API](completion.md). |
|
||||
| `pty` | yes | Terminal sessions. See [Terminal API](#terminal-api). |
|
||||
| `files` | yes | Folders outside the workspace that the user granted to the plugin. See [Folder grants](#folder-grants). |
|
||||
| `services` | yes | Data that one plugin offers to other plugins. See [Plugin services](#plugin-services). |
|
||||
| `backgrounds` | yes | Background image frames. See [Background API](#background-api). |
|
||||
@@ -385,10 +382,9 @@ Only one enabled plugin can own each key. The host removes contributions before
|
||||
|
||||
| Key | Purpose | Owner |
|
||||
| --- | --- | --- |
|
||||
| `terminal` | Mounts terminal controls in a host element. Returns update, command, and dispose functions. | Terminal plugin |
|
||||
| `browser` | The built-in browser. `newTab(url?)` opens a browser tab. `open(url)` returns false when the system browser must open a web link, for example before the engine is installed. | RuneStone |
|
||||
|
||||
A terminal contribution must stop its controls and native sessions before its cleanup finishes.
|
||||
Earlier hosts also had `api.pty` and a `terminal` key for the Terminal plugin. They are gone, because RuneStone now includes Terminal as a native feature.
|
||||
|
||||
### Theme tokens
|
||||
|
||||
@@ -423,46 +419,12 @@ The window sends a `runestone-theme-changed` event after each theme change. A pl
|
||||
## Use the SDK instead of native calls
|
||||
|
||||
Do not call `invoke`, `listen`, or other `@tauri-apps/api` functions from a plugin. Do not read the private files of other plugins.
|
||||
Use the `api` members below. They check plugin shutdown, and they will stay available when a later host runs each plugin in its own isolated context.
|
||||
Make sure that an optional member exists before you use it. Keep the native call only as a fallback for older hosts.
|
||||
Use the `api` members of the [API reference](#api-reference). They check plugin shutdown, and they will stay available when a later host runs each plugin in its own isolated context.
|
||||
Make sure that an optional member exists before you use it.
|
||||
|
||||
The host still accepts the native calls of released plugins. A later host can remove them.
|
||||
|
||||
| Plugin | Current call | Purpose | Use instead |
|
||||
| --- | --- | --- | --- |
|
||||
| Terminal | `invoke("pty_open")`, `listen("pty-data")`, `listen("pty-exit")` | Start a shell and receive its output and exit code | `api.pty.open({ ..., onData, onExit })` |
|
||||
| Terminal | `invoke("pty_write")`, `invoke("pty_resize")`, `invoke("pty_close")` | Send input, change the size, stop the shell | `write`, `resize`, and `close` of the session from `api.pty.open` |
|
||||
| Terminal | `invoke("pty_profiles")` | List the installed shells | `api.pty.profiles()` |
|
||||
| Terminal | `invoke("pty_new_window")` | Open a terminal window | `api.pty.openWindow()` |
|
||||
| Terminal | `invoke("pty_dictation")` | Start Windows voice typing | `api.pty.dictation()` |
|
||||
| Terminal | `invoke("workspace_read", { rel: ".runestone/tasks.json" })` | Read the task list of the workspace | `api.workspace.read(path)` |
|
||||
The Project Management, Local Autocomplete, PDF Viewer, and CSV Viewer plugins make no native calls.
|
||||
Their test scripts replace `window.__TAURI_INTERNALS__` with a test double. That is test code and does not go into the package.
|
||||
|
||||
## Terminal API
|
||||
|
||||
`api.pty` (`version: 1`) starts shells in pseudo terminals. The SDK types are `PtyApi` and `PtySession`.
|
||||
|
||||
| Member | Contract |
|
||||
| --- | --- |
|
||||
| `profiles()` | Returns the installed shells as `{ id, title, kind }`. |
|
||||
| `open(options)` | Starts a shell and returns a session. See the options below. |
|
||||
| `openWindow()` | Opens a terminal window for the workspace of the current window. |
|
||||
| `dictation()` | Starts Windows voice typing. Focus the terminal first. Fails on other systems. |
|
||||
|
||||
| Option | Rule |
|
||||
| --- | --- |
|
||||
| `cwd` | Required. The workspace root of the window. The start fails when the workspace changed. |
|
||||
| `cols`, `rows` | Required. Positive integers. |
|
||||
| `profile` | A profile `id` from `profiles()`. Without it, the host uses the first installed shell. |
|
||||
| `directory` | A start folder other than the workspace root. |
|
||||
| `onData(data)` | Required. Receives the output as a `Uint8Array`. A UTF-8 character can be split between two calls. |
|
||||
| `onExit(code)` | Receives the exit code, or `null`. |
|
||||
|
||||
A session has `id`, `write(text)`, `resize(cols, rows)`, and `close()`. `close()` stops the shell, and more calls return the same promise.
|
||||
Output goes only to the session that started the shell, as raw bytes.
|
||||
When the plugin stops, the host stops the output, runs the plugin cleanup, and then closes the sessions that are still open.
|
||||
|
||||
## Folder grants
|
||||
|
||||
`api.files` (`version: 1`) gives access to folders outside the workspace. The user selects each folder. The plugin cannot supply a path.
|
||||
|
||||
Reference in New Issue
Block a user