brsh 3.10.0 → 3.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
1117
  }
1107
- setEncoding(e) {
1108
- return this._encoding = e, this;
1109
- }
1110
- getWindowSize() {
1111
- return [this.columns, this.rows];
1112
- }
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
  });
@@ -1660,19 +1696,19 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1660
1696
  return !1;
1661
1697
  }
1662
1698
  }
1663
- }, t.exports.isKnownInterpreter = r;
1699
+ }, t.exports.isKnownInterpreter = a;
1664
1700
  })), O = /* @__PURE__ */ t(((e, t) => {
1665
1701
  t.exports = null;
1666
1702
  })), k = /* @__PURE__ */ t(((e, t) => {
1667
1703
  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 {
1704
+ 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
1705
  constructor(e, t, n) {
1670
1706
  super(e, t, n), this._ensurePkgMeta();
1671
1707
  }
1672
1708
  _ensurePkgMeta() {
1673
1709
  if (this._pkgMeta === void 0 && this.script) {
1674
1710
  let e = this.context && this.context.fs || this.fs;
1675
- e && (this._pkgMeta = L(e, this.script));
1711
+ e && (this._pkgMeta = te(e, this.script));
1676
1712
  }
1677
1713
  return this._pkgMeta || null;
1678
1714
  }
@@ -1712,11 +1748,22 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1712
1748
  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
1749
  }
1714
1750
  _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"));
1751
+ 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
1752
  }
1717
1753
  _keyToBytes(e) {
1718
1754
  if (!e) return null;
1719
1755
  if (typeof e != "string") return e instanceof Uint8Array ? e : new Uint8Array([Number(e) & 255]);
1756
+ if ([
1757
+ "Control",
1758
+ "Alt",
1759
+ "Shift",
1760
+ "Meta",
1761
+ "CapsLock",
1762
+ "NumLock",
1763
+ "ScrollLock",
1764
+ "Dead",
1765
+ "Unidentified"
1766
+ ].includes(e)) return null;
1720
1767
  let t = e.match(/^\^([A-Za-z@\[\\\]^_?])$/);
1721
1768
  if (t) {
1722
1769
  let e = t[1].toUpperCase();
@@ -1725,19 +1772,40 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1725
1772
  let n = {
1726
1773
  Enter: "\r",
1727
1774
  Return: "\r",
1775
+ Space: " ",
1776
+ Spacebar: " ",
1728
1777
  Backspace: "",
1729
1778
  Tab: " ",
1779
+ BackTab: "\x1B[Z",
1730
1780
  Escape: "\x1B",
1781
+ Esc: "\x1B",
1731
1782
  ArrowUp: "\x1B[A",
1783
+ Up: "\x1B[A",
1732
1784
  ArrowDown: "\x1B[B",
1785
+ Down: "\x1B[B",
1733
1786
  ArrowRight: "\x1B[C",
1787
+ Right: "\x1B[C",
1734
1788
  ArrowLeft: "\x1B[D",
1789
+ Left: "\x1B[D",
1735
1790
  Home: "\x1B[H",
1736
1791
  End: "\x1B[F",
1737
1792
  PageUp: "\x1B[5~",
1738
1793
  PageDown: "\x1B[6~",
1739
1794
  Delete: "\x1B[3~",
1740
- Insert: "\x1B[2~"
1795
+ Del: "\x1B[3~",
1796
+ Insert: "\x1B[2~",
1797
+ F1: "\x1BOP",
1798
+ F2: "\x1BOQ",
1799
+ F3: "\x1BOR",
1800
+ F4: "\x1BOS",
1801
+ F5: "\x1B[15~",
1802
+ F6: "\x1B[17~",
1803
+ F7: "\x1B[18~",
1804
+ F8: "\x1B[19~",
1805
+ F9: "\x1B[20~",
1806
+ F10: "\x1B[21~",
1807
+ F11: "\x1B[23~",
1808
+ F12: "\x1B[24~"
1741
1809
  };
1742
1810
  return n[e] ? new TextEncoder().encode(n[e]) : new TextEncoder().encode(e);
1743
1811
  }
@@ -1789,7 +1857,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1789
1857
  isWat: this._isWat(e, i)
1790
1858
  });
1791
1859
  }
1792
- return r.then((e) => (!e.isWat && e.bytes && (this._inspectedWasm = P(e.bytes), this._inspectedWasm.isInteractive && (this._isInteractive = !0)), e));
1860
+ return r.then((e) => (!e.isWat && e.bytes && (this._inspectedWasm = F(e.bytes), this._inspectedWasm.isInteractive && (this._isInteractive = !0)), e));
1793
1861
  }
1794
1862
  _isWat(e, t) {
1795
1863
  return e.endsWith(".wat") ? !0 : t.length > 0 && t[0] === 40;
@@ -1830,12 +1898,12 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1830
1898
  let t = {
1831
1899
  1: "",
1832
1900
  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)) {
1901
+ }, 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);
1902
+ B && (this.emit("interactive"), this.context && typeof this.context.emit == "function" && this.context.emit("interactive"));
1903
+ let V = () => {
1904
+ 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));
1905
+ }, H = (e, n) => {
1906
+ if (B && (e === 1 || e === 2)) {
1839
1907
  if (e === 1 && this.stdout) {
1840
1908
  this.stdout.write(n);
1841
1909
  return;
@@ -1849,61 +1917,63 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1849
1917
  let r = t[e].split("\n");
1850
1918
  t[e] = r.pop();
1851
1919
  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) => {
1920
+ }, ne = () => {
1921
+ 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], "");
1922
+ }, U = [], re = (e) => {
1855
1923
  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();
1924
+ for (let t = 0; t < e.length; t++) U.push(e[t]);
1925
+ if (j) {
1926
+ let e = j;
1927
+ j = null, e();
1860
1928
  }
1861
1929
  }
1862
1930
  };
1863
- M = (e) => {
1931
+ R = (e) => {
1864
1932
  this._handlingStreamData = !0;
1865
1933
  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 ?? "")));
1934
+ 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
1935
  } finally {
1868
1936
  this._handlingStreamData = !1;
1869
1937
  }
1870
1938
  }, this._externalKeyHandler = (e) => {
1871
1939
  if (this._handlingStreamData) return;
1872
1940
  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, {
1941
+ t && re(t);
1942
+ };
1943
+ let ie = !!(this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.listeners == "function" && this.stdinStream.listeners("data").includes(this._onStdinStreamData));
1944
+ 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);
1945
+ 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
1946
  type: "preopen",
1877
1947
  path: "/",
1878
1948
  guestName: "/"
1879
1949
  }], [4, {
1880
1950
  type: "preopen",
1881
- path: ne,
1951
+ path: J,
1882
1952
  guestName: "."
1883
- }]]), K = new Map([
1953
+ }]]), ae = new Map([
1884
1954
  [0, 0],
1885
1955
  [1, 0],
1886
1956
  [2, 0]
1887
- ]), re = (e) => {
1957
+ ]), oe = (e) => {
1888
1958
  let t = e.split("/").filter(Boolean);
1889
1959
  return t.pop(), "/" + t.join("/");
1890
- }, q = (e, t) => {
1891
- let n = G.get(e);
1960
+ }, se = (e, t) => {
1961
+ let n = X.get(e);
1892
1962
  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);
1963
+ if (t.startsWith("/")) return K.absolutePath(t);
1964
+ if (!t || t === ".") return K.absolutePath(n.path);
1965
+ let r = n.path.endsWith("/") ? n.path : n.path + "/", i = K.absolutePath(r + t), a = K.absolutePath("/" + t);
1896
1966
  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 {
1967
+ if (K.exists(i)) return i;
1968
+ if (K.exists(a)) return a;
1969
+ let e = K.exists(oe(i));
1970
+ return K.exists(oe(a)) && !e ? a : i;
1971
+ }
1972
+ if (K.exists(i)) return i;
1973
+ let o = K.absolutePath(t);
1974
+ return K.exists(o) ? o : i;
1975
+ }, ce = (e) => {
1976
+ if (!(!e || e.type !== "file" || !e.dirty || !K)) try {
1907
1977
  let t = !0;
1908
1978
  for (let n = 0; n < e.bytes.length; n++) if (e.bytes[n] === 0) {
1909
1979
  t = !1;
@@ -1911,20 +1981,20 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1911
1981
  }
1912
1982
  if (t) {
1913
1983
  let t = n.decode(e.bytes);
1914
- H.setFileByPath(e.path, t, !0);
1984
+ K.setFileByPath(e.path, t, !0);
1915
1985
  } else {
1916
1986
  let t = new Uint8Array(e.bytes.length);
1917
- t.set(e.bytes), H.setFileByPath(e.path, new r(t.buffer, "application/octet-stream"), !0);
1987
+ t.set(e.bytes), K.setFileByPath(e.path, new r(t.buffer, "application/octet-stream"), !0);
1918
1988
  }
1919
1989
  e.dirty = !1;
1920
1990
  } catch {}
1921
- }, Y = {
1991
+ }, 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
1992
  TERM: "xterm-256color",
1923
1993
  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({
1994
+ ...this.context && this.context.vars || {},
1995
+ COLUMNS: String(le),
1996
+ LINES: String(ue)
1997
+ }, Z = Object.entries(de).map(([e, t]) => `${e}=${t}`), fe = new Proxy({
1928
1998
  fd_write: (e, t, r, a) => {
1929
1999
  if (!T) return o;
1930
2000
  let s = new DataView(T.buffer);
@@ -1932,11 +2002,11 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1932
2002
  let o = 0;
1933
2003
  for (let i = 0; i < r; i++) {
1934
2004
  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;
2005
+ a > 0 && H(e, n.decode(new Uint8Array(T.buffer, r, a))), o += a;
1936
2006
  }
1937
2007
  return s.setUint32(a, o, !0), i;
1938
2008
  }
1939
- let c = G.get(e);
2009
+ let c = X.get(e);
1940
2010
  if (!c) return o;
1941
2011
  if (c.type === "dev_null" || c.type === "dev_zero") {
1942
2012
  let e = 0;
@@ -1947,7 +2017,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1947
2017
  let e = 0;
1948
2018
  for (let i = 0; i < r; i++) {
1949
2019
  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;
2020
+ a > 0 && H(1, n.decode(new Uint8Array(T.buffer, r, a))), e += a;
1951
2021
  }
1952
2022
  return s.setUint32(a, e, !0), i;
1953
2023
  }
@@ -1968,50 +2038,56 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1968
2038
  },
1969
2039
  fd_read: (e, t, n, r) => {
1970
2040
  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();
2041
+ let s = new DataView(T.buffer), l = X.get(e), u = !!(l && l.type === "dev_tty");
2042
+ if (e === 0 || B && e === 2 || u) {
2043
+ (u || e === 2) && V();
2044
+ let o = !!((ae.get(e) || 0) & E);
2045
+ if (O) {
2046
+ if ((typeof D?.exports?.asyncify_get_state == "function" ? D.exports.asyncify_get_state() : 0) === 2) {
2047
+ if (D.exports.asyncify_stop_rewind(), L && U.length === 0) return L = !1, s.setUint32(r, 0, !0), c;
2048
+ L = !1;
1978
2049
  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);
2050
+ for (let r = 0; r < n && U.length > 0; r++) {
2051
+ 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
2052
  new Uint8Array(T.buffer).set(o, n), e += a;
1982
2053
  }
1983
2054
  return s.setUint32(r, e, !0), i;
1984
2055
  }
1985
- if (R.length > 0) {
2056
+ if (U.length > 0) {
1986
2057
  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);
2058
+ for (let r = 0; r < n && U.length > 0; r++) {
2059
+ 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
2060
  new Uint8Array(T.buffer).set(o, n), e += a;
1990
2061
  }
1991
2062
  return s.setUint32(r, e, !0), i;
1992
2063
  }
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;
2064
+ return o ? (s.setUint32(r, 0, !0), a) : (L = !1, D.exports.asyncify_start_unwind(k), A = new Promise((e, t) => {
2065
+ let n = () => {
2066
+ L = !1, j = null, M = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
2067
+ };
2068
+ j = n, this._pendingReadResolve = n, M = () => {
2069
+ L = !0, j = null, M = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
2070
+ }, this._asyncifyReject = t;
1995
2071
  }), s.setUint32(r, 0, !0), i);
1996
2072
  }
1997
- if (R.length > 0) {
2073
+ if (U.length > 0) {
1998
2074
  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);
2075
+ for (let r = 0; r < n && U.length > 0; r++) {
2076
+ 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
2077
  new Uint8Array(T.buffer).set(o, n), e += a;
2002
2078
  }
2003
2079
  return s.setUint32(r, e, !0), i;
2004
2080
  }
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;
2081
+ let l = 0;
2082
+ for (let e = 0; e < n && G < W.length; e++) {
2083
+ let n = s.getUint32(t + e * 8, !0), r = s.getUint32(t + e * 8 + 4, !0), i = Math.min(r, W.length - G);
2084
+ new Uint8Array(T.buffer).set(W.slice(G, G + i), n), G += i, l += i;
2009
2085
  }
2010
- return c === 0 && o && V >= B.length ? (s.setUint32(r, 0, !0), a) : (s.setUint32(r, c, !0), i);
2086
+ return l === 0 && o && G >= W.length ? (s.setUint32(r, 0, !0), a) : (s.setUint32(r, l, !0), i);
2011
2087
  }
2012
- if (!c) return o;
2013
- if (c.type === "dev_null") return s.setUint32(r, 0, !0), i;
2014
- if (c.type === "dev_zero") {
2088
+ if (!l) return o;
2089
+ if (l.type === "dev_null") return s.setUint32(r, 0, !0), i;
2090
+ if (l.type === "dev_zero") {
2015
2091
  let e = 0;
2016
2092
  for (let r = 0; r < n; r++) {
2017
2093
  let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0);
@@ -2019,7 +2095,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2019
2095
  }
2020
2096
  return s.setUint32(r, e, !0), i;
2021
2097
  }
2022
- if (c.type === "dev_urandom") {
2098
+ if (l.type === "dev_urandom") {
2023
2099
  let e = 0;
2024
2100
  for (let r = 0; r < n; r++) {
2025
2101
  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 +2105,214 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2029
2105
  }
2030
2106
  return s.setUint32(r, e, !0), i;
2031
2107
  }
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;
2108
+ if (l.type !== "file") return o;
2109
+ let d = 0;
2110
+ for (let e = 0; e < n && l.pos < l.bytes.length; e++) {
2111
+ 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);
2112
+ new Uint8Array(T.buffer).set(l.bytes.subarray(l.pos, l.pos + i), n), l.pos += i, d += i;
2037
2113
  }
2038
- return s.setUint32(r, u, !0), i;
2114
+ return s.setUint32(r, d, !0), i;
2039
2115
  },
2040
2116
  fd_seek: (e, t, n, r, a) => {
2041
2117
  if (!T) return o;
2042
- if (e <= 2) return f;
2043
- let s = G.get(e);
2118
+ if (e <= 2) return p;
2119
+ let s = X.get(e);
2044
2120
  if (!s) return o;
2045
- if (s.type === "dev_tty" || s.type === "dev_null" || s.type === "dev_zero" || s.type === "dev_urandom") return f;
2121
+ if (s.type === "dev_tty" || s.type === "dev_null" || s.type === "dev_zero" || s.type === "dev_urandom") return p;
2046
2122
  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);
2123
+ let c, u, d;
2124
+ typeof t == "bigint" ? (c = Number(t), u = n, d = r) : (c = t, u = r, d = a);
2125
+ let f = s.pos;
2126
+ if (u === 0) f = c;
2127
+ else if (u === 1) f = s.pos + c;
2128
+ else if (u === 2) f = s.bytes.length + c;
2129
+ else return l;
2130
+ return f < 0 ? l : (s.pos = f, d && new DataView(T.buffer).setBigUint64(d, BigInt(s.pos), !0), i);
2055
2131
  },
2056
2132
  fd_tell: (e, t) => {
2057
2133
  if (!T) return o;
2058
- let n = G.get(e);
2134
+ let n = X.get(e);
2059
2135
  return !n || n.type !== "file" ? o : (new DataView(T.buffer).setBigUint64(t, BigInt(n.pos), !0), i);
2060
2136
  },
2061
2137
  fd_close: (e) => {
2062
2138
  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;
2139
+ let t = X.get(e);
2140
+ return t ? (t.type === "file" && ce(t), X.delete(e), ae.delete(e), i) : o;
2065
2141
  },
2066
2142
  fd_sync: (e) => {
2067
- let t = G.get(e);
2068
- return t && J(t), i;
2143
+ let t = X.get(e);
2144
+ return t && ce(t), i;
2069
2145
  },
2070
2146
  fd_datasync: (e) => {
2071
- let t = G.get(e);
2072
- return t && J(t), i;
2147
+ let t = X.get(e);
2148
+ return t && ce(t), i;
2073
2149
  },
2074
2150
  fd_prestat_get: (e, t) => {
2075
2151
  if (!T) return o;
2076
- let n = G.get(e);
2152
+ let n = X.get(e);
2077
2153
  if (!n || n.type !== "preopen") return o;
2078
2154
  let r = new DataView(T.buffer), a = b.encode(n.guestName);
2079
2155
  return r.setUint8(t, 0), r.setUint32(t + 4, a.length, !0), i;
2080
2156
  },
2081
2157
  fd_prestat_dir_name: (e, t, n) => {
2082
2158
  if (!T) return o;
2083
- let r = G.get(e);
2159
+ let r = X.get(e);
2084
2160
  if (!r || r.type !== "preopen") return o;
2085
2161
  let a = b.encode(r.guestName);
2086
2162
  return new Uint8Array(T.buffer, t, Math.min(n, a.length)).set(a.subarray(0, n)), i;
2087
2163
  },
2088
2164
  fd_fdstat_get: (e, t) => {
2089
2165
  if (!T) return o;
2090
- let n = new DataView(T.buffer), r = p;
2091
- if (e <= 2) r = m;
2166
+ let n = new DataView(T.buffer), r = m;
2167
+ if (e <= 2) r = h;
2092
2168
  else {
2093
- let t = G.get(e);
2169
+ let t = X.get(e);
2094
2170
  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;
2171
+ 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
2172
  }
2097
2173
  for (let e = 0; e < 24; e++) n.setUint8(t + e, 0);
2098
2174
  n.setUint8(t, r);
2099
- let a = K.get(e) || (G.get(e)?.append ? C : 0);
2175
+ let a = ae.get(e) || (X.get(e)?.append ? w : 0);
2100
2176
  return n.setUint16(t + 2, a, !0), n.setBigUint64(t + 8, 18446744073709551615n, !0), n.setBigUint64(t + 16, 18446744073709551615n, !0), i;
2101
2177
  },
2102
2178
  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;
2179
+ if (!T || e > 2 && !X.has(e)) return o;
2180
+ ae.set(e, t);
2181
+ let n = X.get(e);
2182
+ return n && (n.append = !!(t & w)), (e === 0 || e === 2 || n && n.type === "dev_tty") && t & E && V(), i;
2107
2183
  },
2108
2184
  fd_filestat_get: (e, t) => {
2109
2185
  if (!T) return o;
2110
2186
  let n = new DataView(T.buffer);
2111
2187
  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);
2188
+ if (e <= 2) return n.setUint8(t + 16, h), i;
2189
+ let r = X.get(e);
2114
2190
  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;
2191
+ 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
2192
  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;
2193
+ 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
2194
  },
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)));
2195
+ path_open: (e, t, r, a, c, l, p, m, h) => {
2196
+ if (!T || !K) return o;
2197
+ let g = se(e, n.decode(new Uint8Array(T.buffer, r, a)));
2122
2198
  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, {
2199
+ let _ = g.replace(/\/+/g, "/").replace(/\/$/, "") || "/";
2200
+ if (_ === "/dev/null") {
2201
+ let e = Y++;
2202
+ return X.set(e, {
2127
2203
  type: "dev_null",
2128
2204
  path: "/dev/null"
2129
2205
  }), new DataView(T.buffer).setUint32(h, e, !0), i;
2130
2206
  }
2131
- if (y === "/dev/zero") {
2132
- let e = W++;
2133
- return G.set(e, {
2207
+ if (_ === "/dev/zero") {
2208
+ let e = Y++;
2209
+ return X.set(e, {
2134
2210
  type: "dev_zero",
2135
2211
  path: "/dev/zero"
2136
2212
  }), new DataView(T.buffer).setUint32(h, e, !0), i;
2137
2213
  }
2138
- if (y === "/dev/urandom" || y === "/dev/random") {
2139
- let e = W++;
2140
- return G.set(e, {
2214
+ if (_ === "/dev/urandom" || _ === "/dev/random") {
2215
+ let e = Y++;
2216
+ return X.set(e, {
2141
2217
  type: "dev_urandom",
2142
- path: y
2218
+ path: _
2143
2219
  }), new DataView(T.buffer).setUint32(h, e, !0), i;
2144
2220
  }
2145
- if (y === "/dev/tty" || y === "/dev/stdin") {
2146
- ee();
2147
- let e = W++;
2148
- return G.set(e, {
2221
+ if (_ === "/dev/tty" || _ === "/dev/stdin") {
2222
+ V();
2223
+ let e = Y++;
2224
+ return X.set(e, {
2149
2225
  type: "dev_tty",
2150
- path: y
2226
+ path: _
2151
2227
  }), new DataView(T.buffer).setUint32(h, e, !0), i;
2152
2228
  }
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, {
2229
+ if (_ === "/dev/stdout") return new DataView(T.buffer).setUint32(h, 1, !0), i;
2230
+ if (_ === "/dev/stderr") return new DataView(T.buffer).setUint32(h, 2, !0), i;
2231
+ let y = K.stat(g), E = y !== null;
2232
+ if (c & S && c & v && E) return s;
2233
+ if (c & x) {
2234
+ if (!E) return d;
2235
+ if (!y.isDirectory) return f;
2236
+ let e = Y++;
2237
+ return X.set(e, {
2162
2238
  type: "dir",
2163
2239
  path: g
2164
2240
  }), new DataView(T.buffer).setUint32(h, e, !0), i;
2165
2241
  }
2166
- if (E && w.isDirectory) return l;
2167
- if (!E && !(c & _)) return u;
2242
+ if (E && y.isDirectory) return u;
2243
+ if (!E && !(c & v)) return d;
2168
2244
  let D = new Uint8Array(), O = !1;
2169
- if (E && !(c & S)) {
2170
- let e = H.getFileByPath(g);
2245
+ if (E && !(c & C)) {
2246
+ let e = K.getFileByPath(g);
2171
2247
  e != null && (D = typeof e == "string" ? b.encode(e) : new Uint8Array(this._contentToBytes(e)));
2172
2248
  } else O = !0;
2173
- let k = W++;
2174
- return G.set(k, {
2249
+ let k = Y++;
2250
+ return X.set(k, {
2175
2251
  type: "file",
2176
2252
  path: g,
2177
2253
  bytes: D,
2178
- pos: m & C ? D.length : 0,
2179
- append: !!(m & C),
2254
+ pos: m & w ? D.length : 0,
2255
+ append: !!(m & w),
2180
2256
  dirty: O
2181
2257
  }), new DataView(T.buffer).setUint32(h, k, !0), i;
2182
2258
  },
2183
2259
  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)));
2260
+ if (!T || !K) return o;
2261
+ let c = se(e, n.decode(new Uint8Array(T.buffer, r, a)));
2186
2262
  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)) {
2263
+ let l = c.replace(/\/+/g, "/").replace(/\/$/, "") || "/", u = K.stat(c);
2264
+ 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
2265
  let e = new DataView(T.buffer);
2190
2266
  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;
2267
+ return e.setUint8(s + 16, h), e.setBigUint64(s + 24, 1n, !0), i;
2192
2268
  }
2193
- if (!d) return u;
2269
+ if (!u) return d;
2194
2270
  let f = new DataView(T.buffer);
2195
2271
  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;
2272
+ 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
2273
  },
2198
2274
  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)));
2275
+ if (!T || !K) return o;
2276
+ let a = se(e, n.decode(new Uint8Array(T.buffer, t, r)));
2201
2277
  if (!a) return o;
2202
- if (H.exists(a)) return s;
2278
+ if (K.exists(a)) return s;
2203
2279
  try {
2204
- return H.setFileByPath(a, {}, !0), i;
2280
+ return K.setFileByPath(a, {}, !0), i;
2205
2281
  } catch {
2206
- return c;
2282
+ return l;
2207
2283
  }
2208
2284
  },
2209
2285
  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;
2286
+ if (!T || !K) return o;
2287
+ let a = se(e, n.decode(new Uint8Array(T.buffer, t, r)));
2288
+ if (!a || !K.exists(a)) return d;
2213
2289
  try {
2214
- return H.deleteFileByPath(a), i;
2290
+ return K.deleteFileByPath(a), i;
2215
2291
  } catch {
2216
- return c;
2292
+ return l;
2217
2293
  }
2218
2294
  },
2219
2295
  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;
2296
+ if (!T || !K) return o;
2297
+ let a = se(e, n.decode(new Uint8Array(T.buffer, t, r)));
2298
+ if (!a || !K.exists(a)) return d;
2223
2299
  try {
2224
- return H.deleteFileByPath(a), i;
2300
+ return K.deleteFileByPath(a), i;
2225
2301
  } catch {
2226
- return c;
2302
+ return l;
2227
2303
  }
2228
2304
  },
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);
2305
+ path_rename: (e, t, r, a, s, c) => {
2306
+ if (!T || !K) return o;
2307
+ 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
2308
  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);
2309
+ if (!K.exists(p)) return d;
2310
+ for (let e of X.values()) e.path === p && (ce(e), e.path = m);
2235
2311
  try {
2236
- let e = H.getFileByPath(p);
2237
- return H.setFileByPath(m, e, !0), H.deleteFileByPath(p), i;
2312
+ let e = K.getFileByPath(p);
2313
+ return K.setFileByPath(m, e, !0), K.deleteFileByPath(p), i;
2238
2314
  } catch {
2239
- return c;
2315
+ return l;
2240
2316
  }
2241
2317
  },
2242
2318
  proc_exit: (e) => {
@@ -2246,12 +2322,12 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2246
2322
  };
2247
2323
  },
2248
2324
  args_sizes_get: (e, t) => {
2249
- if (!T) return c;
2325
+ if (!T) return l;
2250
2326
  let n = [this.script, ...this.arguments || []], r = new DataView(T.buffer);
2251
2327
  return r.setUint32(e, n.length, !0), r.setUint32(t, n.reduce((e, t) => e + b.encode(t).length + 1, 0), !0), i;
2252
2328
  },
2253
2329
  args_get: (e, t) => {
2254
- if (!T) return c;
2330
+ if (!T) return l;
2255
2331
  let n = [this.script, ...this.arguments || []], r = new DataView(T.buffer), a = t;
2256
2332
  for (let t = 0; t < n.length; t++) {
2257
2333
  r.setUint32(e + t * 4, a, !0);
@@ -2261,26 +2337,26 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2261
2337
  return i;
2262
2338
  },
2263
2339
  environ_sizes_get: (e, t) => {
2264
- if (!T) return c;
2340
+ if (!T) return l;
2265
2341
  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);
2342
+ n.setUint32(e, Z.length, !0);
2343
+ let r = Z.reduce((e, t) => e + b.encode(t).length + 1, 0);
2268
2344
  return n.setUint32(t, r, !0), i;
2269
2345
  },
2270
2346
  environ_get: (e, t) => {
2271
- if (!T) return c;
2347
+ if (!T) return l;
2272
2348
  let n = new DataView(T.buffer), r = t;
2273
- for (let t = 0; t < X.length; t++) {
2349
+ for (let t = 0; t < Z.length; t++) {
2274
2350
  n.setUint32(e + t * 4, r, !0);
2275
- let i = b.encode(X[t] + "\0");
2351
+ let i = b.encode(Z[t] + "\0");
2276
2352
  new Uint8Array(T.buffer).set(i, r), r += i.length;
2277
2353
  }
2278
2354
  return i;
2279
2355
  },
2280
2356
  clock_time_get: (e, t, n) => {
2281
2357
  if (T) {
2282
- let e = BigInt(Date.now()) * 1000000n;
2283
- new DataView(T.buffer).setBigUint64(n, e, !0);
2358
+ let t = e === 1 && typeof performance < "u" && typeof performance.now == "function" ? BigInt(Math.round(performance.now() * 1e6)) : BigInt(Date.now()) * 1000000n;
2359
+ new DataView(T.buffer).setBigUint64(n, t, !0);
2284
2360
  }
2285
2361
  return i;
2286
2362
  },
@@ -2298,24 +2374,33 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2298
2374
  let e = BigInt(Date.now()) * 1000000n;
2299
2375
  c = s > e ? Number((s - e) / 1000000n) : 0;
2300
2376
  } 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;
2377
+ 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
2378
  },
2303
2379
  poll_oneoff: (e, t, n, r) => {
2304
2380
  if (!T) return o;
2305
2381
  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();
2382
+ if (O) {
2383
+ if ((typeof D?.exports?.asyncify_get_state == "function" ? D.exports.asyncify_get_state() : 0) === 2) {
2384
+ if (D.exports.asyncify_stop_rewind(), P && U.length === 0) return P = !1, a.setUint32(r, 0, !0), c;
2385
+ P = !1;
2309
2386
  let o = 0;
2310
2387
  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++;
2388
+ let n = e + r * 48, s = a.getBigUint64(n, !0), c = a.getUint8(n + 8), l = !1;
2389
+ if (c === 0) l = N;
2390
+ else if (c === 1) {
2391
+ let e = a.getUint32(n + 16, !0), t = X.get(e), r = !!(t && t.type === "dev_tty");
2392
+ (e === 0 || B && e === 2 || r) && U.length > 0 && (l = !0);
2393
+ } else c === 2 && (l = !0);
2394
+ if (l) {
2395
+ let e = t + o * 32;
2396
+ a.setBigUint64(e, s, !0), a.setUint16(e + 8, i, !0), a.setUint8(e + 10, c);
2397
+ for (let t = 11; t < 32; t++) a.setUint8(e + t, 0);
2398
+ c === 1 && a.setBigUint64(e + 16, BigInt(U.length), !0), o++;
2399
+ }
2315
2400
  }
2316
2401
  return a.setUint32(r, o, !0), i;
2317
2402
  }
2318
- let o = 0, s = Infinity;
2403
+ let o = 0, s = !1, l = Infinity;
2319
2404
  for (let t = 0; t < n; t++) {
2320
2405
  let n = e + t * 48, r = a.getUint8(n + 8);
2321
2406
  if (r === 0) {
@@ -2324,46 +2409,49 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2324
2409
  let t = BigInt(Date.now()) * 1000000n;
2325
2410
  r = e > t ? Number((e - t) / 1000000n) : 0;
2326
2411
  } else r = Number(e / 1000000n);
2327
- r < s && (s = r);
2412
+ r < l && (l = r);
2328
2413
  } 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++;
2414
+ s = !0;
2415
+ let e = a.getUint32(n + 16, !0), t = X.get(e), r = !!(t && t.type === "dev_tty");
2416
+ (e === 0 || e === 2 || r) && V(), (e === 0 || B && e === 2 || r) && U.length > 0 && o++;
2331
2417
  } else r === 2 && o++;
2332
2418
  }
2333
- if (o > 0 || s === 0) {
2419
+ if (o > 0 || l === 0) {
2334
2420
  let o = 0;
2335
2421
  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);
2422
+ let n = e + r * 48, s = a.getBigUint64(n, !0), c = a.getUint8(n + 8), u = !1;
2423
+ if (c === 0 && l === 0) u = !0;
2424
+ else if (c === 1) {
2425
+ let e = a.getUint32(n + 16, !0), t = X.get(e), r = !!(t && t.type === "dev_tty");
2426
+ (e === 0 || B && e === 2 || r) && U.length > 0 && (u = !0);
2427
+ } else c === 2 && (u = !0);
2342
2428
  if (u) {
2343
2429
  let e = t + o * 32;
2344
- a.setBigUint64(e, c, !0), a.setUint16(e + 8, i, !0), a.setUint8(e + 10, l);
2430
+ a.setBigUint64(e, s, !0), a.setUint16(e + 8, i, !0), a.setUint8(e + 10, c);
2345
2431
  for (let t = 11; t < 32; t++) a.setUint8(e + t, 0);
2346
- l === 1 && a.setBigUint64(e + 16, BigInt(R.length), !0), o++;
2432
+ c === 1 && a.setBigUint64(e + 16, BigInt(U.length), !0), o++;
2347
2433
  }
2348
2434
  }
2349
2435
  return a.setUint32(r, o, !0), i;
2350
2436
  }
2351
- return E.exports.asyncify_start_unwind(O), k = new Promise((e, t) => {
2437
+ return N = !1, P = !1, D.exports.asyncify_start_unwind(k), A = new Promise((e, t) => {
2352
2438
  let n = null;
2353
2439
  this._asyncifyReject = t;
2354
2440
  let r = () => {
2355
- n && clearTimeout(n), A = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
2441
+ n && clearTimeout(n), N = !1, P = !1, j = null, M = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
2356
2442
  };
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)));
2443
+ s && (j = r, this._pendingReadResolve = r, M = () => {
2444
+ n && clearTimeout(n), N = !1, P = !0, j = null, M = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
2445
+ }), l !== Infinity && (n = setTimeout(() => {
2446
+ N = !0, P = !1, j = null, M = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
2447
+ }, Math.max(1, l)));
2360
2448
  }), a.setUint32(r, 0, !0), i;
2361
2449
  }
2362
2450
  return a.setUint32(r, 0, !0), i;
2363
2451
  }
2364
2452
  }, { get(e, t) {
2365
2453
  return t in e ? e[t] : () => 0;
2366
- } }), ae = (e) => {
2454
+ } }), pe = (e) => {
2367
2455
  if (!T || !e) return "";
2368
2456
  try {
2369
2457
  let t = new DataView(T.buffer).getUint32(e - 4, !0), n = new Uint16Array(T.buffer, e, t >>> 1);
@@ -2371,33 +2459,33 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2371
2459
  } catch {
2372
2460
  return "";
2373
2461
  }
2374
- }, oe = {
2375
- wasi_snapshot_preview1: ie,
2376
- wasi_unstable: ie,
2462
+ }, me = {
2463
+ wasi_snapshot_preview1: fe,
2464
+ wasi_unstable: fe,
2377
2465
  env: new Proxy({
2378
2466
  print: (e, t) => {
2379
- T && L(1, n.decode(new Uint8Array(T.buffer, e, t)));
2467
+ T && H(1, n.decode(new Uint8Array(T.buffer, e, t)));
2380
2468
  },
2381
2469
  eprint: (e, t) => {
2382
- T && L(2, n.decode(new Uint8Array(T.buffer, e, t)));
2470
+ T && H(2, n.decode(new Uint8Array(T.buffer, e, t)));
2383
2471
  },
2384
2472
  log: (e) => {
2385
- L(1, ae(e) + "\n");
2473
+ H(1, pe(e) + "\n");
2386
2474
  },
2387
2475
  logi: (e) => {
2388
- L(1, String(e) + "\n");
2476
+ H(1, String(e) + "\n");
2389
2477
  },
2390
2478
  logf: (e) => {
2391
- L(1, String(e) + "\n");
2479
+ H(1, String(e) + "\n");
2392
2480
  },
2393
2481
  trace: (e, t, ...n) => {
2394
2482
  let r = t > 0 ? " " + n.slice(0, t).join(", ") : "";
2395
- L(1, `trace: ${ae(e)}${r}\n`);
2483
+ H(1, `trace: ${pe(e)}${r}\n`);
2396
2484
  },
2397
2485
  seed: () => Date.now() * Math.random(),
2398
2486
  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, {
2487
+ let i = pe(e), a = pe(t);
2488
+ throw (i || a) && H(2, `abort: ${i || "aborted"} at ${a || this.script}:${n || 0}:${r || 0}\n`), this.exitCode = 134, {
2401
2489
  _wasmExit: !0,
2402
2490
  code: 134
2403
2491
  };
@@ -2413,82 +2501,97 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2413
2501
  initial: 1,
2414
2502
  maximum: 256
2415
2503
  });
2416
- T = t, oe[e.module] || (oe[e.module] = {}), oe[e.module][e.name] = t;
2504
+ T = t, me[e.module] || (me[e.module] = {}), me[e.module][e.name] = t;
2417
2505
  }
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) {
2506
+ 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
2507
  try {
2420
- O = T.grow(1) * 65536;
2508
+ k = T.grow(1) * 65536;
2421
2509
  } catch {
2422
- O = 16;
2510
+ k = 16;
2423
2511
  }
2424
- let e = O + 8, t = O + 65536 - 8;
2425
- new Int32Array(T.buffer, O, 2).set([e, t]);
2512
+ let e = k + 8, t = k + 65536 - 8;
2513
+ new Int32Array(T.buffer, k, 2).set([e, t]);
2426
2514
  }
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);
2515
+ typeof D.exports.set_terminal_size == "function" && V(), B && this._enterAltScreen();
2516
+ 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;
2517
+ if (typeof D.exports.set_terminal_size == "function") try {
2518
+ D.exports.set_terminal_size(n, r);
2431
2519
  } 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;) {
2520
+ let i = n, a = r, o = (e, t) => {
2521
+ if (!(!e || !t)) {
2522
+ 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 {
2523
+ this.context.setVar("COLUMNS", String(e)), this.context.setVar("LINES", String(t));
2524
+ } catch {}
2525
+ if (!(e === i && t === a)) {
2526
+ if (i = e, a = t, typeof D?.exports?.set_terminal_size == "function") try {
2527
+ D.exports.set_terminal_size(e, t);
2528
+ } catch {}
2529
+ if (M) {
2530
+ let e = M;
2531
+ M = null, e();
2532
+ }
2533
+ }
2534
+ }
2535
+ };
2536
+ ee = () => {
2537
+ 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);
2538
+ }, te = () => {
2539
+ 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);
2540
+ }, 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);
2541
+ let s = D.exports._start || D.exports.__wasi_command || D.exports.main || D.exports.run;
2542
+ if (s) try {
2543
+ let e = s();
2544
+ for (e && typeof e.then == "function" && (e = await e); O && typeof D.exports.asyncify_get_state == "function" && D.exports.asyncify_get_state() === 1;) {
2442
2545
  if (this._killed) {
2443
2546
  this.exitCode = 130;
2444
2547
  break;
2445
2548
  }
2446
- if (E.exports.asyncify_stop_unwind(), k) {
2549
+ if (D.exports.asyncify_stop_unwind(), A) {
2447
2550
  try {
2448
- await k;
2551
+ await A;
2449
2552
  } catch {
2450
2553
  if (this._killed) {
2451
2554
  this.exitCode = 130;
2452
2555
  break;
2453
2556
  }
2454
2557
  }
2455
- k = null;
2558
+ A = null;
2456
2559
  }
2457
2560
  if (this._killed) {
2458
2561
  this.exitCode = 130;
2459
2562
  break;
2460
2563
  }
2461
- E.exports.asyncify_start_rewind(O), e = i(), e && typeof e.then == "function" && (e = await e);
2564
+ D.exports.asyncify_start_rewind(k), e = s(), e && typeof e.then == "function" && (e = await e);
2462
2565
  }
2463
2566
  } catch (e) {
2464
2567
  this._killed ? this.exitCode = 130 : (!e || !e._wasmExit) && (this.stdErr = `${this.script}: runtime error: ${e?.message || String(e)}`, this.exitCode = 1);
2465
2568
  }
2466
2569
  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(", ")})` : "";
2570
+ 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
2571
  this.stdErr = `${this.script}: no CLI entry point found (expected _start, main, or run)${t}`, this.exitCode = 1;
2469
2572
  }
2470
2573
  } catch (e) {
2471
2574
  this._killed ? this.exitCode = 130 : (!e || !e._wasmExit) && (this.stdErr = `${this.script}: ${e?.message || String(e)}`, this.exitCode = 1);
2472
2575
  } 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);
2576
+ 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;
2577
+ for (let e of X.values()) ce(e);
2475
2578
  }
2476
- te();
2477
- let se = this.arguments || [];
2579
+ ne();
2580
+ let he = this.arguments || [];
2478
2581
  if (!(this.result && this.result.getStdOutput && this.result.getStdOutput().length > 0) && (this.exitCode === 0 || this.exitCode === void 0)) {
2479
2582
  let t = this._ensurePkgMeta(), n = t && t.bin || (this.script || "wasm").split("/").pop(), r = Object.assign({
2480
2583
  name: t && t.name || n,
2481
2584
  version: t && t.version || "wasi",
2482
2585
  description: `WebAssembly WASI binary (${this.script})`
2483
2586
  }, 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)`);
2587
+ if (he.includes("--help") || he.includes("-h")) {
2588
+ let t = F(e);
2589
+ for (let e of I(n, r, t)) this.stdOut = e;
2590
+ } else (he.includes("--version") || he.includes("-V") || he.includes("-v")) && (this.stdOut = `${n} (${r.name} ${r.version} wasm)`);
2488
2591
  }
2489
2592
  }
2490
- }, k = /* @__PURE__ */ new Map();
2491
- function A(e, t) {
2593
+ }, A = /* @__PURE__ */ new Map();
2594
+ function j(e, t) {
2492
2595
  if (!e || !e.exists(t)) return null;
2493
2596
  if (e.isRealFilesystem) try {
2494
2597
  let n = O();
@@ -2515,7 +2618,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2515
2618
  }
2516
2619
  return null;
2517
2620
  }
2518
- function j(e, t, n, i = "application/octet-stream") {
2621
+ function M(e, t, n, i = "application/octet-stream") {
2519
2622
  let a = n instanceof Uint8Array ? n : new Uint8Array(n);
2520
2623
  if (e && e.isRealFilesystem) {
2521
2624
  e.setFileByPath(t, a, !0);
@@ -2530,7 +2633,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2530
2633
  }
2531
2634
  e.setFileByPath(t, s, !0);
2532
2635
  }
2533
- async function M(e, t, n = null) {
2636
+ async function N(e, t, n = null) {
2534
2637
  if (typeof n == "function") {
2535
2638
  let r = await n(e, t);
2536
2639
  if (r) return r;
@@ -2558,7 +2661,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2558
2661
  }
2559
2662
  throw Error(`Package '${e}' could not be loaded`);
2560
2663
  }
2561
- function N(e, t = !1) {
2664
+ function P(e, t = !1) {
2562
2665
  let n = {
2563
2666
  usage: null,
2564
2667
  options: []
@@ -2575,7 +2678,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2575
2678
  }
2576
2679
  return n;
2577
2680
  }
2578
- function P(e) {
2681
+ function F(e) {
2579
2682
  let t = {
2580
2683
  usage: null,
2581
2684
  options: [],
@@ -2600,12 +2703,12 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2600
2703
  r.length >= 4 && n.push(r);
2601
2704
  let i = n.join("\n");
2602
2705
  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);
2706
+ let a = P(i, !0);
2604
2707
  t.usage = a.usage, t.options = a.options;
2605
2708
  } catch {}
2606
2709
  return t;
2607
2710
  }
2608
- function F(e, t = {}, n = null) {
2711
+ function I(e, t = {}, n = null) {
2609
2712
  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
2713
  t.details && u.push("", t.details), u.push("", "Options:");
2611
2714
  let d = n && n.options && n.options.length > 0 ? n.options : Array.isArray(t.options) ? t.options : [];
@@ -2613,8 +2716,8 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2613
2716
  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
2717
  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
2718
  }
2616
- function I(e, t = {}, n = null) {
2617
- let r = E(), i = (n || e.bin || e.name).toLowerCase();
2719
+ function L(e, t = {}, n = null) {
2720
+ let r = T(), i = (n || e.bin || e.name).toLowerCase();
2618
2721
  class a extends r {
2619
2722
  static get name() {
2620
2723
  return i;
@@ -2629,7 +2732,16 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2629
2732
  return this._subCommand ? this._subCommand.interactive : this._isInteractive === void 0 ? !!(e && (e.interactive || e.wasm?.interactive) || this._inspectedWasm && this._inspectedWasm.isInteractive) : !!this._isInteractive;
2630
2733
  }
2631
2734
  get captureInput() {
2632
- return this.interactive;
2735
+ return this._subCommand ? !!this._subCommand.captureInput : this.interactive;
2736
+ }
2737
+ get isRaw() {
2738
+ return !!(this.stdinStream && this.stdinStream.isRaw || this._subCommand && (this._subCommand.isRaw || this._subCommand.stdinStream && this._subCommand.stdinStream.isRaw));
2739
+ }
2740
+ get _inAltScreen() {
2741
+ return !!(this.__inAltScreen || this._subCommand && this._subCommand._inAltScreen);
2742
+ }
2743
+ set _inAltScreen(e) {
2744
+ this.__inAltScreen = !!e;
2633
2745
  }
2634
2746
  kill(e = "SIGINT") {
2635
2747
  this._subCommand && typeof this._subCommand.kill == "function" && this._subCommand.kill(e), super.kill(e);
@@ -2638,8 +2750,8 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2638
2750
  this._subCommand && typeof this._subCommand.onInput == "function" && this._subCommand.onInput(e);
2639
2751
  }
2640
2752
  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));
2753
+ 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;
2754
+ 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
2755
  try {
2644
2756
  if ((e.type === "wasm" || e.type === "custom-wasm") && (this._persistedWasmBytes || e.wasmUrl)) {
2645
2757
  let i = this._persistedWasmBytes;
@@ -2648,7 +2760,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2648
2760
  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
2761
  } catch {}
2650
2762
  if (!i && e.wasmUrl && (i = await this._fetchWasmBytes(e.wasmUrl)), i) {
2651
- r && (this._inspectedWasm = P(i)), await this._runRawWasmBytes(i, n);
2763
+ r && (this._inspectedWasm = F(i)), await this._runRawWasmBytes(i, n);
2652
2764
  return;
2653
2765
  }
2654
2766
  } else {
@@ -2665,19 +2777,19 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2665
2777
  }
2666
2778
  let c, l;
2667
2779
  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);
2780
+ 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
2781
  } finally {
2670
2782
  s && (globalThis.fetch = s);
2671
2783
  }
2672
2784
  if (l instanceof Uint8Array || l instanceof ArrayBuffer) {
2673
2785
  let e = l instanceof Uint8Array ? l : new Uint8Array(l);
2674
- r && (this._inspectedWasm = P(e)), await this._runRawWasmBytes(e, n);
2786
+ r && (this._inspectedWasm = F(e)), await this._runRawWasmBytes(e, n);
2675
2787
  } else if (l && (l.wasmBytes instanceof Uint8Array || l.wasm instanceof Uint8Array)) {
2676
2788
  let e = l.wasmBytes || l.wasm;
2677
- r && (this._inspectedWasm = P(e)), await this._runRawWasmBytes(e, n);
2789
+ r && (this._inspectedWasm = F(e)), await this._runRawWasmBytes(e, n);
2678
2790
  } else if (typeof l == "function") await this._runFunctionOrEmscripten(l, n, r, a);
2679
2791
  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));
2792
+ l.ready && await l.ready, r && (l.HEAPU8 instanceof Uint8Array || l.wasmBinary instanceof Uint8Array) && (this._inspectedWasm = F(l.wasmBinary || l.HEAPU8));
2681
2793
  let t = l.main || l.run || l.callMain || l.exec;
2682
2794
  if (typeof t == "function") await this._invokeCliFunction(t.bind(l), n);
2683
2795
  else if (l.promised || typeof l.raw == "function" || typeof l.json == "function") {
@@ -2705,34 +2817,38 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2705
2817
  }
2706
2818
  }
2707
2819
  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);
2820
+ 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
2821
  if (r) if (s) {
2710
2822
  let e = t.map((e) => e.string);
2711
2823
  this.result && Array.isArray(this.result.std) && (this.result.std.length = 0), this.exitCode = 0;
2712
2824
  for (let t of e) this.stdOut = t;
2713
2825
  } else {
2714
2826
  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;
2827
+ for (let t of I(i, e, this._inspectedWasm)) this.stdOut = t;
2716
2828
  }
2717
2829
  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
2830
  }
2719
2831
  }
2720
2832
  async _fetchWasmBytes(e) {
2721
- if (k.has(e)) return k.get(e);
2833
+ if (A.has(e)) return A.get(e);
2722
2834
  let n = t.fetch || (typeof fetch == "function" ? fetch : null);
2723
2835
  if (!n) throw Error("fetch is not available in this environment");
2724
2836
  let r = await n(e);
2725
2837
  if (!r || !r.ok) throw Error(`HTTP ${r ? r.status : "error"} fetching ${e}`);
2726
2838
  let i = new Uint8Array(await r.arrayBuffer());
2727
- return k.set(e, i), i;
2839
+ return A.set(e, i), i;
2728
2840
  }
2729
2841
  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;
2842
+ let r = new k(i, n, this.context);
2843
+ 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);
2844
+ let a = () => {
2845
+ this.emit("interactive"), this.context && typeof this.context.emit == "function" && this.context.emit("interactive");
2846
+ };
2847
+ r.on("interactive", a), this._subCommand = r;
2732
2848
  try {
2733
2849
  await r._runWasm(t);
2734
2850
  } finally {
2735
- this._subCommand = null;
2851
+ 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
2852
  }
2737
2853
  for (let e of r.result.getStdOutput()) e.type === "out" ? this.stdOut = e.string : e.type === "err" && (this.stdErr = e.string);
2738
2854
  this.exitCode = r.result.getExitCode();
@@ -2756,16 +2872,16 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2756
2872
  let n = t && t !== "." && !e.startsWith("/") ? `${t.replace(/\/+$/, "")}/${e}` : e, r = this.fs.getFileByPath(n) ?? this.fs.getFileByPath(e);
2757
2873
  return r == null ? null : typeof r == "string" ? r : new TextDecoder().decode(r);
2758
2874
  },
2759
- readBytes: (e) => A(this.fs, e),
2875
+ readBytes: (e) => j(this.fs, e),
2760
2876
  writeFile: (e, t, n) => {
2761
2877
  if (!this.fs) return;
2762
2878
  let r = n && n !== "." && !e.startsWith("/") ? `${n.replace(/\/+$/, "")}/${e}` : e;
2763
2879
  if (t instanceof Uint8Array || ArrayBuffer.isView(t)) {
2764
2880
  let e = r.endsWith(".wasm") ? "application/wasm" : "application/octet-stream";
2765
- j(this.fs, r, t, e);
2881
+ M(this.fs, r, t, e);
2766
2882
  } else this.fs.setFileByPath(r, String(t), !0);
2767
2883
  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);
2884
+ this.fs.setMode(r, 493);
2769
2885
  } catch {}
2770
2886
  },
2771
2887
  listFiles: (e, t) => {
@@ -2798,7 +2914,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2798
2914
  if (e && typeof e.status == "number") this.exitCode = e.status;
2799
2915
  else throw e;
2800
2916
  }
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") {
2917
+ 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
2918
  f.FS && l.size === 0 && (l = this._syncBrshToEmscriptenFs(f.FS, n));
2803
2919
  try {
2804
2920
  let e = await f.callMain(n);
@@ -2861,14 +2977,14 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2861
2977
  }), !t.loaded && typeof t.load == "function" && await t.load(e.coreUrl ? { coreURL: e.coreUrl } : void 0);
2862
2978
  let a = /* @__PURE__ */ new Set(), o = [];
2863
2979
  for (let e of n) if (!e.startsWith("-") && (o.push(e), this.fs.exists(e))) {
2864
- let n = A(this.fs, e);
2980
+ let n = j(this.fs, e);
2865
2981
  n && (await t.writeFile(e, n), a.add(e));
2866
2982
  }
2867
2983
  let s = await t.exec(n);
2868
2984
  for (let e of o) if (!a.has(e)) try {
2869
2985
  if (typeof t.readFile == "function") {
2870
2986
  let n = await t.readFile(e);
2871
- n && j(this.fs, e, n);
2987
+ n && M(this.fs, e, n);
2872
2988
  }
2873
2989
  } catch {}
2874
2990
  typeof s == "number" && s !== 0 && (this.exitCode = s, i.length === 0 && r.length > 0 && i.push(...r.splice(0, r.length)));
@@ -2885,7 +3001,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2885
3001
  let n = /* @__PURE__ */ new Set();
2886
3002
  if (!this.fs || !e || typeof e.writeFile != "function") return n;
2887
3003
  for (let r of t) if (!r.startsWith("-") && this.fs.exists(r)) {
2888
- let t = A(this.fs, r);
3004
+ let t = j(this.fs, r);
2889
3005
  if (t) try {
2890
3006
  e.writeFile(r, t), n.add(r);
2891
3007
  } catch {}
@@ -2898,8 +3014,8 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2898
3014
  let t = e.readFile(r);
2899
3015
  if (t) {
2900
3016
  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);
3017
+ if (M(this.fs, r, t, e), r.endsWith(".wasm") || r.endsWith(".wat")) try {
3018
+ this.fs.setMode(r, 493);
2903
3019
  } catch {}
2904
3020
  }
2905
3021
  } catch {}
@@ -2911,7 +3027,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2911
3027
  function ee(e, t) {
2912
3028
  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
3029
  }
2914
- function L(e, t) {
3030
+ function te(e, t) {
2915
3031
  if (!e || !t || typeof e.exists != "function" || typeof e.getFileByPath != "function") return null;
2916
3032
  try {
2917
3033
  let n = t.split("/").filter(Boolean);
@@ -2924,7 +3040,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2924
3040
  } catch {}
2925
3041
  return null;
2926
3042
  }
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;
3043
+ 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
3044
  })), A = /* @__PURE__ */ t(((e, t) => {
2929
3045
  var n = T();
2930
3046
  t.exports = class extends n {
@@ -2935,19 +3051,16 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
2935
3051
  return !0;
2936
3052
  }
2937
3053
  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
3054
+ return {
3055
+ 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,
3056
+ 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
3057
  };
2945
3058
  }
2946
3059
  _enterAltScreen() {
2947
3060
  this._inAltScreen || (this._inAltScreen = !0, this.stdinStream && this.stdinStream.setRawMode(!0), this.stdout && this.stdout.write("\x1B[?1049h\x1B[2J\x1B[H"));
2948
3061
  }
2949
3062
  _exitAltScreen() {
2950
- this._inAltScreen && (this._inAltScreen = !1, this.stdinStream && this.stdinStream.setRawMode(!1), this.stdout && this.stdout.write("\x1B[?1049l\x1B[?25h"));
3063
+ 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
3064
  }
2952
3065
  kill(e = "SIGINT") {
2953
3066
  this._exitAltScreen(), super.kill(e);
@@ -3302,12 +3415,13 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
3302
3415
  return n;
3303
3416
  }
3304
3417
  sandbox() {
3305
- let e = this;
3418
+ let e = this, t = Symbol.for("brsh.fs.target");
3306
3419
  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;
3420
+ get(n, i) {
3421
+ if (i === t) return e;
3422
+ if (!r.has(i)) return;
3423
+ let a = e[i];
3424
+ return typeof a == "function" ? a.bind(e) : a;
3311
3425
  },
3312
3426
  set() {
3313
3427
  return !1;
@@ -3366,66 +3480,66 @@ function F() {
3366
3480
  function I() {
3367
3481
  throw Error("clearTimeout has not been defined");
3368
3482
  }
3369
- function ee(e) {
3370
- if (U === setTimeout) return setTimeout(e, 0);
3371
- if ((U === F || !U) && setTimeout) return U = setTimeout, setTimeout(e, 0);
3483
+ function L(e) {
3484
+ if (ne === setTimeout) return setTimeout(e, 0);
3485
+ if ((ne === F || !ne) && setTimeout) return ne = setTimeout, setTimeout(e, 0);
3372
3486
  try {
3373
- return U(e, 0);
3487
+ return ne(e, 0);
3374
3488
  } catch {
3375
3489
  try {
3376
- return U.call(null, e, 0);
3490
+ return ne.call(null, e, 0);
3377
3491
  } catch {
3378
- return U.call(this, e, 0);
3492
+ return ne.call(this, e, 0);
3379
3493
  }
3380
3494
  }
3381
3495
  }
3382
- function L(e) {
3383
- if (ne === clearTimeout) return clearTimeout(e);
3384
- if ((ne === I || !ne) && clearTimeout) return ne = clearTimeout, clearTimeout(e);
3496
+ function ee(e) {
3497
+ if (U === clearTimeout) return clearTimeout(e);
3498
+ if ((U === I || !U) && clearTimeout) return U = clearTimeout, clearTimeout(e);
3385
3499
  try {
3386
- return ne(e);
3500
+ return U(e);
3387
3501
  } catch {
3388
3502
  try {
3389
- return ne.call(null, e);
3503
+ return U.call(null, e);
3390
3504
  } catch {
3391
- return ne.call(this, e);
3505
+ return U.call(this, e);
3392
3506
  }
3393
3507
  }
3394
3508
  }
3395
3509
  function te() {
3396
- !G || !K || (G = !1, K.length ? W = K.concat(W) : re = -1, W.length && R());
3510
+ !ie || !W || (ie = !1, W.length ? re = W.concat(re) : G = -1, re.length && R());
3397
3511
  }
3398
3512
  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;
3513
+ if (!ie) {
3514
+ var e = L(te);
3515
+ ie = !0;
3516
+ for (var t = re.length; t;) {
3517
+ for (W = re, re = []; ++G < t;) W && W[G].run();
3518
+ G = -1, t = re.length;
3405
3519
  }
3406
- K = null, G = !1, L(e);
3520
+ W = null, ie = !1, ee(e);
3407
3521
  }
3408
3522
  }
3409
3523
  function z(e, t) {
3410
3524
  this.fun = e, this.array = t;
3411
3525
  }
3412
3526
  function B() {}
3413
- var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
3527
+ var V, H, ne, U, re, ie, W, G, K, q, J = e((() => {
3414
3528
  V = { exports: {} }, H = V.exports = {}, (function() {
3415
3529
  try {
3416
- U = typeof setTimeout == "function" ? setTimeout : F;
3530
+ ne = typeof setTimeout == "function" ? setTimeout : F;
3417
3531
  } catch {
3418
- U = F;
3532
+ ne = F;
3419
3533
  }
3420
3534
  try {
3421
- ne = typeof clearTimeout == "function" ? clearTimeout : I;
3535
+ U = typeof clearTimeout == "function" ? clearTimeout : I;
3422
3536
  } catch {
3423
- ne = I;
3537
+ U = I;
3424
3538
  }
3425
- })(), W = [], G = !1, re = -1, H.nextTick = function(e) {
3539
+ })(), re = [], ie = !1, G = -1, H.nextTick = function(e) {
3426
3540
  var t = Array(arguments.length - 1);
3427
3541
  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);
3542
+ re.push(new z(e, t)), re.length === 1 && !ie && L(R);
3429
3543
  }, z.prototype.run = function() {
3430
3544
  this.fun.apply(null, this.array);
3431
3545
  }, 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 +3552,9 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
3438
3552
  throw Error("process.chdir is not supported");
3439
3553
  }, H.umask = function() {
3440
3554
  return 0;
3441
- }, q = V.exports, J = /* @__PURE__ */ P(q);
3442
- })), X = /* @__PURE__ */ t(((e, t) => {
3443
- b(), Y();
3555
+ }, K = V.exports, q = /* @__PURE__ */ P(K);
3556
+ })), Y = /* @__PURE__ */ t(((e, t) => {
3557
+ b(), J();
3444
3558
  var { BinaryFile: n, SymlinkRef: r, DeviceFile: i } = N(), a = new Uint8Array([
3445
3559
  66,
3446
3560
  82,
@@ -3468,7 +3582,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
3468
3582
  r
3469
3583
  ] };
3470
3584
  }
3471
- if (typeof e == "function") return n.commandsBundle || (d[t] = e.toString()), { $c: t };
3585
+ if (typeof e == "function") return n.commandsBundle || (d[t] = e.__source || e.toString()), { $c: t };
3472
3586
  if (typeof e == "string") {
3473
3587
  if (e.startsWith("data:")) {
3474
3588
  let t = e.indexOf(";"), n = e.indexOf(",", t);
@@ -3579,8 +3693,8 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
3579
3693
  let t = new DecompressionStream("gzip"), n = new Blob([e]).stream().pipeThrough(t), r = await new Response(n).arrayBuffer();
3580
3694
  return new Uint8Array(r);
3581
3695
  }
3582
- if (J !== void 0 && typeof J.getBuiltinModule == "function") {
3583
- let t = J.getBuiltinModule("zlib");
3696
+ if (q !== void 0 && typeof q.getBuiltinModule == "function") {
3697
+ let t = q.getBuiltinModule("zlib");
3584
3698
  if (t) return new Uint8Array(t.gunzipSync(y.from(e.buffer, e.byteOffset, e.byteLength)));
3585
3699
  }
3586
3700
  throw Error("Gzip decompression is not supported in this environment");
@@ -3599,8 +3713,8 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
3599
3713
  return p(new Uint8Array(n), t);
3600
3714
  }
3601
3715
  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");
3716
+ if (!/^https?:\/\//i.test(e) && q !== void 0 && typeof q.getBuiltinModule == "function" && typeof window > "u") try {
3717
+ let n = q.getBuiltinModule("fs");
3604
3718
  if (n && n.existsSync(e)) {
3605
3719
  let r = await n.promises.readFile(e);
3606
3720
  return p(new Uint8Array(r.buffer, r.byteOffset, r.byteLength), t);
@@ -3712,7 +3826,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
3712
3826
  }
3713
3827
  }
3714
3828
  };
3715
- })), ie = /* @__PURE__ */ t(((e, t) => {
3829
+ })), X = /* @__PURE__ */ t(((e, t) => {
3716
3830
  b();
3717
3831
  var n = N(), { BinaryFile: r, SymlinkRef: i, DeviceFile: a } = n;
3718
3832
  function o(e) {
@@ -3738,10 +3852,10 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
3738
3852
  t.exports = class extends n {
3739
3853
  constructor(e = "/", t = {}, n = {}, r = null) {
3740
3854
  if (super(), t instanceof Uint8Array || t instanceof ArrayBuffer) {
3741
- let { deserializeBinaryFilesystem: e } = X(), r = e(t);
3855
+ let { deserializeBinaryFilesystem: e } = Y(), r = e(t);
3742
3856
  t = r.filesystem, n = Object.assign({}, r.permissions, n);
3743
3857
  } 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);
3858
+ let { deserializeBinaryFilesystem: e } = Y(), r = e(t);
3745
3859
  t = r.filesystem, n = Object.assign({}, r.permissions, n);
3746
3860
  }
3747
3861
  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 +3897,11 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
3783
3897
  }), this._devices.stdin = new i("/dev/tty"), this._devices.stdout = new i("/dev/tty"), this._devices.stderr = new i("/dev/tty");
3784
3898
  }
3785
3899
  toBinaryContainer(e = {}) {
3786
- let { serializeBinaryFilesystem: t } = X();
3900
+ let { serializeBinaryFilesystem: t } = Y();
3787
3901
  return t(this.fileSystem, this.permissions, e);
3788
3902
  }
3789
3903
  static fromBinaryContainer(e, t = {}) {
3790
- let { deserializeBinaryFilesystem: n } = X();
3904
+ let { deserializeBinaryFilesystem: n } = Y();
3791
3905
  return n(e, t);
3792
3906
  }
3793
3907
  getFileByPath(e) {
@@ -4033,7 +4147,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
4033
4147
  }
4034
4148
  }, t.exports.BinaryFile = r, t.exports.SymlinkRef = i;
4035
4149
  })), ae = /* @__PURE__ */ t(((e, t) => {
4036
- Y();
4150
+ J();
4037
4151
  function n(e) {
4038
4152
  if (typeof e != "string") throw TypeError("Path must be a string. Received " + JSON.stringify(e));
4039
4153
  }
@@ -4071,7 +4185,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
4071
4185
  resolve: function() {
4072
4186
  for (var e = "", t = !1, i, a = arguments.length - 1; a >= -1 && !t; a--) {
4073
4187
  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);
4188
+ 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
4189
  }
4076
4190
  return e = r(e, !t), t ? e.length > 0 ? "/" + e : "/" : e.length > 0 ? e : ".";
4077
4191
  },
@@ -4201,11 +4315,11 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
4201
4315
  };
4202
4316
  a.posix = a, t.exports = a;
4203
4317
  })), oe = /* @__PURE__ */ t(((e, t) => {
4204
- b(), Y();
4318
+ b(), J();
4205
4319
  var r = O(), i = ae(), a = N(), { BinaryFile: o, SymlinkRef: s, isUtf8Text: c } = a;
4206
4320
  t.exports = class extends a {
4207
4321
  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()));
4322
+ 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
4323
  }
4210
4324
  get isRealFilesystem() {
4211
4325
  return !0;
@@ -4489,7 +4603,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
4489
4603
  }
4490
4604
  };
4491
4605
  })), se = /* @__PURE__ */ t(((e, t) => {
4492
- var n = ie();
4606
+ var n = X();
4493
4607
  t.exports = class {
4494
4608
  constructor(e) {
4495
4609
  this.options = e;
@@ -4534,7 +4648,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
4534
4648
  this.fs.setCwd(e);
4535
4649
  }
4536
4650
  source(e) {
4537
- this.vars = Object.assign({}, this.vars, e.vars), this.aliases = Object.assign({}, this.aliases, e.aliases);
4651
+ e && (this.vars = Object.assign({}, this.vars, e.vars || {}), this.aliases = Object.assign({}, this.aliases, e.aliases || {}));
4538
4652
  }
4539
4653
  clear() {
4540
4654
  typeof this._clearFn == "function" && this._clearFn();
@@ -4832,11 +4946,11 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
4832
4946
  pe = globalThis || self;
4833
4947
  })), he = /* @__PURE__ */ t(((e, t) => {
4834
4948
  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 + "(?:" + [
4949
+ 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
4950
  O,
4837
4951
  k,
4838
4952
  A
4839
- ].join("|") + ")" + L + ee + ")*", R = L + ee + te, z = "(?:" + [
4953
+ ].join("|") + ")" + ee + L + ")*", R = ee + L + te, z = "(?:" + [
4840
4954
  C,
4841
4955
  k,
4842
4956
  A
@@ -4846,7 +4960,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
4846
4960
  k,
4847
4961
  A,
4848
4962
  y
4849
- ].join("|") + ")", V = RegExp(v, "g"), H = RegExp(x, "g"), U = RegExp(E + "(?=" + E + ")|" + B + R, "g"), ne = RegExp([
4963
+ ].join("|") + ")", V = RegExp(v, "g"), H = RegExp(x, "g"), ne = RegExp(E + "(?=" + E + ")|" + B + R, "g"), U = RegExp([
4850
4964
  j + "?" + w + "+" + F + "(?=" + [
4851
4965
  b,
4852
4966
  j,
@@ -4861,7 +4975,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
4861
4975
  j + "+" + I,
4862
4976
  S,
4863
4977
  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 = {
4978
+ ].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
4979
  À: "A",
4866
4980
  Á: "A",
4867
4981
  Â: "A",
@@ -5052,16 +5166,16 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
5052
5166
  œ: "oe",
5053
5167
  ʼn: "'n",
5054
5168
  ſ: "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) {
5169
+ }, G = typeof pe == "object" && pe && pe.Object === Object && pe, K = typeof self == "object" && self && self.Object === Object && self, q = G || K || Function("return this")();
5170
+ function J(e, t, n, r) {
5057
5171
  var i = -1, a = e ? e.length : 0;
5058
5172
  for (r && a && (n = e[++i]); ++i < a;) n = t(n, e[i], i, e);
5059
5173
  return n;
5060
5174
  }
5061
- function X(e) {
5175
+ function Y(e) {
5062
5176
  return e.split("");
5063
5177
  }
5064
- function ie(e) {
5178
+ function X(e) {
5065
5179
  return e.match(i) || [];
5066
5180
  }
5067
5181
  function ae(e) {
@@ -5069,23 +5183,23 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
5069
5183
  return e?.[t];
5070
5184
  };
5071
5185
  }
5072
- var oe = ae(K);
5186
+ var oe = ae(W);
5073
5187
  function se(e) {
5074
- return W.test(e);
5188
+ return re.test(e);
5075
5189
  }
5076
5190
  function ce(e) {
5077
- return G.test(e);
5191
+ return ie.test(e);
5078
5192
  }
5079
5193
  function le(e) {
5080
- return se(e) ? ue(e) : X(e);
5194
+ return se(e) ? ue(e) : Y(e);
5081
5195
  }
5082
5196
  function ue(e) {
5083
- return e.match(U) || [];
5197
+ return e.match(ne) || [];
5084
5198
  }
5085
5199
  function de(e) {
5086
- return e.match(ne) || [];
5200
+ return e.match(U) || [];
5087
5201
  }
5088
- var Z = Object.prototype.toString, fe = J.Symbol, he = fe ? fe.prototype : void 0, ge = he ? he.toString : void 0;
5202
+ var Z = Object.prototype.toString, fe = q.Symbol, he = fe ? fe.prototype : void 0, ge = he ? he.toString : void 0;
5089
5203
  function _e(e, t, n) {
5090
5204
  var r = -1, i = e.length;
5091
5205
  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 +5225,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
5111
5225
  }
5112
5226
  function xe(e) {
5113
5227
  return function(t) {
5114
- return Y(ke(De(t).replace(V, "")), e, "");
5228
+ return J(ke(De(t).replace(V, "")), e, "");
5115
5229
  };
5116
5230
  }
5117
5231
  function Se(e) {
@@ -5134,11 +5248,11 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
5134
5248
  }
5135
5249
  var Oe = be("toUpperCase");
5136
5250
  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) || [];
5251
+ return e = we(e), t = n ? void 0 : t, t === void 0 ? ce(e) ? de(e) : X(e) : e.match(t) || [];
5138
5252
  }
5139
5253
  t.exports = Te;
5140
5254
  })), ge = /* @__PURE__ */ t(((e, t) => {
5141
- Y();
5255
+ J();
5142
5256
  var n = de(), r = Z(), i = fe(), a = he(), o = {
5143
5257
  short: /^-([^\d-])$/,
5144
5258
  long: /^--(\S+)/,
@@ -5146,10 +5260,10 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
5146
5260
  optEquals: /^(--\S+?)=(.*)/
5147
5261
  }, s = class extends Array {
5148
5262
  load(e) {
5149
- if (this.clear(), e && e !== J.argv) e = n(e);
5263
+ if (this.clear(), e && e !== q.argv) e = n(e);
5150
5264
  else {
5151
- e = J.argv.slice(0);
5152
- let t = J.execArgv.some(m) ? 1 : 2;
5265
+ e = q.argv.slice(0);
5266
+ let t = q.execArgv.some(m) ? 1 : 2;
5153
5267
  e.splice(0, t);
5154
5268
  }
5155
5269
  e.forEach((e) => this.push(String(e)));
@@ -6569,7 +6683,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
6569
6683
  let e = new TextDecoder().decode(t);
6570
6684
  this.fs.setFileByPath(s, e, !0);
6571
6685
  } else {
6572
- let { BinaryFile: e } = ie(), r = e ? new e(t.buffer, n || "application/octet-stream") : t;
6686
+ let { BinaryFile: e } = X(), r = e ? new e(t.buffer, n || "application/octet-stream") : t;
6573
6687
  this.fs.setFileByPath(s, r, !0);
6574
6688
  }
6575
6689
  } catch (e) {
@@ -7037,7 +7151,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7037
7151
  "%URIErrorPrototype%": ["URIError", "prototype"],
7038
7152
  "%WeakMapPrototype%": ["WeakMap", "prototype"],
7039
7153
  "%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) {
7154
+ }, 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
7155
  var t = R(e, 0, 1), n = R(e, -1);
7042
7156
  if (t === "%" && n !== "%") throw new c("invalid intrinsic syntax, expected closing `%`");
7043
7157
  if (n === "%" && t !== "%") throw new c("invalid intrinsic syntax, expected opening `%`");
@@ -7045,7 +7159,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7045
7159
  return te(e, B, function(e, t, n, i) {
7046
7160
  r[r.length] = n ? te(i, V, "$1") : t || e;
7047
7161
  }), r;
7048
- }, U = function(e, t) {
7162
+ }, ne = function(e, t) {
7049
7163
  var n = e, r;
7050
7164
  if (I(P, n) && (r = P[n], n = "%" + r[0] + "%"), I(M, n)) {
7051
7165
  var i = M[n];
@@ -7062,8 +7176,8 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7062
7176
  if (typeof e != "string" || e.length === 0) throw new l("intrinsic name must be a non-empty string");
7063
7177
  if (arguments.length > 1 && typeof t != "boolean") throw new l("\"allowMissing\" argument must be a boolean");
7064
7178
  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)));
7179
+ 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;
7180
+ u && (r = u[0], ee(n, L([0, 1], u)));
7067
7181
  for (var d = 1, f = !0; d < n.length; d += 1) {
7068
7182
  var p = n[d], m = R(p, 0, 1), h = R(p, -1);
7069
7183
  if ((m === "\"" || m === "'" || m === "`" || h === "\"" || h === "'" || h === "`") && m !== h) throw new c("property names with quotes must have matching quotes");
@@ -7279,23 +7393,23 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7279
7393
  }
7280
7394
  return v.call(t, n, "$&_");
7281
7395
  }
7282
- var P = Lt(), F = P.custom, I = K(F) ? F : null, ee = {
7396
+ var P = Lt(), F = P.custom, I = W(F) ? F : null, L = {
7283
7397
  __proto__: null,
7284
7398
  double: "\"",
7285
7399
  single: "'"
7286
- }, L = {
7400
+ }, ee = {
7287
7401
  __proto__: null,
7288
7402
  double: /(["\\])/g,
7289
7403
  single: /(['\\])/g
7290
7404
  };
7291
7405
  t.exports = function e(t, n, r, o) {
7292
7406
  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;
7407
+ if (q(s, "quoteStyle") && !q(L, s.quoteStyle)) throw TypeError("option \"quoteStyle\" must be \"single\" or \"double\"");
7408
+ 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`");
7409
+ var u = q(s, "customInspect") ? s.customInspect : !0;
7296
7410
  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`");
7411
+ 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`");
7412
+ if (q(s, "numericSeparator") && typeof s.numericSeparator != "boolean") throw TypeError("option \"numericSeparator\", if provided, must be `true` or `false`");
7299
7413
  var d = s.numericSeparator;
7300
7414
  if (t === void 0) return "undefined";
7301
7415
  if (t === null) return "null";
@@ -7314,32 +7428,32 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7314
7428
  if (r === void 0 && (r = 0), r >= h && h > 0 && typeof t == "object") return B(t) ? "[Array]" : "[Object]";
7315
7429
  var g = ve(s, r);
7316
7430
  if (o === void 0) o = [];
7317
- else if (ie(o, t) >= 0) return "[Circular]";
7431
+ else if (X(o, t) >= 0) return "[Circular]";
7318
7432
  function y(t, n, i) {
7319
7433
  if (n && (o = w.call(o), o.push(n)), i) {
7320
7434
  var a = { depth: s.depth };
7321
- return J(s, "quoteStyle") && (a.quoteStyle = s.quoteStyle), e(t, a, r + 1, o);
7435
+ return q(s, "quoteStyle") && (a.quoteStyle = s.quoteStyle), e(t, a, r + 1, o);
7322
7436
  }
7323
7437
  return e(t, s, r + 1, o);
7324
7438
  }
7325
7439
  if (typeof t == "function" && !H(t)) {
7326
- var x = X(t), T = be(t, y);
7440
+ var x = Y(t), T = be(t, y);
7327
7441
  return "[Function" + (x ? ": " + x : " (anonymous)") + "]" + (T.length > 0 ? " { " + C.call(T, ", ") + " }" : "");
7328
7442
  }
7329
- if (K(t)) {
7443
+ if (W(t)) {
7330
7444
  var D = k ? v.call(String(t), /^(Symbol\(.*\))_[^)]*$/, "$1") : O.call(t);
7331
7445
  return typeof t == "object" && !k ? fe(D) : D;
7332
7446
  }
7333
7447
  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);
7448
+ 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
7449
  return F += ">", t.childNodes && t.childNodes.length && (F += "..."), F += "</" + b.call(String(t.nodeName)) + ">", F;
7336
7450
  }
7337
7451
  if (B(t)) {
7338
7452
  if (t.length === 0) return "[]";
7339
- var q = be(t, y);
7340
- return g && !_e(q) ? "[" + ye(q, g) + "]" : "[ " + C.call(q, ", ") + " ]";
7453
+ var K = be(t, y);
7454
+ return g && !_e(K) ? "[" + ye(K, g) + "]" : "[ " + C.call(K, ", ") + " ]";
7341
7455
  }
7342
- if (U(t)) {
7456
+ if (ne(t)) {
7343
7457
  var Z = be(t, y);
7344
7458
  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
7459
  }
@@ -7362,20 +7476,20 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7362
7476
  if (oe(t)) return he("WeakMap");
7363
7477
  if (le(t)) return he("WeakSet");
7364
7478
  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)));
7479
+ if (re(t)) return fe(y(Number(t)));
7480
+ if (G(t)) return fe(y(E.call(t)));
7481
+ if (ie(t)) return fe(p.call(t));
7482
+ if (U(t)) return fe(y(String(t)));
7369
7483
  if (typeof window < "u" && t === window) return "{ [object Window] }";
7370
7484
  if (typeof globalThis < "u" && t === globalThis || pe !== void 0 && t === pe) return "{ [object globalThis] }";
7371
7485
  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 || []), ": ") + "] " : "");
7486
+ 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
7487
  return Se.length === 0 ? Ee + "{}" : g ? Ee + "{" + ye(Se, g) + "}" : Ee + "{ " + C.call(Se, ", ") + " }";
7374
7488
  }
7375
7489
  return String(t);
7376
7490
  };
7377
7491
  function te(e, t, n) {
7378
- var r = ee[n.quoteStyle || t];
7492
+ var r = L[n.quoteStyle || t];
7379
7493
  return r + e + r;
7380
7494
  }
7381
7495
  function R(e) {
@@ -7385,27 +7499,27 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7385
7499
  return !A || !(typeof e == "object" && (A in e || e[A] !== void 0));
7386
7500
  }
7387
7501
  function B(e) {
7388
- return Y(e) === "[object Array]" && z(e);
7502
+ return J(e) === "[object Array]" && z(e);
7389
7503
  }
7390
7504
  function V(e) {
7391
- return Y(e) === "[object Date]" && z(e);
7505
+ return J(e) === "[object Date]" && z(e);
7392
7506
  }
7393
7507
  function H(e) {
7394
- return Y(e) === "[object RegExp]" && z(e);
7395
- }
7396
- function U(e) {
7397
- return Y(e) === "[object Error]" && z(e);
7508
+ return J(e) === "[object RegExp]" && z(e);
7398
7509
  }
7399
7510
  function ne(e) {
7400
- return Y(e) === "[object String]" && z(e);
7511
+ return J(e) === "[object Error]" && z(e);
7401
7512
  }
7402
- function W(e) {
7403
- return Y(e) === "[object Number]" && z(e);
7513
+ function U(e) {
7514
+ return J(e) === "[object String]" && z(e);
7404
7515
  }
7405
- function G(e) {
7406
- return Y(e) === "[object Boolean]" && z(e);
7516
+ function re(e) {
7517
+ return J(e) === "[object Number]" && z(e);
7518
+ }
7519
+ function ie(e) {
7520
+ return J(e) === "[object Boolean]" && z(e);
7407
7521
  }
7408
- function K(e) {
7522
+ function W(e) {
7409
7523
  if (k) return e && typeof e == "object" && e instanceof Symbol;
7410
7524
  if (typeof e == "symbol") return !0;
7411
7525
  if (!e || typeof e != "object" || !O) return !1;
@@ -7414,28 +7528,28 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7414
7528
  } catch {}
7415
7529
  return !1;
7416
7530
  }
7417
- function re(e) {
7531
+ function G(e) {
7418
7532
  if (!e || typeof e != "object" || !E) return !1;
7419
7533
  try {
7420
7534
  return E.call(e), !0;
7421
7535
  } catch {}
7422
7536
  return !1;
7423
7537
  }
7424
- var q = Object.prototype.hasOwnProperty || function(e) {
7538
+ var K = Object.prototype.hasOwnProperty || function(e) {
7425
7539
  return e in this;
7426
7540
  };
7427
- function J(e, t) {
7428
- return q.call(e, t);
7541
+ function q(e, t) {
7542
+ return K.call(e, t);
7429
7543
  }
7430
- function Y(e) {
7544
+ function J(e) {
7431
7545
  return m.call(e);
7432
7546
  }
7433
- function X(e) {
7547
+ function Y(e) {
7434
7548
  if (e.name) return e.name;
7435
7549
  var t = g.call(h.call(e), /^function\s*([\w$]+)/);
7436
7550
  return t ? t[1] : null;
7437
7551
  }
7438
- function ie(e, t) {
7552
+ function X(e, t) {
7439
7553
  if (e.indexOf) return e.indexOf(t);
7440
7554
  for (var n = 0, r = e.length; n < r; n++) if (e[n] === t) return n;
7441
7555
  return -1;
@@ -7507,7 +7621,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7507
7621
  var n = e.length - t.maxStringLength, r = "... " + n + " more character" + (n > 1 ? "s" : "");
7508
7622
  return de(_.call(e, 0, t.maxStringLength), t) + r;
7509
7623
  }
7510
- var i = L[t.quoteStyle || "single"];
7624
+ var i = ee[t.quoteStyle || "single"];
7511
7625
  return i.lastIndex = 0, te(v.call(v.call(e, i, "\\$1"), /[\x00-\x1f]/g, Z), "single", t);
7512
7626
  }
7513
7627
  function Z(e) {
@@ -7531,7 +7645,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7531
7645
  return e + " (" + t + ") {" + i + "}";
7532
7646
  }
7533
7647
  function _e(e) {
7534
- for (var t = 0; t < e.length; t++) if (ie(e[t], "\n") >= 0) return !1;
7648
+ for (var t = 0; t < e.length; t++) if (X(e[t], "\n") >= 0) return !1;
7535
7649
  return !0;
7536
7650
  }
7537
7651
  function ve(e, t) {
@@ -7553,14 +7667,14 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
7553
7667
  var n = B(e), r = [];
7554
7668
  if (n) {
7555
7669
  r.length = e.length;
7556
- for (var i = 0; i < e.length; i++) r[i] = J(e, i) ? t(e[i], e) : "";
7670
+ for (var i = 0; i < e.length; i++) r[i] = q(e, i) ? t(e[i], e) : "";
7557
7671
  }
7558
7672
  var a = typeof D == "function" ? D(e) : [], o;
7559
7673
  if (k) {
7560
7674
  o = {};
7561
7675
  for (var s = 0; s < a.length; s++) o["$" + a[s]] = a[s];
7562
7676
  }
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))));
7677
+ 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
7678
  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
7679
  return r;
7566
7680
  }
@@ -8474,15 +8588,15 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
8474
8588
  }), t.exports = s;
8475
8589
  })), ur = /* @__PURE__ */ t(((e, t) => {
8476
8590
  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;
8591
+ 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
8592
  String.prototype.regexIndexOf = function(e, t) {
8479
8593
  let n = this.substring(t || 0).search(e);
8480
8594
  return n >= 0 ? n + (t || 0) : n;
8481
8595
  }, lr().shim();
8482
- var S = class e extends v {
8596
+ var C = class e extends S {
8483
8597
  constructor(e) {
8484
8598
  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;
8599
+ 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
8600
  if (this.context = new n(Object.assign({}, e, {
8487
8601
  clearFn: this.clear.bind(this),
8488
8602
  destroyFn: this.destroy.bind(this),
@@ -8495,19 +8609,24 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
8495
8609
  let e = (o ? "i" : "") + (a ? "c" : "");
8496
8610
  e && this.context.setVar("-", e);
8497
8611
  }
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
8612
+ 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;
8613
+ let v = typeof h == "number" && h > 0 ? Math.floor(h) : 80, y = typeof _ == "number" && _ > 0 ? Math.floor(_) : 24;
8614
+ if ((typeof h == "number" && h > 0 || typeof _ == "number" && _ > 0) && (this._terminalSize = {
8615
+ cols: v,
8616
+ rows: y
8617
+ }, this.context.setVar("COLUMNS", String(v)), this.context.setVar("LINES", String(y))), this.stdinStream = new l({
8618
+ columns: v,
8619
+ rows: y
8501
8620
  }), this.stdout = new l({
8502
- columns: 80,
8503
- rows: 24,
8621
+ columns: v,
8622
+ rows: y,
8504
8623
  onWrite: (e) => this.emit("data", e)
8505
8624
  }), this.stderr = new l({
8506
- columns: 80,
8507
- rows: 24,
8625
+ columns: v,
8626
+ rows: y,
8508
8627
  onWrite: (e) => this.emit("data", e)
8509
8628
  }), 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;
8629
+ 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
8630
  else {
8512
8631
  this.context.setFilesystem(u, d), this.context.setCwd(f);
8513
8632
  let e = this.context.fs.exists(this.context.getVar("PATH"));
@@ -8529,7 +8648,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
8529
8648
  }
8530
8649
  }, o = a();
8531
8650
  try {
8532
- let e = await g(t, n), s = a(), c = [];
8651
+ let e = await _(t, n), s = a(), c = [];
8533
8652
  for (let [e, t] of Object.entries(s)) o[e] !== t && typeof t == "function" && c.push(t);
8534
8653
  let l = this.context._onFsChange;
8535
8654
  this.context._onFsChange = null, this.context.setFilesystem(e.filesystem, e.permissions);
@@ -8587,12 +8706,12 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
8587
8706
  };
8588
8707
  }
8589
8708
  _loadDefaultCommands() {
8590
- f.forEach((e) => {
8709
+ p.forEach((e) => {
8591
8710
  this.context.setCommand(e);
8592
8711
  });
8593
8712
  }
8594
8713
  _loadBuiltinCommands(e = !1) {
8595
- d.forEach((e) => {
8714
+ f.forEach((e) => {
8596
8715
  this.context.setCommand(e);
8597
8716
  }), e || this.context.fs.setMode(this.context.getVar("PATH"), 365);
8598
8717
  }
@@ -8895,7 +9014,9 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
8895
9014
  }, m.set(n.file, e)), e.lines.push(t);
8896
9015
  }
8897
9016
  };
8898
- return this.runningCommand = p, this.runningCommand.on && (this.runningCommand.on("flush", (e) => {
9017
+ this.runningCommand = p;
9018
+ let g = this.stdout && this.stdout.columns || this.stdinStream && this.stdinStream.columns, _ = this.stdout && this.stdout.rows || this.stdinStream && this.stdinStream.rows;
9019
+ 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
9020
  e.forEach(h);
8900
9021
  }), this.runningCommand.on("stdout", (e) => {
8901
9022
  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 +9121,13 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
9000
9121
  }
9001
9122
  _loadHistory() {
9002
9123
  try {
9003
- let e = this.context.fs._getFileRaw(u);
9124
+ let e = this.context.fs._getFileRaw(d);
9004
9125
  e && typeof e == "string" && e.length > 0 && (this._history = e.split("\n").filter((e) => e.length > 0));
9005
9126
  } catch {}
9006
9127
  }
9007
9128
  _saveHistory() {
9008
9129
  try {
9009
- this.context.fs._setFileRaw(u, this._history.join("\n"), !0);
9130
+ this.context.fs._setFileRaw(d, this._history.join("\n"), !0);
9010
9131
  } catch {}
9011
9132
  }
9012
9133
  _navigateHistory(e) {
@@ -9038,13 +9159,13 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
9038
9159
  _handleStdinData(e) {
9039
9160
  let t = typeof e == "string" ? e : e instanceof Uint8Array || y !== void 0 && y.isBuffer(e) ? new TextDecoder().decode(e) : String(e ?? "");
9040
9161
  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)) {
9162
+ 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);
9163
+ if (n && !r) {
9043
9164
  typeof t.kill == "function" && t.kill("SIGINT"), !t.interactive && !t._inAltScreen && this.stdout.write("^C\r\n");
9044
9165
  return;
9045
9166
  }
9046
- let n = t.stdinStream && t.stdinStream.listenerCount("data") > 1;
9047
- if (t.captureInput || t.interactive || t._inAltScreen || n) {
9167
+ let i = u(t);
9168
+ if (t.captureInput || t.interactive || t._inAltScreen || i) {
9048
9169
  t.stdinStream.pushData(e);
9049
9170
  return;
9050
9171
  }
@@ -9259,7 +9380,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
9259
9380
  let n = await this._runAndCapture(e[1]);
9260
9381
  t = t.replace(e[0], n);
9261
9382
  }
9262
- let i = t.matchAll(_), a = i.next();
9383
+ let i = t.matchAll(v), a = i.next();
9263
9384
  for (; !a.done;) {
9264
9385
  let n = a.value[1] || a.value[2], r = this.context.getVar(n);
9265
9386
  t = t.replace(new RegExp(e._escapeRegExp(a.value[0]), "g"), String(r)), a = i.next();
@@ -9381,8 +9502,8 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
9381
9502
  }
9382
9503
  static async create(t = {}) {
9383
9504
  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);
9505
+ if (g(n) || n && typeof n == "object" && g(n.filesystem)) {
9506
+ let e = await _(n, r);
9386
9507
  n = e.filesystem, r = e.permissions;
9387
9508
  }
9388
9509
  let a = new e(Object.assign({}, i, {
@@ -9395,7 +9516,7 @@ var V, H, U, ne, W, G, K, re, q, J, Y = e((() => {
9395
9516
  return e.create(Object.assign({}, n, { filesystem: t }));
9396
9517
  }
9397
9518
  };
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;
9519
+ 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
9520
  }));
9400
9521
  //#endregion
9401
9522
  export default ur();