brsh 3.6.2 → 3.8.0

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.
@@ -24,7 +24,10 @@ function r(e) {
24
24
  link: e.link
25
25
  };
26
26
  }
27
- var i = class {
27
+ function i(e) {
28
+ return e ? e.ch === " " && e.fg === null && e.bg === null && e.flags === 0 && e.link === null : !0;
29
+ }
30
+ var a = class {
28
31
  constructor(e = 80, t = 24, n = {}) {
29
32
  this.cols = Math.max(1, e), this.rows = Math.max(1, t), this.maxScrollback = n.maxScrollback ?? 1e3, this.convertEol = n.convertEol !== !1, this.scrollback = [], this.viewportOffset = 0, this.primaryGrid = this._createGrid(this.cols, this.rows), this.altGrid = this._createGrid(this.cols, this.rows), this.isAltScreen = !1, this.cursorRow = 0, this.cursorCol = 0, this.pendingWrap = !1, this.cursorVisible = !0, this.autoWrap = !0, this.originMode = !1, this.scrollTop = 0, this.scrollBottom = this.rows - 1, this.curFg = null, this.curBg = null, this.curFlags = 0, this.curLink = null, this._savedPrimary = null, this._savedCursorPrimary = null, this._savedCursorAlt = null, this.dirtyRows = /* @__PURE__ */ new Set(), this.fullRedrawNeeded = !0, this._markAllDirty();
30
33
  }
@@ -34,7 +37,7 @@ var i = class {
34
37
  _createRow(e = this.cols, t = !1) {
35
38
  let r = t ? this.curFg : null, i = t ? this.curBg : null, a = t ? this.curFlags : 0, o = Array(e);
36
39
  for (let t = 0; t < e; t++) o[t] = n(" ", r, i, a, null);
37
- return o;
40
+ return o.isWrapped = !1, o;
38
41
  }
39
42
  _createGrid(e, t) {
40
43
  let n = Array(t);
@@ -109,7 +112,10 @@ var i = class {
109
112
  t !== 0 && (this.cursorCol = Math.max(0, Math.min(this.cols - 1, this.cursorCol + t))), this.pendingWrap = !1, this._markRowDirty(this.cursorRow);
110
113
  }
111
114
  putChar(e) {
112
- this.pendingWrap && (this.autoWrap ? (this.cursorCol = 0, this.pendingWrap = !1, this._indexDown()) : this.pendingWrap = !1);
115
+ if (this.pendingWrap) if (this.autoWrap) {
116
+ let e = this.grid[this.cursorRow];
117
+ e && (e.isWrapped = !0), this.cursorCol = 0, this.pendingWrap = !1, this._indexDown();
118
+ } else this.pendingWrap = !1;
113
119
  let t = this.grid[this.cursorRow];
114
120
  if (t && this.cursorCol >= 0 && this.cursorCol < this.cols) {
115
121
  let n = t[this.cursorCol];
@@ -147,7 +153,10 @@ var i = class {
147
153
  let i = this.grid, a = Math.min(e, n - t + 1);
148
154
  for (let e = 0; e < a; e++) {
149
155
  let e = i[t];
150
- !this.isAltScreen && t === 0 && this.maxScrollback > 0 && (this.scrollback.push(e.map(r)), this.scrollback.length > this.maxScrollback && this.scrollback.shift());
156
+ if (!this.isAltScreen && t === 0 && this.maxScrollback > 0) {
157
+ let t = e.map(r);
158
+ t.isWrapped = !!e.isWrapped, this.scrollback.push(t), this.scrollback.length > this.maxScrollback && this.scrollback.shift();
159
+ }
151
160
  for (let e = t; e < n; e++) i[e] = i[e + 1];
152
161
  i[n] = this._createRow(this.cols, !0);
153
162
  }
@@ -168,8 +177,8 @@ var i = class {
168
177
  if (e === 0) r = this.cursorCol;
169
178
  else if (e === 1) i = this.cursorCol;
170
179
  else if (e !== 2) return;
171
- for (let e = r; e <= i; e++) t[e] = n(" ", this.curFg, this.curBg, this.curFlags, null);
172
- this.pendingWrap = !1, this._markRowDirty(this.cursorRow);
180
+ for (let e = r; e <= i; e++) e < t.length && (t[e] = n(" ", this.curFg, this.curBg, this.curFlags, null));
181
+ (e === 2 || e === 0 && this.cursorCol === 0) && (t.isWrapped = !1), this.pendingWrap = !1, this._markRowDirty(this.cursorRow);
173
182
  }
174
183
  eraseInDisplay(e = 0) {
175
184
  let t = this.grid;
@@ -217,16 +226,88 @@ var i = class {
217
226
  resize(e, t) {
218
227
  let r = Math.max(1, e), i = Math.max(1, t);
219
228
  if (r === this.cols && i === this.rows) return;
220
- let a = (e) => {
221
- let t = Array(i);
222
- for (let a = 0; a < i; a++) {
223
- let i = Array(r), o = a < e.length ? e[a] : null;
224
- for (let e = 0; e < r; e++) i[e] = o && e < o.length ? o[e] : n(" ", null, null, 0, null);
225
- t[a] = i;
229
+ if (this.isAltScreen) {
230
+ let e = (e) => {
231
+ let t = Array(i);
232
+ for (let a = 0; a < i; a++) {
233
+ let i = Array(r), o = a < e.length ? e[a] : null;
234
+ for (let e = 0; e < r; e++) i[e] = o && e < o.length ? o[e] : n(" ", null, null, 0, null);
235
+ i.isWrapped = !1, t[a] = i;
236
+ }
237
+ return t;
238
+ };
239
+ this.altGrid = e(this.altGrid), this.cols = r, this.rows = i, this.scrollTop = 0, this.scrollBottom = i - 1, this.cursorRow = Math.min(i - 1, this.cursorRow), this.cursorCol = Math.min(r - 1, this.cursorCol), this.pendingWrap = !1, this._markAllDirty();
240
+ return;
241
+ }
242
+ let a = this._reflowPrimaryBuffer(r, i);
243
+ this.scrollback = a.scrollback, this.primaryGrid = a.primaryGrid, this.cursorRow = a.cursorRow, this.cursorCol = a.cursorCol;
244
+ let o = Array(i);
245
+ for (let e = 0; e < i; e++) {
246
+ let t = Array(r), i = e < this.altGrid.length ? this.altGrid[e] : null;
247
+ for (let e = 0; e < r; e++) t[e] = i && e < i.length ? i[e] : n(" ", null, null, 0, null);
248
+ t.isWrapped = !1, o[e] = t;
249
+ }
250
+ this.altGrid = o, this.cols = r, this.rows = i, this.scrollTop = 0, this.scrollBottom = i - 1, this.pendingWrap = !1, this.viewportOffset = Math.min(this.scrollback.length, this.viewportOffset), this._markAllDirty();
251
+ }
252
+ _reflowPrimaryBuffer(e, t) {
253
+ let a = this.cols, o = [...this.scrollback, ...this.primaryGrid], s = this.scrollback.length + this.cursorRow, c = this.cursorCol, l = s;
254
+ for (let e = o.length - 1; e >= 0; e--) {
255
+ let t = o[e];
256
+ if (t && (t.isWrapped || t.some((e) => !i(e)))) {
257
+ l = Math.max(l, e);
258
+ break;
259
+ }
260
+ }
261
+ let u = o.slice(0, l + 1), d = [], f = null;
262
+ for (let e = 0; e < u.length; e++) {
263
+ let t = u[e], o = e === s;
264
+ f ||= {
265
+ cells: [],
266
+ cursorPos: null,
267
+ isWrapped: !1
268
+ };
269
+ let l = -1;
270
+ for (let e = t.length - 1; e >= 0; e--) if (!i(t[e])) {
271
+ l = e;
272
+ break;
226
273
  }
227
- return t;
274
+ let p = t.isWrapped ? a : l + 1;
275
+ o && c >= p && (p = c + 1);
276
+ let m = f.cells.length;
277
+ o && (f.cursorPos = m + c);
278
+ for (let e = 0; e < p; e++) f.cells.push(e < t.length ? r(t[e]) : n(" "));
279
+ f.isWrapped = !!t.isWrapped, t.isWrapped || (d.push(f), f = null);
280
+ }
281
+ f && d.push(f);
282
+ let p = [], m = null, h = null;
283
+ for (let t of d) {
284
+ let r = t.cells, i = r.length;
285
+ if (i === 0) {
286
+ let n = this._createRow(e);
287
+ t.cursorPos !== null && (m = p.length, h = 0), p.push(n);
288
+ continue;
289
+ }
290
+ let a = 0;
291
+ for (; a < i;) {
292
+ let o = Math.min(e, i - a), s = Array(e);
293
+ for (let t = 0; t < e; t++) t < o ? s[t] = r[a + t] : s[t] = n(" ");
294
+ let c = a + o >= i;
295
+ s.isWrapped = c ? t.isWrapped : !0, t.cursorPos !== null && t.cursorPos >= a && (t.cursorPos < a + e || c) && (m = p.length, h = Math.min(e - 1, t.cursorPos - a)), p.push(s), a += e;
296
+ }
297
+ }
298
+ m === null && (m = Math.min(t - 1, p.length - 1), h = 0);
299
+ let g = [], _ = [];
300
+ if (p.length <= t) for (g = [], _ = p; _.length < t;) _.push(this._createRow(e));
301
+ else {
302
+ let e = p.length - t;
303
+ g = p.slice(0, e), this.maxScrollback > 0 && g.length > this.maxScrollback && (g = g.slice(g.length - this.maxScrollback)), _ = p.slice(e), m = Math.max(0, m - e);
304
+ }
305
+ return {
306
+ scrollback: g,
307
+ primaryGrid: _,
308
+ cursorRow: Math.min(t - 1, m),
309
+ cursorCol: Math.min(e - 1, h)
228
310
  };
229
- this.primaryGrid = a(this.primaryGrid), this.altGrid = a(this.altGrid), this.cols = r, this.rows = i, this.scrollTop = 0, this.scrollBottom = i - 1, this.cursorRow = Math.min(i - 1, this.cursorRow), this.cursorCol = Math.min(r - 1, this.cursorCol), this.pendingWrap = !1, this._markAllDirty();
230
311
  }
231
312
  scrollViewport(e) {
232
313
  if (this.isAltScreen) return;
@@ -260,7 +341,7 @@ var i = class {
260
341
  for (let e = 0; e < this.rows; e++) n.push(this.getLineText(e, t));
261
342
  return n.join("\n");
262
343
  }
263
- }, a = 0, o = 1, s = 2, c = 3, l = 4, u = 5, d = {
344
+ }, o = 0, s = 1, c = 2, l = 3, u = 4, d = 5, f = {
264
345
  "`": "◆",
265
346
  a: "▒",
266
347
  f: "°",
@@ -286,23 +367,23 @@ var i = class {
286
367
  "|": "≠",
287
368
  "}": "£",
288
369
  "~": "·"
289
- }, f = {
370
+ }, p = {
290
371
  http: !0,
291
372
  https: !0,
292
373
  tel: !0,
293
374
  mailto: !0
294
375
  };
295
- function p(e, t = f) {
376
+ function m(e, t = p) {
296
377
  if (!e || typeof e != "string") return null;
297
378
  let n = e.trim(), r = n.match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/);
298
379
  return !r || !t[r[1].toLowerCase()] ? null : n;
299
380
  }
300
- var m = class {
381
+ var h = class {
301
382
  constructor(e, t = {}) {
302
- this.screen = e, this.onResponse = t.onResponse || null, this.onTitle = t.onTitle || null, this.onBell = t.onBell || null, this.urlWhitelist = t.urlWhitelist || f, this.state = a, this._csiPrefix = "", this._csiParams = "", this._csiIntermediate = "", this._escIntermediate = "", this._oscBuffer = "", this._oscEscSeen = !1, this._dcsEscSeen = !1, this._lastPrintedChar = " ", this.charsetG0 = "B", this.charsetG1 = "B", this.activeCharset = 0, this.applicationCursorKeys = !1, this.applicationKeypad = !1, this.bracketedPasteMode = !1, this.mouseTrackingMode = 0, this.mouseProtocol = "x10", this.alternateScrollMode = !1;
383
+ this.screen = e, this.onResponse = t.onResponse || null, this.onTitle = t.onTitle || null, this.onBell = t.onBell || null, this.urlWhitelist = t.urlWhitelist || p, this.state = o, this._csiPrefix = "", this._csiParams = "", this._csiIntermediate = "", this._escIntermediate = "", this._oscBuffer = "", this._oscEscSeen = !1, this._dcsEscSeen = !1, this._lastPrintedChar = " ", this.charsetG0 = "B", this.charsetG1 = "B", this.activeCharset = 0, this.applicationCursorKeys = !1, this.applicationKeypad = !1, this.bracketedPasteMode = !1, this.mouseTrackingMode = 0, this.mouseProtocol = "x10", this.alternateScrollMode = !1;
303
384
  }
304
385
  reset() {
305
- this.state = a, this._csiPrefix = "", this._csiParams = "", this._csiIntermediate = "", this._escIntermediate = "", this._oscBuffer = "", this._oscEscSeen = !1, this._dcsEscSeen = !1, this._lastPrintedChar = " ", this.charsetG0 = "B", this.charsetG1 = "B", this.activeCharset = 0, this.applicationCursorKeys = !1, this.applicationKeypad = !1, this.bracketedPasteMode = !1, this.mouseTrackingMode = 0, this.mouseProtocol = "x10", this.alternateScrollMode = !1, this.screen.reset();
386
+ this.state = o, this._csiPrefix = "", this._csiParams = "", this._csiIntermediate = "", this._escIntermediate = "", this._oscBuffer = "", this._oscEscSeen = !1, this._dcsEscSeen = !1, this._lastPrintedChar = " ", this.charsetG0 = "B", this.charsetG1 = "B", this.activeCharset = 0, this.applicationCursorKeys = !1, this.applicationKeypad = !1, this.bracketedPasteMode = !1, this.mouseTrackingMode = 0, this.mouseProtocol = "x10", this.alternateScrollMode = !1, this.screen.reset();
306
387
  }
307
388
  write(e) {
308
389
  if (e == null) return;
@@ -310,22 +391,22 @@ var m = class {
310
391
  for (let e = 0; e < t.length; e++) {
311
392
  let n = t[e], r = t.charCodeAt(e);
312
393
  switch (this.state) {
313
- case a:
394
+ case o:
314
395
  this._handleGround(n, r);
315
396
  break;
316
- case o:
397
+ case s:
317
398
  this._handleEsc(n, r);
318
399
  break;
319
- case s:
400
+ case c:
320
401
  this._handleEscIntermediate(n, r);
321
402
  break;
322
- case c:
403
+ case l:
323
404
  this._handleCsi(n, r);
324
405
  break;
325
- case l:
406
+ case u:
326
407
  this._handleOsc(n, r);
327
408
  break;
328
- case u:
409
+ case d:
329
410
  this._handleDcs(n, r);
330
411
  break;
331
412
  }
@@ -333,7 +414,7 @@ var m = class {
333
414
  }
334
415
  _handleGround(e, t) {
335
416
  if (t === 27) {
336
- this.state = o, this._escIntermediate = "";
417
+ this.state = s, this._escIntermediate = "";
337
418
  return;
338
419
  }
339
420
  if (t === 13) {
@@ -365,44 +446,44 @@ var m = class {
365
446
  return;
366
447
  }
367
448
  if (t < 32 || t === 127) return;
368
- let n = (this.activeCharset === 0 ? this.charsetG0 : this.charsetG1) === "0" && d[e] ? d[e] : e;
449
+ let n = (this.activeCharset === 0 ? this.charsetG0 : this.charsetG1) === "0" && f[e] ? f[e] : e;
369
450
  this._lastPrintedChar = n, this.screen.putChar(n);
370
451
  }
371
452
  _handleEsc(e, t) {
372
453
  if (e === "[") {
373
- this.state = c, this._csiPrefix = "", this._csiParams = "", this._csiIntermediate = "";
454
+ this.state = l, this._csiPrefix = "", this._csiParams = "", this._csiIntermediate = "";
374
455
  return;
375
456
  }
376
457
  if (e === "]") {
377
- this.state = l, this._oscBuffer = "", this._oscEscSeen = !1;
458
+ this.state = u, this._oscBuffer = "", this._oscEscSeen = !1;
378
459
  return;
379
460
  }
380
461
  if (e === "P" || e === "X" || e === "^" || e === "_") {
381
- this.state = u, this._dcsEscSeen = !1;
462
+ this.state = d, this._dcsEscSeen = !1;
382
463
  return;
383
464
  }
384
465
  if (e === "(" || e === ")" || e === "*" || e === "+" || e === "#") {
385
- this.state = s, this._escIntermediate = e;
466
+ this.state = c, this._escIntermediate = e;
386
467
  return;
387
468
  }
388
469
  if (e === "7") {
389
- this.screen.saveCursor(), this.state = a;
470
+ this.screen.saveCursor(), this.state = o;
390
471
  return;
391
472
  }
392
473
  if (e === "8") {
393
- this.screen.restoreCursor(), this.state = a;
474
+ this.screen.restoreCursor(), this.state = o;
394
475
  return;
395
476
  }
396
477
  if (e === "D") {
397
- this.screen.index(), this.state = a;
478
+ this.screen.index(), this.state = o;
398
479
  return;
399
480
  }
400
481
  if (e === "M") {
401
- this.screen.reverseIndex(), this.state = a;
482
+ this.screen.reverseIndex(), this.state = o;
402
483
  return;
403
484
  }
404
485
  if (e === "E") {
405
- this.screen.nextLine(), this.state = a;
486
+ this.screen.nextLine(), this.state = o;
406
487
  return;
407
488
  }
408
489
  if (e === "c") {
@@ -410,14 +491,14 @@ var m = class {
410
491
  return;
411
492
  }
412
493
  if (e === "=") {
413
- this.applicationKeypad = !0, this.state = a;
494
+ this.applicationKeypad = !0, this.state = o;
414
495
  return;
415
496
  }
416
497
  if (e === ">") {
417
- this.applicationKeypad = !1, this.state = a;
498
+ this.applicationKeypad = !1, this.state = o;
418
499
  return;
419
500
  }
420
- t !== 27 && (this.state = a);
501
+ t !== 27 && (this.state = o);
421
502
  }
422
503
  _handleEscIntermediate(e) {
423
504
  if (this._escIntermediate === "(") this.charsetG0 = e === "0" ? "0" : "B";
@@ -426,7 +507,7 @@ var m = class {
426
507
  for (let e = 0; e < this.screen.rows; e++) for (let t = 0; t < this.screen.cols; t++) this.screen.grid[e][t].ch = "E";
427
508
  this.screen._markAllDirty();
428
509
  }
429
- this.state = a;
510
+ this.state = o;
430
511
  }
431
512
  _handleCsi(e, t) {
432
513
  if (t === 13) {
@@ -442,7 +523,7 @@ var m = class {
442
523
  return;
443
524
  }
444
525
  if (t === 27) {
445
- this.state = o;
526
+ this.state = s;
446
527
  return;
447
528
  }
448
529
  if (this._csiParams.length === 0 && this._csiPrefix.length === 0 && (e === "?" || e === ">" || e === "<" || e === "=")) {
@@ -457,16 +538,16 @@ var m = class {
457
538
  this._csiIntermediate += e;
458
539
  return;
459
540
  }
460
- t >= 64 && t <= 126 && (this._dispatchCsi(this._csiPrefix, this._csiParams, this._csiIntermediate, e), this.state = a);
541
+ t >= 64 && t <= 126 && (this._dispatchCsi(this._csiPrefix, this._csiParams, this._csiIntermediate, e), this.state = o);
461
542
  }
462
543
  _handleOsc(e, t) {
463
544
  if (t === 7) {
464
- this._dispatchOsc(this._oscBuffer), this.state = a;
545
+ this._dispatchOsc(this._oscBuffer), this.state = o;
465
546
  return;
466
547
  }
467
548
  if (this._oscEscSeen) {
468
549
  if (this._oscEscSeen = !1, e === "\\") {
469
- this._dispatchOsc(this._oscBuffer), this.state = a;
550
+ this._dispatchOsc(this._oscBuffer), this.state = o;
470
551
  return;
471
552
  }
472
553
  this._oscBuffer += "\x1B" + e;
@@ -480,11 +561,11 @@ var m = class {
480
561
  }
481
562
  _handleDcs(e, t) {
482
563
  if (t === 7) {
483
- this.state = a;
564
+ this.state = o;
484
565
  return;
485
566
  }
486
567
  if (this._dcsEscSeen && (this._dcsEscSeen = !1, e === "\\")) {
487
- this.state = a;
568
+ this.state = o;
488
569
  return;
489
570
  }
490
571
  t === 27 && (this._dcsEscSeen = !0);
@@ -498,7 +579,7 @@ var m = class {
498
579
  let e = r.indexOf(";");
499
580
  if (e !== -1) {
500
581
  let t = r.slice(e + 1);
501
- this.screen.curLink = t ? p(t, this.urlWhitelist) : null;
582
+ this.screen.curLink = t ? m(t, this.urlWhitelist) : null;
502
583
  }
503
584
  }
504
585
  }
@@ -755,7 +836,7 @@ var m = class {
755
836
  t++;
756
837
  }
757
838
  }
758
- }, h = [
839
+ }, g = [
759
840
  "ansi-black",
760
841
  "ansi-red",
761
842
  "ansi-green",
@@ -772,7 +853,7 @@ var m = class {
772
853
  "ansi-bright-magenta",
773
854
  "ansi-bright-cyan",
774
855
  "ansi-bright-white"
775
- ], g = [
856
+ ], _ = [
776
857
  0,
777
858
  95,
778
859
  135,
@@ -780,7 +861,7 @@ var m = class {
780
861
  215,
781
862
  255
782
863
  ];
783
- function _(e) {
864
+ function v(e) {
784
865
  if (typeof e == "string") return e;
785
866
  if (typeof e != "number" || e < 16 || e > 255) return null;
786
867
  if (e >= 232) {
@@ -788,13 +869,13 @@ function _(e) {
788
869
  return `rgb(${t}, ${t}, ${t})`;
789
870
  }
790
871
  let t = e - 16;
791
- return `rgb(${g[Math.floor(t / 36) % 6]}, ${g[Math.floor(t / 6) % 6]}, ${g[t % 6]})`;
872
+ return `rgb(${_[Math.floor(t / 36) % 6]}, ${_[Math.floor(t / 6) % 6]}, ${_[t % 6]})`;
792
873
  }
793
- function v(e) {
874
+ function y(e) {
794
875
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
795
876
  }
796
- var y = /(?:https?:\/\/|mailto:|tel:)[^\s<>"'`]+/g;
797
- function b(e) {
877
+ var b = /(?:https?:\/\/|mailto:|tel:)[^\s<>"'`]+/g;
878
+ function x(e) {
798
879
  let t = e.length;
799
880
  for (; t > 0;) {
800
881
  let n = e[t - 1];
@@ -811,24 +892,24 @@ function b(e) {
811
892
  }
812
893
  return e.slice(0, t);
813
894
  }
814
- function x(e, t = f) {
895
+ function S(e, t = p) {
815
896
  let n = "";
816
897
  for (let t = 0; t < e.length; t++) n += e[t].ch || " ";
817
898
  let r = Array(e.length).fill(null);
818
899
  for (let t = 0; t < e.length; t++) e[t].link && (r[t] = e[t].link);
819
- y.lastIndex = 0;
900
+ b.lastIndex = 0;
820
901
  let i;
821
- for (; (i = y.exec(n)) !== null;) {
822
- let e = b(i[0]), n = p(e, t);
902
+ for (; (i = b.exec(n)) !== null;) {
903
+ let e = x(i[0]), n = m(e, t);
823
904
  if (!n) continue;
824
905
  let a = i.index, o = a + e.length;
825
906
  for (let e = a; e < o && e < r.length; e++) r[e] || (r[e] = n);
826
907
  }
827
908
  return r;
828
909
  }
829
- var S = class {
910
+ var C = class {
830
911
  constructor(e, t, n = {}) {
831
- this.container = e, this.screen = t, this.cursorStyle = n.cursor || "none", this.urlWhitelist = n.urlWhitelist || f, this._rowElements = [], this._rafId = null, this._lastCursorRow = -1, this._lastCursorCol = -1, this._lastCursorVisible = !1;
912
+ this.container = e, this.screen = t, this.cursorStyle = n.cursor || "none", this.urlWhitelist = n.urlWhitelist || p, this._rowElements = [], this._rafId = null, this._lastCursorRow = -1, this._lastCursorCol = -1, this._lastCursorVisible = !1;
832
913
  }
833
914
  scheduleRender() {
834
915
  this._rafId === null && (typeof requestAnimationFrame == "function" ? this._rafId = requestAnimationFrame(() => {
@@ -857,7 +938,7 @@ var S = class {
857
938
  _renderRow(e, t) {
858
939
  let n = this._rowElements[e], r = this.screen.getVisibleRow(e);
859
940
  if (!n || !r) return;
860
- let i = x(r, this.urlWhitelist), a = this.screen.isAltScreen ? r.length - 1 : -1;
941
+ let i = S(r, this.urlWhitelist), a = this.screen.isAltScreen ? r.length - 1 : -1;
861
942
  if (!this.screen.isAltScreen) {
862
943
  for (let e = r.length - 1; e >= 0; e--) {
863
944
  let t = r[e];
@@ -883,22 +964,22 @@ var S = class {
883
964
  }
884
965
  _formatRun(e, t, n, r) {
885
966
  let i = [], a = [], o = t.flags || 0, s = (o & 32) != 0, c = s ? t.bg : t.fg, l = s ? t.fg : t.bg;
886
- if (s && t.fg === null && t.bg === null && i.push("terminal__inverse"), typeof c == "number" && c >= 0 && c < 16) i.push(`${h[c]}-fg`);
967
+ if (s && t.fg === null && t.bg === null && i.push("terminal__inverse"), typeof c == "number" && c >= 0 && c < 16) i.push(`${g[c]}-fg`);
887
968
  else if (c !== null) {
888
- let e = _(c);
969
+ let e = v(c);
889
970
  e && a.push(`color:${e}`);
890
971
  }
891
- if (typeof l == "number" && l >= 0 && l < 16) i.push(`${h[l]}-bg`);
972
+ if (typeof l == "number" && l >= 0 && l < 16) i.push(`${g[l]}-bg`);
892
973
  else if (l !== null) {
893
- let e = _(l);
974
+ let e = v(l);
894
975
  e && a.push(`background-color:${e}`);
895
976
  }
896
977
  o & 1 && a.push("font-weight:bold"), o & 2 && a.push("opacity:0.65"), o & 4 && a.push("font-style:italic"), o & 8 && o & 128 ? a.push("text-decoration:underline line-through") : o & 8 ? a.push("text-decoration:underline") : o & 128 && a.push("text-decoration:line-through"), o & 16 && i.push("terminal__blink"), o & 64 && a.push("visibility:hidden"), r && (i.push("terminal__cursor"), i.push(this.cursorStyle));
897
- let u = v(e), d = u;
898
- return (i.length > 0 || a.length > 0) && (d = `<span${i.length > 0 ? ` class="${i.join(" ")}"` : ""}${a.length > 0 ? ` style="${a.join(";")}"` : ""}>${u}</span>`), n ? `<a href="${v(n)}" target="_blank" rel="noopener noreferrer" class="terminal__link">${d}</a>` : d;
978
+ let u = y(e), d = u;
979
+ return (i.length > 0 || a.length > 0) && (d = `<span${i.length > 0 ? ` class="${i.join(" ")}"` : ""}${a.length > 0 ? ` style="${a.join(";")}"` : ""}>${u}</span>`), n ? `<a href="${y(n)}" target="_blank" rel="noopener noreferrer" class="terminal__link">${d}</a>` : d;
899
980
  }
900
- }, C = "\nimport os, sys, pty, select, fcntl, termios, struct, signal, json\n\ncmd = sys.argv[1]\nargs = json.loads(sys.argv[2])\ncols = int(sys.argv[3])\nrows = int(sys.argv[4])\ncwd = sys.argv[5]\n\npid, fd = pty.fork()\nif pid == 0:\n if cwd:\n try: os.chdir(cwd)\n except Exception: pass\n os.execvp(cmd, [cmd] + args)\n\ndef set_winsize(c, r):\n try:\n fcntl.ioctl(fd, termios.TIOCSWINSZ, struct.pack(\"HHHH\", r, c, 0, 0))\n os.kill(pid, signal.SIGWINCH)\n except Exception:\n pass\n\nset_winsize(cols, rows)\nstdin_fd = sys.stdin.fileno()\nstdout_fd = sys.stdout.fileno()\n\ntry:\n while True:\n rlist, _, _ = select.select([fd, stdin_fd], [], [])\n if fd in rlist:\n try:\n data = os.read(fd, 8192)\n if not data:\n break\n os.write(stdout_fd, data)\n except OSError:\n break\n if stdin_fd in rlist:\n try:\n chunk = os.read(stdin_fd, 8192)\n if not chunk:\n break\n # Check for inline resize control packet: \\x1b]9999;cols;rows\\x07\n while b\"\\x1b]9999;\" in chunk:\n start = chunk.find(b\"\\x1b]9999;\")\n end = chunk.find(b\"\\x07\", start)\n if end == -1:\n break\n packet = chunk[start+7:end].decode(\"ascii\", \"ignore\")\n parts = packet.split(\";\")\n if len(parts) == 2:\n set_winsize(int(parts[0]), int(parts[1]))\n chunk = chunk[:start] + chunk[end+1:]\n if chunk:\n os.write(fd, chunk)\n except OSError:\n break\nfinally:\n try:\n os.close(fd)\n except Exception:\n pass\n try:\n _, status = os.waitpid(pid, 0)\n sys.exit(os.waitstatus_to_exitcode(status) if hasattr(os, \"waitstatus_to_exitcode\") else 0)\n except Exception:\n sys.exit(0)\n";
901
- function w(e) {
981
+ }, w = "\nimport os, sys, pty, select, fcntl, termios, struct, signal, json\n\ncmd = sys.argv[1]\nargs = json.loads(sys.argv[2])\ncols = int(sys.argv[3])\nrows = int(sys.argv[4])\ncwd = sys.argv[5]\n\npid, fd = pty.fork()\nif pid == 0:\n if cwd:\n try: os.chdir(cwd)\n except Exception: pass\n os.execvp(cmd, [cmd] + args)\n\ndef set_winsize(c, r):\n try:\n fcntl.ioctl(fd, termios.TIOCSWINSZ, struct.pack(\"HHHH\", r, c, 0, 0))\n os.kill(pid, signal.SIGWINCH)\n except Exception:\n pass\n\nset_winsize(cols, rows)\nstdin_fd = sys.stdin.fileno()\nstdout_fd = sys.stdout.fileno()\n\ntry:\n while True:\n rlist, _, _ = select.select([fd, stdin_fd], [], [])\n if fd in rlist:\n try:\n data = os.read(fd, 8192)\n if not data:\n break\n os.write(stdout_fd, data)\n except OSError:\n break\n if stdin_fd in rlist:\n try:\n chunk = os.read(stdin_fd, 8192)\n if not chunk:\n break\n # Check for inline resize control packet: \\x1b]9999;cols;rows\\x07\n while b\"\\x1b]9999;\" in chunk:\n start = chunk.find(b\"\\x1b]9999;\")\n end = chunk.find(b\"\\x07\", start)\n if end == -1:\n break\n packet = chunk[start+7:end].decode(\"ascii\", \"ignore\")\n parts = packet.split(\";\")\n if len(parts) == 2:\n set_winsize(int(parts[0]), int(parts[1]))\n chunk = chunk[:start] + chunk[end+1:]\n if chunk:\n os.write(fd, chunk)\n except OSError:\n break\nfinally:\n try:\n os.close(fd)\n except Exception:\n pass\n try:\n _, status = os.waitpid(pid, 0)\n sys.exit(os.waitstatus_to_exitcode(status) if hasattr(os, \"waitstatus_to_exitcode\") else 0)\n except Exception:\n sys.exit(0)\n";
982
+ function T(e) {
902
983
  if (typeof process < "u" && process.env && process.env.SHELL) return process.env.SHELL;
903
984
  try {
904
985
  let t = e ? e("fs") : null;
@@ -914,10 +995,10 @@ function w(e) {
914
995
  } catch {}
915
996
  return "/bin/sh";
916
997
  }
917
- function T(e, n = [], r = {}) {
998
+ function E(e, n = [], r = {}) {
918
999
  let i = typeof t == "function" ? t : typeof globalThis < "u" && globalThis.process && globalThis.process.getBuiltinModule ? (e) => globalThis.process.getBuiltinModule(e) : null;
919
1000
  if (!i) throw Error("spawnPty is only available in a Node.js environment");
920
- let a = e || w(i), { spawn: o } = i("child_process"), s = r.cols || 80, c = r.rows || 24, l = r.cwd || (typeof process < "u" ? process.cwd() : ""), u = Object.assign({}, typeof process < "u" ? process.env : {}, {
1001
+ let a = e || T(i), { spawn: o } = i("child_process"), s = r.cols || 80, c = r.rows || 24, l = r.cwd || (typeof process < "u" ? process.cwd() : ""), u = Object.assign({}, typeof process < "u" ? process.env : {}, {
921
1002
  TERM: "xterm-256color",
922
1003
  COLORTERM: "truecolor",
923
1004
  COLUMNS: String(s),
@@ -925,7 +1006,7 @@ function T(e, n = [], r = {}) {
925
1006
  }, r.env || {}), d = o("python3", [
926
1007
  "-u",
927
1008
  "-c",
928
- C,
1009
+ w,
929
1010
  a,
930
1011
  JSON.stringify(n),
931
1012
  String(s),
@@ -969,7 +1050,7 @@ function T(e, n = [], r = {}) {
969
1050
  }
970
1051
  //#endregion
971
1052
  //#region lib/Terminal.js
972
- var E = e?.default ?? e, D = class {
1053
+ var D = e?.default ?? e, O = class {
973
1054
  constructor() {
974
1055
  this._listeners = /* @__PURE__ */ new Map(), this.readable = !0, this.writable = !0, this.isTTY = !0;
975
1056
  }
@@ -1027,32 +1108,32 @@ var E = e?.default ?? e, D = class {
1027
1108
  destroy() {
1028
1109
  this.removeAllListeners();
1029
1110
  }
1030
- }, O = class {
1111
+ }, k = class {
1031
1112
  constructor(e = {}) {
1032
- let { el: t, font: n = "Roboto Mono", cursor: r = "none", outputAnimation: a = "none", animateSpeed: o = 1, onExit: s = null, mobileInput: c = "click", lineWrap: l = !1, command: u = null, cols: d = 80, rows: p = 24, maxScrollback: h = 1e3, stream: g = null } = e;
1113
+ let { el: t, font: n = "Roboto Mono", cursor: r = "none", outputAnimation: i = "none", animateSpeed: o = 1, onExit: s = null, mobileInput: c = "click", lineWrap: l = !1, command: u = null, cols: d = 80, rows: f = 24, maxScrollback: m = 1e3, stream: g = null } = e;
1033
1114
  if (!t) throw Error("you must set `el` option");
1034
1115
  if (![
1035
1116
  "none",
1036
1117
  "block",
1037
1118
  "blink"
1038
1119
  ].includes(r)) throw Error("cursor value must be one of: 'none', 'block', 'blink'");
1039
- if (!["none", "type"].includes(a)) throw Error("outputAnimation value must be one of: 'none', 'type'");
1120
+ if (!["none", "type"].includes(i)) throw Error("outputAnimation value must be one of: 'none', 'type'");
1040
1121
  if (!Number.isInteger(o) || o < 1 || o > 20) throw Error("animateSpeed value must be between 1 and 20");
1041
- if (this._exitFn = s, this._cursor = r, this._outputAnimation = a, this._animateSpeed = o, this._lineWrap = l, this._el = t, this._dataListeners = [], this._resizeListeners = [], this._titleListeners = [], this._mouseButtonDown = null, this._mobileInputElement = null, this._onMobileInputClick = null, this._typeQueue = "", this._typeTimer = null, this._isHandlingInput = !1, this._suppressAnimationUntil = 0, this.screen = new i(d, p, { maxScrollback: h }), this.parser = new m(this.screen, {
1042
- urlWhitelist: f,
1122
+ if (this._exitFn = s, this._cursor = r, this._outputAnimation = i, this._animateSpeed = o, this._lineWrap = l, this._el = t, this._dataListeners = [], this._resizeListeners = [], this._titleListeners = [], this._mouseButtonDown = null, this._mobileInputElement = null, this._onMobileInputClick = null, this._typeQueue = "", this._typeTimer = null, this._isHandlingInput = !1, this._suppressAnimationUntil = 0, this.screen = new a(d, f, { maxScrollback: m }), this.parser = new h(this.screen, {
1123
+ urlWhitelist: p,
1043
1124
  onResponse: (e) => this._emitInput(e),
1044
1125
  onTitle: (e) => {
1045
1126
  this.title = e;
1046
1127
  for (let t of this._titleListeners) t(e);
1047
1128
  }
1048
1129
  }), this.cli = e.cli || e.shell || null, !this.cli && !g && e.Shell !== !1) {
1049
- let t = e.Shell === null ? null : e.Shell || typeof globalThis < "u" && (globalThis.Shell || globalThis.shell) || (typeof E == "function" ? E : null);
1130
+ let t = e.Shell === null ? null : e.Shell || typeof globalThis < "u" && (globalThis.Shell || globalThis.shell) || (typeof D == "function" ? D : null);
1050
1131
  if (!t) throw Error("Shell is required by Terminal. Please import Shell from \"brsh\" or include shell.min.js before terminal.min.js.");
1051
1132
  this.cli = new t(Object.assign({}, e, { command: void 0 }));
1052
1133
  }
1053
- this._setupDom(this._el, n), this.renderer = new S(this._cmdList, this.screen, {
1134
+ this._setupDom(this._el, n), this.renderer = new C(this._cmdList, this.screen, {
1054
1135
  cursor: this._cursor,
1055
- urlWhitelist: f
1136
+ urlWhitelist: p
1056
1137
  }), this._listenForEvents(), this.cli && (this.attach(this.cli), typeof this.cli.on == "function" && this.cli.on("exit", (e) => {
1057
1138
  delete this.cli, typeof this._exitFn == "function" && this._exitFn(e);
1058
1139
  }), u && this.onCommand(u)), g && (this.attach(g), u && this.onCommand(u)), c === "click" && this._mobileInput(), this.renderer.flushRender();
@@ -1135,7 +1216,7 @@ var E = e?.default ?? e, D = class {
1135
1216
  };
1136
1217
  }
1137
1218
  spawn(e, t = [], n = {}) {
1138
- let r = T(e, t, Object.assign({
1219
+ let r = E(e, t, Object.assign({
1139
1220
  cols: this.cols,
1140
1221
  rows: this.rows
1141
1222
  }, n)), i = this.attach(r);
@@ -1147,7 +1228,7 @@ var E = e?.default ?? e, D = class {
1147
1228
  };
1148
1229
  }
1149
1230
  createTty(e = {}) {
1150
- let t = new D(), n = new D();
1231
+ let t = new O(), n = new O();
1151
1232
  e.interceptShell, n.columns = this.cols, n.rows = this.rows, n.getWindowSize = () => [n.columns, n.rows], n.write = (e, t, n) => (this.write(e), typeof t == "function" ? t() : typeof n == "function" && n(), !0);
1152
1233
  let r = this.onData((e) => {
1153
1234
  let n = t._encoding ? e : typeof Buffer < "u" ? Buffer.from(e, "utf8") : e;
@@ -1467,8 +1548,8 @@ var E = e?.default ?? e, D = class {
1467
1548
  this._typeTimer !== null && (clearInterval(this._typeTimer), this._typeTimer = null), typeof window < "u" && window.removeEventListener && (this._onKeyDown && window.removeEventListener("keydown", this._onKeyDown), this._onPaste && window.removeEventListener("paste", this._onPaste)), this._mobileInputElement &&= (this._onMobileInputClick && this._el && typeof this._el.removeEventListener == "function" && this._el.removeEventListener("click", this._onMobileInputClick), this._mobileInputElement.parentNode ? this._mobileInputElement.parentNode.removeChild(this._mobileInputElement) : typeof this._mobileInputElement.remove == "function" && this._mobileInputElement.remove(), null), this._dataListeners = [], this._resizeListeners = [], this._titleListeners = [];
1468
1549
  }
1469
1550
  };
1470
- O.Terminal = O, O.spawnPty = T, typeof globalThis < "u" && (globalThis.Terminal = O);
1551
+ k.Terminal = k, k.spawnPty = E, typeof globalThis < "u" && (globalThis.Terminal = k);
1471
1552
  //#endregion
1472
- export { O as default };
1553
+ export { k as default };
1473
1554
 
1474
1555
  //# sourceMappingURL=terminal.es.js.map