brsh 3.9.0 → 3.10.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/Readme.md +22 -4
  3. package/bin/Readme.md +33 -3
  4. package/bin/exportFileSystem.js +127 -110
  5. package/bin/wbt.js +118 -0
  6. package/dist/shell.es.js +4074 -3717
  7. package/dist/shell.es.js.map +1 -1
  8. package/dist/shell.min.js +26 -25
  9. package/dist/shell.min.js.map +1 -1
  10. package/dist/terminal.cjs.js +3 -3
  11. package/dist/terminal.cjs.js.map +1 -1
  12. package/dist/terminal.es.js +55 -33
  13. package/dist/terminal.es.js.map +1 -1
  14. package/dist/terminal.min.js +3 -3
  15. package/dist/terminal.min.js.map +1 -1
  16. package/dist/wbt.es.js +3082 -2710
  17. package/dist/wbt.es.js.map +1 -1
  18. package/dist/wbt.min.js +16 -12
  19. package/dist/wbt.min.js.map +1 -1
  20. package/index.js +102 -80
  21. package/lib/BaseFileSystem.js +57 -2
  22. package/lib/BinaryContainer.js +1 -1
  23. package/lib/Command.js +1 -1
  24. package/lib/Context.js +4 -3
  25. package/lib/FileSystem.js +4 -2
  26. package/lib/InteractiveCommand.js +9 -8
  27. package/lib/JsCommand.js +113 -0
  28. package/lib/NodeFileSystem.js +164 -30
  29. package/lib/Readme.md +1 -0
  30. package/lib/ScriptCommand.js +148 -8
  31. package/lib/Terminal.js +60 -6
  32. package/lib/TtyStream.js +36 -2
  33. package/lib/WasmCommand.js +313 -66
  34. package/lib/buildFilesystemStructure.js +38 -24
  35. package/lib/isUtf8Text.js +47 -0
  36. package/lib/local/which.js +8 -3
  37. package/lib/wbt/index.js +473 -175
  38. package/lib/wbt/registry.js +21 -1
  39. package/package.json +3 -2
  40. package/test/devices-signals.test.js +112 -0
  41. package/test/doom.test.js +7 -4
  42. package/test/exportFileSystem.test.js +37 -15
  43. package/test/js-command.test.js +125 -0
  44. package/test/node-filesystem.test.js +7 -0
  45. package/test/scripts.test.js +30 -0
  46. package/test/terminal.test.js +148 -0
  47. package/test/wasm-cli.test.js +76 -0
  48. package/test/wbt.test.js +418 -10
  49. package/test/wbtCli.test.js +160 -0
@@ -1134,7 +1134,7 @@ var D = e?.default ?? e, O = class {
1134
1134
  this._setupDom(this._el, n), this.renderer = new C(this._cmdList, this.screen, {
1135
1135
  cursor: this._cursor,
1136
1136
  urlWhitelist: p
1137
- }), this._listenForEvents(), this.cli && (this.attach(this.cli), typeof this.cli.on == "function" && this.cli.on("exit", (e) => {
1137
+ }), this._measureAndSetSize(), this._listenForEvents(), this.cli && (this.attach(this.cli), typeof this.cli.on == "function" && this.cli.on("exit", (e) => {
1138
1138
  delete this.cli, typeof this._exitFn == "function" && this._exitFn(e);
1139
1139
  }), u && this.onCommand(u)), g && (this.attach(g), u && this.onCommand(u)), c === "click" && this._mobileInput(), this.renderer.flushRender();
1140
1140
  }
@@ -1303,7 +1303,7 @@ var D = e?.default ?? e, O = class {
1303
1303
  if (this.screen.isAltScreen) return !0;
1304
1304
  if (this.cli && this.cli.runningCommand) {
1305
1305
  let e = this.cli.runningCommand;
1306
- if (e.interactive || e._inAltScreen || e.stdinStream && e.stdinStream.isRaw) return !0;
1306
+ if (e.interactive || e._inAltScreen || e.isRaw || e.stdinStream && e.stdinStream.isRaw) return !0;
1307
1307
  }
1308
1308
  return !!(this._attachedStream && this._attachedStream.isRaw || /\x1b\[\?(?:1049|1047|47)[hl]/.test(e) || /\x1b\[(?:\d*J|(?:\d+;\d+)?[Hf]|\d*[ABLM]|\d*;\d*r)/.test(e));
1309
1309
  }
@@ -1317,25 +1317,39 @@ var D = e?.default ?? e, O = class {
1317
1317
  "Alt",
1318
1318
  "Shift",
1319
1319
  "Meta",
1320
- "CapsLock"
1320
+ "CapsLock",
1321
+ "NumLock",
1322
+ "ScrollLock",
1323
+ "Dead",
1324
+ "Unidentified"
1321
1325
  ].includes(e) || a) return null;
1322
- let o = this.parser.applicationCursorKeys;
1323
- if (e === "ArrowUp") return n ? "\x1B[1;3A" : r ? "\x1B[1;5A" : o ? "\x1BOA" : "\x1B[A";
1324
- if (e === "ArrowDown") return n ? "\x1B[1;3B" : r ? "\x1B[1;5B" : o ? "\x1BOB" : "\x1B[B";
1325
- if (e === "ArrowRight") return n ? "\x1B[1;3C" : r ? "\x1B[1;5C" : o ? "\x1BOC" : "\x1B[C";
1326
- if (e === "ArrowLeft") return n ? "\x1B[1;3D" : r ? "\x1B[1;5D" : o ? "\x1BOD" : "\x1B[D";
1327
- if (e === "Home") return o ? "\x1BOH" : "\x1B[H";
1328
- if (e === "End") return o ? "\x1BOF" : "\x1B[F";
1329
- if (e === "Delete") return "\x1B[3~";
1330
- if (e === "Insert") return "\x1B[2~";
1331
- if (e === "PageUp") return "\x1B[5~";
1332
- if (e === "PageDown") return "\x1B[6~";
1333
- if (e === "Enter") return "\r";
1334
- if (e === "Backspace") return n ? "\x1B" : "";
1335
- if (e === "Tab") return i ? "\x1B[Z" : " ";
1336
- if (e === "Escape") return "\x1B";
1337
- let s = e.match(/^F(\d{1,2})$/);
1338
- if (s) return {
1326
+ let o = {
1327
+ Up: "ArrowUp",
1328
+ Down: "ArrowDown",
1329
+ Right: "ArrowRight",
1330
+ Left: "ArrowLeft",
1331
+ Esc: "Escape",
1332
+ Return: "Enter",
1333
+ Del: "Delete",
1334
+ Space: " ",
1335
+ Spacebar: " "
1336
+ }[e] || e, s = this.parser.applicationCursorKeys;
1337
+ if (o === "ArrowUp") return n ? "\x1B[1;3A" : r ? "\x1B[1;5A" : s ? "\x1BOA" : "\x1B[A";
1338
+ if (o === "ArrowDown") return n ? "\x1B[1;3B" : r ? "\x1B[1;5B" : s ? "\x1BOB" : "\x1B[B";
1339
+ if (o === "ArrowRight") return n ? "\x1B[1;3C" : r ? "\x1B[1;5C" : s ? "\x1BOC" : "\x1B[C";
1340
+ if (o === "ArrowLeft") return n ? "\x1B[1;3D" : r ? "\x1B[1;5D" : s ? "\x1BOD" : "\x1B[D";
1341
+ if (o === "Home") return s ? "\x1BOH" : "\x1B[H";
1342
+ if (o === "End") return s ? "\x1BOF" : "\x1B[F";
1343
+ if (o === "Delete") return "\x1B[3~";
1344
+ if (o === "Insert") return "\x1B[2~";
1345
+ if (o === "PageUp") return "\x1B[5~";
1346
+ if (o === "PageDown") return "\x1B[6~";
1347
+ if (o === "Enter") return "\r";
1348
+ if (o === "Backspace") return n ? "\x1B" : "";
1349
+ if (o === "Tab") return i ? "\x1B[Z" : " ";
1350
+ if (o === "Escape") return "\x1B";
1351
+ let c = o.match(/^F(\d{1,2})$/);
1352
+ if (c) return {
1339
1353
  1: "\x1BOP",
1340
1354
  2: "\x1BOQ",
1341
1355
  3: "\x1BOR",
@@ -1348,15 +1362,15 @@ var D = e?.default ?? e, O = class {
1348
1362
  10: "\x1B[21~",
1349
1363
  11: "\x1B[23~",
1350
1364
  12: "\x1B[24~"
1351
- }[Number(s[1])] || null;
1352
- if (r && e.length === 1) {
1353
- let t = e.toUpperCase().charCodeAt(0);
1354
- if (t >= 64 && t <= 95) {
1355
- let e = String.fromCharCode(t - 64);
1356
- return n ? "\x1B" + e : e;
1365
+ }[Number(c[1])] || null;
1366
+ if (r && o.length === 1) {
1367
+ let e = o.toUpperCase().charCodeAt(0);
1368
+ if (e >= 64 && e <= 95) {
1369
+ let t = String.fromCharCode(e - 64);
1370
+ return n ? "\x1B" + t : t;
1357
1371
  }
1358
1372
  }
1359
- return e.length === 1 ? n ? "\x1B" + e : e : null;
1373
+ return o.length === 1 ? n ? "\x1B" + o : o : null;
1360
1374
  }
1361
1375
  _enqueueTypeAnimation(e) {
1362
1376
  this._typeQueue += e, this._typeTimer === null && (this._typeTimer = setInterval(() => {
@@ -1393,11 +1407,11 @@ var D = e?.default ?? e, O = class {
1393
1407
  _setupDom(e, t = "Roboto Mono") {
1394
1408
  if (typeof document > "u") return;
1395
1409
  let n = document.createElement("link");
1396
- n.href = `https://fonts.googleapis.com/css?family=${encodeURIComponent(t)}:ital,wght@0,400;0,700;1,400;1,700&display=swap`, n.rel = "stylesheet", document.head && document.head.appendChild && document.head.appendChild(n), this._cmdList = document.createElement("ul"), this._cmdList.style.fontFamily = `'${t}', monospace`, this._cmdList.style.listStyle = "none", this._cmdList.style.padding = "0", this._cmdList.style.margin = "0", this._lineWrap && this._cmdList.classList.add("terminal--wrap"), e.appendChild(this._cmdList), this._charMeasure = document.createElement("span"), this._charMeasure.className = "terminal__char-measure", this._charMeasure.style.fontFamily = `'${t}', monospace`, this._charMeasure.textContent = "X", this._charMeasure.setAttribute("aria-hidden", "true"), e.appendChild(this._charMeasure), setTimeout(() => this._measureAndSetSize(), 0), document.fonts && document.fonts.ready && document.fonts.ready.then(() => this._measureAndSetSize()), typeof ResizeObserver < "u" && new ResizeObserver(() => this._measureAndSetSize()).observe(e);
1410
+ n.href = `https://fonts.googleapis.com/css?family=${encodeURIComponent(t)}:ital,wght@0,400;0,700;1,400;1,700&display=swap`, n.rel = "stylesheet", document.head && document.head.appendChild && document.head.appendChild(n), this._cmdList = document.createElement("ul"), this._cmdList.style.fontFamily = `'${t}', monospace`, this._cmdList.style.listStyle = "none", this._cmdList.style.padding = "0", this._cmdList.style.margin = "0", this._cmdList.style.lineHeight = "1.15em", this._lineWrap && this._cmdList.classList.add("terminal--wrap"), e.appendChild(this._cmdList), this._charMeasure = document.createElement("span"), this._charMeasure.className = "terminal__char-measure", this._charMeasure.style.fontFamily = `'${t}', monospace`, this._charMeasure.style.position = "absolute", this._charMeasure.style.top = "0", this._charMeasure.style.left = "0", this._charMeasure.style.visibility = "hidden", this._charMeasure.style.pointerEvents = "none", this._charMeasure.style.whiteSpace = "pre", this._charMeasure.style.lineHeight = "1.15em", this._charMeasure.textContent = "X", this._charMeasure.setAttribute("aria-hidden", "true"), e.appendChild(this._charMeasure), setTimeout(() => this._measureAndSetSize(), 0), document.fonts && document.fonts.ready && document.fonts.ready.then(() => this._measureAndSetSize()), typeof ResizeObserver < "u" && (this._resizeObserver = new ResizeObserver(() => this._measureAndSetSize()), this._resizeObserver.observe(e));
1397
1411
  }
1398
1412
  _listenForEvents() {
1399
- if (!(typeof window > "u") && (this._onKeyDown = (e) => {
1400
- if (e.metaKey) return;
1413
+ if (!(typeof window > "u") && (this._onWindowResize = () => this._measureAndSetSize(), window.addEventListener("resize", this._onWindowResize), this._onKeyDown = (e) => {
1414
+ if (!e || e.defaultPrevented || e.isComposing || e.keyCode === 229 || e.metaKey) return;
1401
1415
  let t = this._encodeKey(e.key, {
1402
1416
  alt: !!e.altKey,
1403
1417
  ctrl: !!e.ctrlKey,
@@ -1541,11 +1555,19 @@ var D = e?.default ?? e, O = class {
1541
1555
  if (!this._charMeasure || !this._el || typeof this._el.getBoundingClientRect != "function") return;
1542
1556
  let e = this._charMeasure.getBoundingClientRect(), t = this._el.getBoundingClientRect();
1543
1557
  if (!e || !t || !e.width || !e.height || !t.width || e.width >= t.width && e.height >= t.height) return;
1544
- let n = Math.max(1, Math.floor(t.width / e.width)), r = Math.max(1, Math.floor((t.height || e.height * 24) / e.height));
1545
- (n !== this._lastCols || r !== this._lastRows) && this.resize(n, r);
1558
+ let n = typeof this._el.clientWidth == "number" && this._el.clientWidth > 0 ? this._el.clientWidth : t.width, r = typeof this._el.clientHeight == "number" && this._el.clientHeight > 0 ? this._el.clientHeight : t.height || e.height * 24;
1559
+ if (typeof window < "u" && typeof window.getComputedStyle == "function") try {
1560
+ let e = window.getComputedStyle(this._el);
1561
+ if (e) {
1562
+ let t = (parseFloat(e.paddingLeft) || 0) + (parseFloat(e.paddingRight) || 0), i = (parseFloat(e.paddingTop) || 0) + (parseFloat(e.paddingBottom) || 0);
1563
+ n > t && (n -= t), r > i && (r -= i);
1564
+ }
1565
+ } catch {}
1566
+ let i = Math.max(1, Math.floor(n / e.width)), a = Math.max(1, Math.floor(r / e.height));
1567
+ (i !== this._lastCols || a !== this._lastRows) && this.resize(i, a);
1546
1568
  }
1547
1569
  destroy() {
1548
- this._typeTimer !== null && (clearInterval(this._typeTimer), this._typeTimer = null), typeof window < "u" && window.removeEventListener && (this._onKeyDown && window.removeEventListener("keydown", this._onKeyDown), this._onPaste && window.removeEventListener("paste", this._onPaste)), this._mobileInputElement &&= (this._onMobileInputClick && this._el && typeof this._el.removeEventListener == "function" && this._el.removeEventListener("click", this._onMobileInputClick), this._mobileInputElement.parentNode ? this._mobileInputElement.parentNode.removeChild(this._mobileInputElement) : typeof this._mobileInputElement.remove == "function" && this._mobileInputElement.remove(), null), this._dataListeners = [], this._resizeListeners = [], this._titleListeners = [];
1570
+ this._typeTimer !== null && (clearInterval(this._typeTimer), this._typeTimer = null), this._resizeObserver && typeof this._resizeObserver.disconnect == "function" && (this._resizeObserver.disconnect(), this._resizeObserver = null), typeof window < "u" && window.removeEventListener && (this._onWindowResize && window.removeEventListener("resize", this._onWindowResize), this._onKeyDown && window.removeEventListener("keydown", this._onKeyDown), this._onPaste && window.removeEventListener("paste", this._onPaste)), this._mobileInputElement &&= (this._onMobileInputClick && this._el && typeof this._el.removeEventListener == "function" && this._el.removeEventListener("click", this._onMobileInputClick), this._mobileInputElement.parentNode ? this._mobileInputElement.parentNode.removeChild(this._mobileInputElement) : typeof this._mobileInputElement.remove == "function" && this._mobileInputElement.remove(), null), this._dataListeners = [], this._resizeListeners = [], this._titleListeners = [];
1549
1571
  }
1550
1572
  };
1551
1573
  k.Terminal = k, k.spawnPty = E, typeof globalThis < "u" && (globalThis.Terminal = k);