@xelandernt/hrns-tui 0.0.0-stage → 0.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +60 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +12 -0
- package/dist/terminal.d.ts +23 -0
- package/dist/terminal.js +93 -0
- package/package.json +32 -4
- package/wasm/hrns_tui.js +1278 -0
- package/wasm/hrns_tui_bg.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hrns contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# hrns browser terminal
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@xelandernt/hrns-tui` embeds the hrns terminal in a browser app.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @xelandernt/hrns-tui
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## React
|
|
10
|
+
|
|
11
|
+
Give the container a height. The canvas follows the container's size. Call
|
|
12
|
+
`focus()` to move keyboard focus to the terminal programmatically. Press Escape, then Tab, to move keyboard focus back
|
|
13
|
+
to the host page.
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { useEffect, useRef, useState } from "react";
|
|
17
|
+
import { mountTerminal } from "@xelandernt/hrns-tui";
|
|
18
|
+
|
|
19
|
+
export function HarnessTerminal({ endpoint }: { endpoint: string }) {
|
|
20
|
+
const host = useRef<HTMLDivElement>(null);
|
|
21
|
+
const [error, setError] = useState<string>();
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!host.current) return;
|
|
25
|
+
const controller = new AbortController();
|
|
26
|
+
setError(undefined);
|
|
27
|
+
mountTerminal(host.current, {
|
|
28
|
+
endpoint,
|
|
29
|
+
cwd: "/workspace",
|
|
30
|
+
signal: controller.signal,
|
|
31
|
+
}).catch((error: Error) => {
|
|
32
|
+
if (!controller.signal.aborted) setError(error.message);
|
|
33
|
+
});
|
|
34
|
+
return () => controller.abort();
|
|
35
|
+
}, [endpoint]);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<>
|
|
39
|
+
{error && <p role="alert">{error}</p>}
|
|
40
|
+
<div ref={host} style={{ height: "32rem" }} />
|
|
41
|
+
</>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The returned handle also has an idempotent `dispose()` method. The abort signal
|
|
47
|
+
covers cleanup during Wasm loading and after mounting.
|
|
48
|
+
|
|
49
|
+
For Vite, exclude the package from dependency pre-bundling so its Wasm URL
|
|
50
|
+
resolves alongside the generated JavaScript in development.
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
export default {
|
|
54
|
+
optimizeDeps: { exclude: ["@xelandernt/hrns-tui"] },
|
|
55
|
+
};
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Omit `endpoint` to connect to `/acp/agent` on the page origin. To connect to a
|
|
59
|
+
different host, pass an absolute `wss://` URL and configure your server to accept
|
|
60
|
+
the page's origin. Loopback development also supports `ws://`. The `cwd`
|
|
61
|
+
option is a path on the remote server. Use `session` to resume a saved session.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import init, { WebTerminal } from "../wasm/hrns_tui.js";
|
|
2
|
+
import { attachTerminal } from "./terminal.js";
|
|
3
|
+
let ready;
|
|
4
|
+
export async function mountTerminal(container, options = {}) {
|
|
5
|
+
options.signal?.throwIfAborted();
|
|
6
|
+
ready ??= init().catch((error) => {
|
|
7
|
+
ready = undefined;
|
|
8
|
+
throw error;
|
|
9
|
+
});
|
|
10
|
+
await ready;
|
|
11
|
+
return attachTerminal(WebTerminal, container, options);
|
|
12
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface TerminalOptions {
|
|
2
|
+
/** ACP WebSocket URL. Defaults to /acp/agent on the current origin. */
|
|
3
|
+
endpoint?: string;
|
|
4
|
+
/** Absolute workspace path on the ACP server. */
|
|
5
|
+
cwd?: string;
|
|
6
|
+
/** ID of an existing ACP session to resume. */
|
|
7
|
+
session?: string;
|
|
8
|
+
theme?: "dark" | "light";
|
|
9
|
+
/** Aborting cancels a pending mount or disposes a mounted terminal. */
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
export interface MountedTerminal {
|
|
13
|
+
focus(): void;
|
|
14
|
+
dispose(): void;
|
|
15
|
+
}
|
|
16
|
+
interface Terminal {
|
|
17
|
+
draw(): void;
|
|
18
|
+
resize(): void;
|
|
19
|
+
free(): void;
|
|
20
|
+
}
|
|
21
|
+
type TerminalConstructor = new (root: HTMLElement, input: HTMLInputElement, endpoint?: string, cwd?: string, session?: string, theme?: string) => Terminal;
|
|
22
|
+
export declare function attachTerminal(WebTerminal: TerminalConstructor, container: HTMLElement, options?: TerminalOptions): MountedTerminal;
|
|
23
|
+
export {};
|
package/dist/terminal.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
let nextTerminalId = 0;
|
|
2
|
+
export function attachTerminal(WebTerminal, container, options = {}) {
|
|
3
|
+
const { endpoint, cwd, session, theme, signal } = options;
|
|
4
|
+
signal?.throwIfAborted();
|
|
5
|
+
const doc = container.ownerDocument;
|
|
6
|
+
const view = doc.defaultView;
|
|
7
|
+
if (doc !== globalThis.document || !view || !container.isConnected) {
|
|
8
|
+
throw new Error("Mount hrns in a connected element in the current document");
|
|
9
|
+
}
|
|
10
|
+
const root = doc.createElement("div");
|
|
11
|
+
do {
|
|
12
|
+
root.id = `hrns-terminal-${++nextTerminalId}`;
|
|
13
|
+
} while (doc.getElementById(root.id));
|
|
14
|
+
root.tabIndex = 0;
|
|
15
|
+
root.setAttribute("role", "region");
|
|
16
|
+
root.setAttribute("aria-label", "hrns terminal");
|
|
17
|
+
root.setAttribute("aria-description", "Press Escape, then Tab, to leave the terminal.");
|
|
18
|
+
Object.assign(root.style, {
|
|
19
|
+
width: "100%",
|
|
20
|
+
height: "100%",
|
|
21
|
+
overflow: "hidden",
|
|
22
|
+
backgroundColor: theme === "light" ? "#f8f7fb" : "#0c0b0f",
|
|
23
|
+
});
|
|
24
|
+
const input = doc.createElement("input");
|
|
25
|
+
input.type = "file";
|
|
26
|
+
input.hidden = true;
|
|
27
|
+
input.setAttribute("aria-label", "Attach a file");
|
|
28
|
+
root.append(input);
|
|
29
|
+
container.append(root);
|
|
30
|
+
let terminal;
|
|
31
|
+
let observer;
|
|
32
|
+
let frame;
|
|
33
|
+
let resize = false;
|
|
34
|
+
let disposed = false;
|
|
35
|
+
let escapePressed = false;
|
|
36
|
+
function allowTabOut(event) {
|
|
37
|
+
if (event.key === "Shift")
|
|
38
|
+
return;
|
|
39
|
+
const leaving = escapePressed && event.key === "Tab";
|
|
40
|
+
escapePressed = event.key === "Escape" && !event.isComposing;
|
|
41
|
+
if (leaving)
|
|
42
|
+
event.stopImmediatePropagation();
|
|
43
|
+
}
|
|
44
|
+
function resetEscape() {
|
|
45
|
+
escapePressed = false;
|
|
46
|
+
}
|
|
47
|
+
const dispose = () => {
|
|
48
|
+
if (disposed)
|
|
49
|
+
return;
|
|
50
|
+
disposed = true;
|
|
51
|
+
signal?.removeEventListener("abort", dispose);
|
|
52
|
+
root.removeEventListener("keydown", allowTabOut, true);
|
|
53
|
+
root.removeEventListener("blur", resetEscape);
|
|
54
|
+
if (frame !== undefined)
|
|
55
|
+
view.cancelAnimationFrame(frame);
|
|
56
|
+
observer?.disconnect();
|
|
57
|
+
try {
|
|
58
|
+
terminal?.free();
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
root.remove();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
try {
|
|
65
|
+
root.addEventListener("keydown", allowTabOut, true);
|
|
66
|
+
root.addEventListener("blur", resetEscape);
|
|
67
|
+
const mounted = new WebTerminal(root, input, endpoint, cwd, session, theme);
|
|
68
|
+
terminal = mounted;
|
|
69
|
+
observer = new view.ResizeObserver(() => { resize = true; });
|
|
70
|
+
observer.observe(root);
|
|
71
|
+
signal?.addEventListener("abort", dispose, { once: true });
|
|
72
|
+
const draw = () => {
|
|
73
|
+
try {
|
|
74
|
+
if (resize) {
|
|
75
|
+
resize = false;
|
|
76
|
+
mounted.resize();
|
|
77
|
+
}
|
|
78
|
+
mounted.draw();
|
|
79
|
+
frame = view.requestAnimationFrame(draw);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
dispose();
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
draw();
|
|
87
|
+
return { focus: () => root.focus(), dispose };
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
dispose();
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xelandernt/hrns-tui",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.30",
|
|
4
|
+
"description": "Mount the hrns terminal in a browser application",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/xelandernt/hrns.git",
|
|
10
|
+
"directory": "rust/npm"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/*.js",
|
|
20
|
+
"dist/*.d.ts",
|
|
21
|
+
"wasm/*.js",
|
|
22
|
+
"wasm/*.wasm"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "node build.mjs && tsc -p tsconfig.package.json",
|
|
26
|
+
"build:wrapper": "tsc"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"typescript": "5.9.3"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
}
|
|
34
|
+
}
|