jsgotty 1.0.0 → 1.1.1

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 CHANGED
@@ -3,6 +3,26 @@
3
3
  [中文 README](README.md)
4
4
 
5
5
  ## News
6
+ ### 2026/07/03 - [1.1.0]
7
+ - Unicode 11 from upstream
8
+ - WebGL support by `--webgl` and query args
9
+ - Frontend help by `--help-web`
10
+ - Added `font-size` and `font-family`
11
+ - Added `touch-scroll-threshold` for fast scrolling
12
+ - Added experimental single-exe build commands: `--build-exe` and `--build-for <target>`
13
+ - Improved ZMODEM / `rz/sz` reliability for large transfers
14
+ * terminal mode is switched for binary transfer and restored after transfer / cancel
15
+ * server-side output parsers are bypassed during ZMODEM sessions
16
+ * ZMODEM data uses ordered WebSocket chunks with acknowledgement / retransmit handling
17
+ - Improved `sz` download UI
18
+ * streams downloads to browser file writer
19
+ * shows current file, transferred bytes / total bytes, progress, and verbose transfer logs
20
+ - Improved `rz` upload UI
21
+ * shows current file, transferred bytes / total bytes, progress, and verbose transfer logs
22
+ * supports back-to-back `sz` then `rz` sessions more reliably
23
+ - `rz` / `sz` terminal commands now print completion summaries with file path and byte size
24
+ - ZMODEM debug logs are opt-in with `JSGOTTY_ZMODEM_LOG`
25
+
6
26
  ### 2026/06/22 - [1.0.0]
7
27
  - Added gotty cli client
8
28
  * compatible with golang gotty
package/README.md CHANGED
@@ -3,6 +3,25 @@
3
3
  [English README](README.en.md)
4
4
 
5
5
  ## News
6
+ ### 2026/07/03 - [1.1.0]
7
+ - Unicode 11 from upstream
8
+ - WebGL support by `--webgl` & query args
9
+ - Frontend help by `--help-web`
10
+ - Added `font-size` and `font-family`
11
+ - Added `touch-scroll-threshold` for fast scrolling
12
+ - Added experimental single-exe build commands: `--build-exe` and `--build-for <target>`
13
+ - 改善 ZMODEM / `rz/sz` 大檔案傳輸可靠度
14
+ * 傳輸時切換終端機模式,結束或取消後恢復
15
+ * ZMODEM 期間繞過 server-side output parsers
16
+ * ZMODEM 資料改用有順序、ACK、重送處理的 WebSocket chunks
17
+ - 改善 `sz` 下載 UI
18
+ * 下載直接串流寫入瀏覽器檔案 writer
19
+ * 顯示目前檔案、已傳輸 bytes / 總 bytes、進度與 verbose transfer logs
20
+ - 改善 `rz` 上傳 UI
21
+ * 顯示目前檔案、已傳輸 bytes / 總 bytes、進度與 verbose transfer logs
22
+ * 改善連續執行 `sz` 後馬上 `rz` 的穩定性
23
+ - `rz` / `sz` 終端機指令完成時會顯示檔案路徑與 byte size
24
+ - ZMODEM debug log 改成透過 `JSGOTTY_ZMODEM_LOG` 才啟用
6
25
  ### 2026/06/22 - [1.0.0]
7
26
  - Added gotty cli client
8
27
  * compatible with golang gotty
package/client.mjs CHANGED
@@ -688,9 +688,7 @@ pid:
688
688
  });
689
689
  }
690
690
 
691
- try {
692
- await main();
693
- } catch (error) {
691
+ main().catch((error) => {
694
692
  console.error(`client.mjs: ${error.message}`);
695
- process.exit(1);
696
- }
693
+ process.exitCode = 1;
694
+ });
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 STATIC_ROOT = path.resolve(__dirname, "./static");
68
- const DEFAULT_INDEX = path.join(STATIC_ROOT, "index.html");
69
- const DEFAULT_MANIFEST = path.join(STATIC_ROOT, "manifest.json");
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
- if (process.argv[2] === `--${i.split(".")[0]}`) {
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
- await import(`./${i}`);
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;
@@ -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, -h Show 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();
@@ -499,6 +571,9 @@ function parseArgs(argv) {
499
571
  case "--ws-query-args":
500
572
  options.wsQueryArgs = next();
501
573
  break;
574
+ case "--webgl":
575
+ options.webgl = true;
576
+ break;
502
577
  case "--quiet":
503
578
  options.quiet = true;
504
579
  break;
@@ -563,7 +638,33 @@ function previewBuffer(buffer, limit = 96) {
563
638
  }
564
639
 
565
640
  function readTextFile(filePath) {
566
- return fs.readFileSync(filePath, "utf8");
641
+ const bundledText = helperReadInternalAssetText?.(internalAssetPathFor(filePath));
642
+ if (bundledText == null) {
643
+ return fs.readFileSync(filePath, "utf8");
644
+ }
645
+ return bundledText;
646
+ }
647
+
648
+ function internalAssetPathFor(filePath) {
649
+ if (!helperAssetPath) {
650
+ return filePath;
651
+ }
652
+
653
+ const normalizedPath = path.normalize(filePath);
654
+ const staticRelativePath = path.relative(STATIC_ROOT, normalizedPath);
655
+ if (staticRelativePath && !staticRelativePath.startsWith("..") && !path.isAbsolute(staticRelativePath)) {
656
+ return helperAssetPath("static", staticRelativePath);
657
+ }
658
+
659
+ if (normalizedPath === DEFAULT_README) {
660
+ return helperAssetPath("README.md");
661
+ }
662
+
663
+ if (normalizedPath === DEFAULT_README_EN) {
664
+ return helperAssetPath("README.en.md");
665
+ }
666
+
667
+ return filePath;
567
668
  }
568
669
 
569
670
  function contentType(filePath) {
@@ -1218,7 +1319,8 @@ class NodePtyBackend {
1218
1319
  constructor(options) {
1219
1320
  let nodePty;
1220
1321
  try {
1221
- nodePty = require("./lib/node-pty");
1322
+ let preventSingleExe="./lib/"
1323
+ nodePty = require(preventSingleExe+"node-pty");
1222
1324
  } catch (error) {
1223
1325
  throw new Error("node-pty is required on Windows but is not installed");
1224
1326
  }
@@ -1472,6 +1574,11 @@ class BunPtyBackend {
1472
1574
 
1473
1575
  function createPtyBackend(options) {
1474
1576
  if (process.platform === "win32") {
1577
+ if (globalThis.Bun?.semver?.satisfies?.(
1578
+ globalThis.Bun?.version, ">=1.3.14"
1579
+ )) {
1580
+ return new BunPtyBackend(options);
1581
+ }
1475
1582
  return new NodePtyBackend(options);
1476
1583
  }
1477
1584
 
@@ -1487,7 +1594,7 @@ class PtySession {
1487
1594
  this.permitWrite = options.permitWrite;
1488
1595
  this.columns = options.width || 0;
1489
1596
  this.rows = options.height || 0;
1490
- this.bufferSize = 1024;
1597
+ this.bufferSize = 64 * 1024;
1491
1598
  this.closed = false;
1492
1599
  this.backendExited = false;
1493
1600
  this.backendExitPromise = new Promise((resolve) => {
@@ -1507,6 +1614,17 @@ class PtySession {
1507
1614
  this.windowsBridgeSeen = new Set();
1508
1615
  this.windowsBridgeSeenOrder = [];
1509
1616
  this.pendingEchoBytes = Buffer.alloc(0);
1617
+ this.zmodemBinaryBypass = false;
1618
+ this.zmodemDetectTail = Buffer.alloc(0);
1619
+ this.zmodemBinaryBytesSent = 0;
1620
+ this.zmodemBinaryBytesLogged = 0;
1621
+ this.zmodemOutputQueue = [];
1622
+ this.zmodemOutputInFlight = new Map();
1623
+ this.zmodemOutputSeq = 0;
1624
+ this.zmodemOutputStreamId = 0;
1625
+ this.zmodemOutputAckedSeq = -1;
1626
+ this.zmodemOutputWindow = 8;
1627
+ this.zmodemRetransmitTimer = null;
1510
1628
 
1511
1629
  this.slaveVars = {
1512
1630
  command: options.command,
@@ -1520,6 +1638,10 @@ class PtySession {
1520
1638
  if (this.closed) {
1521
1639
  return;
1522
1640
  }
1641
+ if (this.shouldBypassOutputParsers(raw)) {
1642
+ this.sendChunk(MSG_OUTPUT, raw);
1643
+ return;
1644
+ }
1523
1645
  const cursorBefore = this.cursorTracker.snapshot();
1524
1646
  const parsed = this.kittyParser.consume(raw, cursorBefore);
1525
1647
  if (parsed.graphics.length > 0) {
@@ -1578,6 +1700,33 @@ class PtySession {
1578
1700
  );
1579
1701
  }
1580
1702
 
1703
+ shouldBypassOutputParsers(raw) {
1704
+ if (this.zmodemBinaryBypass) {
1705
+ return true;
1706
+ }
1707
+
1708
+ const data = this.zmodemDetectTail.length > 0
1709
+ ? Buffer.concat([this.zmodemDetectTail, raw])
1710
+ : raw;
1711
+ this.zmodemDetectTail = data.subarray(Math.max(0, data.length - 8));
1712
+
1713
+ const binaryHeaderA = Buffer.from([0x2a, 0x18, 0x41]);
1714
+ const binaryHeaderC = Buffer.from([0x2a, 0x18, 0x43]);
1715
+ const hexHeader = Buffer.from([0x2a, 0x2a, 0x18, 0x42]);
1716
+ if (
1717
+ data.indexOf(hexHeader) !== -1 ||
1718
+ data.indexOf(binaryHeaderA) !== -1 ||
1719
+ data.indexOf(binaryHeaderC) !== -1
1720
+ ) {
1721
+ this.zmodemBinaryBypass = true;
1722
+ this.resetZmodemOutputFlow();
1723
+ this.log("ZMODEM detected: bypassing server-side output parsers for this session");
1724
+ return true;
1725
+ }
1726
+
1727
+ return false;
1728
+ }
1729
+
1581
1730
  attachWebSocket(ws, remoteAddr = "", readOnly = false) {
1582
1731
  if (!ws || this.closed) {
1583
1732
  return false;
@@ -1591,7 +1740,8 @@ class PtySession {
1591
1740
  this.clients.set(ws, {
1592
1741
  remoteAddr,
1593
1742
  encoding: "null",
1594
- readOnly
1743
+ readOnly,
1744
+ sendQueue: Promise.resolve()
1595
1745
  });
1596
1746
  if (this.permitWrite && !readOnly && !this.writerWs) {
1597
1747
  this.writerWs = ws;
@@ -1969,6 +2119,11 @@ class PtySession {
1969
2119
  }
1970
2120
 
1971
2121
  sendChunk(type, raw) {
2122
+ if (type === MSG_OUTPUT && this.zmodemBinaryBypass) {
2123
+ this.sendZmodemOutput(raw);
2124
+ return;
2125
+ }
2126
+
1972
2127
  if (type === MSG_OUTPUT && this.supportsWindowsBridge) {
1973
2128
  const bridged = this.outgoingWindowsBridgeParser.consume(raw);
1974
2129
  for (const control of bridged.controls) {
@@ -1987,6 +2142,79 @@ class PtySession {
1987
2142
  }
1988
2143
  }
1989
2144
 
2145
+ sendZmodemOutput(raw) {
2146
+ this.zmodemBinaryBytesSent += raw.length;
2147
+ if (this.zmodemBinaryBytesSent - this.zmodemBinaryBytesLogged >= 16 * 1024 * 1024) {
2148
+ this.zmodemBinaryBytesLogged = this.zmodemBinaryBytesSent;
2149
+ this.log(`ZMODEM text websocket output ${this.zmodemBinaryBytesSent.toLocaleString()} bytes`);
2150
+ }
2151
+
2152
+ const maxChunkSize = 3 * 1024;
2153
+ for (let offset = 0; offset < raw.length; offset += maxChunkSize) {
2154
+ const chunk = raw.subarray(offset, Math.min(offset + maxChunkSize, raw.length));
2155
+ this.zmodemOutputQueue.push({
2156
+ seq: this.zmodemOutputSeq,
2157
+ payload: chunk.toString("base64")
2158
+ });
2159
+ this.zmodemOutputSeq += 1;
2160
+ }
2161
+ this.flushZmodemOutput();
2162
+ }
2163
+
2164
+ resetZmodemOutputFlow() {
2165
+ this.zmodemOutputQueue = [];
2166
+ this.zmodemOutputInFlight = new Map();
2167
+ this.zmodemOutputSeq = 0;
2168
+ this.zmodemOutputStreamId += 1;
2169
+ this.zmodemOutputAckedSeq = -1;
2170
+ if (this.zmodemRetransmitTimer) {
2171
+ clearTimeout(this.zmodemRetransmitTimer);
2172
+ this.zmodemRetransmitTimer = null;
2173
+ }
2174
+ }
2175
+
2176
+ flushZmodemOutput() {
2177
+ const targetWs = this.writerWs && this.writerWs.readyState === WebSocket.OPEN
2178
+ ? this.writerWs
2179
+ : this.clients.keys().next().value;
2180
+ if (!targetWs || targetWs.readyState !== WebSocket.OPEN) {
2181
+ return;
2182
+ }
2183
+
2184
+ while (this.zmodemOutputInFlight.size < this.zmodemOutputWindow && this.zmodemOutputQueue.length > 0) {
2185
+ const item = this.zmodemOutputQueue.shift();
2186
+ this.zmodemOutputInFlight.set(item.seq, item);
2187
+ this.sendZmodemOutputItem(item, targetWs);
2188
+ }
2189
+ this.scheduleZmodemRetransmit();
2190
+ }
2191
+
2192
+ sendZmodemOutputItem(item, targetWs) {
2193
+ this.send(MSG_ZMODEM_OUTPUT, `${this.zmodemOutputStreamId}:${item.seq}:${item.payload}`, targetWs);
2194
+ }
2195
+
2196
+ scheduleZmodemRetransmit() {
2197
+ if (this.zmodemRetransmitTimer || this.zmodemOutputInFlight.size === 0) {
2198
+ return;
2199
+ }
2200
+ this.zmodemRetransmitTimer = setTimeout(() => {
2201
+ this.zmodemRetransmitTimer = null;
2202
+ if (!this.zmodemBinaryBypass || this.zmodemOutputInFlight.size === 0) {
2203
+ return;
2204
+ }
2205
+ const targetWs = this.writerWs && this.writerWs.readyState === WebSocket.OPEN
2206
+ ? this.writerWs
2207
+ : this.clients.keys().next().value;
2208
+ if (!targetWs || targetWs.readyState !== WebSocket.OPEN) {
2209
+ return;
2210
+ }
2211
+ for (const item of this.zmodemOutputInFlight.values()) {
2212
+ this.sendZmodemOutputItem(item, targetWs);
2213
+ }
2214
+ this.scheduleZmodemRetransmit();
2215
+ }, 750);
2216
+ }
2217
+
1990
2218
  filterEchoedTerminalReplies(raw) {
1991
2219
  const needle = Buffer.from("^[[?1;2c", "ascii");
1992
2220
  const combined = this.pendingEchoBytes.length > 0 ? Buffer.concat([this.pendingEchoBytes, raw]) : raw;
@@ -2146,6 +2374,41 @@ class PtySession {
2146
2374
  client.encoding = payload;
2147
2375
  }
2148
2376
  break;
2377
+ case MSG_ZMODEM_MODE:
2378
+ if (!this.isWriter(ws)) {
2379
+ return;
2380
+ }
2381
+ {
2382
+ const enabled = payload === "1";
2383
+ const wasEnabled = this.zmodemBinaryBypass;
2384
+ this.zmodemBinaryBypass = enabled;
2385
+ if (this.zmodemBinaryBypass && !wasEnabled) {
2386
+ this.zmodemBinaryBytesSent = 0;
2387
+ this.zmodemBinaryBytesLogged = 0;
2388
+ this.resetZmodemOutputFlow();
2389
+ } else if (!this.zmodemBinaryBypass) {
2390
+ this.resetZmodemOutputFlow();
2391
+ }
2392
+ this.log(`ZMODEM parser bypass ${this.zmodemBinaryBypass ? "enabled" : "disabled"} by browser`);
2393
+ }
2394
+ break;
2395
+ case MSG_ZMODEM_ACK: {
2396
+ if (!this.isWriter(ws)) {
2397
+ return;
2398
+ }
2399
+ const seq = Number.parseInt(payload, 10);
2400
+ if (!Number.isFinite(seq) || seq <= this.zmodemOutputAckedSeq) {
2401
+ return;
2402
+ }
2403
+ for (const key of this.zmodemOutputInFlight.keys()) {
2404
+ if (key <= seq) {
2405
+ this.zmodemOutputInFlight.delete(key);
2406
+ }
2407
+ }
2408
+ this.zmodemOutputAckedSeq = seq;
2409
+ this.flushZmodemOutput();
2410
+ break;
2411
+ }
2149
2412
  case MSG_RESIZE_TERMINAL: {
2150
2413
  if (!this.isWriter(ws) || (this.columns !== 0 && this.rows !== 0)) {
2151
2414
  return;
@@ -2171,19 +2434,53 @@ class PtySession {
2171
2434
 
2172
2435
  send(type, payload, targetWs = null) {
2173
2436
  if (targetWs) {
2174
- if (this.clients.has(targetWs) && targetWs.readyState === WebSocket.OPEN) {
2175
- targetWs.send(type + payload);
2176
- }
2437
+ this.queueSend(targetWs, type + payload);
2177
2438
  return;
2178
2439
  }
2179
2440
 
2180
2441
  for (const ws of this.clients.keys()) {
2181
- if (ws.readyState === WebSocket.OPEN) {
2182
- ws.send(type + payload);
2183
- }
2442
+ this.queueSend(ws, type + payload);
2184
2443
  }
2185
2444
  }
2186
2445
 
2446
+ queueSend(ws, payload, binary = false) {
2447
+ const client = this.clients.get(ws);
2448
+ if (!client || ws.readyState !== WebSocket.OPEN) {
2449
+ return;
2450
+ }
2451
+
2452
+ const sendOne = async () => {
2453
+ await new Promise((resolve, reject) => {
2454
+ try {
2455
+ if (binary) {
2456
+ ws.send(payload, { binary: true }, (error) => {
2457
+ if (error) {
2458
+ reject(error);
2459
+ return;
2460
+ }
2461
+ resolve();
2462
+ });
2463
+ } else {
2464
+ ws.send(payload, (error) => {
2465
+ if (error) {
2466
+ reject(error);
2467
+ return;
2468
+ }
2469
+ resolve();
2470
+ });
2471
+ }
2472
+ } catch (error) {
2473
+ reject(error);
2474
+ }
2475
+ });
2476
+ };
2477
+
2478
+ client.sendQueue = client.sendQueue.then(sendOne, sendOne);
2479
+ client.sendQueue.catch((error) => {
2480
+ this.log(`WebSocket send failed: ${error && error.message ? error.message : error}`);
2481
+ });
2482
+ }
2483
+
2187
2484
  terminateBackend(gracePeriodMs = 5000) {
2188
2485
  if (this.backendTerminationPromise) {
2189
2486
  return this.backendTerminationPromise;
@@ -2392,6 +2689,7 @@ function createServerRuntime(command, argv, options) {
2392
2689
  const lines = [
2393
2690
  "var gotty_term = 'xterm';",
2394
2691
  `var gotty_ws_query_args = ${JSON.stringify(options.wsQueryArgs)};`,
2692
+ `var gotty_enable_webgl = ${options.webgl ? "true" : "false"};`,
2395
2693
  `var gotty_kitty_trace = ${KITTY_TRACE ? "true" : "false"};`
2396
2694
  ];
2397
2695
  res.writeHead(200, {
@@ -2402,6 +2700,23 @@ function createServerRuntime(command, argv, options) {
2402
2700
  return;
2403
2701
  }
2404
2702
 
2703
+ if (relativePath === "help.md" || relativePath === "help") {
2704
+ const markdown = readTextFile(DEFAULT_HELP);
2705
+ const markdownToHtml = global.Bun?.markdown?.html;
2706
+ const renderHtml = relativePath === "help" && typeof markdownToHtml === "function";
2707
+ const body = renderHtml
2708
+ ? markdownToHtml(markdown)
2709
+ : markdown;
2710
+ res.writeHead(200, {
2711
+ "Content-Type": renderHtml
2712
+ ? "text/html; charset=utf-8"
2713
+ : "text/markdown; charset=utf-8",
2714
+ "Server": "GoTTY"
2715
+ });
2716
+ res.end(body);
2717
+ return;
2718
+ }
2719
+
2405
2720
  if (relativePath === "css.md" || relativePath === "css") {
2406
2721
  const sessions = [];
2407
2722
  for (const session of activeSessions) {
@@ -2474,6 +2789,18 @@ function createServerRuntime(command, argv, options) {
2474
2789
  return;
2475
2790
  }
2476
2791
 
2792
+ const bundledAsset = helperReadInternalAssetBytes?.(internalAssetPathFor(assetPath));
2793
+ if (bundledAsset != null) {
2794
+ const body = bundledAsset instanceof Uint8Array ? bundledAsset : new Uint8Array(bundledAsset);
2795
+ res.writeHead(200, {
2796
+ "Content-Type": contentType(assetPath),
2797
+ "Content-Length": body.length,
2798
+ "Server": "GoTTY"
2799
+ });
2800
+ res.end(body);
2801
+ return;
2802
+ }
2803
+
2477
2804
  fs.stat(assetPath, (error, stats) => {
2478
2805
  if (error || !stats.isFile()) {
2479
2806
  res.writeHead(404, { "Server": "GoTTY" });
@@ -2522,6 +2849,7 @@ function createServerRuntime(command, argv, options) {
2522
2849
  const wss = new WebSocketServer({
2523
2850
  noServer: true,
2524
2851
  clientTracking: false,
2852
+ perMessageDeflate: false,
2525
2853
  handleProtocols(protocols) {
2526
2854
  return protocols.has("webtty") ? "webtty" : false;
2527
2855
  }
@@ -2876,6 +3204,29 @@ function main() {
2876
3204
  runtime.start();
2877
3205
  }
2878
3206
 
2879
- if (!cliBootstrapPromise) {
2880
- main();
3207
+ async function bootstrap() {
3208
+ try {
3209
+ const compiledHelper = await compiledHelperPromise;
3210
+ configureResourceRoot(compiledHelper);
3211
+ await compiledHelper?.buildEarlyExit?.(process.argv,'jsgt');
3212
+
3213
+ const assetsHelper = await assetsHelperPromise;
3214
+ if (assetsHelper) {
3215
+ helperAssetPath = assetsHelper.assetPath;
3216
+ helperReadInternalAssetText = assetsHelper.readInternalAssetText;
3217
+ helperReadInternalAssetBytes = assetsHelper.readInternalAssetBytes;
3218
+ }
3219
+ await globalThis.assetsLoaderPromise;
3220
+ } catch (error) {
3221
+ console.error(String(error && error.stack ? error.stack : error));
3222
+ }
3223
+
3224
+ if (!cliBootstrapPromise) {
3225
+ main();
3226
+ }
2881
3227
  }
3228
+
3229
+ bootstrap().catch((error) => {
3230
+ console.error(String(error && error.stack ? error.stack : error));
3231
+ process.exitCode = 1;
3232
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsgotty",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Share your terminal as a web application: A JavaScript rewrite of GoTTY",
5
5
  "bin": {
6
6
  "jsgotty": "./gotty.js"