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
package/gotty.js
CHANGED
|
@@ -30,6 +30,9 @@ const MSG_KITTY_GRAPHICS = "7";
|
|
|
30
30
|
const MSG_WINDOWS_BRIDGE = "9";
|
|
31
31
|
const MSG_SET_ROLE = "a";
|
|
32
32
|
const MSG_CONTROL_RESULT = "b";
|
|
33
|
+
const MSG_ZMODEM_MODE = "z";
|
|
34
|
+
const MSG_ZMODEM_OUTPUT = "y";
|
|
35
|
+
const MSG_ZMODEM_ACK = "Y";
|
|
33
36
|
const KITTY_TRACE = process.env.KITTY_TRACE === "1";
|
|
34
37
|
const WINDOWS_BRIDGE_TRACE = process.env.WINDOWS_BRIDGE_TRACE === "1";
|
|
35
38
|
const WINDOWS_BRIDGE_PREFIX = Buffer.from("@@GOTTYCTL:", "ascii");
|
|
@@ -59,22 +62,53 @@ const DEFAULTS = {
|
|
|
59
62
|
height: 0,
|
|
60
63
|
wsOrigin: "",
|
|
61
64
|
wsQueryArgs: "",
|
|
65
|
+
webgl: false,
|
|
62
66
|
quiet: false,
|
|
63
67
|
closeSignal: "SIGINT",
|
|
64
68
|
closeTimeout: -1
|
|
65
69
|
};
|
|
66
70
|
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
|
|
71
|
+
const compiledHelperPromise = import("./single-exe/compiled.js").catch(() => null);
|
|
72
|
+
const assetsHelperPromise = import("./single-exe/assetsHelper.js").catch(() => null);
|
|
73
|
+
|
|
74
|
+
let RESOURCE_ROOT = __dirname;
|
|
75
|
+
let STATIC_ROOT = path.resolve(RESOURCE_ROOT, "./static");
|
|
76
|
+
let DEFAULT_INDEX = path.join(STATIC_ROOT, "index.html");
|
|
77
|
+
let DEFAULT_MANIFEST = path.join(STATIC_ROOT, "manifest.json");
|
|
78
|
+
let DEFAULT_HELP = path.join(STATIC_ROOT, "help.md");
|
|
79
|
+
let DEFAULT_README = path.resolve(RESOURCE_ROOT, "./README.md");
|
|
80
|
+
let DEFAULT_README_EN = path.resolve(RESOURCE_ROOT, "./README.en.md");
|
|
81
|
+
let helperAssetPath = null;
|
|
82
|
+
let helperReadInternalAssetText = null;
|
|
83
|
+
let helperReadInternalAssetBytes = null;
|
|
84
|
+
|
|
85
|
+
function configureResourceRoot(compiledHelper) {
|
|
86
|
+
RESOURCE_ROOT = compiledHelper?.REPO_ROOT
|
|
87
|
+
STATIC_ROOT = path.resolve(RESOURCE_ROOT, "./static");
|
|
88
|
+
DEFAULT_INDEX = path.join(STATIC_ROOT, "index.html");
|
|
89
|
+
DEFAULT_MANIFEST = path.join(STATIC_ROOT, "manifest.json");
|
|
90
|
+
DEFAULT_HELP = path.join(STATIC_ROOT, "help.md");
|
|
91
|
+
DEFAULT_README = path.resolve(RESOURCE_ROOT, "./README.md");
|
|
92
|
+
DEFAULT_README_EN = path.resolve(RESOURCE_ROOT, "./README.en.md");
|
|
93
|
+
}
|
|
70
94
|
|
|
71
95
|
let cliBootstrapPromise = null;
|
|
72
96
|
for (const i of ["rz.js", "sz.js", "viu.mjs", "client.mjs"]) {
|
|
73
|
-
|
|
97
|
+
let subcmd = i.split(".")[0] ;
|
|
98
|
+
if (process.argv[2] === `--${subcmd}`) {
|
|
74
99
|
process.argv.splice(2, 1);
|
|
75
100
|
process.argv[1] = process.argv[1].replace(/gotty\.js$/, i);
|
|
76
101
|
cliBootstrapPromise = (async () => {
|
|
77
|
-
|
|
102
|
+
|
|
103
|
+
if(subcmd=="rz")
|
|
104
|
+
await import("./rz.js");
|
|
105
|
+
else if(subcmd=="sz")
|
|
106
|
+
await import("./sz.js");
|
|
107
|
+
else if(subcmd=="viu")
|
|
108
|
+
await import("./viu.mjs");
|
|
109
|
+
else if(subcmd=="client")
|
|
110
|
+
await import("./client.mjs");
|
|
111
|
+
|
|
78
112
|
})().catch((error) => {
|
|
79
113
|
console.error(String(error && error.stack ? error.stack : error));
|
|
80
114
|
process.exitCode = 1;
|
|
@@ -134,8 +168,8 @@ Options:
|
|
|
134
168
|
--title-format <value> Title format
|
|
135
169
|
(default: {{ .command }}@{{ .hostname }} )
|
|
136
170
|
|
|
137
|
-
--reconnect
|
|
138
|
-
|
|
171
|
+
--reconnect, --session Enable session mode
|
|
172
|
+
Keep the PTY session resumable after the browser disconnects
|
|
139
173
|
(default: disabled)
|
|
140
174
|
--reconnect-time <value> Time to preserve original TTY (seconds)
|
|
141
175
|
(default: -1 (forever) )
|
|
@@ -165,6 +199,9 @@ Options:
|
|
|
165
199
|
Adds a fixed query string to the WebSocket URL
|
|
166
200
|
Format: keyA=valA&keyB=valB
|
|
167
201
|
(default: empty)
|
|
202
|
+
|
|
203
|
+
--webgl Enable xterm WebGL renderer
|
|
204
|
+
(default: disabled)
|
|
168
205
|
|
|
169
206
|
--quiet Disable logging
|
|
170
207
|
(default: log to stderr)
|
|
@@ -174,7 +211,30 @@ Options:
|
|
|
174
211
|
--close-timeout <value> Seconds before force kill after ${DEFAULTS.closeSignal}
|
|
175
212
|
(default: -1 (disabled) )
|
|
176
213
|
|
|
177
|
-
--help
|
|
214
|
+
--help-web Show help for WebUI frontend
|
|
215
|
+
--readme Show README.md and exit
|
|
216
|
+
--readme-en Show README.en.md and exit
|
|
217
|
+
--help, -h Show help for CLI
|
|
218
|
+
|
|
219
|
+
Experimental:
|
|
220
|
+
--build-exe Build a Bun single-file executable and exit
|
|
221
|
+
--build-for <target> Build a Bun single-file executable for target`);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function printMarkdownFile(filePath) {
|
|
225
|
+
const text = readTextFile(filePath);
|
|
226
|
+
const markdownAnsi =
|
|
227
|
+
typeof Bun !== "undefined" &&
|
|
228
|
+
Bun &&
|
|
229
|
+
Bun.markdown &&
|
|
230
|
+
typeof Bun.markdown.ansi === "function"
|
|
231
|
+
? Bun.markdown.ansi
|
|
232
|
+
: null;
|
|
233
|
+
console.log(markdownAnsi ? markdownAnsi(text, { hyperlinks: true }) : text);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function printWebHelp() {
|
|
237
|
+
printMarkdownFile(DEFAULT_HELP);
|
|
178
238
|
}
|
|
179
239
|
|
|
180
240
|
function fatal(message, code = 1) {
|
|
@@ -423,6 +483,18 @@ function parseArgs(argv) {
|
|
|
423
483
|
printUsage();
|
|
424
484
|
process.exit(0);
|
|
425
485
|
break;
|
|
486
|
+
case "--help-web":
|
|
487
|
+
printWebHelp();
|
|
488
|
+
process.exit(0);
|
|
489
|
+
break;
|
|
490
|
+
case "--readme":
|
|
491
|
+
printMarkdownFile(DEFAULT_README);
|
|
492
|
+
process.exit(0);
|
|
493
|
+
break;
|
|
494
|
+
case "--readme-en":
|
|
495
|
+
printMarkdownFile(DEFAULT_README_EN);
|
|
496
|
+
process.exit(0);
|
|
497
|
+
break;
|
|
426
498
|
case "--address":
|
|
427
499
|
case "-a":
|
|
428
500
|
options.address = next();
|
|
@@ -467,6 +539,7 @@ function parseArgs(argv) {
|
|
|
467
539
|
options.titleFormat = next();
|
|
468
540
|
break;
|
|
469
541
|
case "--reconnect":
|
|
542
|
+
case "--session":
|
|
470
543
|
options.reconnect = true;
|
|
471
544
|
break;
|
|
472
545
|
case "--reconnect-time":
|
|
@@ -499,6 +572,9 @@ function parseArgs(argv) {
|
|
|
499
572
|
case "--ws-query-args":
|
|
500
573
|
options.wsQueryArgs = next();
|
|
501
574
|
break;
|
|
575
|
+
case "--webgl":
|
|
576
|
+
options.webgl = true;
|
|
577
|
+
break;
|
|
502
578
|
case "--quiet":
|
|
503
579
|
options.quiet = true;
|
|
504
580
|
break;
|
|
@@ -563,7 +639,33 @@ function previewBuffer(buffer, limit = 96) {
|
|
|
563
639
|
}
|
|
564
640
|
|
|
565
641
|
function readTextFile(filePath) {
|
|
566
|
-
|
|
642
|
+
const bundledText = helperReadInternalAssetText?.(internalAssetPathFor(filePath));
|
|
643
|
+
if (bundledText == null) {
|
|
644
|
+
return fs.readFileSync(filePath, "utf8");
|
|
645
|
+
}
|
|
646
|
+
return bundledText;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
function internalAssetPathFor(filePath) {
|
|
650
|
+
if (!helperAssetPath) {
|
|
651
|
+
return filePath;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
const normalizedPath = path.normalize(filePath);
|
|
655
|
+
const staticRelativePath = path.relative(STATIC_ROOT, normalizedPath);
|
|
656
|
+
if (staticRelativePath && !staticRelativePath.startsWith("..") && !path.isAbsolute(staticRelativePath)) {
|
|
657
|
+
return helperAssetPath("static", staticRelativePath);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
if (normalizedPath === DEFAULT_README) {
|
|
661
|
+
return helperAssetPath("README.md");
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
if (normalizedPath === DEFAULT_README_EN) {
|
|
665
|
+
return helperAssetPath("README.en.md");
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
return filePath;
|
|
567
669
|
}
|
|
568
670
|
|
|
569
671
|
function contentType(filePath) {
|
|
@@ -1218,7 +1320,8 @@ class NodePtyBackend {
|
|
|
1218
1320
|
constructor(options) {
|
|
1219
1321
|
let nodePty;
|
|
1220
1322
|
try {
|
|
1221
|
-
|
|
1323
|
+
let preventSingleExe="./lib/"
|
|
1324
|
+
nodePty = require(preventSingleExe+"node-pty");
|
|
1222
1325
|
} catch (error) {
|
|
1223
1326
|
throw new Error("node-pty is required on Windows but is not installed");
|
|
1224
1327
|
}
|
|
@@ -1472,6 +1575,11 @@ class BunPtyBackend {
|
|
|
1472
1575
|
|
|
1473
1576
|
function createPtyBackend(options) {
|
|
1474
1577
|
if (process.platform === "win32") {
|
|
1578
|
+
if (globalThis.Bun?.semver?.satisfies?.(
|
|
1579
|
+
globalThis.Bun?.version, ">=1.3.14"
|
|
1580
|
+
)) {
|
|
1581
|
+
return new BunPtyBackend(options);
|
|
1582
|
+
}
|
|
1475
1583
|
return new NodePtyBackend(options);
|
|
1476
1584
|
}
|
|
1477
1585
|
|
|
@@ -1487,7 +1595,7 @@ class PtySession {
|
|
|
1487
1595
|
this.permitWrite = options.permitWrite;
|
|
1488
1596
|
this.columns = options.width || 0;
|
|
1489
1597
|
this.rows = options.height || 0;
|
|
1490
|
-
this.bufferSize = 1024;
|
|
1598
|
+
this.bufferSize = 64 * 1024;
|
|
1491
1599
|
this.closed = false;
|
|
1492
1600
|
this.backendExited = false;
|
|
1493
1601
|
this.backendExitPromise = new Promise((resolve) => {
|
|
@@ -1507,6 +1615,17 @@ class PtySession {
|
|
|
1507
1615
|
this.windowsBridgeSeen = new Set();
|
|
1508
1616
|
this.windowsBridgeSeenOrder = [];
|
|
1509
1617
|
this.pendingEchoBytes = Buffer.alloc(0);
|
|
1618
|
+
this.zmodemBinaryBypass = false;
|
|
1619
|
+
this.zmodemDetectTail = Buffer.alloc(0);
|
|
1620
|
+
this.zmodemBinaryBytesSent = 0;
|
|
1621
|
+
this.zmodemBinaryBytesLogged = 0;
|
|
1622
|
+
this.zmodemOutputQueue = [];
|
|
1623
|
+
this.zmodemOutputInFlight = new Map();
|
|
1624
|
+
this.zmodemOutputSeq = 0;
|
|
1625
|
+
this.zmodemOutputStreamId = 0;
|
|
1626
|
+
this.zmodemOutputAckedSeq = -1;
|
|
1627
|
+
this.zmodemOutputWindow = 8;
|
|
1628
|
+
this.zmodemRetransmitTimer = null;
|
|
1510
1629
|
|
|
1511
1630
|
this.slaveVars = {
|
|
1512
1631
|
command: options.command,
|
|
@@ -1520,6 +1639,10 @@ class PtySession {
|
|
|
1520
1639
|
if (this.closed) {
|
|
1521
1640
|
return;
|
|
1522
1641
|
}
|
|
1642
|
+
if (this.shouldBypassOutputParsers(raw)) {
|
|
1643
|
+
this.sendChunk(MSG_OUTPUT, raw);
|
|
1644
|
+
return;
|
|
1645
|
+
}
|
|
1523
1646
|
const cursorBefore = this.cursorTracker.snapshot();
|
|
1524
1647
|
const parsed = this.kittyParser.consume(raw, cursorBefore);
|
|
1525
1648
|
if (parsed.graphics.length > 0) {
|
|
@@ -1578,6 +1701,33 @@ class PtySession {
|
|
|
1578
1701
|
);
|
|
1579
1702
|
}
|
|
1580
1703
|
|
|
1704
|
+
shouldBypassOutputParsers(raw) {
|
|
1705
|
+
if (this.zmodemBinaryBypass) {
|
|
1706
|
+
return true;
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
const data = this.zmodemDetectTail.length > 0
|
|
1710
|
+
? Buffer.concat([this.zmodemDetectTail, raw])
|
|
1711
|
+
: raw;
|
|
1712
|
+
this.zmodemDetectTail = data.subarray(Math.max(0, data.length - 8));
|
|
1713
|
+
|
|
1714
|
+
const binaryHeaderA = Buffer.from([0x2a, 0x18, 0x41]);
|
|
1715
|
+
const binaryHeaderC = Buffer.from([0x2a, 0x18, 0x43]);
|
|
1716
|
+
const hexHeader = Buffer.from([0x2a, 0x2a, 0x18, 0x42]);
|
|
1717
|
+
if (
|
|
1718
|
+
data.indexOf(hexHeader) !== -1 ||
|
|
1719
|
+
data.indexOf(binaryHeaderA) !== -1 ||
|
|
1720
|
+
data.indexOf(binaryHeaderC) !== -1
|
|
1721
|
+
) {
|
|
1722
|
+
this.zmodemBinaryBypass = true;
|
|
1723
|
+
this.resetZmodemOutputFlow();
|
|
1724
|
+
this.log("ZMODEM detected: bypassing server-side output parsers for this session");
|
|
1725
|
+
return true;
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
return false;
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1581
1731
|
attachWebSocket(ws, remoteAddr = "", readOnly = false) {
|
|
1582
1732
|
if (!ws || this.closed) {
|
|
1583
1733
|
return false;
|
|
@@ -1591,7 +1741,8 @@ class PtySession {
|
|
|
1591
1741
|
this.clients.set(ws, {
|
|
1592
1742
|
remoteAddr,
|
|
1593
1743
|
encoding: "null",
|
|
1594
|
-
readOnly
|
|
1744
|
+
readOnly,
|
|
1745
|
+
sendQueue: Promise.resolve()
|
|
1595
1746
|
});
|
|
1596
1747
|
if (this.permitWrite && !readOnly && !this.writerWs) {
|
|
1597
1748
|
this.writerWs = ws;
|
|
@@ -1969,6 +2120,11 @@ class PtySession {
|
|
|
1969
2120
|
}
|
|
1970
2121
|
|
|
1971
2122
|
sendChunk(type, raw) {
|
|
2123
|
+
if (type === MSG_OUTPUT && this.zmodemBinaryBypass) {
|
|
2124
|
+
this.sendZmodemOutput(raw);
|
|
2125
|
+
return;
|
|
2126
|
+
}
|
|
2127
|
+
|
|
1972
2128
|
if (type === MSG_OUTPUT && this.supportsWindowsBridge) {
|
|
1973
2129
|
const bridged = this.outgoingWindowsBridgeParser.consume(raw);
|
|
1974
2130
|
for (const control of bridged.controls) {
|
|
@@ -1987,6 +2143,79 @@ class PtySession {
|
|
|
1987
2143
|
}
|
|
1988
2144
|
}
|
|
1989
2145
|
|
|
2146
|
+
sendZmodemOutput(raw) {
|
|
2147
|
+
this.zmodemBinaryBytesSent += raw.length;
|
|
2148
|
+
if (this.zmodemBinaryBytesSent - this.zmodemBinaryBytesLogged >= 16 * 1024 * 1024) {
|
|
2149
|
+
this.zmodemBinaryBytesLogged = this.zmodemBinaryBytesSent;
|
|
2150
|
+
this.log(`ZMODEM text websocket output ${this.zmodemBinaryBytesSent.toLocaleString()} bytes`);
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
const maxChunkSize = 3 * 1024;
|
|
2154
|
+
for (let offset = 0; offset < raw.length; offset += maxChunkSize) {
|
|
2155
|
+
const chunk = raw.subarray(offset, Math.min(offset + maxChunkSize, raw.length));
|
|
2156
|
+
this.zmodemOutputQueue.push({
|
|
2157
|
+
seq: this.zmodemOutputSeq,
|
|
2158
|
+
payload: chunk.toString("base64")
|
|
2159
|
+
});
|
|
2160
|
+
this.zmodemOutputSeq += 1;
|
|
2161
|
+
}
|
|
2162
|
+
this.flushZmodemOutput();
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
resetZmodemOutputFlow() {
|
|
2166
|
+
this.zmodemOutputQueue = [];
|
|
2167
|
+
this.zmodemOutputInFlight = new Map();
|
|
2168
|
+
this.zmodemOutputSeq = 0;
|
|
2169
|
+
this.zmodemOutputStreamId += 1;
|
|
2170
|
+
this.zmodemOutputAckedSeq = -1;
|
|
2171
|
+
if (this.zmodemRetransmitTimer) {
|
|
2172
|
+
clearTimeout(this.zmodemRetransmitTimer);
|
|
2173
|
+
this.zmodemRetransmitTimer = null;
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
flushZmodemOutput() {
|
|
2178
|
+
const targetWs = this.writerWs && this.writerWs.readyState === WebSocket.OPEN
|
|
2179
|
+
? this.writerWs
|
|
2180
|
+
: this.clients.keys().next().value;
|
|
2181
|
+
if (!targetWs || targetWs.readyState !== WebSocket.OPEN) {
|
|
2182
|
+
return;
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
while (this.zmodemOutputInFlight.size < this.zmodemOutputWindow && this.zmodemOutputQueue.length > 0) {
|
|
2186
|
+
const item = this.zmodemOutputQueue.shift();
|
|
2187
|
+
this.zmodemOutputInFlight.set(item.seq, item);
|
|
2188
|
+
this.sendZmodemOutputItem(item, targetWs);
|
|
2189
|
+
}
|
|
2190
|
+
this.scheduleZmodemRetransmit();
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
sendZmodemOutputItem(item, targetWs) {
|
|
2194
|
+
this.send(MSG_ZMODEM_OUTPUT, `${this.zmodemOutputStreamId}:${item.seq}:${item.payload}`, targetWs);
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
scheduleZmodemRetransmit() {
|
|
2198
|
+
if (this.zmodemRetransmitTimer || this.zmodemOutputInFlight.size === 0) {
|
|
2199
|
+
return;
|
|
2200
|
+
}
|
|
2201
|
+
this.zmodemRetransmitTimer = setTimeout(() => {
|
|
2202
|
+
this.zmodemRetransmitTimer = null;
|
|
2203
|
+
if (!this.zmodemBinaryBypass || this.zmodemOutputInFlight.size === 0) {
|
|
2204
|
+
return;
|
|
2205
|
+
}
|
|
2206
|
+
const targetWs = this.writerWs && this.writerWs.readyState === WebSocket.OPEN
|
|
2207
|
+
? this.writerWs
|
|
2208
|
+
: this.clients.keys().next().value;
|
|
2209
|
+
if (!targetWs || targetWs.readyState !== WebSocket.OPEN) {
|
|
2210
|
+
return;
|
|
2211
|
+
}
|
|
2212
|
+
for (const item of this.zmodemOutputInFlight.values()) {
|
|
2213
|
+
this.sendZmodemOutputItem(item, targetWs);
|
|
2214
|
+
}
|
|
2215
|
+
this.scheduleZmodemRetransmit();
|
|
2216
|
+
}, 750);
|
|
2217
|
+
}
|
|
2218
|
+
|
|
1990
2219
|
filterEchoedTerminalReplies(raw) {
|
|
1991
2220
|
const needle = Buffer.from("^[[?1;2c", "ascii");
|
|
1992
2221
|
const combined = this.pendingEchoBytes.length > 0 ? Buffer.concat([this.pendingEchoBytes, raw]) : raw;
|
|
@@ -2146,6 +2375,41 @@ class PtySession {
|
|
|
2146
2375
|
client.encoding = payload;
|
|
2147
2376
|
}
|
|
2148
2377
|
break;
|
|
2378
|
+
case MSG_ZMODEM_MODE:
|
|
2379
|
+
if (!this.isWriter(ws)) {
|
|
2380
|
+
return;
|
|
2381
|
+
}
|
|
2382
|
+
{
|
|
2383
|
+
const enabled = payload === "1";
|
|
2384
|
+
const wasEnabled = this.zmodemBinaryBypass;
|
|
2385
|
+
this.zmodemBinaryBypass = enabled;
|
|
2386
|
+
if (this.zmodemBinaryBypass && !wasEnabled) {
|
|
2387
|
+
this.zmodemBinaryBytesSent = 0;
|
|
2388
|
+
this.zmodemBinaryBytesLogged = 0;
|
|
2389
|
+
this.resetZmodemOutputFlow();
|
|
2390
|
+
} else if (!this.zmodemBinaryBypass) {
|
|
2391
|
+
this.resetZmodemOutputFlow();
|
|
2392
|
+
}
|
|
2393
|
+
this.log(`ZMODEM parser bypass ${this.zmodemBinaryBypass ? "enabled" : "disabled"} by browser`);
|
|
2394
|
+
}
|
|
2395
|
+
break;
|
|
2396
|
+
case MSG_ZMODEM_ACK: {
|
|
2397
|
+
if (!this.isWriter(ws)) {
|
|
2398
|
+
return;
|
|
2399
|
+
}
|
|
2400
|
+
const seq = Number.parseInt(payload, 10);
|
|
2401
|
+
if (!Number.isFinite(seq) || seq <= this.zmodemOutputAckedSeq) {
|
|
2402
|
+
return;
|
|
2403
|
+
}
|
|
2404
|
+
for (const key of this.zmodemOutputInFlight.keys()) {
|
|
2405
|
+
if (key <= seq) {
|
|
2406
|
+
this.zmodemOutputInFlight.delete(key);
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
this.zmodemOutputAckedSeq = seq;
|
|
2410
|
+
this.flushZmodemOutput();
|
|
2411
|
+
break;
|
|
2412
|
+
}
|
|
2149
2413
|
case MSG_RESIZE_TERMINAL: {
|
|
2150
2414
|
if (!this.isWriter(ws) || (this.columns !== 0 && this.rows !== 0)) {
|
|
2151
2415
|
return;
|
|
@@ -2171,19 +2435,53 @@ class PtySession {
|
|
|
2171
2435
|
|
|
2172
2436
|
send(type, payload, targetWs = null) {
|
|
2173
2437
|
if (targetWs) {
|
|
2174
|
-
|
|
2175
|
-
targetWs.send(type + payload);
|
|
2176
|
-
}
|
|
2438
|
+
this.queueSend(targetWs, type + payload);
|
|
2177
2439
|
return;
|
|
2178
2440
|
}
|
|
2179
2441
|
|
|
2180
2442
|
for (const ws of this.clients.keys()) {
|
|
2181
|
-
|
|
2182
|
-
ws.send(type + payload);
|
|
2183
|
-
}
|
|
2443
|
+
this.queueSend(ws, type + payload);
|
|
2184
2444
|
}
|
|
2185
2445
|
}
|
|
2186
2446
|
|
|
2447
|
+
queueSend(ws, payload, binary = false) {
|
|
2448
|
+
const client = this.clients.get(ws);
|
|
2449
|
+
if (!client || ws.readyState !== WebSocket.OPEN) {
|
|
2450
|
+
return;
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2453
|
+
const sendOne = async () => {
|
|
2454
|
+
await new Promise((resolve, reject) => {
|
|
2455
|
+
try {
|
|
2456
|
+
if (binary) {
|
|
2457
|
+
ws.send(payload, { binary: true }, (error) => {
|
|
2458
|
+
if (error) {
|
|
2459
|
+
reject(error);
|
|
2460
|
+
return;
|
|
2461
|
+
}
|
|
2462
|
+
resolve();
|
|
2463
|
+
});
|
|
2464
|
+
} else {
|
|
2465
|
+
ws.send(payload, (error) => {
|
|
2466
|
+
if (error) {
|
|
2467
|
+
reject(error);
|
|
2468
|
+
return;
|
|
2469
|
+
}
|
|
2470
|
+
resolve();
|
|
2471
|
+
});
|
|
2472
|
+
}
|
|
2473
|
+
} catch (error) {
|
|
2474
|
+
reject(error);
|
|
2475
|
+
}
|
|
2476
|
+
});
|
|
2477
|
+
};
|
|
2478
|
+
|
|
2479
|
+
client.sendQueue = client.sendQueue.then(sendOne, sendOne);
|
|
2480
|
+
client.sendQueue.catch((error) => {
|
|
2481
|
+
this.log(`WebSocket send failed: ${error && error.message ? error.message : error}`);
|
|
2482
|
+
});
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2187
2485
|
terminateBackend(gracePeriodMs = 5000) {
|
|
2188
2486
|
if (this.backendTerminationPromise) {
|
|
2189
2487
|
return this.backendTerminationPromise;
|
|
@@ -2392,6 +2690,7 @@ function createServerRuntime(command, argv, options) {
|
|
|
2392
2690
|
const lines = [
|
|
2393
2691
|
"var gotty_term = 'xterm';",
|
|
2394
2692
|
`var gotty_ws_query_args = ${JSON.stringify(options.wsQueryArgs)};`,
|
|
2693
|
+
`var gotty_enable_webgl = ${options.webgl ? "true" : "false"};`,
|
|
2395
2694
|
`var gotty_kitty_trace = ${KITTY_TRACE ? "true" : "false"};`
|
|
2396
2695
|
];
|
|
2397
2696
|
res.writeHead(200, {
|
|
@@ -2402,6 +2701,23 @@ function createServerRuntime(command, argv, options) {
|
|
|
2402
2701
|
return;
|
|
2403
2702
|
}
|
|
2404
2703
|
|
|
2704
|
+
if (relativePath === "help.md" || relativePath === "help") {
|
|
2705
|
+
const markdown = readTextFile(DEFAULT_HELP);
|
|
2706
|
+
const markdownToHtml = global.Bun?.markdown?.html;
|
|
2707
|
+
const renderHtml = relativePath === "help" && typeof markdownToHtml === "function";
|
|
2708
|
+
const body = renderHtml
|
|
2709
|
+
? markdownToHtml(markdown)
|
|
2710
|
+
: markdown;
|
|
2711
|
+
res.writeHead(200, {
|
|
2712
|
+
"Content-Type": renderHtml
|
|
2713
|
+
? "text/html; charset=utf-8"
|
|
2714
|
+
: "text/markdown; charset=utf-8",
|
|
2715
|
+
"Server": "GoTTY"
|
|
2716
|
+
});
|
|
2717
|
+
res.end(body);
|
|
2718
|
+
return;
|
|
2719
|
+
}
|
|
2720
|
+
|
|
2405
2721
|
if (relativePath === "css.md" || relativePath === "css") {
|
|
2406
2722
|
const sessions = [];
|
|
2407
2723
|
for (const session of activeSessions) {
|
|
@@ -2474,6 +2790,18 @@ function createServerRuntime(command, argv, options) {
|
|
|
2474
2790
|
return;
|
|
2475
2791
|
}
|
|
2476
2792
|
|
|
2793
|
+
const bundledAsset = helperReadInternalAssetBytes?.(internalAssetPathFor(assetPath));
|
|
2794
|
+
if (bundledAsset != null) {
|
|
2795
|
+
const body = bundledAsset instanceof Uint8Array ? bundledAsset : new Uint8Array(bundledAsset);
|
|
2796
|
+
res.writeHead(200, {
|
|
2797
|
+
"Content-Type": contentType(assetPath),
|
|
2798
|
+
"Content-Length": body.length,
|
|
2799
|
+
"Server": "GoTTY"
|
|
2800
|
+
});
|
|
2801
|
+
res.end(body);
|
|
2802
|
+
return;
|
|
2803
|
+
}
|
|
2804
|
+
|
|
2477
2805
|
fs.stat(assetPath, (error, stats) => {
|
|
2478
2806
|
if (error || !stats.isFile()) {
|
|
2479
2807
|
res.writeHead(404, { "Server": "GoTTY" });
|
|
@@ -2522,6 +2850,7 @@ function createServerRuntime(command, argv, options) {
|
|
|
2522
2850
|
const wss = new WebSocketServer({
|
|
2523
2851
|
noServer: true,
|
|
2524
2852
|
clientTracking: false,
|
|
2853
|
+
perMessageDeflate: false,
|
|
2525
2854
|
handleProtocols(protocols) {
|
|
2526
2855
|
return protocols.has("webtty") ? "webtty" : false;
|
|
2527
2856
|
}
|
|
@@ -2876,6 +3205,29 @@ function main() {
|
|
|
2876
3205
|
runtime.start();
|
|
2877
3206
|
}
|
|
2878
3207
|
|
|
2879
|
-
|
|
2880
|
-
|
|
3208
|
+
async function bootstrap() {
|
|
3209
|
+
try {
|
|
3210
|
+
const compiledHelper = await compiledHelperPromise;
|
|
3211
|
+
configureResourceRoot(compiledHelper);
|
|
3212
|
+
await compiledHelper?.buildEarlyExit?.(process.argv,'jsgt');
|
|
3213
|
+
|
|
3214
|
+
const assetsHelper = await assetsHelperPromise;
|
|
3215
|
+
if (assetsHelper) {
|
|
3216
|
+
helperAssetPath = assetsHelper.assetPath;
|
|
3217
|
+
helperReadInternalAssetText = assetsHelper.readInternalAssetText;
|
|
3218
|
+
helperReadInternalAssetBytes = assetsHelper.readInternalAssetBytes;
|
|
3219
|
+
}
|
|
3220
|
+
await globalThis.assetsLoaderPromise;
|
|
3221
|
+
} catch (error) {
|
|
3222
|
+
console.error(String(error && error.stack ? error.stack : error));
|
|
3223
|
+
}
|
|
3224
|
+
|
|
3225
|
+
if (!cliBootstrapPromise) {
|
|
3226
|
+
main();
|
|
3227
|
+
}
|
|
2881
3228
|
}
|
|
3229
|
+
|
|
3230
|
+
bootstrap().catch((error) => {
|
|
3231
|
+
console.error(String(error && error.stack ? error.stack : error));
|
|
3232
|
+
process.exitCode = 1;
|
|
3233
|
+
});
|
package/package.json
CHANGED
package/rz.js
CHANGED
|
@@ -8,6 +8,7 @@ const {
|
|
|
8
8
|
restoreStdin,
|
|
9
9
|
setRawStdin,
|
|
10
10
|
stderr,
|
|
11
|
+
appendDebugLog,
|
|
11
12
|
writeOctets,
|
|
12
13
|
} = require("./zmodem-node");
|
|
13
14
|
const {
|
|
@@ -30,9 +31,10 @@ async function main() {
|
|
|
30
31
|
return;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
const Zmodem = loadZmodem();
|
|
34
|
+
const Zmodem = await loadZmodem();
|
|
34
35
|
const session = new Zmodem.Session.Receive();
|
|
35
36
|
let ending = false;
|
|
37
|
+
const completedUploads = [];
|
|
36
38
|
|
|
37
39
|
const finish = (code, error) => {
|
|
38
40
|
if (ending) {
|
|
@@ -42,6 +44,10 @@ async function main() {
|
|
|
42
44
|
restoreStdin();
|
|
43
45
|
if (error) {
|
|
44
46
|
stderr(String(error && error.stack ? error.stack : error));
|
|
47
|
+
} else if (code === 0) {
|
|
48
|
+
for (const file of completedUploads) {
|
|
49
|
+
stderr(`uploaded ${file.path} (${formatByteCount(file.size)})`);
|
|
50
|
+
}
|
|
45
51
|
}
|
|
46
52
|
process.exitCode = code;
|
|
47
53
|
};
|
|
@@ -60,7 +66,7 @@ async function main() {
|
|
|
60
66
|
});
|
|
61
67
|
|
|
62
68
|
session.on("offer", (offer) => {
|
|
63
|
-
void receiveOffer(offer, targetDir).catch((error) => {
|
|
69
|
+
void receiveOffer(offer, targetDir, completedUploads).catch((error) => {
|
|
64
70
|
try {
|
|
65
71
|
session.abort();
|
|
66
72
|
} catch {}
|
|
@@ -148,19 +154,22 @@ async function runWindowsBridge(targetDir) {
|
|
|
148
154
|
});
|
|
149
155
|
}
|
|
150
156
|
|
|
151
|
-
async function receiveOffer(offer, targetDir) {
|
|
157
|
+
async function receiveOffer(offer, targetDir, completedUploads) {
|
|
152
158
|
const details = offer.get_details();
|
|
153
159
|
const originalName = details.name;
|
|
154
160
|
const localName = basenameSafe(originalName);
|
|
155
161
|
const outputPath = path.join(targetDir, localName);
|
|
156
162
|
const fd = fs.openSync(outputPath, "w", details.mode ? details.mode & 0o777 : 0o644);
|
|
163
|
+
let receivedBytes = 0;
|
|
157
164
|
|
|
158
|
-
|
|
165
|
+
debug(`receiving ${originalName} -> ${outputPath}`);
|
|
159
166
|
|
|
160
167
|
try {
|
|
161
168
|
await offer.accept({
|
|
162
169
|
on_input: (payload) => {
|
|
163
|
-
|
|
170
|
+
const buffer = Buffer.from(payload);
|
|
171
|
+
fs.writeSync(fd, buffer);
|
|
172
|
+
receivedBytes += buffer.length;
|
|
164
173
|
},
|
|
165
174
|
});
|
|
166
175
|
} finally {
|
|
@@ -171,7 +180,16 @@ async function receiveOffer(offer, targetDir) {
|
|
|
171
180
|
fs.utimesSync(outputPath, new Date(), details.mtime);
|
|
172
181
|
}
|
|
173
182
|
|
|
174
|
-
|
|
183
|
+
completedUploads.push({ path: outputPath, size: receivedBytes });
|
|
184
|
+
debug(`received ${outputPath}`);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function debug(message) {
|
|
188
|
+
appendDebugLog(message);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function formatByteCount(bytes) {
|
|
192
|
+
return `${Number(bytes || 0).toLocaleString()} bytes`;
|
|
175
193
|
}
|
|
176
194
|
|
|
177
195
|
main().catch((error) => {
|