jsgotty 1.0.0 → 1.1.3
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/README.en.md +116 -39
- package/README.md +130 -52
- package/client.mjs +11 -7
- package/gotty.js +372 -20
- package/package.json +1 -1
- package/rz.js +24 -6
- package/single-exe/README.md +80 -0
- package/single-exe/assetsHelper.js +90 -0
- package/single-exe/assetsLoader.mjs +85 -0
- package/single-exe/compiled.js +138 -0
- package/single-exe/entry.mjs +9 -0
- package/single-exe/packAssets.sh +7 -0
- package/static/css/kitty.css +1 -1
- package/static/help.md +125 -0
- package/static/index.html +8 -1
- package/static/js/gotty.js +633 -93
- package/static/js/gotty.licenses.txt +23 -0
- package/static/js/kitty.js +83 -16
- package/static/js/xterm-addon-unicode11.js +2 -0
- package/static/js/zmodem.js +1 -1
- package/sz.js +77 -10
- package/viu.mjs +6 -8
- package/zmodem-node.js +157 -8
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# This is completely optional
|
|
2
|
+
- I still recommend using the methods in the root README.md
|
|
3
|
+
- Bun's Android build is currently not supported
|
|
4
|
+
|
|
5
|
+
# Usage
|
|
6
|
+
- First run `bun ./packAssets.sh` to bundle the assets into `assets.tar`
|
|
7
|
+
- Then run the build script like this
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
bun build --compile --bytecode --minify ./entry.mjs --outfile=binname
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- You'll get a binname executable
|
|
14
|
+
|
|
15
|
+
# Single Executable Intro
|
|
16
|
+
|
|
17
|
+
This folder contains the Bun single-exe bootstrap used by the project.
|
|
18
|
+
|
|
19
|
+
## Entry Flow
|
|
20
|
+
|
|
21
|
+
- `entry.mjs` imports `assetsLoader.mjs` first
|
|
22
|
+
- `assetsLoader.mjs` loads `assets.tar` with `Bun.Archive` and mounts it as `globalThis.internalAssets`
|
|
23
|
+
- `assetsLoaderPromise` is exposed on `globalThis`
|
|
24
|
+
- The main program waits for `assetsLoaderPromise` if it exists
|
|
25
|
+
|
|
26
|
+
That keeps the main program bootable even if asset loading reports errors.
|
|
27
|
+
|
|
28
|
+
## Assets Loading
|
|
29
|
+
|
|
30
|
+
- Bundled assets are loaded sequentially with `await file.bytes()`
|
|
31
|
+
- Load failures are collected and printed to `stderr`
|
|
32
|
+
- Asset loading never rejects the bootstrap promise
|
|
33
|
+
- When loading succeeds, the archive is available through `globalThis.internalAssets`
|
|
34
|
+
|
|
35
|
+
## CLI Flags
|
|
36
|
+
|
|
37
|
+
- `--assets-list`
|
|
38
|
+
- Lists all entries inside bundled `assets.tar`
|
|
39
|
+
- Exits early before the main program starts
|
|
40
|
+
|
|
41
|
+
- `--assets-extract`
|
|
42
|
+
- Extracts bundled assets to the same directory as the executable
|
|
43
|
+
- Exits early before the main program starts
|
|
44
|
+
|
|
45
|
+
- `--assets-external`
|
|
46
|
+
- Skips loading bundled assets into `globalThis.internalAssets`
|
|
47
|
+
- Forces the main program and runtime helpers to use the external file tree
|
|
48
|
+
- Keeps the bootstrap alive while leaving `internalAssets` falsy
|
|
49
|
+
|
|
50
|
+
## Adapting this folder
|
|
51
|
+
|
|
52
|
+
This single-exe folder is intended for reuse by other projects. Usually you
|
|
53
|
+
only need to edit these project-specific files first:
|
|
54
|
+
|
|
55
|
+
- `entry.mjs`
|
|
56
|
+
- `packAssets.sh`
|
|
57
|
+
|
|
58
|
+
Then the main program can import `buildEarlyExit` from `compiled.js` and call
|
|
59
|
+
it before normal CLI parsing. `--build-exe` and `--build-for <target>` will run
|
|
60
|
+
`packAssets.sh` first, so `assets.tar` is generated as part of the build flow.
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
const compiledHelper = await import("./single-exe/compiled.js").catch(() => null);
|
|
64
|
+
await compiledHelper?.buildEarlyExit?.(process.argv, "my-bin");
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
- `--build-exe` builds with no Bun target.
|
|
68
|
+
- `--build-for <target>` passes `<target>` to `bun build --target=<target>`.
|
|
69
|
+
- The second argument is the output filename. If omitted, it defaults to `single.exe`.
|
|
70
|
+
|
|
71
|
+
The main program should also switch its repo/resource root when running as a
|
|
72
|
+
compiled binary. Use `IS_COMPILED` and `REPO_ROOT` from
|
|
73
|
+
`compiled.js`; when compiled, treat the executable directory as the repo root
|
|
74
|
+
used for external fallback files such as `static/`, `README.md`, or other files
|
|
75
|
+
packed by `packAssets.sh`.
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
const compiledHelper = await import("./single-exe/compiled.js").catch(() => null);
|
|
79
|
+
const repoRoot = compiledHelper?.REPO_ROOT
|
|
80
|
+
```
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const textDecoder = new TextDecoder();
|
|
2
|
+
const textEncoder = new TextEncoder();
|
|
3
|
+
|
|
4
|
+
export function hasInternalAssets() {
|
|
5
|
+
return Boolean(getAssetStore());
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function assetPath(...parts) {
|
|
9
|
+
return parts
|
|
10
|
+
.flatMap((part) => String(part).split(/[\\/]+/))
|
|
11
|
+
.filter(Boolean)
|
|
12
|
+
.join("/");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function listInternalAssetPaths(prefix = "") {
|
|
16
|
+
const store = getAssetStore();
|
|
17
|
+
if (!store) return [];
|
|
18
|
+
|
|
19
|
+
const normalizedPrefix = assetPath(prefix);
|
|
20
|
+
const entries = iterateAssetKeys(store);
|
|
21
|
+
if (!normalizedPrefix) {
|
|
22
|
+
return entries.sort();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const base = `${normalizedPrefix}/`;
|
|
26
|
+
return entries.filter((path) => path === normalizedPrefix || path.startsWith(base)).sort();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function listInternalAssetDirs(prefix = "") {
|
|
30
|
+
const normalizedPrefix = assetPath(prefix);
|
|
31
|
+
const base = normalizedPrefix ? `${normalizedPrefix}/` : "";
|
|
32
|
+
const dirs = new Set();
|
|
33
|
+
|
|
34
|
+
for (const path of listInternalAssetPaths(prefix)) {
|
|
35
|
+
const rest = normalizedPrefix ? path.slice(base.length) : path;
|
|
36
|
+
const [dir] = rest.split("/");
|
|
37
|
+
if (dir) dirs.add(dir);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return [...dirs].sort();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getInternalAsset(path) {
|
|
44
|
+
const store = getAssetStore();
|
|
45
|
+
if (!store) return null;
|
|
46
|
+
const key = assetPath(path);
|
|
47
|
+
if (store instanceof Map) return store.get(key) ?? null;
|
|
48
|
+
return store[key] ?? store[path] ?? null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function readInternalAssetBytes(path) {
|
|
52
|
+
const value = getInternalAsset(path);
|
|
53
|
+
if (value == null) return null;
|
|
54
|
+
if (value instanceof Uint8Array) return value;
|
|
55
|
+
if (ArrayBuffer.isView(value)) {
|
|
56
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
57
|
+
}
|
|
58
|
+
if (value instanceof ArrayBuffer) return new Uint8Array(value);
|
|
59
|
+
if (typeof value === "string") return textEncoder.encode(value);
|
|
60
|
+
return textEncoder.encode(String(value));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function readInternalAssetText(path) {
|
|
64
|
+
const bytes = readInternalAssetBytes(path);
|
|
65
|
+
if (!bytes) return null;
|
|
66
|
+
return textDecoder.decode(bytes);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function internalAssetSource(path) {
|
|
70
|
+
return {
|
|
71
|
+
name: path.split("/").pop() ?? path,
|
|
72
|
+
path,
|
|
73
|
+
async text() {
|
|
74
|
+
return readInternalAssetText(path) ?? "";
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function getAssetStore() {
|
|
80
|
+
const store = globalThis.internalAssets;
|
|
81
|
+
if (!store) return null;
|
|
82
|
+
if (store instanceof Map) return store;
|
|
83
|
+
if (typeof store === "object") return store;
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function iterateAssetKeys(store) {
|
|
88
|
+
if (store instanceof Map) return [...store.keys()].map(String);
|
|
89
|
+
return Object.keys(store);
|
|
90
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import assets from "./assets.tar" with { type: "file" };
|
|
2
|
+
import { getExeDirname, isCompiledBinary } from "./compiled.js";
|
|
3
|
+
|
|
4
|
+
const forceExternalAssets = process.argv.includes("--assets-external");
|
|
5
|
+
const debugAssetsLoader = Boolean(process.env.BUNMICRO_DEBUG);
|
|
6
|
+
if (forceExternalAssets) {
|
|
7
|
+
const flagIndex = process.argv.indexOf("--assets-external");
|
|
8
|
+
if (flagIndex >= 0) process.argv.splice(flagIndex, 1);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
globalThis.internalAssets = forceExternalAssets ? null : Object.create(null);
|
|
12
|
+
globalThis.assetsLoaderPromise = main(process.argv).catch((error) => {
|
|
13
|
+
console.error("# assets loader failed");
|
|
14
|
+
console.error(error);
|
|
15
|
+
return globalThis.internalAssets;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
async function main(argv) {
|
|
19
|
+
|
|
20
|
+
if (forceExternalAssets &&
|
|
21
|
+
!argv.includes("--assets-list") &&
|
|
22
|
+
!argv.includes("--assets-extract")) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const startedAt = debugAssetsLoader ? Bun.nanoseconds() : 0;
|
|
27
|
+
|
|
28
|
+
const tarball = await Bun.file(assets).bytes();
|
|
29
|
+
const archive = new Bun.Archive(tarball);
|
|
30
|
+
|
|
31
|
+
await cliEarlyExit(archive, argv);
|
|
32
|
+
|
|
33
|
+
const files = await archive.files();
|
|
34
|
+
const entries = [...files.entries()];
|
|
35
|
+
const assetsByPath = Object.create(null);
|
|
36
|
+
const errors = [];
|
|
37
|
+
|
|
38
|
+
for (const [path, file] of entries) {
|
|
39
|
+
try {
|
|
40
|
+
assetsByPath[path] = await file.bytes();
|
|
41
|
+
} catch (reason) {
|
|
42
|
+
errors.push({ path, reason });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (errors.length > 0) {
|
|
47
|
+
console.error(`# Failed to load ${errors.length} bundled asset(s):`);
|
|
48
|
+
for (const { path, reason } of errors) {
|
|
49
|
+
console.error(`- ${path}`);
|
|
50
|
+
if (reason) {
|
|
51
|
+
console.error(reason);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (debugAssetsLoader) {
|
|
56
|
+
const elapsedMs = (Bun.nanoseconds() - startedAt) / 1e6;
|
|
57
|
+
console.error(`Loaded assets: ${elapsedMs.toFixed(3)} ms`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
globalThis.internalAssets = assetsByPath;
|
|
61
|
+
return assetsByPath;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function cliEarlyExit(archive, argv) {
|
|
65
|
+
if (argv.includes("--assets-list")) {
|
|
66
|
+
const files = await archive.files();
|
|
67
|
+
for (const path of [...files.keys()].sort()) {
|
|
68
|
+
console.log(path);
|
|
69
|
+
}
|
|
70
|
+
process.exit(0);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (argv.includes("--assets-extract")) {
|
|
74
|
+
if (isCompiledBinary())
|
|
75
|
+
{
|
|
76
|
+
const targetDir = getExeDirname();
|
|
77
|
+
const extracted = await archive.extract(targetDir);
|
|
78
|
+
console.log(`Extracted ${extracted} asset(s) to ${targetDir}`);
|
|
79
|
+
} // if isCompiled
|
|
80
|
+
else
|
|
81
|
+
console.log("Assets extraction should only be used in a Bun compiled single-file executable");
|
|
82
|
+
|
|
83
|
+
process.exit(0);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { basename, dirname, resolve } from "node:path";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import child_process from "node:child_process";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export const IS_COMPILED = isCompiledBinary();
|
|
8
|
+
export const REPO_ROOT = IS_COMPILED
|
|
9
|
+
? getExeDirname()
|
|
10
|
+
: resolve(import.meta.dirname, "..");
|
|
11
|
+
const SINGLE_EXE_DIR = resolve(REPO_ROOT, "single-exe");
|
|
12
|
+
const SINGLE_EXE_ENTRY = resolve(SINGLE_EXE_DIR, "entry.mjs");
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export function isCompiledBinary() {
|
|
16
|
+
const argv = process.argv
|
|
17
|
+
return Boolean(argv?.[1]?.startsWith?.("/$bunfs/"));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function getExeDirname() {
|
|
21
|
+
const argv = process.argv
|
|
22
|
+
const execPath = process.execPath
|
|
23
|
+
|
|
24
|
+
const bn = basename(execPath);
|
|
25
|
+
if (bn.startsWith("ld") ||
|
|
26
|
+
bn.startsWith("libld") ||
|
|
27
|
+
bn.startsWith("linker") ) {
|
|
28
|
+
const realArgv = readFileSync("/proc/self/cmdline", "utf8").match(/[^\0]+/g);
|
|
29
|
+
return dirname(realArgv?.[1] ?? execPath);
|
|
30
|
+
}
|
|
31
|
+
return dirname(execPath) || process.cwd();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getDirnameFromUrl(importMetaUrl) {
|
|
35
|
+
return dirname(fileURLToPath(importMetaUrl));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function buildExecutable(target = "",build_outfile="single.exe") {
|
|
39
|
+
|
|
40
|
+
const outfile = resolve(process.cwd(), build_outfile);
|
|
41
|
+
const normalizedTarget = String(target || "").trim();
|
|
42
|
+
if(!globalThis.Bun || IS_COMPILED)
|
|
43
|
+
{
|
|
44
|
+
console.log("Build exe can only be run by Bun in the source tree");
|
|
45
|
+
return 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let bunBin=Bun.which('bun') || process.argv0;
|
|
49
|
+
|
|
50
|
+
const steps = [
|
|
51
|
+
{
|
|
52
|
+
label: "Pack assets",
|
|
53
|
+
cwd: SINGLE_EXE_DIR,
|
|
54
|
+
cmd: bunBin,
|
|
55
|
+
args: ["./packAssets.sh"],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
label: "Compile executable",
|
|
59
|
+
cwd: process.cwd(),
|
|
60
|
+
cmd: bunBin,
|
|
61
|
+
args: [
|
|
62
|
+
"build",
|
|
63
|
+
"--compile",
|
|
64
|
+
"--bytecode",
|
|
65
|
+
"--minify",
|
|
66
|
+
SINGLE_EXE_ENTRY,
|
|
67
|
+
`--outfile=${build_outfile}`,
|
|
68
|
+
...(normalizedTarget ? [`--target=${normalizedTarget}`] : []),
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
for (const step of steps) {
|
|
74
|
+
|
|
75
|
+
console.log('');
|
|
76
|
+
console.log(Bun?.markdown?.ansi?.('## '+step.label)||step.label);
|
|
77
|
+
|
|
78
|
+
const result = child_process.spawnSync(step.cmd, step.args, {
|
|
79
|
+
cwd: step.cwd,
|
|
80
|
+
stdio: "inherit",
|
|
81
|
+
env: process.env,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
console.log("");
|
|
85
|
+
console.log(Bun?.markdown?.ansi?.(
|
|
86
|
+
'- Status: '+result.status+' for '+step.label
|
|
87
|
+
)||result.status);
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if (result.error || result.status !== 0) {
|
|
92
|
+
|
|
93
|
+
if (result.error) {
|
|
94
|
+
console.error(result.error);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (step.label == "Pack assets") {
|
|
98
|
+
console.log("Pack assets failed; continuing with the existing assets.tar if available");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
} // for steps of build
|
|
105
|
+
|
|
106
|
+
if(await Bun.file(outfile).exists())
|
|
107
|
+
{
|
|
108
|
+
console.log(`Built executable: ${outfile}`);
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
else
|
|
112
|
+
{
|
|
113
|
+
console.log(`Error while building executable: ${outfile}`);
|
|
114
|
+
return 1;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export const buildExe = buildExecutable;
|
|
119
|
+
|
|
120
|
+
export async function buildEarlyExit(argv = process.argv,build_outfile) {
|
|
121
|
+
const buildExeIndex = argv.indexOf("--build-exe");
|
|
122
|
+
const buildForIndex = argv.indexOf("--build-for");
|
|
123
|
+
|
|
124
|
+
if (buildExeIndex === -1 && buildForIndex === -1) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (buildForIndex !== -1) {
|
|
129
|
+
const target = argv[buildForIndex + 1];
|
|
130
|
+
if (!target || target.startsWith("-")) {
|
|
131
|
+
console.error("Missing value for --build-for");
|
|
132
|
+
process.exit(2);
|
|
133
|
+
}
|
|
134
|
+
process.exit(await buildExe(target,build_outfile));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
process.exit(await buildExe(null,build_outfile));
|
|
138
|
+
}
|
package/static/css/kitty.css
CHANGED
package/static/help.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Static Frontend Notes
|
|
2
|
+
|
|
3
|
+
## Script Load Order
|
|
4
|
+
|
|
5
|
+
- `kitty.js` and `windows_bridge.js` install page-local helpers that inspect the terminal runtime.
|
|
6
|
+
- `xterm-addon-unicode11.js` must load before `gotty.js` so the terminal constructor can register Unicode 11 width tables when the addon is available.
|
|
7
|
+
|
|
8
|
+
## Internal Page Hooks
|
|
9
|
+
|
|
10
|
+
`gotty.js` exposes internal handles on `window` for this page's helper scripts.
|
|
11
|
+
|
|
12
|
+
## `window.__gottyTerminal`
|
|
13
|
+
|
|
14
|
+
High-level terminal wrapper used by the page.
|
|
15
|
+
|
|
16
|
+
Useful methods:
|
|
17
|
+
|
|
18
|
+
- `info()` -> `{ columns, rows }`
|
|
19
|
+
- `output(bytes)` -> feed remote output into the terminal/ZMODEM pipeline
|
|
20
|
+
- `getMessage()` -> overlay DOM node
|
|
21
|
+
- `showMessage(text, timeout)`
|
|
22
|
+
- `showReconnectMessage()`
|
|
23
|
+
- `removeMessage()`
|
|
24
|
+
- `setWindowTitle(title)`
|
|
25
|
+
- `setPreferences({ "font-size", "font-family", "EnableWebGL" })`
|
|
26
|
+
- `sendInput(data)`
|
|
27
|
+
- `onInput(callback)`
|
|
28
|
+
- `onResize(callback)`
|
|
29
|
+
- `deactivate()`
|
|
30
|
+
- `reset()`
|
|
31
|
+
- `close()`
|
|
32
|
+
- `disableStdin()`
|
|
33
|
+
- `enableStdin()`
|
|
34
|
+
- `focus()`
|
|
35
|
+
|
|
36
|
+
## `window.__gottyWebTTY`
|
|
37
|
+
|
|
38
|
+
Protocol/controller layer that owns the websocket session.
|
|
39
|
+
|
|
40
|
+
Useful methods:
|
|
41
|
+
|
|
42
|
+
- `open()` -> opens the session and returns a cleanup function
|
|
43
|
+
- `initializeConnection(arguments, authToken)`
|
|
44
|
+
- `sendInput(data)`
|
|
45
|
+
- `sendPing()`
|
|
46
|
+
- `sendResizeTerminal(columns, rows)`
|
|
47
|
+
- `sendSetEncoding(encoding)`
|
|
48
|
+
|
|
49
|
+
Properties commonly read by helpers:
|
|
50
|
+
|
|
51
|
+
- `reconnectToken`
|
|
52
|
+
- `reconnect`
|
|
53
|
+
- `bufSize`
|
|
54
|
+
- `disconnected`
|
|
55
|
+
|
|
56
|
+
## `window.__gottyConnection`
|
|
57
|
+
|
|
58
|
+
Lowest-level websocket wrapper for the active connection.
|
|
59
|
+
|
|
60
|
+
Useful methods:
|
|
61
|
+
|
|
62
|
+
- `send(data)`
|
|
63
|
+
- `close()`
|
|
64
|
+
- `isOpen()`
|
|
65
|
+
- `onOpen(callback)`
|
|
66
|
+
- `onReceive(callback)`
|
|
67
|
+
- `onClose(callback)`
|
|
68
|
+
|
|
69
|
+
## `window.__gottyXterm`
|
|
70
|
+
|
|
71
|
+
The raw xterm.js `Terminal` instance.
|
|
72
|
+
|
|
73
|
+
Useful methods/properties:
|
|
74
|
+
|
|
75
|
+
- `write(data)`
|
|
76
|
+
- `clear()`
|
|
77
|
+
- `reset()`
|
|
78
|
+
- `resize(columns, rows)`
|
|
79
|
+
- `focus()`
|
|
80
|
+
- `blur()`
|
|
81
|
+
- `loadAddon(addon)`
|
|
82
|
+
- `dispose()`
|
|
83
|
+
- `onData(callback)`
|
|
84
|
+
- `onResize(callback)`
|
|
85
|
+
- `options`
|
|
86
|
+
- `unicode.activeVersion`
|
|
87
|
+
|
|
88
|
+
## Other Globals
|
|
89
|
+
|
|
90
|
+
- `window.getTerminalText`: helper exposed by `GoTTYXterm` for debugging/copying the full visible buffer as plain text.
|
|
91
|
+
- `window.Zmodem`: ZMODEM helper namespace exposed by `zmodem.js`. Useful methods are used by the file-transfer addon, especially `Browser.send_files(...)` and `Browser.save_to_disk(...)`.
|
|
92
|
+
- `window.gotty_kitty_trace`: boolean trace flag consumed by `kitty.js`. When true, kitty-specific debug logging is enabled.
|
|
93
|
+
- `window.touchScrollThreshold`: mobile touch-scroll threshold in pixels used by `kitty.js` to convert finger movement into synthetic wheel ticks. Default: 24 px. Lower means faster scrolling.
|
|
94
|
+
- `alert_advanced(text, asHtml, closeOnClick)`: page-local modal helper used by custom UI scripts.
|
|
95
|
+
- `noWinOpenUseFetch()`: intentional monkey patch for link handling.
|
|
96
|
+
|
|
97
|
+
## `noWinOpenUseFetch()`
|
|
98
|
+
|
|
99
|
+
When enabled, the page stores:
|
|
100
|
+
|
|
101
|
+
- `realConfirm` -> original `confirm()`
|
|
102
|
+
- `realWinOpen` -> original `window.open()`
|
|
103
|
+
- `fetchText(url)` -> `fetch(url).text()` helper
|
|
104
|
+
|
|
105
|
+
It then replaces `window.open()` with a fetch-and-alert flow for terminal links.
|
|
106
|
+
|
|
107
|
+
## Server-Injected Globals
|
|
108
|
+
|
|
109
|
+
These exist before `gotty.js` runs:
|
|
110
|
+
|
|
111
|
+
- `gotty_auth_token`
|
|
112
|
+
- `gotty_ws_query_args`
|
|
113
|
+
- `gotty_themes`
|
|
114
|
+
- `gotty_enable_webgl`
|
|
115
|
+
|
|
116
|
+
## Frontend-Only Query Args
|
|
117
|
+
|
|
118
|
+
- `font-family`: overrides the terminal font family before xterm is created. If omitted, GoTTY uses the built-in monospace stack from `gotty.js`. Default: `DejaVu Sans Mono, Everson Mono, FreeMono, Menlo, Terminal, monospace, Apple Symbols`.
|
|
119
|
+
- `font-size`: overrides the terminal font size in pixels. Only positive numbers are accepted. If omitted, GoTTY uses the built-in default size. Default: `15`.
|
|
120
|
+
- `webgl`: overrides whether the terminal should enable the xterm WebGL addon. Accepted values: `on`, `true`, `1`, `off`, `false`, `0`. If omitted, GoTTY uses the server-side `gotty_enable_webgl` value, which is `false` unless the server starts with `--webgl`. Default: server value.
|
|
121
|
+
- `touch-scroll-threshold`: overrides the touch gesture distance, in pixels, that kitty.js uses before converting finger movement into scroll ticks. Only positive numbers are accepted. If omitted, kitty.js uses its built-in default. Default: `24`.
|
|
122
|
+
|
|
123
|
+
These are consumed by `gotty.js` for terminal setup and are stripped from the args forwarded to the backend session.
|
|
124
|
+
|
|
125
|
+
These hooks are internal, not a stable public API.
|
package/static/index.html
CHANGED
|
@@ -16,16 +16,23 @@
|
|
|
16
16
|
<body>
|
|
17
17
|
<div id="terminal"></div>
|
|
18
18
|
<div id="kitty-overlay"></div>
|
|
19
|
+
<!-- See static/help.md for script load order and internal page hooks. -->
|
|
19
20
|
<script src="./auth_token.js"></script>
|
|
20
21
|
<script src="./config.js"></script>
|
|
21
22
|
<script src="./js/kitty.js"></script>
|
|
22
23
|
<script src="./js/windows_bridge.js"></script>
|
|
23
24
|
<script src="./js/zmodem.js"></script>
|
|
25
|
+
<script src="./js/xterm-addon-unicode11.js"></script>
|
|
24
26
|
<script src="./js/gotty.js"></script>
|
|
25
27
|
|
|
26
28
|
|
|
27
29
|
<script>
|
|
28
|
-
|
|
30
|
+
// Page-local helpers below use the same window-scoped hooks created by gotty.js.
|
|
31
|
+
// Keep them here so the terminal page can show dialogs and redirect link handling
|
|
32
|
+
// without pulling in another framework layer.
|
|
33
|
+
// The declarations below intentionally leak a few globals for other scripts on this page:
|
|
34
|
+
// alert_advanced, noWinOpenUseFetch, realConfirm, realWinOpen, fetchText, and the
|
|
35
|
+
// window.open override installed by noWinOpenUseFetch().
|
|
29
36
|
|
|
30
37
|
function alert_advanced(text,asHtml,closeOnClick) {
|
|
31
38
|
// 若已有舊 dialog,先移除
|