brsh 3.10.0 → 3.10.2

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/dist/shell.es.js CHANGED
@@ -237,7 +237,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
237
237
  case "hex": return R(this, t, n);
238
238
  case "utf8":
239
239
  case "utf-8": return F(this, t, n);
240
- case "ascii": return L(this, t, n);
240
+ case "ascii": return ee(this, t, n);
241
241
  case "latin1":
242
242
  case "binary": return te(this, t, n);
243
243
  case "base64": return P(this, t, n);
@@ -418,17 +418,17 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
418
418
  }
419
419
  a === null ? (a = 65533, o = 1) : a > 65535 && (a -= 65536, r.push(a >>> 10 & 1023 | 55296), a = 56320 | a & 1023), r.push(a), i += o;
420
420
  }
421
- return ee(r);
421
+ return L(r);
422
422
  }
423
423
  let I = 4096;
424
- function ee(e) {
424
+ function L(e) {
425
425
  let t = e.length;
426
426
  if (t <= I) return String.fromCharCode.apply(String, e);
427
427
  let n = "", r = 0;
428
428
  for (; r < t;) n += String.fromCharCode.apply(String, e.slice(r, r += I));
429
429
  return n;
430
430
  }
431
- function L(e, t, n) {
431
+ function ee(e, t, n) {
432
432
  let r = "";
433
433
  n = Math.min(e.length, n);
434
434
  for (let i = t; i < n; ++i) r += String.fromCharCode(e[i] & 127);
@@ -483,15 +483,15 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
483
483
  }, u.prototype.readUint32BE = u.prototype.readUInt32BE = function(e, t) {
484
484
  return e >>>= 0, t || B(e, 4, this.length), this[e] * 16777216 + (this[e + 1] << 16 | this[e + 2] << 8 | this[e + 3]);
485
485
  }, u.prototype.readBigUInt64LE = me(function(e) {
486
- e >>>= 0, X(e, "offset");
486
+ e >>>= 0, Y(e, "offset");
487
487
  let t = this[e], n = this[e + 7];
488
- (t === void 0 || n === void 0) && ie(e, this.length - 8);
488
+ (t === void 0 || n === void 0) && X(e, this.length - 8);
489
489
  let r = t + this[++e] * 2 ** 8 + this[++e] * 2 ** 16 + this[++e] * 2 ** 24, i = this[++e] + this[++e] * 2 ** 8 + this[++e] * 2 ** 16 + n * 2 ** 24;
490
490
  return BigInt(r) + (BigInt(i) << BigInt(32));
491
491
  }), u.prototype.readBigUInt64BE = me(function(e) {
492
- e >>>= 0, X(e, "offset");
492
+ e >>>= 0, Y(e, "offset");
493
493
  let t = this[e], n = this[e + 7];
494
- (t === void 0 || n === void 0) && ie(e, this.length - 8);
494
+ (t === void 0 || n === void 0) && X(e, this.length - 8);
495
495
  let r = t * 2 ** 24 + this[++e] * 2 ** 16 + this[++e] * 2 ** 8 + this[++e], i = this[++e] * 2 ** 24 + this[++e] * 2 ** 16 + this[++e] * 2 ** 8 + n;
496
496
  return (BigInt(r) << BigInt(32)) + BigInt(i);
497
497
  }), u.prototype.readIntLE = function(e, t, n) {
@@ -519,15 +519,15 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
519
519
  }, u.prototype.readInt32BE = function(e, t) {
520
520
  return e >>>= 0, t || B(e, 4, this.length), this[e] << 24 | this[e + 1] << 16 | this[e + 2] << 8 | this[e + 3];
521
521
  }, u.prototype.readBigInt64LE = me(function(e) {
522
- e >>>= 0, X(e, "offset");
522
+ e >>>= 0, Y(e, "offset");
523
523
  let t = this[e], n = this[e + 7];
524
- (t === void 0 || n === void 0) && ie(e, this.length - 8);
524
+ (t === void 0 || n === void 0) && X(e, this.length - 8);
525
525
  let r = this[e + 4] + this[e + 5] * 2 ** 8 + this[e + 6] * 2 ** 16 + (n << 24);
526
526
  return (BigInt(r) << BigInt(32)) + BigInt(t + this[++e] * 2 ** 8 + this[++e] * 2 ** 16 + this[++e] * 2 ** 24);
527
527
  }), u.prototype.readBigInt64BE = me(function(e) {
528
- e >>>= 0, X(e, "offset");
528
+ e >>>= 0, Y(e, "offset");
529
529
  let t = this[e], n = this[e + 7];
530
- (t === void 0 || n === void 0) && ie(e, this.length - 8);
530
+ (t === void 0 || n === void 0) && X(e, this.length - 8);
531
531
  let r = (t << 24) + this[++e] * 2 ** 16 + this[++e] * 2 ** 8 + this[++e];
532
532
  return (BigInt(r) << BigInt(32)) + BigInt(this[++e] * 2 ** 24 + this[++e] * 2 ** 16 + this[++e] * 2 ** 8 + n);
533
533
  }), u.prototype.readFloatLE = function(e, t) {
@@ -572,14 +572,14 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
572
572
  return e = +e, t >>>= 0, n || V(this, e, t, 4, 4294967295, 0), this[t] = e >>> 24, this[t + 1] = e >>> 16, this[t + 2] = e >>> 8, this[t + 3] = e & 255, t + 4;
573
573
  };
574
574
  function H(e, t, n, r, i) {
575
- Y(t, r, i, e, n, 7);
575
+ J(t, r, i, e, n, 7);
576
576
  let a = Number(t & BigInt(4294967295));
577
577
  e[n++] = a, a >>= 8, e[n++] = a, a >>= 8, e[n++] = a, a >>= 8, e[n++] = a;
578
578
  let o = Number(t >> BigInt(32) & BigInt(4294967295));
579
579
  return e[n++] = o, o >>= 8, e[n++] = o, o >>= 8, e[n++] = o, o >>= 8, e[n++] = o, n;
580
580
  }
581
- function U(e, t, n, r, i) {
582
- Y(t, r, i, e, n, 7);
581
+ function ne(e, t, n, r, i) {
582
+ J(t, r, i, e, n, 7);
583
583
  let a = Number(t & BigInt(4294967295));
584
584
  e[n + 7] = a, a >>= 8, e[n + 6] = a, a >>= 8, e[n + 5] = a, a >>= 8, e[n + 4] = a;
585
585
  let o = Number(t >> BigInt(32) & BigInt(4294967295));
@@ -588,7 +588,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
588
588
  u.prototype.writeBigUInt64LE = me(function(e, t = 0) {
589
589
  return H(this, e, t, BigInt(0), BigInt("0xffffffffffffffff"));
590
590
  }), u.prototype.writeBigUInt64BE = me(function(e, t = 0) {
591
- return U(this, e, t, BigInt(0), BigInt("0xffffffffffffffff"));
591
+ return ne(this, e, t, BigInt(0), BigInt("0xffffffffffffffff"));
592
592
  }), u.prototype.writeIntLE = function(e, t, n, r) {
593
593
  if (e = +e, t >>>= 0, !r) {
594
594
  let r = 2 ** (8 * n - 1);
@@ -618,26 +618,26 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
618
618
  }, u.prototype.writeBigInt64LE = me(function(e, t = 0) {
619
619
  return H(this, e, t, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
620
620
  }), u.prototype.writeBigInt64BE = me(function(e, t = 0) {
621
- return U(this, e, t, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
621
+ return ne(this, e, t, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
622
622
  });
623
- function ne(e, t, n, r, i, a) {
623
+ function U(e, t, n, r, i, a) {
624
624
  if (n + r > e.length || n < 0) throw RangeError("Index out of range");
625
625
  }
626
- function W(e, t, r, i, a) {
627
- return t = +t, r >>>= 0, a || ne(e, t, r, 4), n.write(e, t, r, i, 23, 4), r + 4;
626
+ function re(e, t, r, i, a) {
627
+ return t = +t, r >>>= 0, a || U(e, t, r, 4), n.write(e, t, r, i, 23, 4), r + 4;
628
628
  }
629
629
  u.prototype.writeFloatLE = function(e, t, n) {
630
- return W(this, e, t, !0, n);
630
+ return re(this, e, t, !0, n);
631
631
  }, u.prototype.writeFloatBE = function(e, t, n) {
632
- return W(this, e, t, !1, n);
632
+ return re(this, e, t, !1, n);
633
633
  };
634
- function G(e, t, r, i, a) {
635
- return t = +t, r >>>= 0, a || ne(e, t, r, 8), n.write(e, t, r, i, 52, 8), r + 8;
634
+ function ie(e, t, r, i, a) {
635
+ return t = +t, r >>>= 0, a || U(e, t, r, 8), n.write(e, t, r, i, 52, 8), r + 8;
636
636
  }
637
637
  u.prototype.writeDoubleLE = function(e, t, n) {
638
- return G(this, e, t, !0, n);
638
+ return ie(this, e, t, !0, n);
639
639
  }, u.prototype.writeDoubleBE = function(e, t, n) {
640
- return G(this, e, t, !1, n);
640
+ return ie(this, e, t, !1, n);
641
641
  }, u.prototype.copy = function(e, t, n, r) {
642
642
  if (!u.isBuffer(e)) throw TypeError("argument should be a Buffer");
643
643
  if (n ||= 0, !r && r !== 0 && (r = this.length), t >= e.length && (t = e.length), t ||= 0, r > 0 && r < n && (r = n), r === n || e.length === 0 || this.length === 0) return 0;
@@ -668,9 +668,9 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
668
668
  }
669
669
  return this;
670
670
  };
671
- let K = {};
672
- function re(e, t, n) {
673
- K[e] = class extends n {
671
+ let W = {};
672
+ function G(e, t, n) {
673
+ W[e] = class extends n {
674
674
  constructor() {
675
675
  super(), Object.defineProperty(this, "message", {
676
676
  value: t.apply(this, arguments),
@@ -694,34 +694,34 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
694
694
  }
695
695
  };
696
696
  }
697
- re("ERR_BUFFER_OUT_OF_BOUNDS", function(e) {
697
+ G("ERR_BUFFER_OUT_OF_BOUNDS", function(e) {
698
698
  return e ? `${e} is outside of buffer bounds` : "Attempt to access memory outside buffer bounds";
699
- }, RangeError), re("ERR_INVALID_ARG_TYPE", function(e, t) {
699
+ }, RangeError), G("ERR_INVALID_ARG_TYPE", function(e, t) {
700
700
  return `The "${e}" argument must be of type number. Received type ${typeof t}`;
701
- }, TypeError), re("ERR_OUT_OF_RANGE", function(e, t, n) {
701
+ }, TypeError), G("ERR_OUT_OF_RANGE", function(e, t, n) {
702
702
  let r = `The value of "${e}" is out of range.`, i = n;
703
- return Number.isInteger(n) && Math.abs(n) > 2 ** 32 ? i = q(String(n)) : typeof n == "bigint" && (i = String(n), (n > BigInt(2) ** BigInt(32) || n < -(BigInt(2) ** BigInt(32))) && (i = q(i)), i += "n"), r += ` It must be ${t}. Received ${i}`, r;
703
+ return Number.isInteger(n) && Math.abs(n) > 2 ** 32 ? i = K(String(n)) : typeof n == "bigint" && (i = String(n), (n > BigInt(2) ** BigInt(32) || n < -(BigInt(2) ** BigInt(32))) && (i = K(i)), i += "n"), r += ` It must be ${t}. Received ${i}`, r;
704
704
  }, RangeError);
705
- function q(e) {
705
+ function K(e) {
706
706
  let t = "", n = e.length, r = +(e[0] === "-");
707
707
  for (; n >= r + 4; n -= 3) t = `_${e.slice(n - 3, n)}${t}`;
708
708
  return `${e.slice(0, n)}${t}`;
709
709
  }
710
- function J(e, t, n) {
711
- X(t, "offset"), (e[t] === void 0 || e[t + n] === void 0) && ie(t, e.length - (n + 1));
710
+ function q(e, t, n) {
711
+ Y(t, "offset"), (e[t] === void 0 || e[t + n] === void 0) && X(t, e.length - (n + 1));
712
712
  }
713
- function Y(e, t, n, r, i, a) {
713
+ function J(e, t, n, r, i, a) {
714
714
  if (e > n || e < t) {
715
715
  let r = typeof t == "bigint" ? "n" : "", i;
716
- throw i = a > 3 ? t === 0 || t === BigInt(0) ? `>= 0${r} and < 2${r} ** ${(a + 1) * 8}${r}` : `>= -(2${r} ** ${(a + 1) * 8 - 1}${r}) and < 2 ** ${(a + 1) * 8 - 1}${r}` : `>= ${t}${r} and <= ${n}${r}`, new K.ERR_OUT_OF_RANGE("value", i, e);
716
+ throw i = a > 3 ? t === 0 || t === BigInt(0) ? `>= 0${r} and < 2${r} ** ${(a + 1) * 8}${r}` : `>= -(2${r} ** ${(a + 1) * 8 - 1}${r}) and < 2 ** ${(a + 1) * 8 - 1}${r}` : `>= ${t}${r} and <= ${n}${r}`, new W.ERR_OUT_OF_RANGE("value", i, e);
717
717
  }
718
- J(r, i, a);
718
+ q(r, i, a);
719
719
  }
720
- function X(e, t) {
721
- if (typeof e != "number") throw new K.ERR_INVALID_ARG_TYPE(t, "number", e);
720
+ function Y(e, t) {
721
+ if (typeof e != "number") throw new W.ERR_INVALID_ARG_TYPE(t, "number", e);
722
722
  }
723
- function ie(e, t, n) {
724
- throw Math.floor(e) === e ? t < 0 ? new K.ERR_BUFFER_OUT_OF_BOUNDS() : new K.ERR_OUT_OF_RANGE(n || "offset", `>= ${+!!n} and <= ${t}`, e) : (X(e, n), new K.ERR_OUT_OF_RANGE(n || "offset", "an integer", e));
723
+ function X(e, t, n) {
724
+ throw Math.floor(e) === e ? t < 0 ? new W.ERR_BUFFER_OUT_OF_BOUNDS() : new W.ERR_OUT_OF_RANGE(n || "offset", `>= ${+!!n} and <= ${t}`, e) : (Y(e, n), new W.ERR_OUT_OF_RANGE(n || "offset", "an integer", e));
725
725
  }
726
726
  let ae = /[^+/0-9A-Za-z-_]/g;
727
727
  function oe(e) {
@@ -1038,15 +1038,34 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1038
1038
  D: "ArrowLeft",
1039
1039
  H: "Home",
1040
1040
  F: "End",
1041
+ Z: "BackTab",
1042
+ P: "F1",
1043
+ Q: "F2",
1044
+ R: "F3",
1045
+ S: "F4",
1041
1046
  "1~": "Home",
1047
+ "2~": "Insert",
1042
1048
  "3~": "Delete",
1043
1049
  "4~": "End",
1044
1050
  "5~": "PageUp",
1045
1051
  "6~": "PageDown",
1046
1052
  "7~": "Home",
1047
- "8~": "End"
1053
+ "8~": "End",
1054
+ "15~": "F5",
1055
+ "17~": "F6",
1056
+ "18~": "F7",
1057
+ "19~": "F8",
1058
+ "20~": "F9",
1059
+ "21~": "F10",
1060
+ "23~": "F11",
1061
+ "24~": "F12"
1048
1062
  };
1049
- a[i] && n.push(a[i]), r = e + 1;
1063
+ if (a[i]) n.push(a[i]);
1064
+ else {
1065
+ let e = i.match(/^1;\d+([ABCDHF])$/);
1066
+ e && a[e[1]] && n.push(a[e[1]]);
1067
+ }
1068
+ r = e + 1;
1050
1069
  continue;
1051
1070
  }
1052
1071
  }
@@ -1073,72 +1092,79 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1073
1092
  }
1074
1093
  return n;
1075
1094
  }
1076
- t.exports = {
1077
- TtyStream: class extends r {
1078
- constructor(e = {}) {
1079
- super(), this.isTTY = e.isTTY !== !1, this.readable = !0, this.writable = !0, this.columns = e.columns || 80, this.rows = e.rows || 24, this.isRaw = !1, this._encoding = null, this._onWrite = e.onWrite || null;
1095
+ var a = class extends r {
1096
+ constructor(e = {}) {
1097
+ super(), this.isTTY = e.isTTY !== !1, this.readable = !0, this.writable = !0, this.columns = e.columns || 80, this.rows = e.rows || 24, this.isRaw = !1, this._encoding = null, this._onWrite = e.onWrite || null;
1098
+ }
1099
+ write(e, t, n) {
1100
+ if (e == null) return !0;
1101
+ typeof this._onWrite == "function" && this._onWrite(e), this._isPushing = !0;
1102
+ try {
1103
+ this.emit("data", this._formatChunk(e));
1104
+ } finally {
1105
+ this._isPushing = !1;
1080
1106
  }
1081
- write(e, t, n) {
1082
- if (e == null) return !0;
1083
- typeof this._onWrite == "function" && this._onWrite(e), this._isPushing = !0;
1107
+ return typeof t == "function" ? t() : typeof n == "function" && n(), !0;
1108
+ }
1109
+ pushData(e) {
1110
+ if (e != null) {
1111
+ this._isPushing = !0;
1084
1112
  try {
1085
1113
  this.emit("data", this._formatChunk(e));
1086
1114
  } finally {
1087
1115
  this._isPushing = !1;
1088
1116
  }
1089
- return typeof t == "function" ? t() : typeof n == "function" && n(), !0;
1090
- }
1091
- pushData(e) {
1092
- if (e != null) {
1093
- this._isPushing = !0;
1094
- try {
1095
- this.emit("data", this._formatChunk(e));
1096
- } finally {
1097
- this._isPushing = !1;
1098
- }
1099
- }
1100
- }
1101
- _formatChunk(e) {
1102
- return this._encoding ? typeof e == "string" ? e : e instanceof Uint8Array || y !== void 0 && y.isBuffer(e) ? new TextDecoder().decode(e) : String(e) : e;
1103
- }
1104
- setRawMode(e) {
1105
- return this.isRaw = !!e, this;
1106
- }
1107
- setEncoding(e) {
1108
- return this._encoding = e, this;
1109
- }
1110
- getWindowSize() {
1111
- return [this.columns, this.rows];
1112
1117
  }
1113
- resize(e, t) {
1114
- this.columns = e, this.rows = t, this.emit("resize");
1115
- }
1116
- resume() {
1117
- return this;
1118
- }
1119
- pause() {
1120
- return this;
1121
- }
1122
- pipe(e) {
1123
- return this.on("data", (t) => e.write(t)), e;
1124
- }
1125
- unpipe() {
1126
- return this;
1127
- }
1128
- end(e, t, n) {
1129
- return e != null && this.write(e, typeof t == "string" ? t : void 0), this.emit("end"), typeof t == "function" ? t() : typeof n == "function" && n(), this;
1130
- }
1131
- destroy() {
1132
- this.removeAllListeners();
1133
- }
1134
- toString() {
1135
- return "";
1136
- }
1137
- valueOf() {
1138
- return "";
1139
- }
1140
- },
1141
- parseVtKeys: i
1118
+ }
1119
+ _formatChunk(e) {
1120
+ return this._encoding ? typeof e == "string" ? e : e instanceof Uint8Array || y !== void 0 && y.isBuffer(e) ? new TextDecoder().decode(e) : String(e) : e;
1121
+ }
1122
+ setRawMode(e) {
1123
+ return this.isRaw = !!e, this;
1124
+ }
1125
+ setEncoding(e) {
1126
+ return this._encoding = e, this;
1127
+ }
1128
+ getWindowSize() {
1129
+ return [this.columns, this.rows];
1130
+ }
1131
+ resize(e, t) {
1132
+ this.columns = e, this.rows = t, this.emit("resize");
1133
+ }
1134
+ resume() {
1135
+ return this;
1136
+ }
1137
+ pause() {
1138
+ return this;
1139
+ }
1140
+ pipe(e) {
1141
+ return this.on("data", (t) => e.write(t)), e;
1142
+ }
1143
+ unpipe() {
1144
+ return this;
1145
+ }
1146
+ end(e, t, n) {
1147
+ return e != null && this.write(e, typeof t == "string" ? t : void 0), this.emit("end"), typeof t == "function" ? t() : typeof n == "function" && n(), this;
1148
+ }
1149
+ destroy() {
1150
+ this.removeAllListeners();
1151
+ }
1152
+ toString() {
1153
+ return "";
1154
+ }
1155
+ valueOf() {
1156
+ return "";
1157
+ }
1158
+ };
1159
+ function o(e) {
1160
+ if (!e || e._managesOwnStdinCapture || !e.stdinStream || typeof e.stdinStream.listenerCount != "function") return !1;
1161
+ let t = e.stdinStream.listenerCount("data");
1162
+ return t === 0 ? !1 : e._onStdinStreamData && typeof e.stdinStream.listeners == "function" ? t > +!!e.stdinStream.listeners("data").includes(e._onStdinStreamData) : t > 0;
1163
+ }
1164
+ t.exports = {
1165
+ TtyStream: a,
1166
+ parseVtKeys: i,
1167
+ hasCustomStdinListener: o
1142
1168
  };
1143
1169
  })), T = /* @__PURE__ */ t(((e, t) => {
1144
1170
  var n = x(), r = C(), { TtyStream: i, parseVtKeys: a } = w(), o = n.EventEmitter || n.default || n;
@@ -1161,7 +1187,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1161
1187
  if (!this.captureInput) return;
1162
1188
  let t = a(e);
1163
1189
  for (let e of t) {
1164
- if (e === "^C") {
1190
+ if (e === "^C" && !(this.stdinStream && this.stdinStream.isRaw)) {
1165
1191
  this.kill("SIGINT");
1166
1192
  return;
1167
1193
  }
@@ -1223,8 +1249,8 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1223
1249
  }
1224
1250
  };
1225
1251
  })), D = /* @__PURE__ */ t(((e, t) => {
1226
- var n = E();
1227
- function r(e) {
1252
+ var n = E(), { parseVtKeys: r, hasCustomStdinListener: i } = w();
1253
+ function a(e) {
1228
1254
  return /^#!\/(sh\.js|bin\/(sh|brsh))/.test(e);
1229
1255
  }
1230
1256
  t.exports = class extends n {
@@ -1232,11 +1258,16 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1232
1258
  super(t, n), this.script = e, this.source = r;
1233
1259
  }
1234
1260
  get captureInput() {
1235
- return !!(this.sandbox && this.sandbox.runningCommand && (this.sandbox.runningCommand.captureInput || this.sandbox.runningCommand.interactive));
1261
+ if (!this.sandbox || !this.sandbox.runningCommand) return !1;
1262
+ let e = this.sandbox.runningCommand;
1263
+ return !!(e.captureInput || e.interactive || e._inAltScreen || i(e));
1236
1264
  }
1237
1265
  get interactive() {
1238
1266
  return !!(this.sandbox && this.sandbox.runningCommand && this.sandbox.runningCommand.interactive);
1239
1267
  }
1268
+ get isRaw() {
1269
+ return !!(this.stdinStream && this.stdinStream.isRaw || this.sandbox && this.sandbox.runningCommand && (this.sandbox.runningCommand.isRaw || this.sandbox.runningCommand.stdinStream && this.sandbox.runningCommand.stdinStream.isRaw));
1270
+ }
1240
1271
  get _inAltScreen() {
1241
1272
  return !!(this.__inAltScreen || this.sandbox && this.sandbox.runningCommand && this.sandbox.runningCommand._inAltScreen);
1242
1273
  }
@@ -1250,38 +1281,43 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1250
1281
  this.sandbox && this.sandbox.runningCommand && typeof this.sandbox.runningCommand.kill == "function" && this.sandbox.runningCommand.kill(e), this.sandbox && typeof this.sandbox.destroy == "function" && this.sandbox.destroy(130), super.kill(e);
1251
1282
  }
1252
1283
  run() {
1253
- let e = this.context && this.context.fs || this.fs, t = e && e.isRealFilesystem ? { useRealFilesystem: !0 } : {
1254
- filesystem: e && e.getRaw() || {},
1255
- permissions: e && e.getRawPermissions() || {}
1284
+ this._managesOwnStdinCapture = !0;
1285
+ let e = this.context && this.context.fs || this.fs, t = e && e[Symbol.for("brsh.fs.target")] || e, n = t && t.isRealFilesystem ? { useRealFilesystem: !0 } : {
1286
+ filesystem: t && t.getRaw() || {},
1287
+ permissions: t && t.getRawPermissions() || {}
1256
1288
  };
1257
1289
  this.sandbox = new globalThis.shell({
1258
- cwd: e && e.cwd || "/",
1259
- ...t,
1290
+ cwd: t && t.cwd || "/",
1291
+ ...n,
1260
1292
  subshell: !0
1261
1293
  }), this.sandbox.context.source(this.context);
1262
- let n = this.stdinStream && this.stdinStream.columns || 80, i = this.stdinStream && this.stdinStream.rows || 24;
1263
- typeof this.sandbox.setTerminalSize == "function" && this.sandbox.setTerminalSize(n, i), Array.isArray(this.arguments) && (this.arguments.forEach((e, t) => this.sandbox.context.setVar(String(t + 1), e)), this.sandbox.context.setVar("#", String(this.arguments.length)), this.sandbox.context.setVar("@", this.arguments.join(" ")), this.sandbox.context.setVar("*", this.arguments.join(" "))), this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", this._onStdinStreamData);
1264
- let a = (e) => {
1294
+ let o = this.stdout && this.stdout.columns || this.stdinStream && this.stdinStream.columns || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("COLUMNS"), 10) || 80, s = this.stdout && this.stdout.rows || this.stdinStream && this.stdinStream.rows || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("LINES"), 10) || 24;
1295
+ typeof this.sandbox.setTerminalSize == "function" && this.sandbox.setTerminalSize(o, s), Array.isArray(this.arguments) && (this.arguments.forEach((e, t) => this.sandbox.context.setVar(String(t + 1), e)), this.sandbox.context.setVar("#", String(this.arguments.length)), this.sandbox.context.setVar("@", this.arguments.join(" ")), this.sandbox.context.setVar("*", this.arguments.join(" "))), this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", this._onStdinStreamData);
1296
+ let c = (e) => {
1265
1297
  if (!this.sandbox || !this.sandbox.runningCommand) return;
1266
- let t = this.sandbox.runningCommand, n = t.stdinStream && t.stdinStream.listenerCount("data") > 1;
1298
+ let t = this.sandbox.runningCommand, n = i(t);
1267
1299
  if (t.interactive || t._inAltScreen || n) {
1268
1300
  t.stdinStream && t.stdinStream.pushData(e);
1269
1301
  return;
1270
1302
  }
1271
1303
  if (t.captureInput && typeof t.onInput == "function") {
1272
- let { parseVtKeys: n } = w();
1273
- for (let r of n(e)) {
1274
- if (r === "^C") {
1304
+ let n = !!(t.isRaw || t.stdinStream && t.stdinStream.isRaw);
1305
+ for (let i of r(e)) {
1306
+ if (i === "^C" && !n) {
1275
1307
  this.kill("SIGINT");
1276
1308
  return;
1277
1309
  }
1278
- (!t.stdinStream || !t.stdinStream.isRaw) && (r === "Enter" ? this.stdout.write("\r\n") : r === "Backspace" ? this.stdout.write("\b \b") : r.length === 1 && this.stdout.write(r)), t.onInput(r);
1310
+ n || (i === "Enter" ? this.stdout.write("\r\n") : i === "Backspace" ? this.stdout.write("\b \b") : i.length === 1 && this.stdout.write(i)), t.onInput(i);
1279
1311
  }
1280
1312
  }
1281
- }, o = () => {
1313
+ }, l = () => {
1282
1314
  this.sandbox && typeof this.sandbox.setTerminalSize == "function" && this.stdinStream && this.sandbox.setTerminalSize(this.stdinStream.columns, this.stdinStream.rows);
1315
+ }, u = () => {
1316
+ this.sandbox && typeof this.sandbox.setTerminalSize == "function" && this.stdout && this.sandbox.setTerminalSize(this.stdout.columns, this.stdout.rows);
1317
+ }, d = () => {
1318
+ this.stdinStream && typeof this.stdinStream.off == "function" && (this.stdinStream.off("data", c), this.stdinStream.off("resize", l)), this.stdout && typeof this.stdout.off == "function" && this.stdout.off("resize", u);
1283
1319
  };
1284
- this.stdinStream && typeof this.stdinStream.on == "function" && (this.stdinStream.on("data", a), this.stdinStream.on("resize", o)), this.sandbox.on("stdOut", (e) => {
1320
+ this.stdinStream && typeof this.stdinStream.on == "function" && (this.stdinStream.on("data", c), this.stdinStream.on("resize", l)), this.stdout && this.stdout !== this.stdinStream && typeof this.stdout.on == "function" && this.stdout.on("resize", u), this.sandbox.on("stdOut", (e) => {
1285
1321
  this.stdOut = e, this.flush();
1286
1322
  }), this.sandbox.on("stdErr", (e) => {
1287
1323
  this.stdErr = e, this.flush();
@@ -1290,19 +1326,19 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1290
1326
  }), this.sandbox.stderr && typeof this.sandbox.stderr.on == "function" && this.sandbox.stderr.on("data", (e) => {
1291
1327
  this.stderr && typeof this.stderr.write == "function" && this.stderr.write(e);
1292
1328
  }), this._scriptFunctions = {};
1293
- let s = this.script.split(/\r?\n/);
1294
- if (!r(s[0])) {
1295
- let e = s[0].startsWith("#!") ? s[0].slice(2).split(/\s/)[0] : s[0];
1296
- return this.stdinStream && typeof this.stdinStream.off == "function" && (this.stdinStream.off("data", a), this.stdinStream.off("resize", o)), Promise.reject(`${e}: bad interpreter: No such file or directory`);
1329
+ let f = this.script.split(/\r?\n/);
1330
+ if (!a(f[0])) {
1331
+ let e = f[0].startsWith("#!") ? f[0].slice(2).split(/\s/)[0] : f[0];
1332
+ return d(), Promise.reject(`${e}: bad interpreter: No such file or directory`);
1297
1333
  }
1298
- let c = this._parseLines(s.slice(1));
1299
- return this._executeNodes(c).catch((e) => {
1334
+ let p = this._parseLines(f.slice(1));
1335
+ return this._executeNodes(p).catch((e) => {
1300
1336
  if (e && e.__type === "return") this.sandbox.lastCode = e.code;
1301
1337
  else if (e && e.__type === "errexit") this.sandbox.lastCode = e.code;
1302
1338
  else if (e && (e.__type === "break" || e.__type === "continue")) this.stdErr = `${e.__type}: only meaningful in a for or while loop`, this.sandbox.lastCode = 1;
1303
1339
  else return Promise.reject(e);
1304
1340
  }).finally(() => {
1305
- this.stdinStream && typeof this.stdinStream.off == "function" && (this.stdinStream.off("data", a), this.stdinStream.off("resize", o));
1341
+ d();
1306
1342
  }).then(() => {
1307
1343
  this.exitCode = this.sandbox.lastCode, this.source && this.context.source(this.sandbox.context);
1308
1344
  });
@@ -1461,16 +1497,28 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1461
1497
  return t;
1462
1498
  }
1463
1499
  run() {
1464
- let e = this.arguments.map((e, t) => ({
1465
- key: String(t + 1),
1466
- prev: r.sandbox.context.getVar(String(t + 1))
1467
- }));
1468
- this.arguments.forEach((e, t) => r.sandbox.context.setVar(String(t + 1), e));
1469
- let t = () => e.forEach(({ key: e, prev: t }) => t ? r.sandbox.context.setVar(e, t) : r.sandbox.context.unsetVar(e));
1500
+ let e = parseInt(r.sandbox.context.getVar("#") || "0", 10) || 0, t = Math.max(e, this.arguments.length), i = [];
1501
+ for (let e = 1; e <= t; e++) {
1502
+ let t = String(e);
1503
+ i.push({
1504
+ key: t,
1505
+ prev: r.sandbox.context.getVar(t)
1506
+ }), e <= this.arguments.length ? r.sandbox.context.setVar(t, this.arguments[e - 1]) : r.sandbox.context.unsetVar(t);
1507
+ }
1508
+ for (let e of [
1509
+ "#",
1510
+ "@",
1511
+ "*"
1512
+ ]) i.push({
1513
+ key: e,
1514
+ prev: r.sandbox.context.getVar(e)
1515
+ });
1516
+ r.sandbox.context.setVar("#", String(this.arguments.length)), r.sandbox.context.setVar("@", this.arguments.join(" ")), r.sandbox.context.setVar("*", this.arguments.join(" "));
1517
+ let a = () => i.forEach(({ key: e, prev: t }) => t ? r.sandbox.context.setVar(e, t) : r.sandbox.context.unsetVar(e));
1470
1518
  return r._executeFunctionBody(n).then(() => {
1471
- t();
1519
+ a();
1472
1520
  }).catch((e) => {
1473
- if (t(), e && e.__type === "return") {
1521
+ if (a(), e && e.__type === "return") {
1474
1522
  this.exitCode = e.code;
1475
1523
  return;
1476
1524
  }
@@ -1660,19 +1708,19 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1660
1708
  return !1;
1661
1709
  }
1662
1710
  }
1663
- }, t.exports.isKnownInterpreter = r;
1711
+ }, t.exports.isKnownInterpreter = a;
1664
1712
  })), O = /* @__PURE__ */ t(((e, t) => {
1665
1713
  t.exports = null;
1666
1714
  })), k = /* @__PURE__ */ t(((e, t) => {
1667
1715
  b();
1668
- var n = D(), { BinaryFile: r } = ie(), i = 0, a = 6, o = 8, s = 20, c = 28, l = 31, u = 44, d = 54, f = 70, p = 0, m = 2, h = 3, g = 4, _ = 1, v = 2, x = 4, S = 8, C = 1, w = 4, T = class extends n {
1716
+ var n = D(), { BinaryFile: r } = X(), i = 0, a = 6, o = 8, s = 20, c = 27, l = 28, u = 31, d = 44, f = 54, p = 70, m = 0, h = 2, g = 3, _ = 4, v = 1, x = 2, S = 4, C = 8, w = 1, E = 4, k = class extends n {
1669
1717
  constructor(e, t, n) {
1670
1718
  super(e, t, n), this._ensurePkgMeta();
1671
1719
  }
1672
1720
  _ensurePkgMeta() {
1673
1721
  if (this._pkgMeta === void 0 && this.script) {
1674
1722
  let e = this.context && this.context.fs || this.fs;
1675
- e && (this._pkgMeta = L(e, this.script));
1723
+ e && (this._pkgMeta = te(e, this.script));
1676
1724
  }
1677
1725
  return this._pkgMeta || null;
1678
1726
  }
@@ -1712,11 +1760,22 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1712
1760
  this._inAltScreen || (this._inAltScreen = !0, this.stdinStream && typeof this.stdinStream.setRawMode == "function" && this.stdinStream.setRawMode(!0), this.stdout && typeof this.stdout.write == "function" && this.stdout.write("\x1B[?1049h\x1B[2J\x1B[H"));
1713
1761
  }
1714
1762
  _exitAltScreen() {
1715
- this._inAltScreen && (this._inAltScreen = !1, this.stdinStream && typeof this.stdinStream.setRawMode == "function" && this.stdinStream.setRawMode(!1), this.stdout && typeof this.stdout.write == "function" && this.stdout.write("\x1B[?1049l\x1B[?25h"));
1763
+ this._inAltScreen && (this._inAltScreen = !1, this.stdinStream && typeof this.stdinStream.setRawMode == "function" && this.stdinStream.setRawMode(!1), this.stdout && typeof this.stdout.write == "function" && this.stdout.write("\x1B[0m\x1B[?1l\x1B[?1000l\x1B[?1002l\x1B[?1003l\x1B[?1006l\x1B[?1049l\x1B[?25h"));
1716
1764
  }
1717
1765
  _keyToBytes(e) {
1718
1766
  if (!e) return null;
1719
1767
  if (typeof e != "string") return e instanceof Uint8Array ? e : new Uint8Array([Number(e) & 255]);
1768
+ if ([
1769
+ "Control",
1770
+ "Alt",
1771
+ "Shift",
1772
+ "Meta",
1773
+ "CapsLock",
1774
+ "NumLock",
1775
+ "ScrollLock",
1776
+ "Dead",
1777
+ "Unidentified"
1778
+ ].includes(e)) return null;
1720
1779
  let t = e.match(/^\^([A-Za-z@\[\\\]^_?])$/);
1721
1780
  if (t) {
1722
1781
  let e = t[1].toUpperCase();
@@ -1725,19 +1784,40 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1725
1784
  let n = {
1726
1785
  Enter: "\r",
1727
1786
  Return: "\r",
1787
+ Space: " ",
1788
+ Spacebar: " ",
1728
1789
  Backspace: "",
1729
1790
  Tab: " ",
1791
+ BackTab: "\x1B[Z",
1730
1792
  Escape: "\x1B",
1793
+ Esc: "\x1B",
1731
1794
  ArrowUp: "\x1B[A",
1795
+ Up: "\x1B[A",
1732
1796
  ArrowDown: "\x1B[B",
1797
+ Down: "\x1B[B",
1733
1798
  ArrowRight: "\x1B[C",
1799
+ Right: "\x1B[C",
1734
1800
  ArrowLeft: "\x1B[D",
1801
+ Left: "\x1B[D",
1735
1802
  Home: "\x1B[H",
1736
1803
  End: "\x1B[F",
1737
1804
  PageUp: "\x1B[5~",
1738
1805
  PageDown: "\x1B[6~",
1739
1806
  Delete: "\x1B[3~",
1740
- Insert: "\x1B[2~"
1807
+ Del: "\x1B[3~",
1808
+ Insert: "\x1B[2~",
1809
+ F1: "\x1BOP",
1810
+ F2: "\x1BOQ",
1811
+ F3: "\x1BOR",
1812
+ F4: "\x1BOS",
1813
+ F5: "\x1B[15~",
1814
+ F6: "\x1B[17~",
1815
+ F7: "\x1B[18~",
1816
+ F8: "\x1B[19~",
1817
+ F9: "\x1B[20~",
1818
+ F10: "\x1B[21~",
1819
+ F11: "\x1B[23~",
1820
+ F12: "\x1B[24~"
1741
1821
  };
1742
1822
  return n[e] ? new TextEncoder().encode(n[e]) : new TextEncoder().encode(e);
1743
1823
  }
@@ -1789,7 +1869,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1789
1869
  isWat: this._isWat(e, i)
1790
1870
  });
1791
1871
  }
1792
- return r.then((e) => (!e.isWat && e.bytes && (this._inspectedWasm = P(e.bytes), this._inspectedWasm.isInteractive && (this._isInteractive = !0)), e));
1872
+ return r.then((e) => (!e.isWat && e.bytes && (this._inspectedWasm = F(e.bytes), this._inspectedWasm.isInteractive && (this._isInteractive = !0)), e));
1793
1873
  }
1794
1874
  _isWat(e, t) {
1795
1875
  return e.endsWith(".wat") ? !0 : t.length > 0 && t[0] === 40;
@@ -1830,12 +1910,12 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1830
1910
  let t = {
1831
1911
  1: "",
1832
1912
  2: ""
1833
- }, n = new TextDecoder(), b = new TextEncoder(), T = null, E = null, D = !1, O = 0, k = null, A = null, j = null, M = null, N = this.stdin === void 0 || this.stdin === null || this.stdin === this.stdinStream || this.stdin && this.stdin.isTTY, I = !!(this.interactive && N);
1834
- I && (this.emit("interactive"), this.context && typeof this.context.emit == "function" && this.context.emit("interactive"));
1835
- let ee = () => {
1836
- I || !N || (I = !0, this._isInteractive = !0, this.emit("interactive"), this.context && typeof this.context.emit == "function" && this.context.emit("interactive"), this._enterAltScreen(), t[1] &&= (this.stdout && typeof this.stdout.write == "function" && this.stdout.write(t[1]), ""), t[2] &&= (this.stderr && typeof this.stderr.write == "function" && this.stderr.write(t[2]), ""), this.stdinStream && typeof this.stdinStream.setRawMode == "function" && this.stdinStream.setRawMode(!0));
1837
- }, L = (e, n) => {
1838
- if (I && (e === 1 || e === 2)) {
1913
+ }, n = new TextDecoder(), b = new TextEncoder(), T = null, D = null, O = !1, k = 0, A = null, j = null, M = null, N = !1, P = !1, L = !1, ee = null, te = null, R = null, z = this.stdin === void 0 || this.stdin === null || this.stdin === this.stdinStream || this.stdin && this.stdin.isTTY, B = !!(this.interactive && z);
1914
+ B && (this.emit("interactive"), this.context && typeof this.context.emit == "function" && this.context.emit("interactive"));
1915
+ let V = () => {
1916
+ B || !z || (B = !0, this._isInteractive = !0, this.emit("interactive"), this.context && typeof this.context.emit == "function" && this.context.emit("interactive"), this._enterAltScreen(), t[1] &&= (this.stdout && typeof this.stdout.write == "function" && this.stdout.write(t[1]), ""), t[2] &&= (this.stderr && typeof this.stderr.write == "function" && this.stderr.write(t[2]), ""), this.stdinStream && typeof this.stdinStream.setRawMode == "function" && this.stdinStream.setRawMode(!0));
1917
+ }, H = (e, n) => {
1918
+ if (B && (e === 1 || e === 2)) {
1839
1919
  if (e === 1 && this.stdout) {
1840
1920
  this.stdout.write(n);
1841
1921
  return;
@@ -1849,61 +1929,63 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1849
1929
  let r = t[e].split("\n");
1850
1930
  t[e] = r.pop();
1851
1931
  for (let t of r) e === 1 ? this.stdOut = t : this.stdErr = t;
1852
- }, te = () => {
1853
- t[1] &&= (I && this.stdout ? this.stdout.write(t[1]) : this.stdOut = t[1], ""), t[2] &&= (I && this.stderr ? this.stderr.write(t[2]) : this.stdErr = t[2], "");
1854
- }, R = [], z = (e) => {
1932
+ }, ne = () => {
1933
+ t[1] &&= (B && this.stdout ? this.stdout.write(t[1]) : this.stdOut = t[1], ""), t[2] &&= (B && this.stderr ? this.stderr.write(t[2]) : this.stdErr = t[2], "");
1934
+ }, U = [], re = (e) => {
1855
1935
  if (!(!e || e.length === 0)) {
1856
- for (let t = 0; t < e.length; t++) R.push(e[t]);
1857
- if (A) {
1858
- let e = A;
1859
- A = null, e();
1936
+ for (let t = 0; t < e.length; t++) U.push(e[t]);
1937
+ if (j) {
1938
+ let e = j;
1939
+ j = null, e();
1860
1940
  }
1861
1941
  }
1862
1942
  };
1863
- M = (e) => {
1943
+ R = (e) => {
1864
1944
  this._handlingStreamData = !0;
1865
1945
  try {
1866
- z(typeof e == "string" ? b.encode(e) : e instanceof Uint8Array ? e : y !== void 0 && y.isBuffer(e) ? new Uint8Array(e) : b.encode(String(e ?? "")));
1946
+ re(typeof e == "string" ? b.encode(e) : e instanceof Uint8Array ? e : y !== void 0 && y.isBuffer(e) ? new Uint8Array(e) : b.encode(String(e ?? "")));
1867
1947
  } finally {
1868
1948
  this._handlingStreamData = !1;
1869
1949
  }
1870
1950
  }, this._externalKeyHandler = (e) => {
1871
1951
  if (this._handlingStreamData) return;
1872
1952
  let t = this._keyToBytes(e);
1873
- t && z(t);
1874
- }, this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", this._onStdinStreamData), N && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", M), N && this.stdin && this.stdin !== this.stdinStream && typeof this.stdin.on == "function" && this.stdin.on("data", M);
1875
- let B = !N && typeof this.stdin == "string" ? b.encode(this.stdin) : !N && this.stdin instanceof Uint8Array ? this.stdin : !N && y !== void 0 && y.isBuffer(this.stdin) ? new Uint8Array(this.stdin) : new Uint8Array(), V = 0, H = this.context && this.context.fs ? this.context.fs : this.fs, U = this.context && this.context.fs && this.context.fs.cwd || this.fs && this.fs.cwd || this.context && typeof this.context.getVar == "function" && this.context.getVar("PWD") || H && H.cwd || "/", ne = U.length > 1 && U.endsWith("/") ? U.slice(0, -1) : U, W = 5, G = new Map([[3, {
1953
+ t && re(t);
1954
+ };
1955
+ let ie = !!(this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.listeners == "function" && this.stdinStream.listeners("data").includes(this._onStdinStreamData));
1956
+ ie && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", this._onStdinStreamData), z && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", R), z && this.stdin && this.stdin !== this.stdinStream && typeof this.stdin.on == "function" && this.stdin.on("data", R);
1957
+ let W = !z && typeof this.stdin == "string" ? b.encode(this.stdin) : !z && this.stdin instanceof Uint8Array ? this.stdin : !z && y !== void 0 && y.isBuffer(this.stdin) ? new Uint8Array(this.stdin) : new Uint8Array(), G = 0, K = this.context && this.context.fs ? this.context.fs : this.fs, q = this.context && this.context.fs && this.context.fs.cwd || this.fs && this.fs.cwd || this.context && typeof this.context.getVar == "function" && this.context.getVar("PWD") || K && K.cwd || "/", J = q.length > 1 && q.endsWith("/") ? q.slice(0, -1) : q, Y = 5, X = new Map([[3, {
1876
1958
  type: "preopen",
1877
1959
  path: "/",
1878
1960
  guestName: "/"
1879
1961
  }], [4, {
1880
1962
  type: "preopen",
1881
- path: ne,
1963
+ path: J,
1882
1964
  guestName: "."
1883
- }]]), K = new Map([
1965
+ }]]), ae = new Map([
1884
1966
  [0, 0],
1885
1967
  [1, 0],
1886
1968
  [2, 0]
1887
- ]), re = (e) => {
1969
+ ]), oe = (e) => {
1888
1970
  let t = e.split("/").filter(Boolean);
1889
1971
  return t.pop(), "/" + t.join("/");
1890
- }, q = (e, t) => {
1891
- let n = G.get(e);
1972
+ }, se = (e, t) => {
1973
+ let n = X.get(e);
1892
1974
  if (!n || n.type !== "preopen" && n.type !== "dir") return null;
1893
- if (t.startsWith("/")) return H.absolutePath(t);
1894
- if (!t || t === ".") return H.absolutePath(n.path);
1895
- let r = n.path.endsWith("/") ? n.path : n.path + "/", i = H.absolutePath(r + t), a = H.absolutePath("/" + t);
1975
+ if (t.startsWith("/")) return K.absolutePath(t);
1976
+ if (!t || t === ".") return K.absolutePath(n.path);
1977
+ let r = n.path.endsWith("/") ? n.path : n.path + "/", i = K.absolutePath(r + t), a = K.absolutePath("/" + t);
1896
1978
  if (n.path !== "/") {
1897
- if (H.exists(i)) return i;
1898
- if (H.exists(a)) return a;
1899
- let e = H.exists(re(i));
1900
- return H.exists(re(a)) && !e ? a : i;
1901
- }
1902
- if (H.exists(i)) return i;
1903
- let o = H.absolutePath(t);
1904
- return H.exists(o) ? o : i;
1905
- }, J = (e) => {
1906
- if (!(!e || e.type !== "file" || !e.dirty || !H)) try {
1979
+ if (K.exists(i)) return i;
1980
+ if (K.exists(a)) return a;
1981
+ let e = K.exists(oe(i));
1982
+ return K.exists(oe(a)) && !e ? a : i;
1983
+ }
1984
+ if (K.exists(i)) return i;
1985
+ let o = K.absolutePath(t);
1986
+ return K.exists(o) ? o : i;
1987
+ }, ce = (e) => {
1988
+ if (!(!e || e.type !== "file" || !e.dirty || !K)) try {
1907
1989
  let t = !0;
1908
1990
  for (let n = 0; n < e.bytes.length; n++) if (e.bytes[n] === 0) {
1909
1991
  t = !1;
@@ -1911,20 +1993,20 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1911
1993
  }
1912
1994
  if (t) {
1913
1995
  let t = n.decode(e.bytes);
1914
- H.setFileByPath(e.path, t, !0);
1996
+ K.setFileByPath(e.path, t, !0);
1915
1997
  } else {
1916
1998
  let t = new Uint8Array(e.bytes.length);
1917
- t.set(e.bytes), H.setFileByPath(e.path, new r(t.buffer, "application/octet-stream"), !0);
1999
+ t.set(e.bytes), K.setFileByPath(e.path, new r(t.buffer, "application/octet-stream"), !0);
1918
2000
  }
1919
2001
  e.dirty = !1;
1920
2002
  } catch {}
1921
- }, Y = {
2003
+ }, le = this.stdout && this.stdout.columns || this.stdinStream && this.stdinStream.columns || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("COLUMNS"), 10) || 80, ue = this.stdout && this.stdout.rows || this.stdinStream && this.stdinStream.rows || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("LINES"), 10) || 24, de = {
1922
2004
  TERM: "xterm-256color",
1923
2005
  COLORTERM: "truecolor",
1924
- COLUMNS: String(this.stdout && this.stdout.columns || this.context && typeof this.context.getVar == "function" && this.context.getVar("COLUMNS") || 80),
1925
- LINES: String(this.stdout && this.stdout.rows || this.context && typeof this.context.getVar == "function" && this.context.getVar("LINES") || 24),
1926
- ...this.context && this.context.vars || {}
1927
- }, X = Object.entries(Y).map(([e, t]) => `${e}=${t}`), ie = new Proxy({
2006
+ ...this.context && this.context.vars || {},
2007
+ COLUMNS: String(le),
2008
+ LINES: String(ue)
2009
+ }, Z = Object.entries(de).map(([e, t]) => `${e}=${t}`), fe = new Proxy({
1928
2010
  fd_write: (e, t, r, a) => {
1929
2011
  if (!T) return o;
1930
2012
  let s = new DataView(T.buffer);
@@ -1932,11 +2014,11 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1932
2014
  let o = 0;
1933
2015
  for (let i = 0; i < r; i++) {
1934
2016
  let r = s.getUint32(t + i * 8, !0), a = s.getUint32(t + i * 8 + 4, !0);
1935
- a > 0 && L(e, n.decode(new Uint8Array(T.buffer, r, a))), o += a;
2017
+ a > 0 && H(e, n.decode(new Uint8Array(T.buffer, r, a))), o += a;
1936
2018
  }
1937
2019
  return s.setUint32(a, o, !0), i;
1938
2020
  }
1939
- let c = G.get(e);
2021
+ let c = X.get(e);
1940
2022
  if (!c) return o;
1941
2023
  if (c.type === "dev_null" || c.type === "dev_zero") {
1942
2024
  let e = 0;
@@ -1947,7 +2029,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1947
2029
  let e = 0;
1948
2030
  for (let i = 0; i < r; i++) {
1949
2031
  let r = s.getUint32(t + i * 8, !0), a = s.getUint32(t + i * 8 + 4, !0);
1950
- a > 0 && L(1, n.decode(new Uint8Array(T.buffer, r, a))), e += a;
2032
+ a > 0 && H(1, n.decode(new Uint8Array(T.buffer, r, a))), e += a;
1951
2033
  }
1952
2034
  return s.setUint32(a, e, !0), i;
1953
2035
  }
@@ -1968,50 +2050,56 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1968
2050
  },
1969
2051
  fd_read: (e, t, n, r) => {
1970
2052
  if (!T) return o;
1971
- let s = new DataView(T.buffer), c = G.get(e), l = !!(c && c.type === "dev_tty");
1972
- if (e === 0 || I && e === 2 || l) {
1973
- (l || e === 2) && ee();
1974
- let o = !!((K.get(e) || 0) & w);
1975
- if (D) {
1976
- if ((typeof E?.exports?.asyncify_get_state == "function" ? E.exports.asyncify_get_state() : 0) === 2) {
1977
- E.exports.asyncify_stop_rewind();
2053
+ let s = new DataView(T.buffer), l = X.get(e), u = !!(l && l.type === "dev_tty");
2054
+ if (e === 0 || B && e === 2 || u) {
2055
+ (u || e === 2) && V();
2056
+ let o = !!((ae.get(e) || 0) & E);
2057
+ if (O) {
2058
+ if ((typeof D?.exports?.asyncify_get_state == "function" ? D.exports.asyncify_get_state() : 0) === 2) {
2059
+ if (D.exports.asyncify_stop_rewind(), L && U.length === 0) return L = !1, s.setUint32(r, 0, !0), c;
2060
+ L = !1;
1978
2061
  let e = 0;
1979
- for (let r = 0; r < n && R.length > 0; r++) {
1980
- let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0), a = Math.min(i, R.length), o = R.splice(0, a);
2062
+ for (let r = 0; r < n && U.length > 0; r++) {
2063
+ let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0), a = Math.min(i, U.length), o = U.splice(0, a);
1981
2064
  new Uint8Array(T.buffer).set(o, n), e += a;
1982
2065
  }
1983
2066
  return s.setUint32(r, e, !0), i;
1984
2067
  }
1985
- if (R.length > 0) {
2068
+ if (U.length > 0) {
1986
2069
  let e = 0;
1987
- for (let r = 0; r < n && R.length > 0; r++) {
1988
- let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0), a = Math.min(i, R.length), o = R.splice(0, a);
2070
+ for (let r = 0; r < n && U.length > 0; r++) {
2071
+ let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0), a = Math.min(i, U.length), o = U.splice(0, a);
1989
2072
  new Uint8Array(T.buffer).set(o, n), e += a;
1990
2073
  }
1991
2074
  return s.setUint32(r, e, !0), i;
1992
2075
  }
1993
- return o ? (s.setUint32(r, 0, !0), a) : (E.exports.asyncify_start_unwind(O), k = new Promise((e, t) => {
1994
- A = e, this._pendingReadResolve = e, this._asyncifyReject = t;
2076
+ return o ? (s.setUint32(r, 0, !0), a) : (L = !1, D.exports.asyncify_start_unwind(k), A = new Promise((e, t) => {
2077
+ let n = () => {
2078
+ L = !1, j = null, M = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
2079
+ };
2080
+ j = n, this._pendingReadResolve = n, M = () => {
2081
+ L = !0, j = null, M = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
2082
+ }, this._asyncifyReject = t;
1995
2083
  }), s.setUint32(r, 0, !0), i);
1996
2084
  }
1997
- if (R.length > 0) {
2085
+ if (U.length > 0) {
1998
2086
  let e = 0;
1999
- for (let r = 0; r < n && R.length > 0; r++) {
2000
- let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0), a = Math.min(i, R.length), o = R.splice(0, a);
2087
+ for (let r = 0; r < n && U.length > 0; r++) {
2088
+ let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0), a = Math.min(i, U.length), o = U.splice(0, a);
2001
2089
  new Uint8Array(T.buffer).set(o, n), e += a;
2002
2090
  }
2003
2091
  return s.setUint32(r, e, !0), i;
2004
2092
  }
2005
- let c = 0;
2006
- for (let e = 0; e < n && V < B.length; e++) {
2007
- let n = s.getUint32(t + e * 8, !0), r = s.getUint32(t + e * 8 + 4, !0), i = Math.min(r, B.length - V);
2008
- new Uint8Array(T.buffer).set(B.slice(V, V + i), n), V += i, c += i;
2093
+ let l = 0;
2094
+ for (let e = 0; e < n && G < W.length; e++) {
2095
+ let n = s.getUint32(t + e * 8, !0), r = s.getUint32(t + e * 8 + 4, !0), i = Math.min(r, W.length - G);
2096
+ new Uint8Array(T.buffer).set(W.slice(G, G + i), n), G += i, l += i;
2009
2097
  }
2010
- return c === 0 && o && V >= B.length ? (s.setUint32(r, 0, !0), a) : (s.setUint32(r, c, !0), i);
2098
+ return l === 0 && o && G >= W.length ? (s.setUint32(r, 0, !0), a) : (s.setUint32(r, l, !0), i);
2011
2099
  }
2012
- if (!c) return o;
2013
- if (c.type === "dev_null") return s.setUint32(r, 0, !0), i;
2014
- if (c.type === "dev_zero") {
2100
+ if (!l) return o;
2101
+ if (l.type === "dev_null") return s.setUint32(r, 0, !0), i;
2102
+ if (l.type === "dev_zero") {
2015
2103
  let e = 0;
2016
2104
  for (let r = 0; r < n; r++) {
2017
2105
  let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0);
@@ -2019,7 +2107,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2019
2107
  }
2020
2108
  return s.setUint32(r, e, !0), i;
2021
2109
  }
2022
- if (c.type === "dev_urandom") {
2110
+ if (l.type === "dev_urandom") {
2023
2111
  let e = 0;
2024
2112
  for (let r = 0; r < n; r++) {
2025
2113
  let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0), a = new Uint8Array(T.buffer, n, i);
@@ -2029,214 +2117,214 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2029
2117
  }
2030
2118
  return s.setUint32(r, e, !0), i;
2031
2119
  }
2032
- if (c.type !== "file") return o;
2033
- let u = 0;
2034
- for (let e = 0; e < n && c.pos < c.bytes.length; e++) {
2035
- let n = s.getUint32(t + e * 8, !0), r = s.getUint32(t + e * 8 + 4, !0), i = Math.min(r, c.bytes.length - c.pos);
2036
- new Uint8Array(T.buffer).set(c.bytes.subarray(c.pos, c.pos + i), n), c.pos += i, u += i;
2120
+ if (l.type !== "file") return o;
2121
+ let d = 0;
2122
+ for (let e = 0; e < n && l.pos < l.bytes.length; e++) {
2123
+ let n = s.getUint32(t + e * 8, !0), r = s.getUint32(t + e * 8 + 4, !0), i = Math.min(r, l.bytes.length - l.pos);
2124
+ new Uint8Array(T.buffer).set(l.bytes.subarray(l.pos, l.pos + i), n), l.pos += i, d += i;
2037
2125
  }
2038
- return s.setUint32(r, u, !0), i;
2126
+ return s.setUint32(r, d, !0), i;
2039
2127
  },
2040
2128
  fd_seek: (e, t, n, r, a) => {
2041
2129
  if (!T) return o;
2042
- if (e <= 2) return f;
2043
- let s = G.get(e);
2130
+ if (e <= 2) return p;
2131
+ let s = X.get(e);
2044
2132
  if (!s) return o;
2045
- if (s.type === "dev_tty" || s.type === "dev_null" || s.type === "dev_zero" || s.type === "dev_urandom") return f;
2133
+ if (s.type === "dev_tty" || s.type === "dev_null" || s.type === "dev_zero" || s.type === "dev_urandom") return p;
2046
2134
  if (s.type !== "file") return o;
2047
- let l, u, d;
2048
- typeof t == "bigint" ? (l = Number(t), u = n, d = r) : (l = t, u = r, d = a);
2049
- let p = s.pos;
2050
- if (u === 0) p = l;
2051
- else if (u === 1) p = s.pos + l;
2052
- else if (u === 2) p = s.bytes.length + l;
2053
- else return c;
2054
- return p < 0 ? c : (s.pos = p, d && new DataView(T.buffer).setBigUint64(d, BigInt(s.pos), !0), i);
2135
+ let c, u, d;
2136
+ typeof t == "bigint" ? (c = Number(t), u = n, d = r) : (c = t, u = r, d = a);
2137
+ let f = s.pos;
2138
+ if (u === 0) f = c;
2139
+ else if (u === 1) f = s.pos + c;
2140
+ else if (u === 2) f = s.bytes.length + c;
2141
+ else return l;
2142
+ return f < 0 ? l : (s.pos = f, d && new DataView(T.buffer).setBigUint64(d, BigInt(s.pos), !0), i);
2055
2143
  },
2056
2144
  fd_tell: (e, t) => {
2057
2145
  if (!T) return o;
2058
- let n = G.get(e);
2146
+ let n = X.get(e);
2059
2147
  return !n || n.type !== "file" ? o : (new DataView(T.buffer).setBigUint64(t, BigInt(n.pos), !0), i);
2060
2148
  },
2061
2149
  fd_close: (e) => {
2062
2150
  if (e <= 2) return i;
2063
- let t = G.get(e);
2064
- return t ? (t.type === "file" && J(t), G.delete(e), K.delete(e), i) : o;
2151
+ let t = X.get(e);
2152
+ return t ? (t.type === "file" && ce(t), X.delete(e), ae.delete(e), i) : o;
2065
2153
  },
2066
2154
  fd_sync: (e) => {
2067
- let t = G.get(e);
2068
- return t && J(t), i;
2155
+ let t = X.get(e);
2156
+ return t && ce(t), i;
2069
2157
  },
2070
2158
  fd_datasync: (e) => {
2071
- let t = G.get(e);
2072
- return t && J(t), i;
2159
+ let t = X.get(e);
2160
+ return t && ce(t), i;
2073
2161
  },
2074
2162
  fd_prestat_get: (e, t) => {
2075
2163
  if (!T) return o;
2076
- let n = G.get(e);
2164
+ let n = X.get(e);
2077
2165
  if (!n || n.type !== "preopen") return o;
2078
2166
  let r = new DataView(T.buffer), a = b.encode(n.guestName);
2079
2167
  return r.setUint8(t, 0), r.setUint32(t + 4, a.length, !0), i;
2080
2168
  },
2081
2169
  fd_prestat_dir_name: (e, t, n) => {
2082
2170
  if (!T) return o;
2083
- let r = G.get(e);
2171
+ let r = X.get(e);
2084
2172
  if (!r || r.type !== "preopen") return o;
2085
2173
  let a = b.encode(r.guestName);
2086
2174
  return new Uint8Array(T.buffer, t, Math.min(n, a.length)).set(a.subarray(0, n)), i;
2087
2175
  },
2088
2176
  fd_fdstat_get: (e, t) => {
2089
2177
  if (!T) return o;
2090
- let n = new DataView(T.buffer), r = p;
2091
- if (e <= 2) r = m;
2178
+ let n = new DataView(T.buffer), r = m;
2179
+ if (e <= 2) r = h;
2092
2180
  else {
2093
- let t = G.get(e);
2181
+ let t = X.get(e);
2094
2182
  if (!t) return o;
2095
- r = t.type === "dev_null" || t.type === "dev_zero" || t.type === "dev_urandom" || t.type === "dev_tty" ? m : t.type === "preopen" || t.type === "dir" ? h : g;
2183
+ r = t.type === "dev_null" || t.type === "dev_zero" || t.type === "dev_urandom" || t.type === "dev_tty" ? h : t.type === "preopen" || t.type === "dir" ? g : _;
2096
2184
  }
2097
2185
  for (let e = 0; e < 24; e++) n.setUint8(t + e, 0);
2098
2186
  n.setUint8(t, r);
2099
- let a = K.get(e) || (G.get(e)?.append ? C : 0);
2187
+ let a = ae.get(e) || (X.get(e)?.append ? w : 0);
2100
2188
  return n.setUint16(t + 2, a, !0), n.setBigUint64(t + 8, 18446744073709551615n, !0), n.setBigUint64(t + 16, 18446744073709551615n, !0), i;
2101
2189
  },
2102
2190
  fd_fdstat_set_flags: (e, t) => {
2103
- if (!T || e > 2 && !G.has(e)) return o;
2104
- K.set(e, t);
2105
- let n = G.get(e);
2106
- return n && (n.append = !!(t & C)), (e === 0 || e === 2 || n && n.type === "dev_tty") && t & w && ee(), i;
2191
+ if (!T || e > 2 && !X.has(e)) return o;
2192
+ ae.set(e, t);
2193
+ let n = X.get(e);
2194
+ return n && (n.append = !!(t & w)), (e === 0 || e === 2 || n && n.type === "dev_tty") && t & E && V(), i;
2107
2195
  },
2108
2196
  fd_filestat_get: (e, t) => {
2109
2197
  if (!T) return o;
2110
2198
  let n = new DataView(T.buffer);
2111
2199
  for (let e = 0; e < 64; e++) n.setUint8(t + e, 0);
2112
- if (e <= 2) return n.setUint8(t + 16, m), i;
2113
- let r = G.get(e);
2200
+ if (e <= 2) return n.setUint8(t + 16, h), i;
2201
+ let r = X.get(e);
2114
2202
  if (!r) return o;
2115
- if (r.type === "dev_null" || r.type === "dev_zero" || r.type === "dev_urandom" || r.type === "dev_tty") return n.setUint8(t + 16, m), n.setBigUint64(t + 24, 1n, !0), i;
2203
+ if (r.type === "dev_null" || r.type === "dev_zero" || r.type === "dev_urandom" || r.type === "dev_tty") return n.setUint8(t + 16, h), n.setBigUint64(t + 24, 1n, !0), i;
2116
2204
  let a = r.type === "preopen" || r.type === "dir";
2117
- return n.setUint8(t + 16, a ? h : g), n.setBigUint64(t + 24, 1n, !0), n.setBigUint64(t + 32, BigInt(r.bytes ? r.bytes.length : 0), !0), i;
2205
+ return n.setUint8(t + 16, a ? g : _), n.setBigUint64(t + 24, 1n, !0), n.setBigUint64(t + 32, BigInt(r.bytes ? r.bytes.length : 0), !0), i;
2118
2206
  },
2119
- path_open: (e, t, r, a, c, f, p, m, h) => {
2120
- if (!T || !H) return o;
2121
- let g = q(e, n.decode(new Uint8Array(T.buffer, r, a)));
2207
+ path_open: (e, t, r, a, c, l, p, m, h) => {
2208
+ if (!T || !K) return o;
2209
+ let g = se(e, n.decode(new Uint8Array(T.buffer, r, a)));
2122
2210
  if (!g) return o;
2123
- let y = g.replace(/\/+/g, "/").replace(/\/$/, "") || "/";
2124
- if (y === "/dev/null") {
2125
- let e = W++;
2126
- return G.set(e, {
2211
+ let _ = g.replace(/\/+/g, "/").replace(/\/$/, "") || "/";
2212
+ if (_ === "/dev/null") {
2213
+ let e = Y++;
2214
+ return X.set(e, {
2127
2215
  type: "dev_null",
2128
2216
  path: "/dev/null"
2129
2217
  }), new DataView(T.buffer).setUint32(h, e, !0), i;
2130
2218
  }
2131
- if (y === "/dev/zero") {
2132
- let e = W++;
2133
- return G.set(e, {
2219
+ if (_ === "/dev/zero") {
2220
+ let e = Y++;
2221
+ return X.set(e, {
2134
2222
  type: "dev_zero",
2135
2223
  path: "/dev/zero"
2136
2224
  }), new DataView(T.buffer).setUint32(h, e, !0), i;
2137
2225
  }
2138
- if (y === "/dev/urandom" || y === "/dev/random") {
2139
- let e = W++;
2140
- return G.set(e, {
2226
+ if (_ === "/dev/urandom" || _ === "/dev/random") {
2227
+ let e = Y++;
2228
+ return X.set(e, {
2141
2229
  type: "dev_urandom",
2142
- path: y
2230
+ path: _
2143
2231
  }), new DataView(T.buffer).setUint32(h, e, !0), i;
2144
2232
  }
2145
- if (y === "/dev/tty" || y === "/dev/stdin") {
2146
- ee();
2147
- let e = W++;
2148
- return G.set(e, {
2233
+ if (_ === "/dev/tty" || _ === "/dev/stdin") {
2234
+ V();
2235
+ let e = Y++;
2236
+ return X.set(e, {
2149
2237
  type: "dev_tty",
2150
- path: y
2238
+ path: _
2151
2239
  }), new DataView(T.buffer).setUint32(h, e, !0), i;
2152
2240
  }
2153
- if (y === "/dev/stdout") return new DataView(T.buffer).setUint32(h, 1, !0), i;
2154
- if (y === "/dev/stderr") return new DataView(T.buffer).setUint32(h, 2, !0), i;
2155
- let w = H.stat(g), E = w !== null;
2156
- if (c & x && c & _ && E) return s;
2157
- if (c & v) {
2158
- if (!E) return u;
2159
- if (!w.isDirectory) return d;
2160
- let e = W++;
2161
- return G.set(e, {
2241
+ if (_ === "/dev/stdout") return new DataView(T.buffer).setUint32(h, 1, !0), i;
2242
+ if (_ === "/dev/stderr") return new DataView(T.buffer).setUint32(h, 2, !0), i;
2243
+ let y = K.stat(g), E = y !== null;
2244
+ if (c & S && c & v && E) return s;
2245
+ if (c & x) {
2246
+ if (!E) return d;
2247
+ if (!y.isDirectory) return f;
2248
+ let e = Y++;
2249
+ return X.set(e, {
2162
2250
  type: "dir",
2163
2251
  path: g
2164
2252
  }), new DataView(T.buffer).setUint32(h, e, !0), i;
2165
2253
  }
2166
- if (E && w.isDirectory) return l;
2167
- if (!E && !(c & _)) return u;
2254
+ if (E && y.isDirectory) return u;
2255
+ if (!E && !(c & v)) return d;
2168
2256
  let D = new Uint8Array(), O = !1;
2169
- if (E && !(c & S)) {
2170
- let e = H.getFileByPath(g);
2257
+ if (E && !(c & C)) {
2258
+ let e = K.getFileByPath(g);
2171
2259
  e != null && (D = typeof e == "string" ? b.encode(e) : new Uint8Array(this._contentToBytes(e)));
2172
2260
  } else O = !0;
2173
- let k = W++;
2174
- return G.set(k, {
2261
+ let k = Y++;
2262
+ return X.set(k, {
2175
2263
  type: "file",
2176
2264
  path: g,
2177
2265
  bytes: D,
2178
- pos: m & C ? D.length : 0,
2179
- append: !!(m & C),
2266
+ pos: m & w ? D.length : 0,
2267
+ append: !!(m & w),
2180
2268
  dirty: O
2181
2269
  }), new DataView(T.buffer).setUint32(h, k, !0), i;
2182
2270
  },
2183
2271
  path_filestat_get: (e, t, r, a, s) => {
2184
- if (!T || !H) return o;
2185
- let c = q(e, n.decode(new Uint8Array(T.buffer, r, a)));
2272
+ if (!T || !K) return o;
2273
+ let c = se(e, n.decode(new Uint8Array(T.buffer, r, a)));
2186
2274
  if (!c) return o;
2187
- let l = c.replace(/\/+/g, "/").replace(/\/$/, "") || "/", d = H.stat(c);
2188
- if (l === "/dev/null" || l === "/dev/zero" || l === "/dev/urandom" || l === "/dev/random" || l === "/dev/tty" || l === "/dev/stdin" || l === "/dev/stdout" || l === "/dev/stderr" || d && (d.isDevice || d.isCharacterDevice)) {
2275
+ let l = c.replace(/\/+/g, "/").replace(/\/$/, "") || "/", u = K.stat(c);
2276
+ if (l === "/dev/null" || l === "/dev/zero" || l === "/dev/urandom" || l === "/dev/random" || l === "/dev/tty" || l === "/dev/stdin" || l === "/dev/stdout" || l === "/dev/stderr" || u && (u.isDevice || u.isCharacterDevice)) {
2189
2277
  let e = new DataView(T.buffer);
2190
2278
  for (let t = 0; t < 64; t++) e.setUint8(s + t, 0);
2191
- return e.setUint8(s + 16, m), e.setBigUint64(s + 24, 1n, !0), i;
2279
+ return e.setUint8(s + 16, h), e.setBigUint64(s + 24, 1n, !0), i;
2192
2280
  }
2193
- if (!d) return u;
2281
+ if (!u) return d;
2194
2282
  let f = new DataView(T.buffer);
2195
2283
  for (let e = 0; e < 64; e++) f.setUint8(s + e, 0);
2196
- return f.setUint8(s + 16, d.isDirectory ? h : g), f.setBigUint64(s + 24, 1n, !0), f.setBigUint64(s + 32, BigInt(H.getSize(c) || 0), !0), i;
2284
+ return f.setUint8(s + 16, u.isDirectory ? g : _), f.setBigUint64(s + 24, 1n, !0), f.setBigUint64(s + 32, BigInt(K.getSize(c) || 0), !0), i;
2197
2285
  },
2198
2286
  path_create_directory: (e, t, r) => {
2199
- if (!T || !H) return o;
2200
- let a = q(e, n.decode(new Uint8Array(T.buffer, t, r)));
2287
+ if (!T || !K) return o;
2288
+ let a = se(e, n.decode(new Uint8Array(T.buffer, t, r)));
2201
2289
  if (!a) return o;
2202
- if (H.exists(a)) return s;
2290
+ if (K.exists(a)) return s;
2203
2291
  try {
2204
- return H.setFileByPath(a, {}, !0), i;
2292
+ return K.setFileByPath(a, {}, !0), i;
2205
2293
  } catch {
2206
- return c;
2294
+ return l;
2207
2295
  }
2208
2296
  },
2209
2297
  path_unlink_file: (e, t, r) => {
2210
- if (!T || !H) return o;
2211
- let a = q(e, n.decode(new Uint8Array(T.buffer, t, r)));
2212
- if (!a || !H.exists(a)) return u;
2298
+ if (!T || !K) return o;
2299
+ let a = se(e, n.decode(new Uint8Array(T.buffer, t, r)));
2300
+ if (!a || !K.exists(a)) return d;
2213
2301
  try {
2214
- return H.deleteFileByPath(a), i;
2302
+ return K.deleteFileByPath(a), i;
2215
2303
  } catch {
2216
- return c;
2304
+ return l;
2217
2305
  }
2218
2306
  },
2219
2307
  path_remove_directory: (e, t, r) => {
2220
- if (!T || !H) return o;
2221
- let a = q(e, n.decode(new Uint8Array(T.buffer, t, r)));
2222
- if (!a || !H.exists(a)) return u;
2308
+ if (!T || !K) return o;
2309
+ let a = se(e, n.decode(new Uint8Array(T.buffer, t, r)));
2310
+ if (!a || !K.exists(a)) return d;
2223
2311
  try {
2224
- return H.deleteFileByPath(a), i;
2312
+ return K.deleteFileByPath(a), i;
2225
2313
  } catch {
2226
- return c;
2314
+ return l;
2227
2315
  }
2228
2316
  },
2229
- path_rename: (e, t, r, a, s, l) => {
2230
- if (!T || !H) return o;
2231
- let d = n.decode(new Uint8Array(T.buffer, t, r)), f = n.decode(new Uint8Array(T.buffer, s, l)), p = q(e, d), m = q(a, f);
2317
+ path_rename: (e, t, r, a, s, c) => {
2318
+ if (!T || !K) return o;
2319
+ let u = n.decode(new Uint8Array(T.buffer, t, r)), f = n.decode(new Uint8Array(T.buffer, s, c)), p = se(e, u), m = se(a, f);
2232
2320
  if (!p || !m) return o;
2233
- if (!H.exists(p)) return u;
2234
- for (let e of G.values()) e.path === p && (J(e), e.path = m);
2321
+ if (!K.exists(p)) return d;
2322
+ for (let e of X.values()) e.path === p && (ce(e), e.path = m);
2235
2323
  try {
2236
- let e = H.getFileByPath(p);
2237
- return H.setFileByPath(m, e, !0), H.deleteFileByPath(p), i;
2324
+ let e = K.getFileByPath(p);
2325
+ return K.setFileByPath(m, e, !0), K.deleteFileByPath(p), i;
2238
2326
  } catch {
2239
- return c;
2327
+ return l;
2240
2328
  }
2241
2329
  },
2242
2330
  proc_exit: (e) => {
@@ -2246,12 +2334,12 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2246
2334
  };
2247
2335
  },
2248
2336
  args_sizes_get: (e, t) => {
2249
- if (!T) return c;
2337
+ if (!T) return l;
2250
2338
  let n = [this.script, ...this.arguments || []], r = new DataView(T.buffer);
2251
2339
  return r.setUint32(e, n.length, !0), r.setUint32(t, n.reduce((e, t) => e + b.encode(t).length + 1, 0), !0), i;
2252
2340
  },
2253
2341
  args_get: (e, t) => {
2254
- if (!T) return c;
2342
+ if (!T) return l;
2255
2343
  let n = [this.script, ...this.arguments || []], r = new DataView(T.buffer), a = t;
2256
2344
  for (let t = 0; t < n.length; t++) {
2257
2345
  r.setUint32(e + t * 4, a, !0);
@@ -2261,26 +2349,26 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2261
2349
  return i;
2262
2350
  },
2263
2351
  environ_sizes_get: (e, t) => {
2264
- if (!T) return c;
2352
+ if (!T) return l;
2265
2353
  let n = new DataView(T.buffer);
2266
- n.setUint32(e, X.length, !0);
2267
- let r = X.reduce((e, t) => e + b.encode(t).length + 1, 0);
2354
+ n.setUint32(e, Z.length, !0);
2355
+ let r = Z.reduce((e, t) => e + b.encode(t).length + 1, 0);
2268
2356
  return n.setUint32(t, r, !0), i;
2269
2357
  },
2270
2358
  environ_get: (e, t) => {
2271
- if (!T) return c;
2359
+ if (!T) return l;
2272
2360
  let n = new DataView(T.buffer), r = t;
2273
- for (let t = 0; t < X.length; t++) {
2361
+ for (let t = 0; t < Z.length; t++) {
2274
2362
  n.setUint32(e + t * 4, r, !0);
2275
- let i = b.encode(X[t] + "\0");
2363
+ let i = b.encode(Z[t] + "\0");
2276
2364
  new Uint8Array(T.buffer).set(i, r), r += i.length;
2277
2365
  }
2278
2366
  return i;
2279
2367
  },
2280
2368
  clock_time_get: (e, t, n) => {
2281
2369
  if (T) {
2282
- let e = BigInt(Date.now()) * 1000000n;
2283
- new DataView(T.buffer).setBigUint64(n, e, !0);
2370
+ let t = e === 1 && typeof performance < "u" && typeof performance.now == "function" ? BigInt(Math.round(performance.now() * 1e6)) : BigInt(Date.now()) * 1000000n;
2371
+ new DataView(T.buffer).setBigUint64(n, t, !0);
2284
2372
  }
2285
2373
  return i;
2286
2374
  },
@@ -2298,24 +2386,33 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2298
2386
  let e = BigInt(Date.now()) * 1000000n;
2299
2387
  c = s > e ? Number((s - e) / 1000000n) : 0;
2300
2388
  } else c = Number(s / 1000000n);
2301
- return D && c > 0 ? (typeof E?.exports?.asyncify_get_state == "function" ? E.exports.asyncify_get_state() : 0) === 2 ? (E.exports.asyncify_stop_rewind(), i) : (E.exports.asyncify_start_unwind(O), k = new Promise((e) => setTimeout(e, Math.max(1, c))), i) : i;
2389
+ return O && c > 0 ? (typeof D?.exports?.asyncify_get_state == "function" ? D.exports.asyncify_get_state() : 0) === 2 ? (D.exports.asyncify_stop_rewind(), i) : (D.exports.asyncify_start_unwind(k), A = new Promise((e) => setTimeout(e, Math.max(1, c))), i) : i;
2302
2390
  },
2303
2391
  poll_oneoff: (e, t, n, r) => {
2304
2392
  if (!T) return o;
2305
2393
  let a = new DataView(T.buffer);
2306
- if (D) {
2307
- if ((typeof E?.exports?.asyncify_get_state == "function" ? E.exports.asyncify_get_state() : 0) === 2) {
2308
- E.exports.asyncify_stop_rewind();
2394
+ if (O) {
2395
+ if ((typeof D?.exports?.asyncify_get_state == "function" ? D.exports.asyncify_get_state() : 0) === 2) {
2396
+ if (D.exports.asyncify_stop_rewind(), P && U.length === 0) return P = !1, a.setUint32(r, 0, !0), c;
2397
+ P = !1;
2309
2398
  let o = 0;
2310
2399
  for (let r = 0; r < n; r++) {
2311
- let n = e + r * 48, s = a.getBigUint64(n, !0), c = a.getUint8(n + 8), l = t + o * 32;
2312
- a.setBigUint64(l, s, !0), a.setUint16(l + 8, i, !0), a.setUint8(l + 10, c);
2313
- for (let e = 11; e < 32; e++) a.setUint8(l + e, 0);
2314
- c === 1 && a.setBigUint64(l + 16, BigInt(R.length), !0), o++;
2400
+ let n = e + r * 48, s = a.getBigUint64(n, !0), c = a.getUint8(n + 8), l = !1;
2401
+ if (c === 0) l = N;
2402
+ else if (c === 1) {
2403
+ let e = a.getUint32(n + 16, !0), t = X.get(e), r = !!(t && t.type === "dev_tty");
2404
+ (e === 0 || B && e === 2 || r) && U.length > 0 && (l = !0);
2405
+ } else c === 2 && (l = !0);
2406
+ if (l) {
2407
+ let e = t + o * 32;
2408
+ a.setBigUint64(e, s, !0), a.setUint16(e + 8, i, !0), a.setUint8(e + 10, c);
2409
+ for (let t = 11; t < 32; t++) a.setUint8(e + t, 0);
2410
+ c === 1 && a.setBigUint64(e + 16, BigInt(U.length), !0), o++;
2411
+ }
2315
2412
  }
2316
2413
  return a.setUint32(r, o, !0), i;
2317
2414
  }
2318
- let o = 0, s = Infinity;
2415
+ let o = 0, s = !1, l = Infinity;
2319
2416
  for (let t = 0; t < n; t++) {
2320
2417
  let n = e + t * 48, r = a.getUint8(n + 8);
2321
2418
  if (r === 0) {
@@ -2324,46 +2421,49 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2324
2421
  let t = BigInt(Date.now()) * 1000000n;
2325
2422
  r = e > t ? Number((e - t) / 1000000n) : 0;
2326
2423
  } else r = Number(e / 1000000n);
2327
- r < s && (s = r);
2424
+ r < l && (l = r);
2328
2425
  } else if (r === 1) {
2329
- let e = a.getUint32(n + 16, !0), t = G.get(e), r = !!(t && t.type === "dev_tty");
2330
- (e === 0 || e === 2 || r) && ee(), (e === 0 || I && e === 2 || r) && R.length > 0 && o++;
2426
+ s = !0;
2427
+ let e = a.getUint32(n + 16, !0), t = X.get(e), r = !!(t && t.type === "dev_tty");
2428
+ (e === 0 || e === 2 || r) && V(), (e === 0 || B && e === 2 || r) && U.length > 0 && o++;
2331
2429
  } else r === 2 && o++;
2332
2430
  }
2333
- if (o > 0 || s === 0) {
2431
+ if (o > 0 || l === 0) {
2334
2432
  let o = 0;
2335
2433
  for (let r = 0; r < n; r++) {
2336
- let n = e + r * 48, c = a.getBigUint64(n, !0), l = a.getUint8(n + 8), u = !1;
2337
- if (l === 0 && s === 0) u = !0;
2338
- else if (l === 1) {
2339
- let e = a.getUint32(n + 16, !0), t = G.get(e), r = !!(t && t.type === "dev_tty");
2340
- (e === 0 || I && e === 2 || r) && R.length > 0 && (u = !0);
2341
- } else l === 2 && (u = !0);
2434
+ let n = e + r * 48, s = a.getBigUint64(n, !0), c = a.getUint8(n + 8), u = !1;
2435
+ if (c === 0 && l === 0) u = !0;
2436
+ else if (c === 1) {
2437
+ let e = a.getUint32(n + 16, !0), t = X.get(e), r = !!(t && t.type === "dev_tty");
2438
+ (e === 0 || B && e === 2 || r) && U.length > 0 && (u = !0);
2439
+ } else c === 2 && (u = !0);
2342
2440
  if (u) {
2343
2441
  let e = t + o * 32;
2344
- a.setBigUint64(e, c, !0), a.setUint16(e + 8, i, !0), a.setUint8(e + 10, l);
2442
+ a.setBigUint64(e, s, !0), a.setUint16(e + 8, i, !0), a.setUint8(e + 10, c);
2345
2443
  for (let t = 11; t < 32; t++) a.setUint8(e + t, 0);
2346
- l === 1 && a.setBigUint64(e + 16, BigInt(R.length), !0), o++;
2444
+ c === 1 && a.setBigUint64(e + 16, BigInt(U.length), !0), o++;
2347
2445
  }
2348
2446
  }
2349
2447
  return a.setUint32(r, o, !0), i;
2350
2448
  }
2351
- return E.exports.asyncify_start_unwind(O), k = new Promise((e, t) => {
2449
+ return N = !1, P = !1, D.exports.asyncify_start_unwind(k), A = new Promise((e, t) => {
2352
2450
  let n = null;
2353
2451
  this._asyncifyReject = t;
2354
2452
  let r = () => {
2355
- n && clearTimeout(n), A = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
2453
+ n && clearTimeout(n), N = !1, P = !1, j = null, M = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
2356
2454
  };
2357
- A = r, this._pendingReadResolve = r, s !== Infinity && (n = setTimeout(() => {
2358
- A = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
2359
- }, Math.max(1, s)));
2455
+ s && (j = r, this._pendingReadResolve = r, M = () => {
2456
+ n && clearTimeout(n), N = !1, P = !0, j = null, M = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
2457
+ }), l !== Infinity && (n = setTimeout(() => {
2458
+ N = !0, P = !1, j = null, M = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
2459
+ }, Math.max(1, l)));
2360
2460
  }), a.setUint32(r, 0, !0), i;
2361
2461
  }
2362
2462
  return a.setUint32(r, 0, !0), i;
2363
2463
  }
2364
2464
  }, { get(e, t) {
2365
2465
  return t in e ? e[t] : () => 0;
2366
- } }), ae = (e) => {
2466
+ } }), pe = (e) => {
2367
2467
  if (!T || !e) return "";
2368
2468
  try {
2369
2469
  let t = new DataView(T.buffer).getUint32(e - 4, !0), n = new Uint16Array(T.buffer, e, t >>> 1);
@@ -2371,33 +2471,33 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2371
2471
  } catch {
2372
2472
  return "";
2373
2473
  }
2374
- }, oe = {
2375
- wasi_snapshot_preview1: ie,
2376
- wasi_unstable: ie,
2474
+ }, me = {
2475
+ wasi_snapshot_preview1: fe,
2476
+ wasi_unstable: fe,
2377
2477
  env: new Proxy({
2378
2478
  print: (e, t) => {
2379
- T && L(1, n.decode(new Uint8Array(T.buffer, e, t)));
2479
+ T && H(1, n.decode(new Uint8Array(T.buffer, e, t)));
2380
2480
  },
2381
2481
  eprint: (e, t) => {
2382
- T && L(2, n.decode(new Uint8Array(T.buffer, e, t)));
2482
+ T && H(2, n.decode(new Uint8Array(T.buffer, e, t)));
2383
2483
  },
2384
2484
  log: (e) => {
2385
- L(1, ae(e) + "\n");
2485
+ H(1, pe(e) + "\n");
2386
2486
  },
2387
2487
  logi: (e) => {
2388
- L(1, String(e) + "\n");
2488
+ H(1, String(e) + "\n");
2389
2489
  },
2390
2490
  logf: (e) => {
2391
- L(1, String(e) + "\n");
2491
+ H(1, String(e) + "\n");
2392
2492
  },
2393
2493
  trace: (e, t, ...n) => {
2394
2494
  let r = t > 0 ? " " + n.slice(0, t).join(", ") : "";
2395
- L(1, `trace: ${ae(e)}${r}\n`);
2495
+ H(1, `trace: ${pe(e)}${r}\n`);
2396
2496
  },
2397
2497
  seed: () => Date.now() * Math.random(),
2398
2498
  abort: (e, t, n, r) => {
2399
- let i = ae(e), a = ae(t);
2400
- throw (i || a) && L(2, `abort: ${i || "aborted"} at ${a || this.script}:${n || 0}:${r || 0}\n`), this.exitCode = 134, {
2499
+ let i = pe(e), a = pe(t);
2500
+ throw (i || a) && H(2, `abort: ${i || "aborted"} at ${a || this.script}:${n || 0}:${r || 0}\n`), this.exitCode = 134, {
2401
2501
  _wasmExit: !0,
2402
2502
  code: 134
2403
2503
  };
@@ -2413,82 +2513,97 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2413
2513
  initial: 1,
2414
2514
  maximum: 256
2415
2515
  });
2416
- T = t, oe[e.module] || (oe[e.module] = {}), oe[e.module][e.name] = t;
2516
+ T = t, me[e.module] || (me[e.module] = {}), me[e.module][e.name] = t;
2417
2517
  }
2418
- if (E = await WebAssembly.instantiate(t, oe), E.exports.memory && (T = E.exports.memory), D = !!(E.exports.asyncify_start_unwind && E.exports.asyncify_stop_unwind), D && T) {
2518
+ if (D = await WebAssembly.instantiate(t, me), D.exports.memory && (T = D.exports.memory), O = !!(D.exports.asyncify_start_unwind && D.exports.asyncify_stop_unwind), O && T) {
2419
2519
  try {
2420
- O = T.grow(1) * 65536;
2520
+ k = T.grow(1) * 65536;
2421
2521
  } catch {
2422
- O = 16;
2522
+ k = 16;
2423
2523
  }
2424
- let e = O + 8, t = O + 65536 - 8;
2425
- new Int32Array(T.buffer, O, 2).set([e, t]);
2524
+ let e = k + 8, t = k + 65536 - 8;
2525
+ new Int32Array(T.buffer, k, 2).set([e, t]);
2426
2526
  }
2427
- typeof E.exports.set_terminal_size == "function" && ee(), I && this._enterAltScreen();
2428
- let n = this.stdout && this.stdout.columns || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("COLUMNS"), 10) || 80, r = this.stdout && this.stdout.rows || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("LINES"), 10) || 24;
2429
- if (typeof E.exports.set_terminal_size == "function") try {
2430
- E.exports.set_terminal_size(n, r);
2527
+ typeof D.exports.set_terminal_size == "function" && V(), B && this._enterAltScreen();
2528
+ let n = this.stdout && this.stdout.columns || this.stdinStream && this.stdinStream.columns || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("COLUMNS"), 10) || 80, r = this.stdout && this.stdout.rows || this.stdinStream && this.stdinStream.rows || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("LINES"), 10) || 24;
2529
+ if (typeof D.exports.set_terminal_size == "function") try {
2530
+ D.exports.set_terminal_size(n, r);
2431
2531
  } catch {}
2432
- j = () => {
2433
- let e = this.stdout && this.stdout.columns || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("COLUMNS"), 10) || 80, t = this.stdout && this.stdout.rows || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("LINES"), 10) || 24;
2434
- if (typeof E?.exports?.set_terminal_size == "function") try {
2435
- E.exports.set_terminal_size(e, t);
2436
- } catch {}
2437
- }, this.stdout && typeof this.stdout.on == "function" && this.stdout.on("resize", j), this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("resize", j);
2438
- let i = E.exports._start || E.exports.__wasi_command || E.exports.main || E.exports.run;
2439
- if (i) try {
2440
- let e = i();
2441
- for (e && typeof e.then == "function" && (e = await e); D && typeof E.exports.asyncify_get_state == "function" && E.exports.asyncify_get_state() === 1;) {
2532
+ let i = n, a = r, o = (e, t) => {
2533
+ if (!(!e || !t)) {
2534
+ if (this.stdout && (this.stdout.columns !== e || this.stdout.rows !== t) && (this.stdout.columns = e, this.stdout.rows = t), this.stdinStream && (this.stdinStream.columns !== e || this.stdinStream.rows !== t) && (this.stdinStream.columns = e, this.stdinStream.rows = t), this.context && typeof this.context.setVar == "function") try {
2535
+ this.context.setVar("COLUMNS", String(e)), this.context.setVar("LINES", String(t));
2536
+ } catch {}
2537
+ if (!(e === i && t === a)) {
2538
+ if (i = e, a = t, typeof D?.exports?.set_terminal_size == "function") try {
2539
+ D.exports.set_terminal_size(e, t);
2540
+ } catch {}
2541
+ if (M) {
2542
+ let e = M;
2543
+ M = null, e();
2544
+ }
2545
+ }
2546
+ }
2547
+ };
2548
+ ee = () => {
2549
+ o(this.stdout && this.stdout.columns || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("COLUMNS"), 10) || 80, this.stdout && this.stdout.rows || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("LINES"), 10) || 24);
2550
+ }, te = () => {
2551
+ o(this.stdinStream && this.stdinStream.columns || this.stdout && this.stdout.columns || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("COLUMNS"), 10) || 80, this.stdinStream && this.stdinStream.rows || this.stdout && this.stdout.rows || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("LINES"), 10) || 24);
2552
+ }, this.stdout && typeof this.stdout.on == "function" && this.stdout.on("resize", ee), this.stdinStream && this.stdinStream !== this.stdout && typeof this.stdinStream.on == "function" && this.stdinStream.on("resize", te);
2553
+ let s = D.exports._start || D.exports.__wasi_command || D.exports.main || D.exports.run;
2554
+ if (s) try {
2555
+ let e = s();
2556
+ for (e && typeof e.then == "function" && (e = await e); O && typeof D.exports.asyncify_get_state == "function" && D.exports.asyncify_get_state() === 1;) {
2442
2557
  if (this._killed) {
2443
2558
  this.exitCode = 130;
2444
2559
  break;
2445
2560
  }
2446
- if (E.exports.asyncify_stop_unwind(), k) {
2561
+ if (D.exports.asyncify_stop_unwind(), A) {
2447
2562
  try {
2448
- await k;
2563
+ await A;
2449
2564
  } catch {
2450
2565
  if (this._killed) {
2451
2566
  this.exitCode = 130;
2452
2567
  break;
2453
2568
  }
2454
2569
  }
2455
- k = null;
2570
+ A = null;
2456
2571
  }
2457
2572
  if (this._killed) {
2458
2573
  this.exitCode = 130;
2459
2574
  break;
2460
2575
  }
2461
- E.exports.asyncify_start_rewind(O), e = i(), e && typeof e.then == "function" && (e = await e);
2576
+ D.exports.asyncify_start_rewind(k), e = s(), e && typeof e.then == "function" && (e = await e);
2462
2577
  }
2463
2578
  } catch (e) {
2464
2579
  this._killed ? this.exitCode = 130 : (!e || !e._wasmExit) && (this.stdErr = `${this.script}: runtime error: ${e?.message || String(e)}`, this.exitCode = 1);
2465
2580
  }
2466
2581
  else {
2467
- let e = Object.entries(E.exports).filter(([, e]) => typeof e == "function").map(([e]) => e), t = e.length > 0 ? ` (module is a library exporting: ${e.join(", ")})` : "";
2582
+ let e = Object.entries(D.exports).filter(([, e]) => typeof e == "function").map(([e]) => e), t = e.length > 0 ? ` (module is a library exporting: ${e.join(", ")})` : "";
2468
2583
  this.stdErr = `${this.script}: no CLI entry point found (expected _start, main, or run)${t}`, this.exitCode = 1;
2469
2584
  }
2470
2585
  } catch (e) {
2471
2586
  this._killed ? this.exitCode = 130 : (!e || !e._wasmExit) && (this.stdErr = `${this.script}: ${e?.message || String(e)}`, this.exitCode = 1);
2472
2587
  } finally {
2473
- I && this._exitAltScreen(), M && (this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", M), this.stdin && typeof this.stdin.off == "function" && this.stdin.off("data", M)), this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", this._onStdinStreamData), j && (this.stdout && typeof this.stdout.off == "function" && this.stdout.off("resize", j), this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("resize", j)), this._externalKeyHandler = null;
2474
- for (let e of G.values()) J(e);
2588
+ B && this._exitAltScreen(), R && (this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", R), this.stdin && typeof this.stdin.off == "function" && this.stdin.off("data", R)), ie && this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", this._onStdinStreamData), ee && this.stdout && typeof this.stdout.off == "function" && this.stdout.off("resize", ee), te && this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("resize", te), this._externalKeyHandler = null;
2589
+ for (let e of X.values()) ce(e);
2475
2590
  }
2476
- te();
2477
- let se = this.arguments || [];
2591
+ ne();
2592
+ let he = this.arguments || [];
2478
2593
  if (!(this.result && this.result.getStdOutput && this.result.getStdOutput().length > 0) && (this.exitCode === 0 || this.exitCode === void 0)) {
2479
2594
  let t = this._ensurePkgMeta(), n = t && t.bin || (this.script || "wasm").split("/").pop(), r = Object.assign({
2480
2595
  name: t && t.name || n,
2481
2596
  version: t && t.version || "wasi",
2482
2597
  description: `WebAssembly WASI binary (${this.script})`
2483
2598
  }, t || {});
2484
- if (se.includes("--help") || se.includes("-h")) {
2485
- let t = P(e);
2486
- for (let e of F(n, r, t)) this.stdOut = e;
2487
- } else (se.includes("--version") || se.includes("-V") || se.includes("-v")) && (this.stdOut = `${n} (${r.name} ${r.version} wasm)`);
2599
+ if (he.includes("--help") || he.includes("-h")) {
2600
+ let t = F(e);
2601
+ for (let e of I(n, r, t)) this.stdOut = e;
2602
+ } else (he.includes("--version") || he.includes("-V") || he.includes("-v")) && (this.stdOut = `${n} (${r.name} ${r.version} wasm)`);
2488
2603
  }
2489
2604
  }
2490
- }, k = /* @__PURE__ */ new Map();
2491
- function A(e, t) {
2605
+ }, A = /* @__PURE__ */ new Map();
2606
+ function j(e, t) {
2492
2607
  if (!e || !e.exists(t)) return null;
2493
2608
  if (e.isRealFilesystem) try {
2494
2609
  let n = O();
@@ -2515,7 +2630,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2515
2630
  }
2516
2631
  return null;
2517
2632
  }
2518
- function j(e, t, n, i = "application/octet-stream") {
2633
+ function M(e, t, n, i = "application/octet-stream") {
2519
2634
  let a = n instanceof Uint8Array ? n : new Uint8Array(n);
2520
2635
  if (e && e.isRealFilesystem) {
2521
2636
  e.setFileByPath(t, a, !0);
@@ -2530,7 +2645,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2530
2645
  }
2531
2646
  e.setFileByPath(t, s, !0);
2532
2647
  }
2533
- async function M(e, t, n = null) {
2648
+ async function N(e, t, n = null) {
2534
2649
  if (typeof n == "function") {
2535
2650
  let r = await n(e, t);
2536
2651
  if (r) return r;
@@ -2558,7 +2673,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2558
2673
  }
2559
2674
  throw Error(`Package '${e}' could not be loaded`);
2560
2675
  }
2561
- function N(e, t = !1) {
2676
+ function P(e, t = !1) {
2562
2677
  let n = {
2563
2678
  usage: null,
2564
2679
  options: []
@@ -2575,7 +2690,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2575
2690
  }
2576
2691
  return n;
2577
2692
  }
2578
- function P(e) {
2693
+ function F(e) {
2579
2694
  let t = {
2580
2695
  usage: null,
2581
2696
  options: [],
@@ -2600,12 +2715,12 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2600
2715
  r.length >= 4 && n.push(r);
2601
2716
  let i = n.join("\n");
2602
2717
  t.isInteractive || (i.includes("/dev/tty") || i.includes("\x1B[?1049h") || i.includes("smcup") || i.includes("xterm")) && (t.isInteractive = !0);
2603
- let a = N(i, !0);
2718
+ let a = P(i, !0);
2604
2719
  t.usage = a.usage, t.options = a.options;
2605
2720
  } catch {}
2606
2721
  return t;
2607
2722
  }
2608
- function F(e, t = {}, n = null) {
2723
+ function I(e, t = {}, n = null) {
2609
2724
  let r = t.name || e, i = t.version || "wasm", a = t.description || "WebAssembly binary", o = t && typeof t.repl == "object" ? t.repl : t.repl ? {} : null, s = n && n.usage || t.usage, c = s ? s.replace(/%s/g, e) : null, l = o ? `${e} [options] ${o.evalFlag ? `[${o.evalFlag} <code>] ` : ""}[file] [args...]` : `${e} [options] [args...]`, u = [`${e} (${r} ${i} wasm) — ${a}`, `Usage: ${c || l}`];
2610
2725
  t.details && u.push("", t.details), u.push("", "Options:");
2611
2726
  let d = n && n.options && n.options.length > 0 ? n.options : Array.isArray(t.options) ? t.options : [];
@@ -2613,8 +2728,8 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2613
2728
  else o && (o.evalFlag && u.push(` ${o.evalFlag.padEnd(20)}Evaluate inline code and print result`), u.push(` (no arguments) Start interactive ${e} REPL shell`));
2614
2729
  return u.push(" -h, --help Show this help message and exit"), u.push(" -V, --version Show WebAssembly binary version and exit"), n && n.exports && n.exports.length > 0 && u.push("", `WASM Exports: ${n.exports.join(", ")}`), Array.isArray(t.aliases) && t.aliases.length > 0 && u.push("", `Aliases: ${t.aliases.join(", ")}`), (t.homepage || t.cdnUrl || t.wasmUrl) && u.push(`Source: ${t.homepage || t.cdnUrl || t.wasmUrl}`), u;
2615
2730
  }
2616
- function I(e, t = {}, n = null) {
2617
- let r = E(), i = (n || e.bin || e.name).toLowerCase();
2731
+ function L(e, t = {}, n = null) {
2732
+ let r = T(), i = (n || e.bin || e.name).toLowerCase();
2618
2733
  class a extends r {
2619
2734
  static get name() {
2620
2735
  return i;
@@ -2629,7 +2744,16 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2629
2744
  return this._subCommand ? this._subCommand.interactive : this._isInteractive === void 0 ? !!(e && (e.interactive || e.wasm?.interactive) || this._inspectedWasm && this._inspectedWasm.isInteractive) : !!this._isInteractive;
2630
2745
  }
2631
2746
  get captureInput() {
2632
- return this.interactive;
2747
+ return this._subCommand ? !!this._subCommand.captureInput : this.interactive;
2748
+ }
2749
+ get isRaw() {
2750
+ return !!(this.stdinStream && this.stdinStream.isRaw || this._subCommand && (this._subCommand.isRaw || this._subCommand.stdinStream && this._subCommand.stdinStream.isRaw));
2751
+ }
2752
+ get _inAltScreen() {
2753
+ return !!(this.__inAltScreen || this._subCommand && this._subCommand._inAltScreen);
2754
+ }
2755
+ set _inAltScreen(e) {
2756
+ this.__inAltScreen = !!e;
2633
2757
  }
2634
2758
  kill(e = "SIGINT") {
2635
2759
  this._subCommand && typeof this._subCommand.kill == "function" && this._subCommand.kill(e), super.kill(e);
@@ -2638,8 +2762,8 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2638
2762
  this._subCommand && typeof this._subCommand.onInput == "function" && this._subCommand.onInput(e);
2639
2763
  }
2640
2764
  async run() {
2641
- let n = [...this.arguments || []], r = n.includes("--help") || n.includes("-h"), a = !r && (n.includes("--version") || n.includes("-V") || n.includes("-v"));
2642
- this._inspectedWasm = null, this._persistedWasmBytes = e.wasmPath ? A(this.context && this.context.fs || this.fs, e.wasmPath) : null, r && this._persistedWasmBytes && this._persistedWasmBytes.byteLength > 0 && (this._inspectedWasm = P(this._persistedWasmBytes));
2765
+ let n = [...this.arguments || []], r = n.includes("--help") || n.includes("-h"), a = !r && (n.includes("--version") || n.includes("-V") || n.includes("-v")), o = this.fs || this.context && this.context.fs;
2766
+ this._inspectedWasm = null, this._persistedWasmBytes = e.wasmPath ? j(o, e.wasmPath) : null, r && this._persistedWasmBytes && this._persistedWasmBytes.byteLength > 0 && (this._inspectedWasm = F(this._persistedWasmBytes));
2643
2767
  try {
2644
2768
  if ((e.type === "wasm" || e.type === "custom-wasm") && (this._persistedWasmBytes || e.wasmUrl)) {
2645
2769
  let i = this._persistedWasmBytes;
@@ -2648,7 +2772,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2648
2772
  n instanceof Uint8Array || n instanceof ArrayBuffer ? i = n instanceof Uint8Array ? n : new Uint8Array(n) : n && (n.wasmBytes || n.wasm || n.wasmBinary) && (i = n.wasmBytes || n.wasm || n.wasmBinary);
2649
2773
  } catch {}
2650
2774
  if (!i && e.wasmUrl && (i = await this._fetchWasmBytes(e.wasmUrl)), i) {
2651
- r && (this._inspectedWasm = P(i)), await this._runRawWasmBytes(i, n);
2775
+ r && (this._inspectedWasm = F(i)), await this._runRawWasmBytes(i, n);
2652
2776
  return;
2653
2777
  }
2654
2778
  } else {
@@ -2665,19 +2789,19 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2665
2789
  }
2666
2790
  let c, l;
2667
2791
  try {
2668
- c = await M(e.name, o, t.moduleLoader), l = c && c.default !== void 0 ? c.default : c, l && typeof l.then == "function" && (l = await l);
2792
+ c = await N(e.name, o, t.moduleLoader), l = c && c.default !== void 0 ? c.default : c, l && typeof l.then == "function" && (l = await l);
2669
2793
  } finally {
2670
2794
  s && (globalThis.fetch = s);
2671
2795
  }
2672
2796
  if (l instanceof Uint8Array || l instanceof ArrayBuffer) {
2673
2797
  let e = l instanceof Uint8Array ? l : new Uint8Array(l);
2674
- r && (this._inspectedWasm = P(e)), await this._runRawWasmBytes(e, n);
2798
+ r && (this._inspectedWasm = F(e)), await this._runRawWasmBytes(e, n);
2675
2799
  } else if (l && (l.wasmBytes instanceof Uint8Array || l.wasm instanceof Uint8Array)) {
2676
2800
  let e = l.wasmBytes || l.wasm;
2677
- r && (this._inspectedWasm = P(e)), await this._runRawWasmBytes(e, n);
2801
+ r && (this._inspectedWasm = F(e)), await this._runRawWasmBytes(e, n);
2678
2802
  } else if (typeof l == "function") await this._runFunctionOrEmscripten(l, n, r, a);
2679
2803
  else if (l && typeof l == "object") {
2680
- l.ready && await l.ready, r && (l.HEAPU8 instanceof Uint8Array || l.wasmBinary instanceof Uint8Array) && (this._inspectedWasm = P(l.wasmBinary || l.HEAPU8));
2804
+ l.ready && await l.ready, r && (l.HEAPU8 instanceof Uint8Array || l.wasmBinary instanceof Uint8Array) && (this._inspectedWasm = F(l.wasmBinary || l.HEAPU8));
2681
2805
  let t = l.main || l.run || l.callMain || l.exec;
2682
2806
  if (typeof t == "function") await this._invokeCliFunction(t.bind(l), n);
2683
2807
  else if (l.promised || typeof l.raw == "function" || typeof l.json == "function") {
@@ -2705,34 +2829,38 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2705
2829
  }
2706
2830
  }
2707
2831
  if (r || a) {
2708
- let t = this.result && this.result.getStdOutput ? this.result.getStdOutput() : [], n = t.map((e) => e.string).join("\n"), o = r ? N(n) : null, s = r && !!(o && (o.usage || o.options.length > 0) || t.some((e) => /\b(usage|options):/i.test(e.string))), c = t.filter((e) => e.type === "out").map((e) => e.string), l = a && c.length > 0 && (this.exitCode === 0 || this.exitCode === void 0);
2832
+ let t = this.result && this.result.getStdOutput ? this.result.getStdOutput() : [], n = t.map((e) => e.string).join("\n"), o = r ? P(n) : null, s = r && !!(o && (o.usage || o.options.length > 0) || t.some((e) => /\b(usage|options):/i.test(e.string))), c = t.filter((e) => e.type === "out").map((e) => e.string), l = a && c.length > 0 && (this.exitCode === 0 || this.exitCode === void 0);
2709
2833
  if (r) if (s) {
2710
2834
  let e = t.map((e) => e.string);
2711
2835
  this.result && Array.isArray(this.result.std) && (this.result.std.length = 0), this.exitCode = 0;
2712
2836
  for (let t of e) this.stdOut = t;
2713
2837
  } else {
2714
2838
  this.result && Array.isArray(this.result.std) && (this.result.std.length = 0), this.exitCode = 0;
2715
- for (let t of F(i, e, this._inspectedWasm)) this.stdOut = t;
2839
+ for (let t of I(i, e, this._inspectedWasm)) this.stdOut = t;
2716
2840
  }
2717
2841
  else a && !l ? (this.result && Array.isArray(this.result.std) && (this.result.std.length = 0), this.exitCode = 0, this.stdOut = `${i} (${e.name} ${e.version || "wasm"} wasm)`) : this.exitCode = 0;
2718
2842
  }
2719
2843
  }
2720
2844
  async _fetchWasmBytes(e) {
2721
- if (k.has(e)) return k.get(e);
2845
+ if (A.has(e)) return A.get(e);
2722
2846
  let n = t.fetch || (typeof fetch == "function" ? fetch : null);
2723
2847
  if (!n) throw Error("fetch is not available in this environment");
2724
2848
  let r = await n(e);
2725
2849
  if (!r || !r.ok) throw Error(`HTTP ${r ? r.status : "error"} fetching ${e}`);
2726
2850
  let i = new Uint8Array(await r.arrayBuffer());
2727
- return k.set(e, i), i;
2851
+ return A.set(e, i), i;
2728
2852
  }
2729
2853
  async _runRawWasmBytes(t, n) {
2730
- let r = new T(i, n, this.context);
2731
- r.script = i, r.arguments = n, r.context = this.context, r.fs = this.fs, r._pkgMeta = e, this.stdin !== void 0 && (r.stdin = this.stdin), this._subCommand = r;
2854
+ let r = new k(i, n, this.context);
2855
+ r.script = i, r.arguments = n, r.context = this.context, r.fs = this.fs, r._pkgMeta = e, r.stdinStream = this.stdinStream, r.stdout = this.stdout, r.stderr = this.stderr, r.stdin = this.stdin && !this.stdin.isTTY ? this.stdin : this.stdinStream, this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", this._onStdinStreamData);
2856
+ let a = () => {
2857
+ this.emit("interactive"), this.context && typeof this.context.emit == "function" && this.context.emit("interactive");
2858
+ };
2859
+ r.on("interactive", a), this._subCommand = r;
2732
2860
  try {
2733
2861
  await r._runWasm(t);
2734
2862
  } finally {
2735
- this._subCommand = null;
2863
+ r.removeListener("interactive", a), r._inAltScreen && r._exitAltScreen(), this._subCommand = null, this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", this._onStdinStreamData);
2736
2864
  }
2737
2865
  for (let e of r.result.getStdOutput()) e.type === "out" ? this.stdOut = e.string : e.type === "err" && (this.stdErr = e.string);
2738
2866
  this.exitCode = r.result.getExitCode();
@@ -2756,16 +2884,16 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2756
2884
  let n = t && t !== "." && !e.startsWith("/") ? `${t.replace(/\/+$/, "")}/${e}` : e, r = this.fs.getFileByPath(n) ?? this.fs.getFileByPath(e);
2757
2885
  return r == null ? null : typeof r == "string" ? r : new TextDecoder().decode(r);
2758
2886
  },
2759
- readBytes: (e) => A(this.fs, e),
2887
+ readBytes: (e) => j(this.fs, e),
2760
2888
  writeFile: (e, t, n) => {
2761
2889
  if (!this.fs) return;
2762
2890
  let r = n && n !== "." && !e.startsWith("/") ? `${n.replace(/\/+$/, "")}/${e}` : e;
2763
2891
  if (t instanceof Uint8Array || ArrayBuffer.isView(t)) {
2764
2892
  let e = r.endsWith(".wasm") ? "application/wasm" : "application/octet-stream";
2765
- j(this.fs, r, t, e);
2893
+ M(this.fs, r, t, e);
2766
2894
  } else this.fs.setFileByPath(r, String(t), !0);
2767
2895
  if (r.endsWith(".wasm") || r.endsWith(".wat")) try {
2768
- this.context && this.context.fs ? this.context.fs.setMode(r, 493) : this.fs.setMode(r, 493);
2896
+ this.fs.setMode(r, 493);
2769
2897
  } catch {}
2770
2898
  },
2771
2899
  listFiles: (e, t) => {
@@ -2798,7 +2926,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2798
2926
  if (e && typeof e.status == "number") this.exitCode = e.status;
2799
2927
  else throw e;
2800
2928
  }
2801
- if (f && typeof f == "object") if (r && (f.wasmBinary instanceof Uint8Array || f.HEAPU8 instanceof Uint8Array) && (this._inspectedWasm = P(f.wasmBinary || f.HEAPU8)), typeof f.callMain == "function") {
2929
+ if (f && typeof f == "object") if (r && (f.wasmBinary instanceof Uint8Array || f.HEAPU8 instanceof Uint8Array) && (this._inspectedWasm = F(f.wasmBinary || f.HEAPU8)), typeof f.callMain == "function") {
2802
2930
  f.FS && l.size === 0 && (l = this._syncBrshToEmscriptenFs(f.FS, n));
2803
2931
  try {
2804
2932
  let e = await f.callMain(n);
@@ -2861,14 +2989,14 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2861
2989
  }), !t.loaded && typeof t.load == "function" && await t.load(e.coreUrl ? { coreURL: e.coreUrl } : void 0);
2862
2990
  let a = /* @__PURE__ */ new Set(), o = [];
2863
2991
  for (let e of n) if (!e.startsWith("-") && (o.push(e), this.fs.exists(e))) {
2864
- let n = A(this.fs, e);
2992
+ let n = j(this.fs, e);
2865
2993
  n && (await t.writeFile(e, n), a.add(e));
2866
2994
  }
2867
2995
  let s = await t.exec(n);
2868
2996
  for (let e of o) if (!a.has(e)) try {
2869
2997
  if (typeof t.readFile == "function") {
2870
2998
  let n = await t.readFile(e);
2871
- n && j(this.fs, e, n);
2999
+ n && M(this.fs, e, n);
2872
3000
  }
2873
3001
  } catch {}
2874
3002
  typeof s == "number" && s !== 0 && (this.exitCode = s, i.length === 0 && r.length > 0 && i.push(...r.splice(0, r.length)));
@@ -2885,7 +3013,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2885
3013
  let n = /* @__PURE__ */ new Set();
2886
3014
  if (!this.fs || !e || typeof e.writeFile != "function") return n;
2887
3015
  for (let r of t) if (!r.startsWith("-") && this.fs.exists(r)) {
2888
- let t = A(this.fs, r);
3016
+ let t = j(this.fs, r);
2889
3017
  if (t) try {
2890
3018
  e.writeFile(r, t), n.add(r);
2891
3019
  } catch {}
@@ -2898,8 +3026,8 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2898
3026
  let t = e.readFile(r);
2899
3027
  if (t) {
2900
3028
  let e = r.endsWith(".wasm") ? "application/wasm" : "application/octet-stream";
2901
- if (j(this.fs, r, t, e), r.endsWith(".wasm") || r.endsWith(".wat")) try {
2902
- this.context && this.context.fs ? this.context.fs.setMode(r, 493) : this.fs.setMode(r, 493);
3029
+ if (M(this.fs, r, t, e), r.endsWith(".wasm") || r.endsWith(".wat")) try {
3030
+ this.fs.setMode(r, 493);
2903
3031
  } catch {}
2904
3032
  }
2905
3033
  } catch {}
@@ -2911,7 +3039,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2911
3039
  function ee(e, t) {
2912
3040
  return e && (e.endsWith(".wasm") || e.endsWith(".wat")) ? !0 : t instanceof Uint8Array ? t.length >= 4 && t[0] === 0 && t[1] === 97 && t[2] === 115 && t[3] === 109 : typeof t == "string" ? t.charCodeAt(0) === 0 && t.slice(1, 4) === "asm" ? !0 : t.trimStart().startsWith("(module") : !1;
2913
3041
  }
2914
- function L(e, t) {
3042
+ function te(e, t) {
2915
3043
  if (!e || !t || typeof e.exists != "function" || typeof e.getFileByPath != "function") return null;
2916
3044
  try {
2917
3045
  let n = t.split("/").filter(Boolean);
@@ -2924,7 +3052,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2924
3052
  } catch {}
2925
3053
  return null;
2926
3054
  }
2927
- T.isWasmFile = ee, T.readSiblingPkgMeta = L, T.readBytesFromFs = A, T.writeBytesToFs = j, T.loadModule = M, T.extractHelpFromText = N, T.inspectWasmBytes = P, T.formatWasmHelp = F, T.createGenericWasmCommand = I, T.createCommand = I, t.exports = T;
3055
+ k.isWasmFile = ee, k.readSiblingPkgMeta = te, k.readBytesFromFs = j, k.writeBytesToFs = M, k.loadModule = N, k.extractHelpFromText = P, k.inspectWasmBytes = F, k.formatWasmHelp = I, k.createGenericWasmCommand = L, k.createCommand = L, t.exports = k;
2928
3056
  })), A = /* @__PURE__ */ t(((e, t) => {
2929
3057
  var n = T();
2930
3058
  t.exports = class extends n {
@@ -2935,19 +3063,16 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2935
3063
  return !0;
2936
3064
  }
2937
3065
  get terminalSize() {
2938
- return this.stdout && this.stdout.columns && this.stdout.rows ? {
2939
- cols: parseInt(this.context && this.context.getVar && this.context.getVar("COLUMNS"), 10) || this.stdout.columns || 80,
2940
- rows: parseInt(this.context && this.context.getVar && this.context.getVar("LINES"), 10) || this.stdout.rows || 24
2941
- } : {
2942
- cols: parseInt(this.context.getVar("COLUMNS"), 10) || 80,
2943
- rows: parseInt(this.context.getVar("LINES"), 10) || 24
3066
+ return {
3067
+ cols: this.stdout && this.stdout.columns || this.stdinStream && this.stdinStream.columns || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("COLUMNS"), 10) || 80,
3068
+ rows: this.stdout && this.stdout.rows || this.stdinStream && this.stdinStream.rows || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("LINES"), 10) || 24
2944
3069
  };
2945
3070
  }
2946
3071
  _enterAltScreen() {
2947
3072
  this._inAltScreen || (this._inAltScreen = !0, this.stdinStream && this.stdinStream.setRawMode(!0), this.stdout && this.stdout.write("\x1B[?1049h\x1B[2J\x1B[H"));
2948
3073
  }
2949
3074
  _exitAltScreen() {
2950
- this._inAltScreen && (this._inAltScreen = !1, this.stdinStream && this.stdinStream.setRawMode(!1), this.stdout && this.stdout.write("\x1B[?1049l\x1B[?25h"));
3075
+ this._inAltScreen && (this._inAltScreen = !1, this.stdinStream && this.stdinStream.setRawMode(!1), this.stdout && this.stdout.write("\x1B[0m\x1B[?1l\x1B[?1000l\x1B[?1002l\x1B[?1003l\x1B[?1006l\x1B[?1049l\x1B[?25h"));
2951
3076
  }
2952
3077
  kill(e = "SIGINT") {
2953
3078
  this._exitAltScreen(), super.kill(e);
@@ -3302,12 +3427,13 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
3302
3427
  return n;
3303
3428
  }
3304
3429
  sandbox() {
3305
- let e = this;
3430
+ let e = this, t = Symbol.for("brsh.fs.target");
3306
3431
  return new Proxy(Object.create(null), {
3307
- get(t, n) {
3308
- if (!r.has(n)) return;
3309
- let i = e[n];
3310
- return typeof i == "function" ? i.bind(e) : i;
3432
+ get(n, i) {
3433
+ if (i === t) return e;
3434
+ if (!r.has(i)) return;
3435
+ let a = e[i];
3436
+ return typeof a == "function" ? a.bind(e) : a;
3311
3437
  },
3312
3438
  set() {
3313
3439
  return !1;
@@ -3366,66 +3492,66 @@ function F() {
3366
3492
  function I() {
3367
3493
  throw Error("clearTimeout has not been defined");
3368
3494
  }
3369
- function ee(e) {
3370
- if (U === setTimeout) return setTimeout(e, 0);
3371
- if ((U === F || !U) && setTimeout) return U = setTimeout, setTimeout(e, 0);
3495
+ function L(e) {
3496
+ if (ne === setTimeout) return setTimeout(e, 0);
3497
+ if ((ne === F || !ne) && setTimeout) return ne = setTimeout, setTimeout(e, 0);
3372
3498
  try {
3373
- return U(e, 0);
3499
+ return ne(e, 0);
3374
3500
  } catch {
3375
3501
  try {
3376
- return U.call(null, e, 0);
3502
+ return ne.call(null, e, 0);
3377
3503
  } catch {
3378
- return U.call(this, e, 0);
3504
+ return ne.call(this, e, 0);
3379
3505
  }
3380
3506
  }
3381
3507
  }
3382
- function L(e) {
3383
- if (ne === clearTimeout) return clearTimeout(e);
3384
- if ((ne === I || !ne) && clearTimeout) return ne = clearTimeout, clearTimeout(e);
3508
+ function ee(e) {
3509
+ if (U === clearTimeout) return clearTimeout(e);
3510
+ if ((U === I || !U) && clearTimeout) return U = clearTimeout, clearTimeout(e);
3385
3511
  try {
3386
- return ne(e);
3512
+ return U(e);
3387
3513
  } catch {
3388
3514
  try {
3389
- return ne.call(null, e);
3515
+ return U.call(null, e);
3390
3516
  } catch {
3391
- return ne.call(this, e);
3517
+ return U.call(this, e);
3392
3518
  }
3393
3519
  }
3394
3520
  }
3395
3521
  function te() {
3396
- !G || !K || (G = !1, K.length ? W = K.concat(W) : re = -1, W.length && R());
3522
+ !ie || !W || (ie = !1, W.length ? re = W.concat(re) : G = -1, re.length && R());
3397
3523
  }
3398
3524
  function R() {
3399
- if (!G) {
3400
- var e = ee(te);
3401
- G = !0;
3402
- for (var t = W.length; t;) {
3403
- for (K = W, W = []; ++re < t;) K && K[re].run();
3404
- re = -1, t = W.length;
3525
+ if (!ie) {
3526
+ var e = L(te);
3527
+ ie = !0;
3528
+ for (var t = re.length; t;) {
3529
+ for (W = re, re = []; ++G < t;) W && W[G].run();
3530
+ G = -1, t = re.length;
3405
3531
  }
3406
- K = null, G = !1, L(e);
3532
+ W = null, ie = !1, ee(e);
3407
3533
  }
3408
3534
  }
3409
3535
  function z(e, t) {
3410
3536
  this.fun = e, this.array = t;
3411
3537
  }
3412
3538
  function B() {}
3413
- var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
3539
+ var V, H, ne, U, re, ie, W, G, K, q, J = e((() => {
3414
3540
  V = { exports: {} }, H = V.exports = {}, (function() {
3415
3541
  try {
3416
- U = typeof setTimeout == "function" ? setTimeout : F;
3542
+ ne = typeof setTimeout == "function" ? setTimeout : F;
3417
3543
  } catch {
3418
- U = F;
3544
+ ne = F;
3419
3545
  }
3420
3546
  try {
3421
- ne = typeof clearTimeout == "function" ? clearTimeout : I;
3547
+ U = typeof clearTimeout == "function" ? clearTimeout : I;
3422
3548
  } catch {
3423
- ne = I;
3549
+ U = I;
3424
3550
  }
3425
- })(), W = [], G = !1, re = -1, H.nextTick = function(e) {
3551
+ })(), re = [], ie = !1, G = -1, H.nextTick = function(e) {
3426
3552
  var t = Array(arguments.length - 1);
3427
3553
  if (arguments.length > 1) for (var n = 1; n < arguments.length; n++) t[n - 1] = arguments[n];
3428
- W.push(new z(e, t)), W.length === 1 && !G && ee(R);
3554
+ re.push(new z(e, t)), re.length === 1 && !ie && L(R);
3429
3555
  }, z.prototype.run = function() {
3430
3556
  this.fun.apply(null, this.array);
3431
3557
  }, H.title = "browser", H.browser = !0, H.env = {}, H.argv = [], H.version = "", H.versions = {}, H.on = B, H.addListener = B, H.once = B, H.off = B, H.removeListener = B, H.removeAllListeners = B, H.emit = B, H.prependListener = B, H.prependOnceListener = B, H.listeners = function(e) {
@@ -3438,9 +3564,9 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
3438
3564
  throw Error("process.chdir is not supported");
3439
3565
  }, H.umask = function() {
3440
3566
  return 0;
3441
- }, q = V.exports, J = /* @__PURE__ */ P(q);
3442
- })), X = /* @__PURE__ */ t(((e, t) => {
3443
- b(), Y();
3567
+ }, K = V.exports, q = /* @__PURE__ */ P(K);
3568
+ })), Y = /* @__PURE__ */ t(((e, t) => {
3569
+ b(), J();
3444
3570
  var { BinaryFile: n, SymlinkRef: r, DeviceFile: i } = N(), a = new Uint8Array([
3445
3571
  66,
3446
3572
  82,
@@ -3468,7 +3594,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
3468
3594
  r
3469
3595
  ] };
3470
3596
  }
3471
- if (typeof e == "function") return n.commandsBundle || (d[t] = e.toString()), { $c: t };
3597
+ if (typeof e == "function") return n.commandsBundle || (d[t] = e.__source || e.toString()), { $c: t };
3472
3598
  if (typeof e == "string") {
3473
3599
  if (e.startsWith("data:")) {
3474
3600
  let t = e.indexOf(";"), n = e.indexOf(",", t);
@@ -3579,8 +3705,8 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
3579
3705
  let t = new DecompressionStream("gzip"), n = new Blob([e]).stream().pipeThrough(t), r = await new Response(n).arrayBuffer();
3580
3706
  return new Uint8Array(r);
3581
3707
  }
3582
- if (J !== void 0 && typeof J.getBuiltinModule == "function") {
3583
- let t = J.getBuiltinModule("zlib");
3708
+ if (q !== void 0 && typeof q.getBuiltinModule == "function") {
3709
+ let t = q.getBuiltinModule("zlib");
3584
3710
  if (t) return new Uint8Array(t.gunzipSync(y.from(e.buffer, e.byteOffset, e.byteLength)));
3585
3711
  }
3586
3712
  throw Error("Gzip decompression is not supported in this environment");
@@ -3599,8 +3725,8 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
3599
3725
  return p(new Uint8Array(n), t);
3600
3726
  }
3601
3727
  if (typeof e == "string") {
3602
- if (!/^https?:\/\//i.test(e) && J !== void 0 && typeof J.getBuiltinModule == "function" && typeof window > "u") try {
3603
- let n = J.getBuiltinModule("fs");
3728
+ if (!/^https?:\/\//i.test(e) && q !== void 0 && typeof q.getBuiltinModule == "function" && typeof window > "u") try {
3729
+ let n = q.getBuiltinModule("fs");
3604
3730
  if (n && n.existsSync(e)) {
3605
3731
  let r = await n.promises.readFile(e);
3606
3732
  return p(new Uint8Array(r.buffer, r.byteOffset, r.byteLength), t);
@@ -3712,7 +3838,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
3712
3838
  }
3713
3839
  }
3714
3840
  };
3715
- })), ie = /* @__PURE__ */ t(((e, t) => {
3841
+ })), X = /* @__PURE__ */ t(((e, t) => {
3716
3842
  b();
3717
3843
  var n = N(), { BinaryFile: r, SymlinkRef: i, DeviceFile: a } = n;
3718
3844
  function o(e) {
@@ -3738,10 +3864,10 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
3738
3864
  t.exports = class extends n {
3739
3865
  constructor(e = "/", t = {}, n = {}, r = null) {
3740
3866
  if (super(), t instanceof Uint8Array || t instanceof ArrayBuffer) {
3741
- let { deserializeBinaryFilesystem: e } = X(), r = e(t);
3867
+ let { deserializeBinaryFilesystem: e } = Y(), r = e(t);
3742
3868
  t = r.filesystem, n = Object.assign({}, r.permissions, n);
3743
3869
  } else if (t && typeof t == "object" && t.filesystem && (t.filesystem instanceof Uint8Array || typeof t.filesystem == "object") && (n = Object.assign({}, t.permissions || {}, n), t = t.filesystem, t instanceof Uint8Array || t instanceof ArrayBuffer)) {
3744
- let { deserializeBinaryFilesystem: e } = X(), r = e(t);
3870
+ let { deserializeBinaryFilesystem: e } = Y(), r = e(t);
3745
3871
  t = r.filesystem, n = Object.assign({}, r.permissions, n);
3746
3872
  }
3747
3873
  o(t), this.fileSystem = t, this.permissions = Object.assign({}, n), this.cwd = e.endsWith("/") ? e : e + "/", this._onChange = r, this._changeScheduled = !1, this._initDevices();
@@ -3783,11 +3909,11 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
3783
3909
  }), this._devices.stdin = new i("/dev/tty"), this._devices.stdout = new i("/dev/tty"), this._devices.stderr = new i("/dev/tty");
3784
3910
  }
3785
3911
  toBinaryContainer(e = {}) {
3786
- let { serializeBinaryFilesystem: t } = X();
3912
+ let { serializeBinaryFilesystem: t } = Y();
3787
3913
  return t(this.fileSystem, this.permissions, e);
3788
3914
  }
3789
3915
  static fromBinaryContainer(e, t = {}) {
3790
- let { deserializeBinaryFilesystem: n } = X();
3916
+ let { deserializeBinaryFilesystem: n } = Y();
3791
3917
  return n(e, t);
3792
3918
  }
3793
3919
  getFileByPath(e) {
@@ -4033,7 +4159,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
4033
4159
  }
4034
4160
  }, t.exports.BinaryFile = r, t.exports.SymlinkRef = i;
4035
4161
  })), ae = /* @__PURE__ */ t(((e, t) => {
4036
- Y();
4162
+ J();
4037
4163
  function n(e) {
4038
4164
  if (typeof e != "string") throw TypeError("Path must be a string. Received " + JSON.stringify(e));
4039
4165
  }
@@ -4071,7 +4197,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
4071
4197
  resolve: function() {
4072
4198
  for (var e = "", t = !1, i, a = arguments.length - 1; a >= -1 && !t; a--) {
4073
4199
  var o;
4074
- a >= 0 ? o = arguments[a] : (i === void 0 && (i = J.cwd()), o = i), n(o), o.length !== 0 && (e = o + "/" + e, t = o.charCodeAt(0) === 47);
4200
+ a >= 0 ? o = arguments[a] : (i === void 0 && (i = q.cwd()), o = i), n(o), o.length !== 0 && (e = o + "/" + e, t = o.charCodeAt(0) === 47);
4075
4201
  }
4076
4202
  return e = r(e, !t), t ? e.length > 0 ? "/" + e : "/" : e.length > 0 ? e : ".";
4077
4203
  },
@@ -4201,11 +4327,11 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
4201
4327
  };
4202
4328
  a.posix = a, t.exports = a;
4203
4329
  })), oe = /* @__PURE__ */ t(((e, t) => {
4204
- b(), Y();
4330
+ b(), J();
4205
4331
  var r = O(), i = ae(), a = N(), { BinaryFile: o, SymlinkRef: s, isUtf8Text: c } = a;
4206
4332
  t.exports = class extends a {
4207
4333
  constructor(e = "/", t = null, n = {}) {
4208
- super(), this._onChange = t, this._changeScheduled = !1, this._virtualFiles = {}, this._rootDir = n && n.rootDir ? i.resolve(n.rootDir) : null, this.cwd = this._normalizeCwd(e || (this._rootDir ? "/" : J.cwd()));
4334
+ super(), this._onChange = t, this._changeScheduled = !1, this._virtualFiles = {}, this._rootDir = n && n.rootDir ? i.resolve(n.rootDir) : null, this.cwd = this._normalizeCwd(e || (this._rootDir ? "/" : q.cwd()));
4209
4335
  }
4210
4336
  get isRealFilesystem() {
4211
4337
  return !0;
@@ -4489,7 +4615,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
4489
4615
  }
4490
4616
  };
4491
4617
  })), se = /* @__PURE__ */ t(((e, t) => {
4492
- var n = ie();
4618
+ var n = X();
4493
4619
  t.exports = class {
4494
4620
  constructor(e) {
4495
4621
  this.options = e;
@@ -4534,7 +4660,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
4534
4660
  this.fs.setCwd(e);
4535
4661
  }
4536
4662
  source(e) {
4537
- this.vars = Object.assign({}, this.vars, e.vars), this.aliases = Object.assign({}, this.aliases, e.aliases);
4663
+ e && (this.vars = Object.assign({}, this.vars, e.vars || {}), this.aliases = Object.assign({}, this.aliases, e.aliases || {}));
4538
4664
  }
4539
4665
  clear() {
4540
4666
  typeof this._clearFn == "function" && this._clearFn();
@@ -4832,11 +4958,11 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
4832
4958
  pe = globalThis || self;
4833
4959
  })), he = /* @__PURE__ */ t(((e, t) => {
4834
4960
  me();
4835
- var n = Infinity, r = "[object Symbol]", i = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g, a = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g, o = "\\ud800-\\udfff", s = "\\u0300-\\u036f\\ufe20-\\ufe23", c = "\\u20d0-\\u20f0", l = "\\u2700-\\u27bf", u = "a-z\\xdf-\\xf6\\xf8-\\xff", d = "\\xac\\xb1\\xd7\\xf7", f = "\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf", p = "\\u2000-\\u206f", m = " \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000", h = "A-Z\\xc0-\\xd6\\xd8-\\xde", g = "\\ufe0e\\ufe0f", _ = d + f + p + m, v = "['’]", y = "[" + o + "]", b = "[" + _ + "]", x = "[" + s + c + "]", S = "\\d+", C = "[" + l + "]", w = "[" + u + "]", T = "[^" + o + _ + S + l + u + h + "]", E = "\\ud83c[\\udffb-\\udfff]", D = "(?:" + x + "|" + E + ")", O = "[^" + o + "]", k = "(?:\\ud83c[\\udde6-\\uddff]){2}", A = "[\\ud800-\\udbff][\\udc00-\\udfff]", j = "[" + h + "]", M = "\\u200d", N = "(?:" + w + "|" + T + ")", P = "(?:" + j + "|" + T + ")", F = "(?:" + v + "(?:d|ll|m|re|s|t|ve))?", I = "(?:" + v + "(?:D|LL|M|RE|S|T|VE))?", ee = D + "?", L = "[" + g + "]?", te = "(?:" + M + "(?:" + [
4961
+ var n = Infinity, r = "[object Symbol]", i = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g, a = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g, o = "\\ud800-\\udfff", s = "\\u0300-\\u036f\\ufe20-\\ufe23", c = "\\u20d0-\\u20f0", l = "\\u2700-\\u27bf", u = "a-z\\xdf-\\xf6\\xf8-\\xff", d = "\\xac\\xb1\\xd7\\xf7", f = "\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf", p = "\\u2000-\\u206f", m = " \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000", h = "A-Z\\xc0-\\xd6\\xd8-\\xde", g = "\\ufe0e\\ufe0f", _ = d + f + p + m, v = "['’]", y = "[" + o + "]", b = "[" + _ + "]", x = "[" + s + c + "]", S = "\\d+", C = "[" + l + "]", w = "[" + u + "]", T = "[^" + o + _ + S + l + u + h + "]", E = "\\ud83c[\\udffb-\\udfff]", D = "(?:" + x + "|" + E + ")", O = "[^" + o + "]", k = "(?:\\ud83c[\\udde6-\\uddff]){2}", A = "[\\ud800-\\udbff][\\udc00-\\udfff]", j = "[" + h + "]", M = "\\u200d", N = "(?:" + w + "|" + T + ")", P = "(?:" + j + "|" + T + ")", F = "(?:" + v + "(?:d|ll|m|re|s|t|ve))?", I = "(?:" + v + "(?:D|LL|M|RE|S|T|VE))?", L = D + "?", ee = "[" + g + "]?", te = "(?:" + M + "(?:" + [
4836
4962
  O,
4837
4963
  k,
4838
4964
  A
4839
- ].join("|") + ")" + L + ee + ")*", R = L + ee + te, z = "(?:" + [
4965
+ ].join("|") + ")" + ee + L + ")*", R = ee + L + te, z = "(?:" + [
4840
4966
  C,
4841
4967
  k,
4842
4968
  A
@@ -4846,7 +4972,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
4846
4972
  k,
4847
4973
  A,
4848
4974
  y
4849
- ].join("|") + ")", V = RegExp(v, "g"), H = RegExp(x, "g"), U = RegExp(E + "(?=" + E + ")|" + B + R, "g"), ne = RegExp([
4975
+ ].join("|") + ")", V = RegExp(v, "g"), H = RegExp(x, "g"), ne = RegExp(E + "(?=" + E + ")|" + B + R, "g"), U = RegExp([
4850
4976
  j + "?" + w + "+" + F + "(?=" + [
4851
4977
  b,
4852
4978
  j,
@@ -4861,7 +4987,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
4861
4987
  j + "+" + I,
4862
4988
  S,
4863
4989
  z
4864
- ].join("|"), "g"), W = RegExp("[" + M + o + s + c + g + "]"), G = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/, K = {
4990
+ ].join("|"), "g"), re = RegExp("[" + M + o + s + c + g + "]"), ie = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/, W = {
4865
4991
  À: "A",
4866
4992
  Á: "A",
4867
4993
  Â: "A",
@@ -5052,16 +5178,16 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
5052
5178
  œ: "oe",
5053
5179
  ʼn: "'n",
5054
5180
  ſ: "ss"
5055
- }, re = typeof pe == "object" && pe && pe.Object === Object && pe, q = typeof self == "object" && self && self.Object === Object && self, J = re || q || Function("return this")();
5056
- function Y(e, t, n, r) {
5181
+ }, G = typeof pe == "object" && pe && pe.Object === Object && pe, K = typeof self == "object" && self && self.Object === Object && self, q = G || K || Function("return this")();
5182
+ function J(e, t, n, r) {
5057
5183
  var i = -1, a = e ? e.length : 0;
5058
5184
  for (r && a && (n = e[++i]); ++i < a;) n = t(n, e[i], i, e);
5059
5185
  return n;
5060
5186
  }
5061
- function X(e) {
5187
+ function Y(e) {
5062
5188
  return e.split("");
5063
5189
  }
5064
- function ie(e) {
5190
+ function X(e) {
5065
5191
  return e.match(i) || [];
5066
5192
  }
5067
5193
  function ae(e) {
@@ -5069,23 +5195,23 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
5069
5195
  return e?.[t];
5070
5196
  };
5071
5197
  }
5072
- var oe = ae(K);
5198
+ var oe = ae(W);
5073
5199
  function se(e) {
5074
- return W.test(e);
5200
+ return re.test(e);
5075
5201
  }
5076
5202
  function ce(e) {
5077
- return G.test(e);
5203
+ return ie.test(e);
5078
5204
  }
5079
5205
  function le(e) {
5080
- return se(e) ? ue(e) : X(e);
5206
+ return se(e) ? ue(e) : Y(e);
5081
5207
  }
5082
5208
  function ue(e) {
5083
- return e.match(U) || [];
5209
+ return e.match(ne) || [];
5084
5210
  }
5085
5211
  function de(e) {
5086
- return e.match(ne) || [];
5212
+ return e.match(U) || [];
5087
5213
  }
5088
- var Z = Object.prototype.toString, fe = J.Symbol, he = fe ? fe.prototype : void 0, ge = he ? he.toString : void 0;
5214
+ var Z = Object.prototype.toString, fe = q.Symbol, he = fe ? fe.prototype : void 0, ge = he ? he.toString : void 0;
5089
5215
  function _e(e, t, n) {
5090
5216
  var r = -1, i = e.length;
5091
5217
  t < 0 && (t = -t > i ? 0 : i + t), n = n > i ? i : n, n < 0 && (n += i), i = t > n ? 0 : n - t >>> 0, t >>>= 0;
@@ -5111,7 +5237,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
5111
5237
  }
5112
5238
  function xe(e) {
5113
5239
  return function(t) {
5114
- return Y(ke(De(t).replace(V, "")), e, "");
5240
+ return J(ke(De(t).replace(V, "")), e, "");
5115
5241
  };
5116
5242
  }
5117
5243
  function Se(e) {
@@ -5134,11 +5260,11 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
5134
5260
  }
5135
5261
  var Oe = be("toUpperCase");
5136
5262
  function ke(e, t, n) {
5137
- return e = we(e), t = n ? void 0 : t, t === void 0 ? ce(e) ? de(e) : ie(e) : e.match(t) || [];
5263
+ return e = we(e), t = n ? void 0 : t, t === void 0 ? ce(e) ? de(e) : X(e) : e.match(t) || [];
5138
5264
  }
5139
5265
  t.exports = Te;
5140
5266
  })), ge = /* @__PURE__ */ t(((e, t) => {
5141
- Y();
5267
+ J();
5142
5268
  var n = de(), r = Z(), i = fe(), a = he(), o = {
5143
5269
  short: /^-([^\d-])$/,
5144
5270
  long: /^--(\S+)/,
@@ -5146,10 +5272,10 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
5146
5272
  optEquals: /^(--\S+?)=(.*)/
5147
5273
  }, s = class extends Array {
5148
5274
  load(e) {
5149
- if (this.clear(), e && e !== J.argv) e = n(e);
5275
+ if (this.clear(), e && e !== q.argv) e = n(e);
5150
5276
  else {
5151
- e = J.argv.slice(0);
5152
- let t = J.execArgv.some(m) ? 1 : 2;
5277
+ e = q.argv.slice(0);
5278
+ let t = q.execArgv.some(m) ? 1 : 2;
5153
5279
  e.splice(0, t);
5154
5280
  }
5155
5281
  e.forEach((e) => this.push(String(e)));
@@ -6569,7 +6695,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
6569
6695
  let e = new TextDecoder().decode(t);
6570
6696
  this.fs.setFileByPath(s, e, !0);
6571
6697
  } else {
6572
- let { BinaryFile: e } = ie(), r = e ? new e(t.buffer, n || "application/octet-stream") : t;
6698
+ let { BinaryFile: e } = X(), r = e ? new e(t.buffer, n || "application/octet-stream") : t;
6573
6699
  this.fs.setFileByPath(s, r, !0);
6574
6700
  }
6575
6701
  } catch (e) {
@@ -7037,7 +7163,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7037
7163
  "%URIErrorPrototype%": ["URIError", "prototype"],
7038
7164
  "%WeakMapPrototype%": ["WeakMap", "prototype"],
7039
7165
  "%WeakSetPrototype%": ["WeakSet", "prototype"]
7040
- }, F = ht(), I = Ct(), ee = F.call(k, Array.prototype.concat), L = F.call(O, Array.prototype.splice), te = F.call(k, String.prototype.replace), R = F.call(k, String.prototype.slice), z = F.call(k, RegExp.prototype.exec), B = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g, V = /\\(\\)?/g, H = function(e) {
7166
+ }, F = ht(), I = Ct(), L = F.call(k, Array.prototype.concat), ee = F.call(O, Array.prototype.splice), te = F.call(k, String.prototype.replace), R = F.call(k, String.prototype.slice), z = F.call(k, RegExp.prototype.exec), B = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g, V = /\\(\\)?/g, H = function(e) {
7041
7167
  var t = R(e, 0, 1), n = R(e, -1);
7042
7168
  if (t === "%" && n !== "%") throw new c("invalid intrinsic syntax, expected closing `%`");
7043
7169
  if (n === "%" && t !== "%") throw new c("invalid intrinsic syntax, expected opening `%`");
@@ -7045,7 +7171,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7045
7171
  return te(e, B, function(e, t, n, i) {
7046
7172
  r[r.length] = n ? te(i, V, "$1") : t || e;
7047
7173
  }), r;
7048
- }, U = function(e, t) {
7174
+ }, ne = function(e, t) {
7049
7175
  var n = e, r;
7050
7176
  if (I(P, n) && (r = P[n], n = "%" + r[0] + "%"), I(M, n)) {
7051
7177
  var i = M[n];
@@ -7062,8 +7188,8 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7062
7188
  if (typeof e != "string" || e.length === 0) throw new l("intrinsic name must be a non-empty string");
7063
7189
  if (arguments.length > 1 && typeof t != "boolean") throw new l("\"allowMissing\" argument must be a boolean");
7064
7190
  if (z(/^%?[^%]*%?$/, e) === null) throw new c("`%` may not be present anywhere but at the beginning and end of the intrinsic name");
7065
- var n = H(e), r = n.length > 0 ? n[0] : "", i = U("%" + r + "%", t), a = i.name, o = i.value, s = !1, u = i.alias;
7066
- u && (r = u[0], L(n, ee([0, 1], u)));
7191
+ var n = H(e), r = n.length > 0 ? n[0] : "", i = ne("%" + r + "%", t), a = i.name, o = i.value, s = !1, u = i.alias;
7192
+ u && (r = u[0], ee(n, L([0, 1], u)));
7067
7193
  for (var d = 1, f = !0; d < n.length; d += 1) {
7068
7194
  var p = n[d], m = R(p, 0, 1), h = R(p, -1);
7069
7195
  if ((m === "\"" || m === "'" || m === "`" || h === "\"" || h === "'" || h === "`") && m !== h) throw new c("property names with quotes must have matching quotes");
@@ -7279,23 +7405,23 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7279
7405
  }
7280
7406
  return v.call(t, n, "$&_");
7281
7407
  }
7282
- var P = Lt(), F = P.custom, I = K(F) ? F : null, ee = {
7408
+ var P = Lt(), F = P.custom, I = W(F) ? F : null, L = {
7283
7409
  __proto__: null,
7284
7410
  double: "\"",
7285
7411
  single: "'"
7286
- }, L = {
7412
+ }, ee = {
7287
7413
  __proto__: null,
7288
7414
  double: /(["\\])/g,
7289
7415
  single: /(['\\])/g
7290
7416
  };
7291
7417
  t.exports = function e(t, n, r, o) {
7292
7418
  var s = n || {};
7293
- if (J(s, "quoteStyle") && !J(ee, s.quoteStyle)) throw TypeError("option \"quoteStyle\" must be \"single\" or \"double\"");
7294
- if (J(s, "maxStringLength") && (typeof s.maxStringLength == "number" ? s.maxStringLength < 0 && s.maxStringLength !== Infinity : s.maxStringLength !== null)) throw TypeError("option \"maxStringLength\", if provided, must be a positive integer, Infinity, or `null`");
7295
- var u = J(s, "customInspect") ? s.customInspect : !0;
7419
+ if (q(s, "quoteStyle") && !q(L, s.quoteStyle)) throw TypeError("option \"quoteStyle\" must be \"single\" or \"double\"");
7420
+ if (q(s, "maxStringLength") && (typeof s.maxStringLength == "number" ? s.maxStringLength < 0 && s.maxStringLength !== Infinity : s.maxStringLength !== null)) throw TypeError("option \"maxStringLength\", if provided, must be a positive integer, Infinity, or `null`");
7421
+ var u = q(s, "customInspect") ? s.customInspect : !0;
7296
7422
  if (typeof u != "boolean" && u !== "symbol") throw TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");
7297
- if (J(s, "indent") && s.indent !== null && s.indent !== " " && !(parseInt(s.indent, 10) === s.indent && s.indent > 0)) throw TypeError("option \"indent\" must be \"\\t\", an integer > 0, or `null`");
7298
- if (J(s, "numericSeparator") && typeof s.numericSeparator != "boolean") throw TypeError("option \"numericSeparator\", if provided, must be `true` or `false`");
7423
+ if (q(s, "indent") && s.indent !== null && s.indent !== " " && !(parseInt(s.indent, 10) === s.indent && s.indent > 0)) throw TypeError("option \"indent\" must be \"\\t\", an integer > 0, or `null`");
7424
+ if (q(s, "numericSeparator") && typeof s.numericSeparator != "boolean") throw TypeError("option \"numericSeparator\", if provided, must be `true` or `false`");
7299
7425
  var d = s.numericSeparator;
7300
7426
  if (t === void 0) return "undefined";
7301
7427
  if (t === null) return "null";
@@ -7314,32 +7440,32 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7314
7440
  if (r === void 0 && (r = 0), r >= h && h > 0 && typeof t == "object") return B(t) ? "[Array]" : "[Object]";
7315
7441
  var g = ve(s, r);
7316
7442
  if (o === void 0) o = [];
7317
- else if (ie(o, t) >= 0) return "[Circular]";
7443
+ else if (X(o, t) >= 0) return "[Circular]";
7318
7444
  function y(t, n, i) {
7319
7445
  if (n && (o = w.call(o), o.push(n)), i) {
7320
7446
  var a = { depth: s.depth };
7321
- return J(s, "quoteStyle") && (a.quoteStyle = s.quoteStyle), e(t, a, r + 1, o);
7447
+ return q(s, "quoteStyle") && (a.quoteStyle = s.quoteStyle), e(t, a, r + 1, o);
7322
7448
  }
7323
7449
  return e(t, s, r + 1, o);
7324
7450
  }
7325
7451
  if (typeof t == "function" && !H(t)) {
7326
- var x = X(t), T = be(t, y);
7452
+ var x = Y(t), T = be(t, y);
7327
7453
  return "[Function" + (x ? ": " + x : " (anonymous)") + "]" + (T.length > 0 ? " { " + C.call(T, ", ") + " }" : "");
7328
7454
  }
7329
- if (K(t)) {
7455
+ if (W(t)) {
7330
7456
  var D = k ? v.call(String(t), /^(Symbol\(.*\))_[^)]*$/, "$1") : O.call(t);
7331
7457
  return typeof t == "object" && !k ? fe(D) : D;
7332
7458
  }
7333
7459
  if (ue(t)) {
7334
- for (var F = "<" + b.call(String(t.nodeName)), L = t.attributes || [], z = 0; z < L.length; z++) F += " " + L[z].name + "=" + te(R(L[z].value), "double", s);
7460
+ for (var F = "<" + b.call(String(t.nodeName)), ee = t.attributes || [], z = 0; z < ee.length; z++) F += " " + ee[z].name + "=" + te(R(ee[z].value), "double", s);
7335
7461
  return F += ">", t.childNodes && t.childNodes.length && (F += "..."), F += "</" + b.call(String(t.nodeName)) + ">", F;
7336
7462
  }
7337
7463
  if (B(t)) {
7338
7464
  if (t.length === 0) return "[]";
7339
- var q = be(t, y);
7340
- return g && !_e(q) ? "[" + ye(q, g) + "]" : "[ " + C.call(q, ", ") + " ]";
7465
+ var K = be(t, y);
7466
+ return g && !_e(K) ? "[" + ye(K, g) + "]" : "[ " + C.call(K, ", ") + " ]";
7341
7467
  }
7342
- if (U(t)) {
7468
+ if (ne(t)) {
7343
7469
  var Z = be(t, y);
7344
7470
  return !("cause" in Error.prototype) && "cause" in t && !j.call(t, "cause") ? "{ [" + String(t) + "] " + C.call(S.call("[cause]: " + y(t.cause), Z), ", ") + " }" : Z.length === 0 ? "[" + String(t) + "]" : "{ [" + String(t) + "] " + C.call(Z, ", ") + " }";
7345
7471
  }
@@ -7362,20 +7488,20 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7362
7488
  if (oe(t)) return he("WeakMap");
7363
7489
  if (le(t)) return he("WeakSet");
7364
7490
  if (se(t)) return he("WeakRef");
7365
- if (W(t)) return fe(y(Number(t)));
7366
- if (re(t)) return fe(y(E.call(t)));
7367
- if (G(t)) return fe(p.call(t));
7368
- if (ne(t)) return fe(y(String(t)));
7491
+ if (re(t)) return fe(y(Number(t)));
7492
+ if (G(t)) return fe(y(E.call(t)));
7493
+ if (ie(t)) return fe(p.call(t));
7494
+ if (U(t)) return fe(y(String(t)));
7369
7495
  if (typeof window < "u" && t === window) return "{ [object Window] }";
7370
7496
  if (typeof globalThis < "u" && t === globalThis || pe !== void 0 && t === pe) return "{ [object globalThis] }";
7371
7497
  if (!V(t) && !H(t)) {
7372
- var Se = be(t, y), Ce = M ? M(t) === Object.prototype : t instanceof Object || t.constructor === Object, we = t instanceof Object ? "" : "null prototype", Te = !Ce && A && Object(t) === t && A in t ? _.call(Y(t), 8, -1) : we ? "Object" : "", Ee = (Ce || typeof t.constructor != "function" ? "" : t.constructor.name ? t.constructor.name + " " : "") + (Te || we ? "[" + C.call(S.call([], Te || [], we || []), ": ") + "] " : "");
7498
+ var Se = be(t, y), Ce = M ? M(t) === Object.prototype : t instanceof Object || t.constructor === Object, we = t instanceof Object ? "" : "null prototype", Te = !Ce && A && Object(t) === t && A in t ? _.call(J(t), 8, -1) : we ? "Object" : "", Ee = (Ce || typeof t.constructor != "function" ? "" : t.constructor.name ? t.constructor.name + " " : "") + (Te || we ? "[" + C.call(S.call([], Te || [], we || []), ": ") + "] " : "");
7373
7499
  return Se.length === 0 ? Ee + "{}" : g ? Ee + "{" + ye(Se, g) + "}" : Ee + "{ " + C.call(Se, ", ") + " }";
7374
7500
  }
7375
7501
  return String(t);
7376
7502
  };
7377
7503
  function te(e, t, n) {
7378
- var r = ee[n.quoteStyle || t];
7504
+ var r = L[n.quoteStyle || t];
7379
7505
  return r + e + r;
7380
7506
  }
7381
7507
  function R(e) {
@@ -7385,27 +7511,27 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7385
7511
  return !A || !(typeof e == "object" && (A in e || e[A] !== void 0));
7386
7512
  }
7387
7513
  function B(e) {
7388
- return Y(e) === "[object Array]" && z(e);
7514
+ return J(e) === "[object Array]" && z(e);
7389
7515
  }
7390
7516
  function V(e) {
7391
- return Y(e) === "[object Date]" && z(e);
7517
+ return J(e) === "[object Date]" && z(e);
7392
7518
  }
7393
7519
  function H(e) {
7394
- return Y(e) === "[object RegExp]" && z(e);
7395
- }
7396
- function U(e) {
7397
- return Y(e) === "[object Error]" && z(e);
7520
+ return J(e) === "[object RegExp]" && z(e);
7398
7521
  }
7399
7522
  function ne(e) {
7400
- return Y(e) === "[object String]" && z(e);
7523
+ return J(e) === "[object Error]" && z(e);
7401
7524
  }
7402
- function W(e) {
7403
- return Y(e) === "[object Number]" && z(e);
7525
+ function U(e) {
7526
+ return J(e) === "[object String]" && z(e);
7404
7527
  }
7405
- function G(e) {
7406
- return Y(e) === "[object Boolean]" && z(e);
7528
+ function re(e) {
7529
+ return J(e) === "[object Number]" && z(e);
7407
7530
  }
7408
- function K(e) {
7531
+ function ie(e) {
7532
+ return J(e) === "[object Boolean]" && z(e);
7533
+ }
7534
+ function W(e) {
7409
7535
  if (k) return e && typeof e == "object" && e instanceof Symbol;
7410
7536
  if (typeof e == "symbol") return !0;
7411
7537
  if (!e || typeof e != "object" || !O) return !1;
@@ -7414,28 +7540,28 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7414
7540
  } catch {}
7415
7541
  return !1;
7416
7542
  }
7417
- function re(e) {
7543
+ function G(e) {
7418
7544
  if (!e || typeof e != "object" || !E) return !1;
7419
7545
  try {
7420
7546
  return E.call(e), !0;
7421
7547
  } catch {}
7422
7548
  return !1;
7423
7549
  }
7424
- var q = Object.prototype.hasOwnProperty || function(e) {
7550
+ var K = Object.prototype.hasOwnProperty || function(e) {
7425
7551
  return e in this;
7426
7552
  };
7427
- function J(e, t) {
7428
- return q.call(e, t);
7553
+ function q(e, t) {
7554
+ return K.call(e, t);
7429
7555
  }
7430
- function Y(e) {
7556
+ function J(e) {
7431
7557
  return m.call(e);
7432
7558
  }
7433
- function X(e) {
7559
+ function Y(e) {
7434
7560
  if (e.name) return e.name;
7435
7561
  var t = g.call(h.call(e), /^function\s*([\w$]+)/);
7436
7562
  return t ? t[1] : null;
7437
7563
  }
7438
- function ie(e, t) {
7564
+ function X(e, t) {
7439
7565
  if (e.indexOf) return e.indexOf(t);
7440
7566
  for (var n = 0, r = e.length; n < r; n++) if (e[n] === t) return n;
7441
7567
  return -1;
@@ -7507,7 +7633,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7507
7633
  var n = e.length - t.maxStringLength, r = "... " + n + " more character" + (n > 1 ? "s" : "");
7508
7634
  return de(_.call(e, 0, t.maxStringLength), t) + r;
7509
7635
  }
7510
- var i = L[t.quoteStyle || "single"];
7636
+ var i = ee[t.quoteStyle || "single"];
7511
7637
  return i.lastIndex = 0, te(v.call(v.call(e, i, "\\$1"), /[\x00-\x1f]/g, Z), "single", t);
7512
7638
  }
7513
7639
  function Z(e) {
@@ -7531,7 +7657,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7531
7657
  return e + " (" + t + ") {" + i + "}";
7532
7658
  }
7533
7659
  function _e(e) {
7534
- for (var t = 0; t < e.length; t++) if (ie(e[t], "\n") >= 0) return !1;
7660
+ for (var t = 0; t < e.length; t++) if (X(e[t], "\n") >= 0) return !1;
7535
7661
  return !0;
7536
7662
  }
7537
7663
  function ve(e, t) {
@@ -7553,14 +7679,14 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7553
7679
  var n = B(e), r = [];
7554
7680
  if (n) {
7555
7681
  r.length = e.length;
7556
- for (var i = 0; i < e.length; i++) r[i] = J(e, i) ? t(e[i], e) : "";
7682
+ for (var i = 0; i < e.length; i++) r[i] = q(e, i) ? t(e[i], e) : "";
7557
7683
  }
7558
7684
  var a = typeof D == "function" ? D(e) : [], o;
7559
7685
  if (k) {
7560
7686
  o = {};
7561
7687
  for (var s = 0; s < a.length; s++) o["$" + a[s]] = a[s];
7562
7688
  }
7563
- for (var c in e) J(e, c) && (n && String(Number(c)) === c && c < e.length || k && o["$" + c] instanceof Symbol || (x.call(/[^\w$]/, c) ? r.push(t(c, e) + ": " + t(e[c], e)) : r.push(c + ": " + t(e[c], e))));
7689
+ for (var c in e) q(e, c) && (n && String(Number(c)) === c && c < e.length || k && o["$" + c] instanceof Symbol || (x.call(/[^\w$]/, c) ? r.push(t(c, e) + ": " + t(e[c], e)) : r.push(c + ": " + t(e[c], e))));
7564
7690
  if (typeof D == "function") for (var l = 0; l < a.length; l++) j.call(e, a[l]) && r.push("[" + t(a[l]) + "]: " + t(e[a[l]], e));
7565
7691
  return r;
7566
7692
  }
@@ -8474,15 +8600,15 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
8474
8600
  }), t.exports = s;
8475
8601
  })), ur = /* @__PURE__ */ t(((e, t) => {
8476
8602
  b();
8477
- var n = se(), r = E(), i = D(), a = k(), o = ce(), s = T(), c = A(), { TtyStream: l } = w(), u = "/.brsh_history", d = Ce(), f = Ge(), p = x(), m = N(), { isAsyncFilesystemSource: h, resolveFilesystemSource: g } = X(), _ = /\$(?:\{([\w\d?#@*-]+)\}|([\w\d]+|[?#@*-]))/g, v = p.EventEmitter || p.default || p;
8603
+ var n = se(), r = E(), i = D(), a = k(), o = ce(), s = T(), c = A(), { TtyStream: l, hasCustomStdinListener: u } = w(), d = "/.brsh_history", f = Ce(), p = Ge(), m = x(), h = N(), { isAsyncFilesystemSource: g, resolveFilesystemSource: _ } = Y(), v = /\$(?:\{([\w\d?#@*-]+)\}|([\w\d]+|[?#@*-]))/g, S = m.EventEmitter || m.default || m;
8478
8604
  String.prototype.regexIndexOf = function(e, t) {
8479
8605
  let n = this.substring(t || 0).search(e);
8480
8606
  return n >= 0 ? n + (t || 0) : n;
8481
8607
  }, lr().shim();
8482
- var S = class e extends v {
8608
+ var C = class e extends S {
8483
8609
  constructor(e) {
8484
8610
  super();
8485
- let { path: t = "/bin", profile: r, motd: i, command: a, interactive: o = !0, subshell: s = !1, hostname: c = "browser", filesystem: u = {}, permissions: d = {}, cwd: f = "/", onFsChange: p, useRealFilesystem: m = !1 } = e;
8611
+ let { path: t = "/bin", profile: r, motd: i, command: a, interactive: o = !0, subshell: s = !1, hostname: c = "browser", filesystem: u = {}, permissions: d = {}, cwd: f = "/", onFsChange: p, useRealFilesystem: m = !1, cols: h, rows: _ } = e;
8486
8612
  if (this.context = new n(Object.assign({}, e, {
8487
8613
  clearFn: this.clear.bind(this),
8488
8614
  destroyFn: this.destroy.bind(this),
@@ -8495,19 +8621,24 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
8495
8621
  let e = (o ? "i" : "") + (a ? "c" : "");
8496
8622
  e && this.context.setVar("-", e);
8497
8623
  }
8498
- if (this._lastCode = 0, this._subshell = s, this._useRealFilesystem = m, this._profile = r, this._motd = i, this._initialCommand = a || null, this._suppressMotd = !!a, this._loadingFs = null, this._queuedWhileLoading = !1, this.stdinStream = new l({
8499
- columns: 80,
8500
- rows: 24
8624
+ this._lastCode = 0, this._subshell = s, this._useRealFilesystem = m, this._profile = r, this._motd = i, this._initialCommand = a || null, this._suppressMotd = !!a, this._loadingFs = null, this._queuedWhileLoading = !1;
8625
+ let v = typeof h == "number" && h > 0 ? Math.floor(h) : 80, y = typeof _ == "number" && _ > 0 ? Math.floor(_) : 24;
8626
+ if ((typeof h == "number" && h > 0 || typeof _ == "number" && _ > 0) && (this._terminalSize = {
8627
+ cols: v,
8628
+ rows: y
8629
+ }, this.context.setVar("COLUMNS", String(v)), this.context.setVar("LINES", String(y))), this.stdinStream = new l({
8630
+ columns: v,
8631
+ rows: y
8501
8632
  }), this.stdout = new l({
8502
- columns: 80,
8503
- rows: 24,
8633
+ columns: v,
8634
+ rows: y,
8504
8635
  onWrite: (e) => this.emit("data", e)
8505
8636
  }), this.stderr = new l({
8506
- columns: 80,
8507
- rows: 24,
8637
+ columns: v,
8638
+ rows: y,
8508
8639
  onWrite: (e) => this.emit("data", e)
8509
8640
  }), this._lineBuffer = [], this._cursorPos = 0, this._history = [], this._historyPos = null, this._savedInput = null, this._historyLoaded = !1, this._working = !0, this._promptReady = !1, this._inProgressLine = !1, this._fromLineEditor = !1, this._lastPromptRowOffset = 0, this._pendingCommands = [], s || this._setupTtyStreams(), m) this.context.setNodeFilesystem(f), this.context.setCwd(f), this._loadDefaultCommands(), this._loadBuiltinCommands(!0), this.ready = Promise.resolve(this), s ? this._initializing = !1 : (this._initializing = !0, setTimeout(() => this._init(), 0));
8510
- else if (h(u) || u && typeof u == "object" && h(u.filesystem)) this.context.setFilesystem({}, d), this._loadDefaultCommands(), this._loadBuiltinCommands(!1), this._initializing = !s, this._loadingFs = this._initAsyncFilesystem(u, d, f, r), this.ready = this._loadingFs;
8641
+ else if (g(u) || u && typeof u == "object" && g(u.filesystem)) this.context.setFilesystem({}, d), this._loadDefaultCommands(), this._loadBuiltinCommands(!1), this._initializing = !s, this._loadingFs = this._initAsyncFilesystem(u, d, f, r), this.ready = this._loadingFs;
8511
8642
  else {
8512
8643
  this.context.setFilesystem(u, d), this.context.setCwd(f);
8513
8644
  let e = this.context.fs.exists(this.context.getVar("PATH"));
@@ -8529,7 +8660,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
8529
8660
  }
8530
8661
  }, o = a();
8531
8662
  try {
8532
- let e = await g(t, n), s = a(), c = [];
8663
+ let e = await _(t, n), s = a(), c = [];
8533
8664
  for (let [e, t] of Object.entries(s)) o[e] !== t && typeof t == "function" && c.push(t);
8534
8665
  let l = this.context._onFsChange;
8535
8666
  this.context._onFsChange = null, this.context.setFilesystem(e.filesystem, e.permissions);
@@ -8587,12 +8718,12 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
8587
8718
  };
8588
8719
  }
8589
8720
  _loadDefaultCommands() {
8590
- f.forEach((e) => {
8721
+ p.forEach((e) => {
8591
8722
  this.context.setCommand(e);
8592
8723
  });
8593
8724
  }
8594
8725
  _loadBuiltinCommands(e = !1) {
8595
- d.forEach((e) => {
8726
+ f.forEach((e) => {
8596
8727
  this.context.setCommand(e);
8597
8728
  }), e || this.context.fs.setMode(this.context.getVar("PATH"), 365);
8598
8729
  }
@@ -8895,7 +9026,9 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
8895
9026
  }, m.set(n.file, e)), e.lines.push(t);
8896
9027
  }
8897
9028
  };
8898
- return this.runningCommand = p, this.runningCommand.on && (this.runningCommand.on("flush", (e) => {
9029
+ this.runningCommand = p;
9030
+ let g = this.stdout && this.stdout.columns || this.stdinStream && this.stdinStream.columns, _ = this.stdout && this.stdout.rows || this.stdinStream && this.stdinStream.rows;
9031
+ return g && _ && (p.stdinStream && (p.stdinStream.columns = g, p.stdinStream.rows = _), p.stdout && (p.stdout.columns = g, p.stdout.rows = _), p.stderr && (p.stderr.columns = g, p.stderr.rows = _)), this.runningCommand.on && (this.runningCommand.on("flush", (e) => {
8899
9032
  e.forEach(h);
8900
9033
  }), this.runningCommand.on("stdout", (e) => {
8901
9034
  o.type === "file" ? p._streamedStdout || (p.stdOut = String(e ?? "")) : o.type === "stderr" ? this.stderr.write(e) : o.type === "null" || (this.stdout.write(e), this.emit("stdOutRaw", e));
@@ -9000,13 +9133,13 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
9000
9133
  }
9001
9134
  _loadHistory() {
9002
9135
  try {
9003
- let e = this.context.fs._getFileRaw(u);
9136
+ let e = this.context.fs._getFileRaw(d);
9004
9137
  e && typeof e == "string" && e.length > 0 && (this._history = e.split("\n").filter((e) => e.length > 0));
9005
9138
  } catch {}
9006
9139
  }
9007
9140
  _saveHistory() {
9008
9141
  try {
9009
- this.context.fs._setFileRaw(u, this._history.join("\n"), !0);
9142
+ this.context.fs._setFileRaw(d, this._history.join("\n"), !0);
9010
9143
  } catch {}
9011
9144
  }
9012
9145
  _navigateHistory(e) {
@@ -9038,13 +9171,13 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
9038
9171
  _handleStdinData(e) {
9039
9172
  let t = typeof e == "string" ? e : e instanceof Uint8Array || y !== void 0 && y.isBuffer(e) ? new TextDecoder().decode(e) : String(e ?? "");
9040
9173
  if (this.runningCommand) {
9041
- let t = this.runningCommand;
9042
- if ((typeof e == "string" && e === "" || e instanceof Uint8Array && e.length === 1 && e[0] === 3 || y !== void 0 && y.isBuffer(e) && e.length === 1 && e[0] === 3) && (!t.stdinStream || !t.stdinStream.isRaw)) {
9174
+ let t = this.runningCommand, n = typeof e == "string" && e === "" || e instanceof Uint8Array && e.length === 1 && e[0] === 3 || y !== void 0 && y.isBuffer(e) && e.length === 1 && e[0] === 3, r = !!(t.isRaw || t.stdinStream && t.stdinStream.isRaw);
9175
+ if (n && !r) {
9043
9176
  typeof t.kill == "function" && t.kill("SIGINT"), !t.interactive && !t._inAltScreen && this.stdout.write("^C\r\n");
9044
9177
  return;
9045
9178
  }
9046
- let n = t.stdinStream && t.stdinStream.listenerCount("data") > 1;
9047
- if (t.captureInput || t.interactive || t._inAltScreen || n) {
9179
+ let i = u(t);
9180
+ if (t.captureInput || t.interactive || t._inAltScreen || i) {
9048
9181
  t.stdinStream.pushData(e);
9049
9182
  return;
9050
9183
  }
@@ -9239,11 +9372,32 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
9239
9372
  throw Error(`${e}: Command not found`);
9240
9373
  }
9241
9374
  async _parseCommandLine(t) {
9242
- let n = e._splitCommand(t);
9243
- return (await Promise.all(n.map(({ value: e, hasQuote: t }) => this._replaceVariables(e).then((e) => ({
9244
- value: e,
9245
- hasQuote: t
9246
- }))))).filter(({ value: e, hasQuote: t }) => e.length > 0 || t);
9375
+ let n = e._splitCommand(t), r = n.length > 0 ? n[0].value : "", i = r === "export" || r === "alias" || r === "local", a = [];
9376
+ for (let e = 0; e < n.length; e++) {
9377
+ let { value: t, hasQuote: r } = n[e];
9378
+ if (r && t === "$@") {
9379
+ let e = parseInt(this.context.getVar("#") || "0", 10) || 0;
9380
+ for (let t = 1; t <= e; t++) a.push({
9381
+ value: String(this.context.getVar(String(t))),
9382
+ hasQuote: !0
9383
+ });
9384
+ continue;
9385
+ }
9386
+ let o = await this._replaceVariables(t), s = n.length === 1 && /^[A-Za-z_]\w*=/.test(t), c = e > 0 && i && /^[A-Za-z_]\w*=/.test(t);
9387
+ if (r || s || c || !t.includes("$")) {
9388
+ (o.length > 0 || r) && a.push({
9389
+ value: o,
9390
+ hasQuote: r
9391
+ });
9392
+ continue;
9393
+ }
9394
+ let l = o.trim().split(/\s+/).filter(Boolean);
9395
+ for (let e of l) a.push({
9396
+ value: e,
9397
+ hasQuote: !1
9398
+ });
9399
+ }
9400
+ return a;
9247
9401
  }
9248
9402
  static _sanitiseCommandPart(e) {
9249
9403
  return e.startsWith("\"") && e.endsWith("\"") || e.startsWith("'") && e.endsWith("'") ? e.substring(1, e.length - 1) : e;
@@ -9259,7 +9413,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
9259
9413
  let n = await this._runAndCapture(e[1]);
9260
9414
  t = t.replace(e[0], n);
9261
9415
  }
9262
- let i = t.matchAll(_), a = i.next();
9416
+ let i = t.matchAll(v), a = i.next();
9263
9417
  for (; !a.done;) {
9264
9418
  let n = a.value[1] || a.value[2], r = this.context.getVar(n);
9265
9419
  t = t.replace(new RegExp(e._escapeRegExp(a.value[0]), "g"), String(r)), a = i.next();
@@ -9381,8 +9535,8 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
9381
9535
  }
9382
9536
  static async create(t = {}) {
9383
9537
  let { filesystem: n, permissions: r, ...i } = t;
9384
- if (h(n) || n && typeof n == "object" && h(n.filesystem)) {
9385
- let e = await g(n, r);
9538
+ if (g(n) || n && typeof n == "object" && g(n.filesystem)) {
9539
+ let e = await _(n, r);
9386
9540
  n = e.filesystem, r = e.permissions;
9387
9541
  }
9388
9542
  let a = new e(Object.assign({}, i, {
@@ -9395,7 +9549,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
9395
9549
  return e.create(Object.assign({}, n, { filesystem: t }));
9396
9550
  }
9397
9551
  };
9398
- S.STATUS_READY = "READY", S.STATUS_WORKING = "WORKING", S.STATUS_DESTROYED = "DESTROYED", S.Command = s, S.InteractiveCommand = c, S.WasmCommand = a, S.createWasmCommand = a.createGenericWasmCommand || a.createCommand, S.ReplCommand = j(), S.JsCommand = o, S.FS = m, S.BinaryContainer = X(), S.Storage = S.BinaryContainer.FilesystemStorage, globalThis.shell = S, globalThis.Shell = S, t.exports = S;
9552
+ C.STATUS_READY = "READY", C.STATUS_WORKING = "WORKING", C.STATUS_DESTROYED = "DESTROYED", C.Command = s, C.InteractiveCommand = c, C.WasmCommand = a, C.createWasmCommand = a.createGenericWasmCommand || a.createCommand, C.ReplCommand = j(), C.JsCommand = o, C.FS = h, C.BinaryContainer = Y(), C.Storage = C.BinaryContainer.FilesystemStorage, globalThis.shell = C, globalThis.Shell = C, t.exports = C;
9399
9553
  }));
9400
9554
  //#endregion
9401
9555
  export default ur();