@opentui/core 0.0.0-20251106-dd34dace → 0.0.0-20251108-0c7899b1

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.
@@ -27,7 +27,7 @@ var __export = (target, all) => {
27
27
  };
28
28
  var __require = import.meta.require;
29
29
 
30
- // ../../node_modules/.bun/yoga-layout@3.2.1/node_modules/yoga-layout/dist/src/index.js
30
+ // ../../node_modules/yoga-layout/dist/src/index.js
31
31
  var exports_src = {};
32
32
  __export(exports_src, {
33
33
  default: () => src_default,
@@ -51,7 +51,7 @@ __export(exports_src, {
51
51
  Align: () => Align
52
52
  });
53
53
 
54
- // ../../node_modules/.bun/yoga-layout@3.2.1/node_modules/yoga-layout/dist/binaries/yoga-wasm-base64-esm.js
54
+ // ../../node_modules/yoga-layout/dist/binaries/yoga-wasm-base64-esm.js
55
55
  var loadYoga = (() => {
56
56
  var _scriptDir = import.meta.url;
57
57
  return function(loadYoga2) {
@@ -1356,7 +1356,7 @@ var loadYoga = (() => {
1356
1356
  })();
1357
1357
  var yoga_wasm_base64_esm_default = loadYoga;
1358
1358
 
1359
- // ../../node_modules/.bun/yoga-layout@3.2.1/node_modules/yoga-layout/dist/src/generated/YGEnums.js
1359
+ // ../../node_modules/yoga-layout/dist/src/generated/YGEnums.js
1360
1360
  var Align = /* @__PURE__ */ function(Align2) {
1361
1361
  Align2[Align2["Auto"] = 0] = "Auto";
1362
1362
  Align2[Align2["FlexStart"] = 1] = "FlexStart";
@@ -1559,7 +1559,7 @@ var constants = {
1559
1559
  };
1560
1560
  var YGEnums_default = constants;
1561
1561
 
1562
- // ../../node_modules/.bun/yoga-layout@3.2.1/node_modules/yoga-layout/dist/src/wrapAssembly.js
1562
+ // ../../node_modules/yoga-layout/dist/src/wrapAssembly.js
1563
1563
  function wrapAssembly(lib) {
1564
1564
  function patch(prototype, name, fn) {
1565
1565
  const original = prototype[name];
@@ -1661,7 +1661,7 @@ function wrapAssembly(lib) {
1661
1661
  };
1662
1662
  }
1663
1663
 
1664
- // ../../node_modules/.bun/yoga-layout@3.2.1/node_modules/yoga-layout/dist/src/index.js
1664
+ // ../../node_modules/yoga-layout/dist/src/index.js
1665
1665
  var Yoga = wrapAssembly(await yoga_wasm_base64_esm_default());
1666
1666
  var src_default = Yoga;
1667
1667
 
@@ -2079,6 +2079,7 @@ var isShiftKey = (code) => {
2079
2079
  var isCtrlKey = (code) => {
2080
2080
  return ["Oa", "Ob", "Oc", "Od", "Oe", "[2^", "[3^", "[5^", "[6^", "[7^", "[8^"].includes(code);
2081
2081
  };
2082
+ var ghosttyModifiedKeyRe = /^\x1b\[27;(\d+);(\d+)~$/;
2082
2083
  var parseKeypress = (s = "", options = {}) => {
2083
2084
  let parts;
2084
2085
  if (Buffer2.isBuffer(s)) {
@@ -2118,6 +2119,29 @@ var parseKeypress = (s = "", options = {}) => {
2118
2119
  return kittyResult;
2119
2120
  }
2120
2121
  }
2122
+ const ghosttyMatch = ghosttyModifiedKeyRe.exec(s);
2123
+ if (ghosttyMatch) {
2124
+ const modifier = parseInt(ghosttyMatch[1], 10) - 1;
2125
+ const charCode = parseInt(ghosttyMatch[2], 10);
2126
+ key.ctrl = !!(modifier & 4);
2127
+ key.meta = !!(modifier & 10);
2128
+ key.shift = !!(modifier & 1);
2129
+ key.option = !!(modifier & 2);
2130
+ if (charCode === 13) {
2131
+ key.name = "return";
2132
+ } else if (charCode === 27) {
2133
+ key.name = "escape";
2134
+ } else if (charCode === 9) {
2135
+ key.name = "tab";
2136
+ } else if (charCode === 32) {
2137
+ key.name = "space";
2138
+ } else if (charCode === 127 || charCode === 8) {
2139
+ key.name = "backspace";
2140
+ } else {
2141
+ key.name = String.fromCharCode(charCode);
2142
+ }
2143
+ return key;
2144
+ }
2121
2145
  if (s === "\r" || s === "\x1B\r") {
2122
2146
  key.name = "return";
2123
2147
  key.meta = s.length === 2;
@@ -5631,6 +5655,8 @@ import markdown_language from "./assets/markdown/tree-sitter-markdown.wasm" with
5631
5655
  import markdown_injections from "./assets/markdown/injections.scm" with { type: "file" };
5632
5656
  import markdown_inline_highlights from "./assets/markdown_inline/highlights.scm" with { type: "file" };
5633
5657
  import markdown_inline_language from "./assets/markdown_inline/tree-sitter-markdown_inline.wasm" with { type: "file" };
5658
+ import zig_highlights from "./assets/zig/highlights.scm" with { type: "file" };
5659
+ import zig_language from "./assets/zig/tree-sitter-zig.wasm" with { type: "file" };
5634
5660
  var _cachedParsers;
5635
5661
  function getParsers() {
5636
5662
  if (!_cachedParsers) {
@@ -5677,6 +5703,13 @@ function getParsers() {
5677
5703
  highlights: [resolve(dirname(fileURLToPath(import.meta.url)), markdown_inline_highlights)]
5678
5704
  },
5679
5705
  wasm: resolve(dirname(fileURLToPath(import.meta.url)), markdown_inline_language)
5706
+ },
5707
+ {
5708
+ filetype: "zig",
5709
+ queries: {
5710
+ highlights: [resolve(dirname(fileURLToPath(import.meta.url)), zig_highlights)]
5711
+ },
5712
+ wasm: resolve(dirname(fileURLToPath(import.meta.url)), zig_language)
5680
5713
  }
5681
5714
  ];
5682
5715
  }
@@ -7341,6 +7374,271 @@ class ExtmarksController {
7341
7374
  function createExtmarksController(editBuffer, editorView) {
7342
7375
  return new ExtmarksController(editBuffer, editorView);
7343
7376
  }
7377
+
7378
+ // src/lib/terminal-palette.ts
7379
+ var OSC4_RESPONSE = /\x1b]4;(\d+);(?:(?:rgb:)([0-9a-fA-F]+)\/([0-9a-fA-F]+)\/([0-9a-fA-F]+)|#([0-9a-fA-F]{6}))(?:\x07|\x1b\\)/g;
7380
+ var OSC_SPECIAL_RESPONSE = /\x1b](\d+);(?:(?:rgb:)([0-9a-fA-F]+)\/([0-9a-fA-F]+)\/([0-9a-fA-F]+)|#([0-9a-fA-F]{6}))(?:\x07|\x1b\\)/g;
7381
+ function scaleComponent(comp) {
7382
+ const val = parseInt(comp, 16);
7383
+ const maxIn = (1 << 4 * comp.length) - 1;
7384
+ return Math.round(val / maxIn * 255).toString(16).padStart(2, "0");
7385
+ }
7386
+ function toHex(r, g, b, hex6) {
7387
+ if (hex6)
7388
+ return `#${hex6.toLowerCase()}`;
7389
+ if (r && g && b)
7390
+ return `#${scaleComponent(r)}${scaleComponent(g)}${scaleComponent(b)}`;
7391
+ return "#000000";
7392
+ }
7393
+
7394
+ class TerminalPalette {
7395
+ stdin;
7396
+ stdout;
7397
+ writeFn;
7398
+ activeListeners = [];
7399
+ activeTimers = [];
7400
+ constructor(stdin, stdout, writeFn) {
7401
+ this.stdin = stdin;
7402
+ this.stdout = stdout;
7403
+ this.writeFn = writeFn || ((data) => stdout.write(data));
7404
+ }
7405
+ cleanup() {
7406
+ for (const { event, handler } of this.activeListeners) {
7407
+ this.stdin.removeListener(event, handler);
7408
+ }
7409
+ this.activeListeners = [];
7410
+ for (const timer of this.activeTimers) {
7411
+ clearTimeout(timer);
7412
+ }
7413
+ this.activeTimers = [];
7414
+ }
7415
+ async detectOSCSupport(timeoutMs = 300) {
7416
+ const out = this.stdout;
7417
+ const inp = this.stdin;
7418
+ if (!out.isTTY || !inp.isTTY)
7419
+ return false;
7420
+ return new Promise((resolve4) => {
7421
+ let buffer = "";
7422
+ const onData = (chunk) => {
7423
+ buffer += chunk.toString();
7424
+ OSC4_RESPONSE.lastIndex = 0;
7425
+ if (OSC4_RESPONSE.test(buffer)) {
7426
+ cleanup();
7427
+ resolve4(true);
7428
+ }
7429
+ };
7430
+ const onTimeout = () => {
7431
+ cleanup();
7432
+ resolve4(false);
7433
+ };
7434
+ const cleanup = () => {
7435
+ clearTimeout(timer);
7436
+ inp.removeListener("data", onData);
7437
+ const listenerIdx = this.activeListeners.findIndex((l) => l.handler === onData);
7438
+ if (listenerIdx !== -1)
7439
+ this.activeListeners.splice(listenerIdx, 1);
7440
+ const timerIdx = this.activeTimers.indexOf(timer);
7441
+ if (timerIdx !== -1)
7442
+ this.activeTimers.splice(timerIdx, 1);
7443
+ };
7444
+ const timer = setTimeout(onTimeout, timeoutMs);
7445
+ this.activeTimers.push(timer);
7446
+ inp.on("data", onData);
7447
+ this.activeListeners.push({ event: "data", handler: onData });
7448
+ this.writeFn("\x1B]4;0;?\x07");
7449
+ });
7450
+ }
7451
+ async queryPalette(indices, timeoutMs = 1200) {
7452
+ const out = this.stdout;
7453
+ const inp = this.stdin;
7454
+ const results = new Map;
7455
+ indices.forEach((i) => results.set(i, null));
7456
+ if (!out.isTTY || !inp.isTTY) {
7457
+ return results;
7458
+ }
7459
+ return new Promise((resolve4) => {
7460
+ let buffer = "";
7461
+ let lastResponseTime = Date.now();
7462
+ let idleTimer = null;
7463
+ const onData = (chunk) => {
7464
+ buffer += chunk.toString();
7465
+ lastResponseTime = Date.now();
7466
+ let m;
7467
+ OSC4_RESPONSE.lastIndex = 0;
7468
+ while (m = OSC4_RESPONSE.exec(buffer)) {
7469
+ const idx = parseInt(m[1], 10);
7470
+ if (results.has(idx))
7471
+ results.set(idx, toHex(m[2], m[3], m[4], m[5]));
7472
+ }
7473
+ if (buffer.length > 8192)
7474
+ buffer = buffer.slice(-4096);
7475
+ const done = [...results.values()].filter((v) => v !== null).length;
7476
+ if (done === results.size) {
7477
+ cleanup();
7478
+ resolve4(results);
7479
+ return;
7480
+ }
7481
+ if (idleTimer)
7482
+ clearTimeout(idleTimer);
7483
+ idleTimer = setTimeout(() => {
7484
+ cleanup();
7485
+ resolve4(results);
7486
+ }, 150);
7487
+ if (idleTimer)
7488
+ this.activeTimers.push(idleTimer);
7489
+ };
7490
+ const onTimeout = () => {
7491
+ cleanup();
7492
+ resolve4(results);
7493
+ };
7494
+ const cleanup = () => {
7495
+ clearTimeout(timer);
7496
+ if (idleTimer)
7497
+ clearTimeout(idleTimer);
7498
+ inp.removeListener("data", onData);
7499
+ const listenerIdx = this.activeListeners.findIndex((l) => l.handler === onData);
7500
+ if (listenerIdx !== -1)
7501
+ this.activeListeners.splice(listenerIdx, 1);
7502
+ const timerIdx = this.activeTimers.indexOf(timer);
7503
+ if (timerIdx !== -1)
7504
+ this.activeTimers.splice(timerIdx, 1);
7505
+ if (idleTimer) {
7506
+ const idleTimerIdx = this.activeTimers.indexOf(idleTimer);
7507
+ if (idleTimerIdx !== -1)
7508
+ this.activeTimers.splice(idleTimerIdx, 1);
7509
+ }
7510
+ };
7511
+ const timer = setTimeout(onTimeout, timeoutMs);
7512
+ this.activeTimers.push(timer);
7513
+ inp.on("data", onData);
7514
+ this.activeListeners.push({ event: "data", handler: onData });
7515
+ this.writeFn(indices.map((i) => `\x1B]4;${i};?\x07`).join(""));
7516
+ });
7517
+ }
7518
+ async querySpecialColors(timeoutMs = 1200) {
7519
+ const out = this.stdout;
7520
+ const inp = this.stdin;
7521
+ const results = {
7522
+ 10: null,
7523
+ 11: null,
7524
+ 12: null,
7525
+ 13: null,
7526
+ 14: null,
7527
+ 15: null,
7528
+ 16: null,
7529
+ 17: null,
7530
+ 19: null
7531
+ };
7532
+ if (!out.isTTY || !inp.isTTY) {
7533
+ return results;
7534
+ }
7535
+ return new Promise((resolve4) => {
7536
+ let buffer = "";
7537
+ let idleTimer = null;
7538
+ const onData = (chunk) => {
7539
+ buffer += chunk.toString();
7540
+ let m;
7541
+ OSC_SPECIAL_RESPONSE.lastIndex = 0;
7542
+ while (m = OSC_SPECIAL_RESPONSE.exec(buffer)) {
7543
+ const idx = parseInt(m[1], 10);
7544
+ if (idx in results) {
7545
+ results[idx] = toHex(m[2], m[3], m[4], m[5]);
7546
+ }
7547
+ }
7548
+ if (buffer.length > 8192)
7549
+ buffer = buffer.slice(-4096);
7550
+ const done = Object.values(results).filter((v) => v !== null).length;
7551
+ if (done === Object.keys(results).length) {
7552
+ cleanup();
7553
+ resolve4(results);
7554
+ return;
7555
+ }
7556
+ if (idleTimer)
7557
+ clearTimeout(idleTimer);
7558
+ idleTimer = setTimeout(() => {
7559
+ cleanup();
7560
+ resolve4(results);
7561
+ }, 150);
7562
+ if (idleTimer)
7563
+ this.activeTimers.push(idleTimer);
7564
+ };
7565
+ const onTimeout = () => {
7566
+ cleanup();
7567
+ resolve4(results);
7568
+ };
7569
+ const cleanup = () => {
7570
+ clearTimeout(timer);
7571
+ if (idleTimer)
7572
+ clearTimeout(idleTimer);
7573
+ inp.removeListener("data", onData);
7574
+ const listenerIdx = this.activeListeners.findIndex((l) => l.handler === onData);
7575
+ if (listenerIdx !== -1)
7576
+ this.activeListeners.splice(listenerIdx, 1);
7577
+ const timerIdx = this.activeTimers.indexOf(timer);
7578
+ if (timerIdx !== -1)
7579
+ this.activeTimers.splice(timerIdx, 1);
7580
+ if (idleTimer) {
7581
+ const idleTimerIdx = this.activeTimers.indexOf(idleTimer);
7582
+ if (idleTimerIdx !== -1)
7583
+ this.activeTimers.splice(idleTimerIdx, 1);
7584
+ }
7585
+ };
7586
+ const timer = setTimeout(onTimeout, timeoutMs);
7587
+ this.activeTimers.push(timer);
7588
+ inp.on("data", onData);
7589
+ this.activeListeners.push({ event: "data", handler: onData });
7590
+ this.writeFn([
7591
+ "\x1B]10;?\x07",
7592
+ "\x1B]11;?\x07",
7593
+ "\x1B]12;?\x07",
7594
+ "\x1B]13;?\x07",
7595
+ "\x1B]14;?\x07",
7596
+ "\x1B]15;?\x07",
7597
+ "\x1B]16;?\x07",
7598
+ "\x1B]17;?\x07",
7599
+ "\x1B]19;?\x07"
7600
+ ].join(""));
7601
+ });
7602
+ }
7603
+ async detect(options) {
7604
+ const { timeout = 5000, size = 16 } = options || {};
7605
+ const supported = await this.detectOSCSupport();
7606
+ if (!supported) {
7607
+ return {
7608
+ palette: Array(size).fill(null),
7609
+ defaultForeground: null,
7610
+ defaultBackground: null,
7611
+ cursorColor: null,
7612
+ mouseForeground: null,
7613
+ mouseBackground: null,
7614
+ tekForeground: null,
7615
+ tekBackground: null,
7616
+ highlightBackground: null,
7617
+ highlightForeground: null
7618
+ };
7619
+ }
7620
+ const indicesToQuery = [...Array(size).keys()];
7621
+ const [paletteResults, specialColors] = await Promise.all([
7622
+ this.queryPalette(indicesToQuery, timeout),
7623
+ this.querySpecialColors(timeout)
7624
+ ]);
7625
+ return {
7626
+ palette: [...Array(size).keys()].map((i) => paletteResults.get(i) ?? null),
7627
+ defaultForeground: specialColors[10],
7628
+ defaultBackground: specialColors[11],
7629
+ cursorColor: specialColors[12],
7630
+ mouseForeground: specialColors[13],
7631
+ mouseBackground: specialColors[14],
7632
+ tekForeground: specialColors[15],
7633
+ tekBackground: specialColors[16],
7634
+ highlightBackground: specialColors[17],
7635
+ highlightForeground: specialColors[19]
7636
+ };
7637
+ }
7638
+ }
7639
+ function createTerminalPalette(stdin, stdout, writeFn) {
7640
+ return new TerminalPalette(stdin, stdout, writeFn);
7641
+ }
7344
7642
  // src/zig.ts
7345
7643
  import { dlopen, toArrayBuffer as toArrayBuffer4, JSCallback, ptr as ptr3 } from "bun:ffi";
7346
7644
  import { existsSync as existsSync2 } from "fs";
@@ -7546,7 +7844,7 @@ class OptimizedBuffer {
7546
7844
  }
7547
7845
  }
7548
7846
 
7549
- // ../../node_modules/.bun/bun-ffi-structs@0.1.0+ca84541ac88a3075/node_modules/bun-ffi-structs/index.js
7847
+ // ../../node_modules/bun-ffi-structs/index.js
7550
7848
  import { ptr, toArrayBuffer as toArrayBuffer2 } from "bun:ffi";
7551
7849
  function fatalError(...args) {
7552
7850
  const message = args.join(" ");
@@ -8484,6 +8782,14 @@ function getOpenTUILib(libPath) {
8484
8782
  args: ["ptr", "u8"],
8485
8783
  returns: "void"
8486
8784
  },
8785
+ textBufferAppend: {
8786
+ args: ["ptr", "ptr", "usize"],
8787
+ returns: "void"
8788
+ },
8789
+ textBufferAppendFromMemId: {
8790
+ args: ["ptr", "u8"],
8791
+ returns: "void"
8792
+ },
8487
8793
  textBufferLoadFile: {
8488
8794
  args: ["ptr", "ptr", "usize"],
8489
8795
  returns: "bool"
@@ -9447,6 +9753,12 @@ class FFIRenderLib {
9447
9753
  textBufferSetTextFromMem(buffer, memId) {
9448
9754
  this.opentui.symbols.textBufferSetTextFromMem(buffer, memId);
9449
9755
  }
9756
+ textBufferAppend(buffer, bytes) {
9757
+ this.opentui.symbols.textBufferAppend(buffer, bytes, bytes.length);
9758
+ }
9759
+ textBufferAppendFromMemId(buffer, memId) {
9760
+ this.opentui.symbols.textBufferAppendFromMemId(buffer, memId);
9761
+ }
9450
9762
  textBufferLoadFile(buffer, path4) {
9451
9763
  const pathBytes = this.encoder.encode(path4);
9452
9764
  return this.opentui.symbols.textBufferLoadFile(buffer, pathBytes, pathBytes.length);
@@ -10088,6 +10400,7 @@ class TextBuffer {
10088
10400
  _syntaxStyle;
10089
10401
  _textBytes;
10090
10402
  _memId;
10403
+ _appendedChunks = [];
10091
10404
  constructor(lib, ptr4) {
10092
10405
  this.lib = lib;
10093
10406
  this.bufferPtr = ptr4;
@@ -10112,6 +10425,16 @@ class TextBuffer {
10112
10425
  this._length = this.lib.textBufferGetLength(this.bufferPtr);
10113
10426
  this._byteSize = this.lib.textBufferGetByteSize(this.bufferPtr);
10114
10427
  this._lineInfo = undefined;
10428
+ this._appendedChunks = [];
10429
+ }
10430
+ append(text) {
10431
+ this.guard();
10432
+ const textBytes = this.lib.encoder.encode(text);
10433
+ this._appendedChunks.push(textBytes);
10434
+ this.lib.textBufferAppend(this.bufferPtr, textBytes);
10435
+ this._length = this.lib.textBufferGetLength(this.bufferPtr);
10436
+ this._byteSize = this.lib.textBufferGetByteSize(this.bufferPtr);
10437
+ this._lineInfo = undefined;
10115
10438
  }
10116
10439
  loadFile(path4) {
10117
10440
  this.guard();
@@ -10237,6 +10560,7 @@ class TextBuffer {
10237
10560
  this._byteSize = 0;
10238
10561
  this._lineInfo = undefined;
10239
10562
  this._textBytes = undefined;
10563
+ this._appendedChunks = [];
10240
10564
  }
10241
10565
  reset() {
10242
10566
  this.guard();
@@ -10246,6 +10570,7 @@ class TextBuffer {
10246
10570
  this._lineInfo = undefined;
10247
10571
  this._textBytes = undefined;
10248
10572
  this._memId = undefined;
10573
+ this._appendedChunks = [];
10249
10574
  }
10250
10575
  destroy() {
10251
10576
  if (this._destroyed)
@@ -10429,7 +10754,6 @@ class Renderable extends BaseRenderable {
10429
10754
  parent = null;
10430
10755
  childrenPrimarySortDirty = true;
10431
10756
  childrenSortedByPrimaryAxis = [];
10432
- _newChildren = [];
10433
10757
  onLifecyclePass = null;
10434
10758
  renderBefore;
10435
10759
  renderAfter;
@@ -11087,7 +11411,6 @@ class Renderable extends BaseRenderable {
11087
11411
  }
11088
11412
  obj.parent = this;
11089
11413
  }
11090
- _forceLayoutUpdateFor = null;
11091
11414
  add(obj, index) {
11092
11415
  if (!obj) {
11093
11416
  return -1;
@@ -11121,7 +11444,6 @@ class Renderable extends BaseRenderable {
11121
11444
  this.propagateLiveCount(renderable._liveCount);
11122
11445
  }
11123
11446
  }
11124
- this._newChildren.push(renderable);
11125
11447
  const childLayoutNode = renderable.getLayoutNode();
11126
11448
  const insertedIndex = this._childrenInLayoutOrder.length;
11127
11449
  this._childrenInLayoutOrder.push(renderable);
@@ -11174,11 +11496,9 @@ class Renderable extends BaseRenderable {
11174
11496
  this.propagateLiveCount(renderable._liveCount);
11175
11497
  }
11176
11498
  }
11177
- this._newChildren.push(renderable);
11178
11499
  this.childrenPrimarySortDirty = true;
11179
11500
  const anchorIndex = this._childrenInLayoutOrder.indexOf(anchor);
11180
11501
  const insertedIndex = Math.max(0, Math.min(anchorIndex, this._childrenInLayoutOrder.length));
11181
- this._forceLayoutUpdateFor = this._childrenInLayoutOrder.slice(insertedIndex);
11182
11502
  this._childrenInLayoutOrder.splice(insertedIndex, 0, renderable);
11183
11503
  this.yogaNode.insertChild(renderable.getLayoutNode(), insertedIndex);
11184
11504
  this.requestRender();
@@ -11212,16 +11532,6 @@ class Renderable extends BaseRenderable {
11212
11532
  if (zIndexIndex !== -1) {
11213
11533
  this._childrenInZIndexOrder.splice(zIndexIndex, 1);
11214
11534
  }
11215
- if (this._forceLayoutUpdateFor) {
11216
- const forceIndex = this._forceLayoutUpdateFor.findIndex((obj2) => obj2.id === id);
11217
- if (forceIndex !== -1) {
11218
- this._forceLayoutUpdateFor?.splice(forceIndex, 1);
11219
- }
11220
- }
11221
- const newChildIndex = this._newChildren.findIndex((obj2) => obj2.id === id);
11222
- if (newChildIndex !== -1) {
11223
- this._newChildren?.splice(newChildIndex, 1);
11224
- }
11225
11535
  this.childrenPrimarySortDirty = true;
11226
11536
  }
11227
11537
  }
@@ -11239,18 +11549,6 @@ class Renderable extends BaseRenderable {
11239
11549
  this.onUpdate(deltaTime);
11240
11550
  this.updateFromLayout();
11241
11551
  renderList.push({ action: "render", renderable: this });
11242
- if (this._newChildren.length > 0) {
11243
- for (const child of this._newChildren) {
11244
- child.updateFromLayout();
11245
- }
11246
- this._newChildren = [];
11247
- }
11248
- if (this._forceLayoutUpdateFor) {
11249
- for (const child of this._forceLayoutUpdateFor) {
11250
- child.updateFromLayout();
11251
- }
11252
- this._forceLayoutUpdateFor = null;
11253
- }
11254
11552
  this.ensureZIndexSorted();
11255
11553
  const shouldPushScissor = this._overflow !== "visible" && this.width > 0 && this.height > 0;
11256
11554
  if (shouldPushScissor) {
@@ -11263,7 +11561,12 @@ class Renderable extends BaseRenderable {
11263
11561
  height: scissorRect.height
11264
11562
  });
11265
11563
  }
11266
- for (const child of this._getChildren()) {
11564
+ const visibleChildren = this._getVisibleChildren();
11565
+ for (const child of this._childrenInZIndexOrder) {
11566
+ if (!visibleChildren.includes(child.num)) {
11567
+ child.updateFromLayout();
11568
+ continue;
11569
+ }
11267
11570
  child.updateLayout(deltaTime, renderList);
11268
11571
  }
11269
11572
  if (shouldPushScissor) {
@@ -11288,8 +11591,8 @@ class Renderable extends BaseRenderable {
11288
11591
  buffer.drawFrameBuffer(this.x, this.y, this.frameBuffer);
11289
11592
  }
11290
11593
  }
11291
- _getChildren() {
11292
- return this._childrenInZIndexOrder;
11594
+ _getVisibleChildren() {
11595
+ return this._childrenInZIndexOrder.map((child) => child.num);
11293
11596
  }
11294
11597
  onUpdate(deltaTime) {}
11295
11598
  getScissorRect() {
@@ -11886,7 +12189,7 @@ class TerminalConsole extends EventEmitter8 {
11886
12189
  isVisible = false;
11887
12190
  isFocused = false;
11888
12191
  renderer;
11889
- stdinHandler;
12192
+ keyHandler;
11890
12193
  options;
11891
12194
  _debugModeEnabled = false;
11892
12195
  frameBuffer = null;
@@ -11924,7 +12227,7 @@ class TerminalConsole extends EventEmitter8 {
11924
12227
  super();
11925
12228
  this.renderer = renderer;
11926
12229
  this.options = { ...DEFAULT_CONSOLE_OPTIONS, ...options };
11927
- this.stdinHandler = this.handleStdin.bind(this);
12230
+ this.keyHandler = this.handleKeyPress.bind(this);
11928
12231
  this._debugModeEnabled = this.options.startInDebugMode;
11929
12232
  terminalConsoleCache.setCollectCallerInfo(this._debugModeEnabled);
11930
12233
  this._rgbaInfo = parseColor(this.options.colorInfo);
@@ -12003,75 +12306,65 @@ class TerminalConsole extends EventEmitter8 {
12003
12306
  }
12004
12307
  this.currentLineIndex = Math.max(0, Math.min(this.currentLineIndex, this.consoleHeight - 1));
12005
12308
  }
12006
- handleStdin(data) {
12007
- const key = data.toString();
12309
+ handleKeyPress(event) {
12008
12310
  let needsRedraw = false;
12009
12311
  const displayLineCount = this._displayLines.length;
12010
12312
  const logAreaHeight = Math.max(1, this.consoleHeight - 1);
12011
12313
  const maxScrollTop = Math.max(0, displayLineCount - logAreaHeight);
12012
12314
  const currentPositionIndex = this._positions.indexOf(this.options.position);
12013
- switch (key) {
12014
- case "\x1B":
12015
- this.blur();
12016
- break;
12017
- case "\x1B[1;2A":
12018
- if (this.scrollTopIndex > 0 || this.currentLineIndex > 0) {
12019
- this.scrollTopIndex = 0;
12020
- this.currentLineIndex = 0;
12021
- this.isScrolledToBottom = this._displayLines.length <= Math.max(1, this.consoleHeight - 1);
12022
- needsRedraw = true;
12023
- }
12024
- break;
12025
- case "\x1B[1;2B":
12026
- const logAreaHeightForScroll = Math.max(1, this.consoleHeight - 1);
12027
- const maxScrollPossible = Math.max(0, this._displayLines.length - logAreaHeightForScroll);
12028
- if (this.scrollTopIndex < maxScrollPossible || !this.isScrolledToBottom) {
12029
- this._scrollToBottom(true);
12030
- needsRedraw = true;
12031
- }
12032
- break;
12033
- case "\x1B[A":
12034
- if (this.currentLineIndex > 0) {
12035
- this.currentLineIndex--;
12036
- needsRedraw = true;
12037
- } else if (this.scrollTopIndex > 0) {
12038
- this.scrollTopIndex--;
12039
- this.isScrolledToBottom = false;
12040
- needsRedraw = true;
12041
- }
12042
- break;
12043
- case "\x1B[B":
12044
- const canCursorMoveDown = this.currentLineIndex < logAreaHeight - 1 && this.scrollTopIndex + this.currentLineIndex < displayLineCount - 1;
12045
- if (canCursorMoveDown) {
12046
- this.currentLineIndex++;
12047
- needsRedraw = true;
12048
- } else if (this.scrollTopIndex < maxScrollTop) {
12049
- this.scrollTopIndex++;
12050
- this.isScrolledToBottom = this.scrollTopIndex === maxScrollTop;
12051
- needsRedraw = true;
12052
- }
12053
- break;
12054
- case "\x10":
12055
- const prevIndex = (currentPositionIndex - 1 + this._positions.length) % this._positions.length;
12056
- this.options.position = this._positions[prevIndex];
12057
- this.resize(this.renderer.terminalWidth, this.renderer.terminalHeight);
12058
- break;
12059
- case "\x0F":
12060
- const nextIndex = (currentPositionIndex + 1) % this._positions.length;
12061
- this.options.position = this._positions[nextIndex];
12062
- this.resize(this.renderer.terminalWidth, this.renderer.terminalHeight);
12063
- break;
12064
- case "+":
12065
- this.options.sizePercent = Math.min(100, this.options.sizePercent + 5);
12066
- this.resize(this.renderer.terminalWidth, this.renderer.terminalHeight);
12067
- break;
12068
- case "-":
12069
- this.options.sizePercent = Math.max(10, this.options.sizePercent - 5);
12070
- this.resize(this.renderer.terminalWidth, this.renderer.terminalHeight);
12071
- break;
12072
- case "\x13":
12073
- this.saveLogsToFile();
12074
- break;
12315
+ if (event.name === "escape") {
12316
+ this.blur();
12317
+ return;
12318
+ }
12319
+ if (event.name === "up" && event.shift) {
12320
+ if (this.scrollTopIndex > 0 || this.currentLineIndex > 0) {
12321
+ this.scrollTopIndex = 0;
12322
+ this.currentLineIndex = 0;
12323
+ this.isScrolledToBottom = this._displayLines.length <= Math.max(1, this.consoleHeight - 1);
12324
+ needsRedraw = true;
12325
+ }
12326
+ } else if (event.name === "down" && event.shift) {
12327
+ const logAreaHeightForScroll = Math.max(1, this.consoleHeight - 1);
12328
+ const maxScrollPossible = Math.max(0, this._displayLines.length - logAreaHeightForScroll);
12329
+ if (this.scrollTopIndex < maxScrollPossible || !this.isScrolledToBottom) {
12330
+ this._scrollToBottom(true);
12331
+ needsRedraw = true;
12332
+ }
12333
+ } else if (event.name === "up") {
12334
+ if (this.currentLineIndex > 0) {
12335
+ this.currentLineIndex--;
12336
+ needsRedraw = true;
12337
+ } else if (this.scrollTopIndex > 0) {
12338
+ this.scrollTopIndex--;
12339
+ this.isScrolledToBottom = false;
12340
+ needsRedraw = true;
12341
+ }
12342
+ } else if (event.name === "down") {
12343
+ const canCursorMoveDown = this.currentLineIndex < logAreaHeight - 1 && this.scrollTopIndex + this.currentLineIndex < displayLineCount - 1;
12344
+ if (canCursorMoveDown) {
12345
+ this.currentLineIndex++;
12346
+ needsRedraw = true;
12347
+ } else if (this.scrollTopIndex < maxScrollTop) {
12348
+ this.scrollTopIndex++;
12349
+ this.isScrolledToBottom = this.scrollTopIndex === maxScrollTop;
12350
+ needsRedraw = true;
12351
+ }
12352
+ } else if (event.name === "p" && event.ctrl) {
12353
+ const prevIndex = (currentPositionIndex - 1 + this._positions.length) % this._positions.length;
12354
+ this.options.position = this._positions[prevIndex];
12355
+ this.resize(this.renderer.terminalWidth, this.renderer.terminalHeight);
12356
+ } else if (event.name === "o" && event.ctrl) {
12357
+ const nextIndex = (currentPositionIndex + 1) % this._positions.length;
12358
+ this.options.position = this._positions[nextIndex];
12359
+ this.resize(this.renderer.terminalWidth, this.renderer.terminalHeight);
12360
+ } else if (event.name === "+" || event.name === "=" && event.shift) {
12361
+ this.options.sizePercent = Math.min(100, this.options.sizePercent + 5);
12362
+ this.resize(this.renderer.terminalWidth, this.renderer.terminalHeight);
12363
+ } else if (event.name === "-") {
12364
+ this.options.sizePercent = Math.max(10, this.options.sizePercent - 5);
12365
+ this.resize(this.renderer.terminalWidth, this.renderer.terminalHeight);
12366
+ } else if (event.name === "s" && event.ctrl) {
12367
+ this.saveLogsToFile();
12075
12368
  }
12076
12369
  if (needsRedraw) {
12077
12370
  this.markNeedsRerender();
@@ -12080,13 +12373,13 @@ class TerminalConsole extends EventEmitter8 {
12080
12373
  attachStdin() {
12081
12374
  if (this.isFocused)
12082
12375
  return;
12083
- process.stdin.on("data", this.stdinHandler);
12376
+ this.renderer.keyInput.on("keypress", this.keyHandler);
12084
12377
  this.isFocused = true;
12085
12378
  }
12086
12379
  detachStdin() {
12087
12380
  if (!this.isFocused)
12088
12381
  return;
12089
- process.stdin.off("data", this.stdinHandler);
12382
+ this.renderer.keyInput.off("keypress", this.keyHandler);
12090
12383
  this.isFocused = false;
12091
12384
  }
12092
12385
  formatTimestamp(date) {
@@ -12662,6 +12955,9 @@ class CliRenderer extends EventEmitter9 {
12662
12955
  _currentFocusedRenderable = null;
12663
12956
  lifecyclePasses = new Set;
12664
12957
  _openConsoleOnError = true;
12958
+ _paletteDetector = null;
12959
+ _cachedPalette = null;
12960
+ _paletteDetectionPromise = null;
12665
12961
  handleError = ((error) => {
12666
12962
  console.error(error);
12667
12963
  if (this._openConsoleOnError) {
@@ -12747,9 +13043,6 @@ Captured output:
12747
13043
  process.on("uncaughtException", this.handleError);
12748
13044
  process.on("unhandledRejection", this.handleError);
12749
13045
  process.on("exit", this.exitHandler);
12750
- this._console = new TerminalConsole(this, config.consoleOptions);
12751
- this.useConsole = config.useConsole ?? true;
12752
- this._openConsoleOnError = config.openConsoleOnError ?? true;
12753
13046
  this._keyHandler = new InternalKeyHandler(this.stdin, config.useKittyKeyboard ?? true);
12754
13047
  this._keyHandler.on("keypress", (event) => {
12755
13048
  if (this.exitOnCtrlC && event.name === "c" && event.ctrl) {
@@ -12759,6 +13052,9 @@ Captured output:
12759
13052
  return;
12760
13053
  }
12761
13054
  });
13055
+ this._console = new TerminalConsole(this, config.consoleOptions);
13056
+ this.useConsole = config.useConsole ?? true;
13057
+ this._openConsoleOnError = config.openConsoleOnError ?? true;
12762
13058
  global.requestAnimationFrame = (callback) => {
12763
13059
  const id = CliRenderer.animationFrameId++;
12764
13060
  this.animationRequest.set(id, callback);
@@ -13409,6 +13705,12 @@ Captured output:
13409
13705
  if (this.memorySnapshotTimer) {
13410
13706
  clearInterval(this.memorySnapshotTimer);
13411
13707
  }
13708
+ if (this._paletteDetector) {
13709
+ this._paletteDetector.cleanup();
13710
+ this._paletteDetector = null;
13711
+ }
13712
+ this._paletteDetectionPromise = null;
13713
+ this._cachedPalette = null;
13412
13714
  if (this._isDestroyed)
13413
13715
  return;
13414
13716
  this._isDestroyed = true;
@@ -13661,9 +13963,43 @@ Captured output:
13661
13963
  }
13662
13964
  }
13663
13965
  }
13966
+ get paletteDetectionStatus() {
13967
+ if (this._cachedPalette)
13968
+ return "cached";
13969
+ if (this._paletteDetectionPromise)
13970
+ return "detecting";
13971
+ return "idle";
13972
+ }
13973
+ clearPaletteCache() {
13974
+ this._cachedPalette = null;
13975
+ }
13976
+ async getPalette(options) {
13977
+ if (this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */) {
13978
+ throw new Error("Cannot detect palette while renderer is suspended");
13979
+ }
13980
+ const requestedSize = options?.size ?? 16;
13981
+ if (this._cachedPalette && this._cachedPalette.palette.length !== requestedSize) {
13982
+ this._cachedPalette = null;
13983
+ }
13984
+ if (this._cachedPalette) {
13985
+ return this._cachedPalette;
13986
+ }
13987
+ if (this._paletteDetectionPromise) {
13988
+ return this._paletteDetectionPromise;
13989
+ }
13990
+ if (!this._paletteDetector) {
13991
+ this._paletteDetector = createTerminalPalette(this.stdin, this.stdout, this.writeOut.bind(this));
13992
+ }
13993
+ this._paletteDetectionPromise = this._paletteDetector.detect(options).then((result) => {
13994
+ this._cachedPalette = result;
13995
+ this._paletteDetectionPromise = null;
13996
+ return result;
13997
+ });
13998
+ return this._paletteDetectionPromise;
13999
+ }
13664
14000
  }
13665
14001
 
13666
- export { __toESM, __commonJS, __export, __require, Edge, Gutter, exports_src, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, nonAlphanumericKeys, parseKeypress, ANSI, StdinBuffer, KeyEvent, PasteEvent, KeyHandler, InternalKeyHandler, RGBA, hexToRgb, rgbToHex, hsvToRgb, parseColor, fonts, measureText, getCharacterPositions, coordinateToCharacterIndex, renderFontToFrameBuffer, TextAttributes, DebugOverlayCorner, createTextAttributes, visualizeRenderableTree, isStyledText, StyledText, stringToStyledText, black, red, green, yellow, blue, magenta, cyan, white, brightBlack, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bold, italic, underline, strikethrough, dim, reverse, blink, fg, bg, t, hastToStyledText, LinearScrollAccel, MacOSScrollAccel, parseAlign, parseBoxSizing, parseDimension, parseDirection, parseDisplay, parseEdge, parseFlexDirection, parseGutter, parseJustify, parseLogLevel, parseMeasureMode, parseOverflow, parsePositionType, parseUnit, parseWrap, MouseParser, Selection, convertGlobalToLocalSelection, ASCIIFontSelectionHelper, envRegistry, registerEnvVar, clearEnvCache, generateEnvMarkdown, generateEnvColored, env, treeSitterToTextChunks, treeSitterToStyledText, addDefaultParsers, TreeSitterClient, DataPathsManager, getDataPaths, extToFiletype, pathToFiletype, main, getTreeSitterClient, ExtmarksController, createExtmarksController, TextBuffer, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, isValidPercentage, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, RendererControlState, CliRenderer };
14002
+ export { __toESM, __commonJS, __export, __require, Edge, Gutter, exports_src, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, nonAlphanumericKeys, parseKeypress, ANSI, StdinBuffer, KeyEvent, PasteEvent, KeyHandler, InternalKeyHandler, RGBA, hexToRgb, rgbToHex, hsvToRgb, parseColor, fonts, measureText, getCharacterPositions, coordinateToCharacterIndex, renderFontToFrameBuffer, TextAttributes, DebugOverlayCorner, createTextAttributes, visualizeRenderableTree, isStyledText, StyledText, stringToStyledText, black, red, green, yellow, blue, magenta, cyan, white, brightBlack, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bold, italic, underline, strikethrough, dim, reverse, blink, fg, bg, t, hastToStyledText, LinearScrollAccel, MacOSScrollAccel, parseAlign, parseBoxSizing, parseDimension, parseDirection, parseDisplay, parseEdge, parseFlexDirection, parseGutter, parseJustify, parseLogLevel, parseMeasureMode, parseOverflow, parsePositionType, parseUnit, parseWrap, MouseParser, Selection, convertGlobalToLocalSelection, ASCIIFontSelectionHelper, envRegistry, registerEnvVar, clearEnvCache, generateEnvMarkdown, generateEnvColored, env, treeSitterToTextChunks, treeSitterToStyledText, addDefaultParsers, TreeSitterClient, DataPathsManager, getDataPaths, extToFiletype, pathToFiletype, main, getTreeSitterClient, ExtmarksController, createExtmarksController, TerminalPalette, createTerminalPalette, TextBuffer, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, isValidPercentage, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, RendererControlState, CliRenderer };
13667
14003
 
13668
- //# debugId=A88F8272C607FC3964756E2164756E21
13669
- //# sourceMappingURL=index-n8nbvvhk.js.map
14004
+ //# debugId=FE3334220FB993E564756E2164756E21
14005
+ //# sourceMappingURL=index-z5bb2h2z.js.map