@opentui/core 0.0.0-20251010-2eed09fd → 0.0.0-20251026-63abf532

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/3d.js +140 -140
  2. package/3d.js.map +3 -3
  3. package/README.md +10 -0
  4. package/Renderable.d.ts +25 -24
  5. package/buffer.d.ts +4 -7
  6. package/edit-buffer.d.ts +83 -0
  7. package/editor-view.d.ts +55 -0
  8. package/{index-kqk5knmb.js → index-g5xctwrm.js} +2572 -494
  9. package/index-g5xctwrm.js.map +55 -0
  10. package/index.d.ts +4 -0
  11. package/index.js +3542 -2025
  12. package/index.js.map +19 -12
  13. package/lib/extmarks-history.d.ts +17 -0
  14. package/lib/extmarks.d.ts +88 -0
  15. package/lib/hast-styled-text.d.ts +2 -3
  16. package/lib/index.d.ts +1 -1
  17. package/lib/keymapping.d.ts +10 -0
  18. package/lib/objects-in-viewport.d.ts +14 -0
  19. package/lib/parse.keypress.d.ts +1 -1
  20. package/lib/tree-sitter/index.d.ts +0 -2
  21. package/lib/tree-sitter-styled-text.d.ts +1 -1
  22. package/lib/yoga.options.d.ts +6 -6
  23. package/package.json +9 -7
  24. package/renderables/Code.d.ts +1 -1
  25. package/renderables/EditBufferRenderable.d.ts +119 -0
  26. package/renderables/Text.d.ts +0 -3
  27. package/renderables/TextBufferRenderable.d.ts +8 -14
  28. package/renderables/TextNode.d.ts +2 -1
  29. package/renderables/Textarea.d.ts +95 -0
  30. package/renderables/index.d.ts +11 -9
  31. package/renderer.d.ts +7 -2
  32. package/{lib/syntax-style.d.ts → syntax-style.d.ts} +21 -5
  33. package/testing/mock-keys.d.ts +39 -2
  34. package/testing.js +54 -6
  35. package/testing.js.map +3 -3
  36. package/text-buffer-view.d.ts +31 -0
  37. package/text-buffer.d.ts +28 -21
  38. package/types.d.ts +10 -0
  39. package/zig-structs.d.ts +22 -0
  40. package/zig.d.ts +154 -23
  41. package/index-kqk5knmb.js.map +0 -52
  42. package/lib/word-jumps.d.ts +0 -2
@@ -27,7 +27,7 @@ var __export = (target, all) => {
27
27
  };
28
28
  var __require = import.meta.require;
29
29
 
30
- // ../../node_modules/yoga-layout/dist/src/index.js
30
+ // ../../node_modules/.bun/yoga-layout@3.2.1/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/yoga-layout/dist/binaries/yoga-wasm-base64-esm.js
54
+ // ../../node_modules/.bun/yoga-layout@3.2.1/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/yoga-layout/dist/src/generated/YGEnums.js
1359
+ // ../../node_modules/.bun/yoga-layout@3.2.1/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/yoga-layout/dist/src/wrapAssembly.js
1562
+ // ../../node_modules/.bun/yoga-layout@3.2.1/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/yoga-layout/dist/src/index.js
1664
+ // ../../node_modules/.bun/yoga-layout@3.2.1/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
 
@@ -2092,6 +2092,12 @@ var parseKeypress = (s = "", options = {}) => {
2092
2092
  } else if (!s) {
2093
2093
  s = "";
2094
2094
  }
2095
+ if (/^\x1b\[<\d+;\d+;\d+[Mm]$/.test(s)) {
2096
+ return null;
2097
+ }
2098
+ if (s.startsWith("\x1B[M") && s.length >= 6) {
2099
+ return null;
2100
+ }
2095
2101
  const key = {
2096
2102
  name: "",
2097
2103
  ctrl: false,
@@ -2110,11 +2116,14 @@ var parseKeypress = (s = "", options = {}) => {
2110
2116
  return kittyResult;
2111
2117
  }
2112
2118
  }
2113
- if (s === "\r") {
2119
+ if (s === "\r" || s === "\x1B\r") {
2114
2120
  key.name = "return";
2121
+ key.meta = s.length === 2;
2115
2122
  } else if (s === `
2123
+ ` || s === `\x1B
2116
2124
  `) {
2117
2125
  key.name = "enter";
2126
+ key.meta = s.length === 2;
2118
2127
  } else if (s === "\t") {
2119
2128
  key.name = "tab";
2120
2129
  } else if (s === "\b" || s === "\x1B\b" || s === "\x7F" || s === "\x1B\x7F") {
@@ -2277,6 +2286,9 @@ class KeyHandler extends EventEmitter {
2277
2286
  return;
2278
2287
  }
2279
2288
  const parsedKey = parseKeypress(key, { useKittyKeyboard: this.useKittyKeyboard });
2289
+ if (!parsedKey) {
2290
+ return;
2291
+ }
2280
2292
  switch (parsedKey.eventType) {
2281
2293
  case "press":
2282
2294
  this.emit("keypress", new KeyEvent(parsedKey));
@@ -2406,18 +2418,22 @@ function hexToRgb(hex) {
2406
2418
  hex = hex.replace(/^#/, "");
2407
2419
  if (hex.length === 3) {
2408
2420
  hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
2421
+ } else if (hex.length === 4) {
2422
+ hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3];
2409
2423
  }
2410
- if (!/^[0-9A-Fa-f]{6}$/.test(hex)) {
2424
+ if (!/^[0-9A-Fa-f]{6}$/.test(hex) && !/^[0-9A-Fa-f]{8}$/.test(hex)) {
2411
2425
  console.warn(`Invalid hex color: ${hex}, defaulting to magenta`);
2412
2426
  return RGBA.fromValues(1, 0, 1, 1);
2413
2427
  }
2414
2428
  const r = parseInt(hex.substring(0, 2), 16) / 255;
2415
2429
  const g = parseInt(hex.substring(2, 4), 16) / 255;
2416
2430
  const b = parseInt(hex.substring(4, 6), 16) / 255;
2417
- return RGBA.fromValues(r, g, b, 1);
2431
+ const a = hex.length === 8 ? parseInt(hex.substring(6, 8), 16) / 255 : 1;
2432
+ return RGBA.fromValues(r, g, b, a);
2418
2433
  }
2419
2434
  function rgbToHex(rgb) {
2420
- return "#" + [rgb.r, rgb.g, rgb.b].map((x) => {
2435
+ const components = rgb.a === 1 ? [rgb.r, rgb.g, rgb.b] : [rgb.r, rgb.g, rgb.b, rgb.a];
2436
+ return "#" + components.map((x) => {
2421
2437
  const hex = Math.floor(Math.max(0, Math.min(1, x) * 255)).toString(16);
2422
2438
  return hex.length === 1 ? "0" + hex : hex;
2423
2439
  }).join("");
@@ -4299,104 +4315,6 @@ function t(strings, ...values) {
4299
4315
  return new StyledText(chunks);
4300
4316
  }
4301
4317
 
4302
- // src/lib/syntax-style.ts
4303
- function convertThemeToStyles(theme) {
4304
- const flatStyles = {};
4305
- for (const tokenStyle of theme) {
4306
- const styleDefinition = {};
4307
- if (tokenStyle.style.foreground) {
4308
- styleDefinition.fg = parseColor(tokenStyle.style.foreground);
4309
- }
4310
- if (tokenStyle.style.background) {
4311
- styleDefinition.bg = parseColor(tokenStyle.style.background);
4312
- }
4313
- if (tokenStyle.style.bold !== undefined) {
4314
- styleDefinition.bold = tokenStyle.style.bold;
4315
- }
4316
- if (tokenStyle.style.italic !== undefined) {
4317
- styleDefinition.italic = tokenStyle.style.italic;
4318
- }
4319
- if (tokenStyle.style.underline !== undefined) {
4320
- styleDefinition.underline = tokenStyle.style.underline;
4321
- }
4322
- if (tokenStyle.style.dim !== undefined) {
4323
- styleDefinition.dim = tokenStyle.style.dim;
4324
- }
4325
- for (const scope of tokenStyle.scope) {
4326
- flatStyles[scope] = styleDefinition;
4327
- }
4328
- }
4329
- return flatStyles;
4330
- }
4331
-
4332
- class SyntaxStyle {
4333
- styles;
4334
- mergedStyleCache;
4335
- constructor(styles) {
4336
- this.styles = styles;
4337
- this.mergedStyleCache = new Map;
4338
- }
4339
- static fromTheme(theme) {
4340
- const flatStyles = convertThemeToStyles(theme);
4341
- return new SyntaxStyle(flatStyles);
4342
- }
4343
- mergeStyles(...styleNames) {
4344
- const cacheKey = styleNames.join(":");
4345
- const cached = this.mergedStyleCache.get(cacheKey);
4346
- if (cached)
4347
- return cached;
4348
- const styleDefinition = {};
4349
- for (const name of styleNames) {
4350
- const style = this.getStyle(name);
4351
- if (!style)
4352
- continue;
4353
- if (style.fg)
4354
- styleDefinition.fg = style.fg;
4355
- if (style.bg)
4356
- styleDefinition.bg = style.bg;
4357
- if (style.bold !== undefined)
4358
- styleDefinition.bold = style.bold;
4359
- if (style.italic !== undefined)
4360
- styleDefinition.italic = style.italic;
4361
- if (style.underline !== undefined)
4362
- styleDefinition.underline = style.underline;
4363
- if (style.dim !== undefined)
4364
- styleDefinition.dim = style.dim;
4365
- }
4366
- const attributes = createTextAttributes({
4367
- bold: styleDefinition.bold,
4368
- italic: styleDefinition.italic,
4369
- underline: styleDefinition.underline,
4370
- dim: styleDefinition.dim
4371
- });
4372
- const merged = {
4373
- fg: styleDefinition.fg,
4374
- bg: styleDefinition.bg,
4375
- attributes
4376
- };
4377
- this.mergedStyleCache.set(cacheKey, merged);
4378
- return merged;
4379
- }
4380
- getStyle(name) {
4381
- if (Object.prototype.hasOwnProperty.call(this.styles, name)) {
4382
- return this.styles[name];
4383
- }
4384
- if (name.includes(".")) {
4385
- const baseName = name.split(".")[0];
4386
- if (Object.prototype.hasOwnProperty.call(this.styles, baseName)) {
4387
- return this.styles[baseName];
4388
- }
4389
- }
4390
- return;
4391
- }
4392
- clearCache() {
4393
- this.mergedStyleCache.clear();
4394
- }
4395
- getCacheSize() {
4396
- return this.mergedStyleCache.size;
4397
- }
4398
- }
4399
-
4400
4318
  // src/lib/hast-styled-text.ts
4401
4319
  function hastToTextChunks(node, syntaxStyle, parentStyles = []) {
4402
4320
  const chunks = [];
@@ -4480,6 +4398,9 @@ class MacOSScrollAccel {
4480
4398
 
4481
4399
  // src/lib/yoga.options.ts
4482
4400
  function parseAlign(value) {
4401
+ if (value == null) {
4402
+ return Align.Auto;
4403
+ }
4483
4404
  switch (value.toLowerCase()) {
4484
4405
  case "auto":
4485
4406
  return Align.Auto;
@@ -4504,6 +4425,9 @@ function parseAlign(value) {
4504
4425
  }
4505
4426
  }
4506
4427
  function parseBoxSizing(value) {
4428
+ if (value == null) {
4429
+ return BoxSizing.BorderBox;
4430
+ }
4507
4431
  switch (value.toLowerCase()) {
4508
4432
  case "border-box":
4509
4433
  return BoxSizing.BorderBox;
@@ -4514,6 +4438,9 @@ function parseBoxSizing(value) {
4514
4438
  }
4515
4439
  }
4516
4440
  function parseDimension(value) {
4441
+ if (value == null) {
4442
+ return Dimension.Width;
4443
+ }
4517
4444
  switch (value.toLowerCase()) {
4518
4445
  case "width":
4519
4446
  return Dimension.Width;
@@ -4524,6 +4451,9 @@ function parseDimension(value) {
4524
4451
  }
4525
4452
  }
4526
4453
  function parseDirection(value) {
4454
+ if (value == null) {
4455
+ return Direction.LTR;
4456
+ }
4527
4457
  switch (value.toLowerCase()) {
4528
4458
  case "inherit":
4529
4459
  return Direction.Inherit;
@@ -4536,6 +4466,9 @@ function parseDirection(value) {
4536
4466
  }
4537
4467
  }
4538
4468
  function parseDisplay(value) {
4469
+ if (value == null) {
4470
+ return Display.Flex;
4471
+ }
4539
4472
  switch (value.toLowerCase()) {
4540
4473
  case "flex":
4541
4474
  return Display.Flex;
@@ -4548,6 +4481,9 @@ function parseDisplay(value) {
4548
4481
  }
4549
4482
  }
4550
4483
  function parseEdge(value) {
4484
+ if (value == null) {
4485
+ return Edge.All;
4486
+ }
4551
4487
  switch (value.toLowerCase()) {
4552
4488
  case "left":
4553
4489
  return Edge.Left;
@@ -4572,6 +4508,9 @@ function parseEdge(value) {
4572
4508
  }
4573
4509
  }
4574
4510
  function parseFlexDirection(value) {
4511
+ if (value == null) {
4512
+ return FlexDirection.Column;
4513
+ }
4575
4514
  switch (value.toLowerCase()) {
4576
4515
  case "column":
4577
4516
  return FlexDirection.Column;
@@ -4586,6 +4525,9 @@ function parseFlexDirection(value) {
4586
4525
  }
4587
4526
  }
4588
4527
  function parseGutter(value) {
4528
+ if (value == null) {
4529
+ return Gutter.All;
4530
+ }
4589
4531
  switch (value.toLowerCase()) {
4590
4532
  case "column":
4591
4533
  return Gutter.Column;
@@ -4598,6 +4540,9 @@ function parseGutter(value) {
4598
4540
  }
4599
4541
  }
4600
4542
  function parseJustify(value) {
4543
+ if (value == null) {
4544
+ return Justify.FlexStart;
4545
+ }
4601
4546
  switch (value.toLowerCase()) {
4602
4547
  case "flex-start":
4603
4548
  return Justify.FlexStart;
@@ -4616,6 +4561,9 @@ function parseJustify(value) {
4616
4561
  }
4617
4562
  }
4618
4563
  function parseLogLevel(value) {
4564
+ if (value == null) {
4565
+ return LogLevel.Info;
4566
+ }
4619
4567
  switch (value.toLowerCase()) {
4620
4568
  case "error":
4621
4569
  return LogLevel.Error;
@@ -4634,6 +4582,9 @@ function parseLogLevel(value) {
4634
4582
  }
4635
4583
  }
4636
4584
  function parseMeasureMode(value) {
4585
+ if (value == null) {
4586
+ return MeasureMode.Undefined;
4587
+ }
4637
4588
  switch (value.toLowerCase()) {
4638
4589
  case "undefined":
4639
4590
  return MeasureMode.Undefined;
@@ -4646,6 +4597,9 @@ function parseMeasureMode(value) {
4646
4597
  }
4647
4598
  }
4648
4599
  function parseOverflow(value) {
4600
+ if (value == null) {
4601
+ return Overflow.Visible;
4602
+ }
4649
4603
  switch (value.toLowerCase()) {
4650
4604
  case "visible":
4651
4605
  return Overflow.Visible;
@@ -4658,6 +4612,9 @@ function parseOverflow(value) {
4658
4612
  }
4659
4613
  }
4660
4614
  function parsePositionType(value) {
4615
+ if (value == null) {
4616
+ return PositionType.Relative;
4617
+ }
4661
4618
  switch (value.toLowerCase()) {
4662
4619
  case "static":
4663
4620
  return PositionType.Static;
@@ -4670,6 +4627,9 @@ function parsePositionType(value) {
4670
4627
  }
4671
4628
  }
4672
4629
  function parseUnit(value) {
4630
+ if (value == null) {
4631
+ return Unit.Point;
4632
+ }
4673
4633
  switch (value.toLowerCase()) {
4674
4634
  case "undefined":
4675
4635
  return Unit.Undefined;
@@ -4684,6 +4644,9 @@ function parseUnit(value) {
4684
4644
  }
4685
4645
  }
4686
4646
  function parseWrap(value) {
4647
+ if (value == null) {
4648
+ return Wrap.NoWrap;
4649
+ }
4687
4650
  switch (value.toLowerCase()) {
4688
4651
  case "no-wrap":
4689
4652
  return Wrap.NoWrap;
@@ -6253,9 +6216,684 @@ function getTreeSitterClient() {
6253
6216
  return client2;
6254
6217
  });
6255
6218
  }
6219
+
6220
+ // src/lib/extmarks-history.ts
6221
+ class ExtmarksHistory {
6222
+ undoStack = [];
6223
+ redoStack = [];
6224
+ saveSnapshot(extmarks, nextId) {
6225
+ const snapshot = {
6226
+ extmarks: new Map(Array.from(extmarks.entries()).map(([id, extmark]) => [id, { ...extmark }])),
6227
+ nextId
6228
+ };
6229
+ this.undoStack.push(snapshot);
6230
+ this.redoStack = [];
6231
+ }
6232
+ undo() {
6233
+ if (this.undoStack.length === 0)
6234
+ return null;
6235
+ return this.undoStack.pop();
6236
+ }
6237
+ redo() {
6238
+ if (this.redoStack.length === 0)
6239
+ return null;
6240
+ return this.redoStack.pop();
6241
+ }
6242
+ pushRedo(snapshot) {
6243
+ this.redoStack.push(snapshot);
6244
+ }
6245
+ pushUndo(snapshot) {
6246
+ this.undoStack.push(snapshot);
6247
+ }
6248
+ clear() {
6249
+ this.undoStack = [];
6250
+ this.redoStack = [];
6251
+ }
6252
+ canUndo() {
6253
+ return this.undoStack.length > 0;
6254
+ }
6255
+ canRedo() {
6256
+ return this.redoStack.length > 0;
6257
+ }
6258
+ }
6259
+
6260
+ // src/lib/extmarks.ts
6261
+ class ExtmarksController {
6262
+ editBuffer;
6263
+ editorView;
6264
+ extmarks = new Map;
6265
+ extmarksByTypeId = new Map;
6266
+ metadata = new Map;
6267
+ nextId = 1;
6268
+ destroyed = false;
6269
+ history = new ExtmarksHistory;
6270
+ typeNameToId = new Map;
6271
+ typeIdToName = new Map;
6272
+ nextTypeId = 1;
6273
+ originalMoveCursorLeft;
6274
+ originalMoveCursorRight;
6275
+ originalSetCursorByOffset;
6276
+ originalMoveUpVisual;
6277
+ originalMoveDownVisual;
6278
+ originalDeleteCharBackward;
6279
+ originalDeleteChar;
6280
+ originalInsertText;
6281
+ originalInsertChar;
6282
+ originalDeleteRange;
6283
+ originalSetText;
6284
+ originalClear;
6285
+ originalNewLine;
6286
+ originalDeleteLine;
6287
+ originalEditorViewDeleteSelectedText;
6288
+ originalUndo;
6289
+ originalRedo;
6290
+ constructor(editBuffer, editorView) {
6291
+ this.editBuffer = editBuffer;
6292
+ this.editorView = editorView;
6293
+ this.originalMoveCursorLeft = editBuffer.moveCursorLeft.bind(editBuffer);
6294
+ this.originalMoveCursorRight = editBuffer.moveCursorRight.bind(editBuffer);
6295
+ this.originalSetCursorByOffset = editBuffer.setCursorByOffset.bind(editBuffer);
6296
+ this.originalMoveUpVisual = editorView.moveUpVisual.bind(editorView);
6297
+ this.originalMoveDownVisual = editorView.moveDownVisual.bind(editorView);
6298
+ this.originalDeleteCharBackward = editBuffer.deleteCharBackward.bind(editBuffer);
6299
+ this.originalDeleteChar = editBuffer.deleteChar.bind(editBuffer);
6300
+ this.originalInsertText = editBuffer.insertText.bind(editBuffer);
6301
+ this.originalInsertChar = editBuffer.insertChar.bind(editBuffer);
6302
+ this.originalDeleteRange = editBuffer.deleteRange.bind(editBuffer);
6303
+ this.originalSetText = editBuffer.setText.bind(editBuffer);
6304
+ this.originalClear = editBuffer.clear.bind(editBuffer);
6305
+ this.originalNewLine = editBuffer.newLine.bind(editBuffer);
6306
+ this.originalDeleteLine = editBuffer.deleteLine.bind(editBuffer);
6307
+ this.originalEditorViewDeleteSelectedText = editorView.deleteSelectedText.bind(editorView);
6308
+ this.originalUndo = editBuffer.undo.bind(editBuffer);
6309
+ this.originalRedo = editBuffer.redo.bind(editBuffer);
6310
+ this.wrapCursorMovement();
6311
+ this.wrapDeletion();
6312
+ this.wrapInsertion();
6313
+ this.wrapEditorViewDeleteSelectedText();
6314
+ this.wrapUndoRedo();
6315
+ this.setupContentChangeListener();
6316
+ }
6317
+ wrapCursorMovement() {
6318
+ this.editBuffer.moveCursorLeft = () => {
6319
+ if (this.destroyed) {
6320
+ this.originalMoveCursorLeft();
6321
+ return;
6322
+ }
6323
+ const currentOffset = this.editorView.getVisualCursor().offset;
6324
+ const hasSelection = this.editorView.hasSelection();
6325
+ if (hasSelection) {
6326
+ this.originalMoveCursorLeft();
6327
+ return;
6328
+ }
6329
+ const targetOffset = currentOffset - 1;
6330
+ if (targetOffset < 0) {
6331
+ this.originalMoveCursorLeft();
6332
+ return;
6333
+ }
6334
+ const virtualExtmark = this.findVirtualExtmarkContaining(targetOffset);
6335
+ if (virtualExtmark && currentOffset >= virtualExtmark.end) {
6336
+ this.editBuffer.setCursorByOffset(virtualExtmark.start - 1);
6337
+ return;
6338
+ }
6339
+ this.originalMoveCursorLeft();
6340
+ };
6341
+ this.editBuffer.moveCursorRight = () => {
6342
+ if (this.destroyed) {
6343
+ this.originalMoveCursorRight();
6344
+ return;
6345
+ }
6346
+ const currentOffset = this.editorView.getVisualCursor().offset;
6347
+ const hasSelection = this.editorView.hasSelection();
6348
+ if (hasSelection) {
6349
+ this.originalMoveCursorRight();
6350
+ return;
6351
+ }
6352
+ const targetOffset = currentOffset + 1;
6353
+ const textLength = this.editBuffer.getText().length;
6354
+ if (targetOffset > textLength) {
6355
+ this.originalMoveCursorRight();
6356
+ return;
6357
+ }
6358
+ const virtualExtmark = this.findVirtualExtmarkContaining(targetOffset);
6359
+ if (virtualExtmark && currentOffset <= virtualExtmark.start) {
6360
+ this.editBuffer.setCursorByOffset(virtualExtmark.end);
6361
+ return;
6362
+ }
6363
+ this.originalMoveCursorRight();
6364
+ };
6365
+ this.editorView.moveUpVisual = () => {
6366
+ if (this.destroyed) {
6367
+ this.originalMoveUpVisual();
6368
+ return;
6369
+ }
6370
+ const hasSelection = this.editorView.hasSelection();
6371
+ if (hasSelection) {
6372
+ this.originalMoveUpVisual();
6373
+ return;
6374
+ }
6375
+ const currentOffset = this.editorView.getVisualCursor().offset;
6376
+ this.originalMoveUpVisual();
6377
+ const newOffset = this.editorView.getVisualCursor().offset;
6378
+ const virtualExtmark = this.findVirtualExtmarkContaining(newOffset);
6379
+ if (virtualExtmark) {
6380
+ const distanceToStart = newOffset - virtualExtmark.start;
6381
+ const distanceToEnd = virtualExtmark.end - newOffset;
6382
+ if (distanceToStart < distanceToEnd) {
6383
+ this.editorView.setCursorByOffset(virtualExtmark.start - 1);
6384
+ } else {
6385
+ this.editorView.setCursorByOffset(virtualExtmark.end);
6386
+ }
6387
+ }
6388
+ };
6389
+ this.editorView.moveDownVisual = () => {
6390
+ if (this.destroyed) {
6391
+ this.originalMoveDownVisual();
6392
+ return;
6393
+ }
6394
+ const hasSelection = this.editorView.hasSelection();
6395
+ if (hasSelection) {
6396
+ this.originalMoveDownVisual();
6397
+ return;
6398
+ }
6399
+ this.originalMoveDownVisual();
6400
+ const newOffset = this.editorView.getVisualCursor().offset;
6401
+ const virtualExtmark = this.findVirtualExtmarkContaining(newOffset);
6402
+ if (virtualExtmark) {
6403
+ const distanceToStart = newOffset - virtualExtmark.start;
6404
+ const distanceToEnd = virtualExtmark.end - newOffset;
6405
+ if (distanceToStart < distanceToEnd) {
6406
+ this.editorView.setCursorByOffset(virtualExtmark.start - 1);
6407
+ } else {
6408
+ this.editorView.setCursorByOffset(virtualExtmark.end);
6409
+ }
6410
+ }
6411
+ };
6412
+ this.editBuffer.setCursorByOffset = (offset) => {
6413
+ if (this.destroyed) {
6414
+ this.originalSetCursorByOffset(offset);
6415
+ return;
6416
+ }
6417
+ const currentOffset = this.editorView.getVisualCursor().offset;
6418
+ const hasSelection = this.editorView.hasSelection();
6419
+ if (hasSelection) {
6420
+ this.originalSetCursorByOffset(offset);
6421
+ return;
6422
+ }
6423
+ const movingForward = offset > currentOffset;
6424
+ if (movingForward) {
6425
+ const virtualExtmark = this.findVirtualExtmarkContaining(offset);
6426
+ if (virtualExtmark && currentOffset <= virtualExtmark.start) {
6427
+ this.originalSetCursorByOffset(virtualExtmark.end);
6428
+ return;
6429
+ }
6430
+ } else {
6431
+ for (const extmark of this.extmarks.values()) {
6432
+ if (extmark.virtual && currentOffset >= extmark.end && offset < extmark.end && offset >= extmark.start) {
6433
+ this.originalSetCursorByOffset(extmark.start - 1);
6434
+ return;
6435
+ }
6436
+ }
6437
+ }
6438
+ this.originalSetCursorByOffset(offset);
6439
+ };
6440
+ }
6441
+ wrapDeletion() {
6442
+ this.editBuffer.deleteCharBackward = () => {
6443
+ if (this.destroyed) {
6444
+ this.originalDeleteCharBackward();
6445
+ return;
6446
+ }
6447
+ this.saveSnapshot();
6448
+ const currentOffset = this.editorView.getVisualCursor().offset;
6449
+ const hadSelection = this.editorView.hasSelection();
6450
+ if (currentOffset === 0) {
6451
+ this.originalDeleteCharBackward();
6452
+ return;
6453
+ }
6454
+ if (hadSelection) {
6455
+ this.originalDeleteCharBackward();
6456
+ return;
6457
+ }
6458
+ const targetOffset = currentOffset - 1;
6459
+ const virtualExtmark = this.findVirtualExtmarkContaining(targetOffset);
6460
+ if (virtualExtmark && currentOffset === virtualExtmark.end) {
6461
+ const startCursor = this.offsetToPosition(virtualExtmark.start);
6462
+ const endCursor = this.offsetToPosition(virtualExtmark.end);
6463
+ const deleteOffset = virtualExtmark.start;
6464
+ const deleteLength = virtualExtmark.end - virtualExtmark.start;
6465
+ this.deleteExtmarkById(virtualExtmark.id);
6466
+ this.originalDeleteRange(startCursor.row, startCursor.col, endCursor.row, endCursor.col);
6467
+ this.adjustExtmarksAfterDeletion(deleteOffset, deleteLength);
6468
+ this.updateHighlights();
6469
+ return;
6470
+ }
6471
+ this.originalDeleteCharBackward();
6472
+ this.adjustExtmarksAfterDeletion(targetOffset, 1);
6473
+ };
6474
+ this.editBuffer.deleteChar = () => {
6475
+ if (this.destroyed) {
6476
+ this.originalDeleteChar();
6477
+ return;
6478
+ }
6479
+ this.saveSnapshot();
6480
+ const currentOffset = this.editorView.getVisualCursor().offset;
6481
+ const textLength = this.editBuffer.getText().length;
6482
+ const hadSelection = this.editorView.hasSelection();
6483
+ if (currentOffset >= textLength) {
6484
+ this.originalDeleteChar();
6485
+ return;
6486
+ }
6487
+ if (hadSelection) {
6488
+ this.originalDeleteChar();
6489
+ return;
6490
+ }
6491
+ const targetOffset = currentOffset;
6492
+ const virtualExtmark = this.findVirtualExtmarkContaining(targetOffset);
6493
+ if (virtualExtmark && currentOffset === virtualExtmark.start) {
6494
+ const startCursor = this.offsetToPosition(virtualExtmark.start);
6495
+ const endCursor = this.offsetToPosition(virtualExtmark.end);
6496
+ const deleteOffset = virtualExtmark.start;
6497
+ const deleteLength = virtualExtmark.end - virtualExtmark.start;
6498
+ this.deleteExtmarkById(virtualExtmark.id);
6499
+ this.originalDeleteRange(startCursor.row, startCursor.col, endCursor.row, endCursor.col);
6500
+ this.adjustExtmarksAfterDeletion(deleteOffset, deleteLength);
6501
+ this.updateHighlights();
6502
+ return;
6503
+ }
6504
+ this.originalDeleteChar();
6505
+ this.adjustExtmarksAfterDeletion(targetOffset, 1);
6506
+ };
6507
+ this.editBuffer.deleteRange = (startLine, startCol, endLine, endCol) => {
6508
+ if (this.destroyed) {
6509
+ this.originalDeleteRange(startLine, startCol, endLine, endCol);
6510
+ return;
6511
+ }
6512
+ this.saveSnapshot();
6513
+ const startOffset = this.positionToOffset(startLine, startCol);
6514
+ const endOffset = this.positionToOffset(endLine, endCol);
6515
+ const length = endOffset - startOffset;
6516
+ this.originalDeleteRange(startLine, startCol, endLine, endCol);
6517
+ this.adjustExtmarksAfterDeletion(startOffset, length);
6518
+ };
6519
+ this.editBuffer.deleteLine = () => {
6520
+ if (this.destroyed) {
6521
+ this.originalDeleteLine();
6522
+ return;
6523
+ }
6524
+ this.saveSnapshot();
6525
+ const text = this.editBuffer.getText();
6526
+ const currentOffset = this.editorView.getVisualCursor().offset;
6527
+ let lineStart = 0;
6528
+ for (let i = currentOffset - 1;i >= 0; i--) {
6529
+ if (text[i] === `
6530
+ `) {
6531
+ lineStart = i + 1;
6532
+ break;
6533
+ }
6534
+ }
6535
+ let lineEnd = text.length;
6536
+ for (let i = currentOffset;i < text.length; i++) {
6537
+ if (text[i] === `
6538
+ `) {
6539
+ lineEnd = i + 1;
6540
+ break;
6541
+ }
6542
+ }
6543
+ const deleteLength = lineEnd - lineStart;
6544
+ this.originalDeleteLine();
6545
+ this.adjustExtmarksAfterDeletion(lineStart, deleteLength);
6546
+ };
6547
+ }
6548
+ wrapInsertion() {
6549
+ this.editBuffer.insertText = (text) => {
6550
+ if (this.destroyed) {
6551
+ this.originalInsertText(text);
6552
+ return;
6553
+ }
6554
+ this.saveSnapshot();
6555
+ const currentOffset = this.editorView.getVisualCursor().offset;
6556
+ this.originalInsertText(text);
6557
+ this.adjustExtmarksAfterInsertion(currentOffset, text.length);
6558
+ };
6559
+ this.editBuffer.insertChar = (char) => {
6560
+ if (this.destroyed) {
6561
+ this.originalInsertChar(char);
6562
+ return;
6563
+ }
6564
+ this.saveSnapshot();
6565
+ const currentOffset = this.editorView.getVisualCursor().offset;
6566
+ this.originalInsertChar(char);
6567
+ this.adjustExtmarksAfterInsertion(currentOffset, 1);
6568
+ };
6569
+ this.editBuffer.setText = (text, opts) => {
6570
+ if (this.destroyed) {
6571
+ this.originalSetText(text, opts);
6572
+ return;
6573
+ }
6574
+ if (opts?.history !== false) {
6575
+ this.saveSnapshot();
6576
+ }
6577
+ this.clear();
6578
+ this.originalSetText(text, opts);
6579
+ };
6580
+ this.editBuffer.clear = () => {
6581
+ if (this.destroyed) {
6582
+ this.originalClear();
6583
+ return;
6584
+ }
6585
+ this.saveSnapshot();
6586
+ this.clear();
6587
+ this.originalClear();
6588
+ };
6589
+ this.editBuffer.newLine = () => {
6590
+ if (this.destroyed) {
6591
+ this.originalNewLine();
6592
+ return;
6593
+ }
6594
+ this.saveSnapshot();
6595
+ const currentOffset = this.editorView.getVisualCursor().offset;
6596
+ this.originalNewLine();
6597
+ this.adjustExtmarksAfterInsertion(currentOffset, 1);
6598
+ };
6599
+ }
6600
+ wrapEditorViewDeleteSelectedText() {
6601
+ this.editorView.deleteSelectedText = () => {
6602
+ if (this.destroyed) {
6603
+ this.originalEditorViewDeleteSelectedText();
6604
+ return;
6605
+ }
6606
+ this.saveSnapshot();
6607
+ const selection = this.editorView.getSelection();
6608
+ if (!selection) {
6609
+ this.originalEditorViewDeleteSelectedText();
6610
+ return;
6611
+ }
6612
+ const deleteOffset = Math.min(selection.start, selection.end);
6613
+ const deleteLength = Math.abs(selection.end - selection.start);
6614
+ this.originalEditorViewDeleteSelectedText();
6615
+ if (deleteLength > 0) {
6616
+ this.adjustExtmarksAfterDeletion(deleteOffset, deleteLength);
6617
+ }
6618
+ };
6619
+ }
6620
+ setupContentChangeListener() {
6621
+ this.editBuffer.on("content-changed", () => {
6622
+ if (this.destroyed)
6623
+ return;
6624
+ this.updateHighlights();
6625
+ });
6626
+ }
6627
+ deleteExtmarkById(id) {
6628
+ const extmark = this.extmarks.get(id);
6629
+ if (extmark) {
6630
+ this.extmarks.delete(id);
6631
+ this.extmarksByTypeId.get(extmark.typeId)?.delete(id);
6632
+ this.metadata.delete(id);
6633
+ }
6634
+ }
6635
+ findVirtualExtmarkContaining(offset) {
6636
+ for (const extmark of this.extmarks.values()) {
6637
+ if (extmark.virtual && offset >= extmark.start && offset < extmark.end) {
6638
+ return extmark;
6639
+ }
6640
+ }
6641
+ return null;
6642
+ }
6643
+ adjustExtmarksAfterInsertion(insertOffset, length) {
6644
+ for (const extmark of this.extmarks.values()) {
6645
+ if (extmark.start >= insertOffset) {
6646
+ extmark.start += length;
6647
+ extmark.end += length;
6648
+ } else if (extmark.end > insertOffset) {
6649
+ extmark.end += length;
6650
+ }
6651
+ }
6652
+ this.updateHighlights();
6653
+ }
6654
+ adjustExtmarksAfterDeletion(deleteOffset, length) {
6655
+ const toDelete = [];
6656
+ for (const extmark of this.extmarks.values()) {
6657
+ if (extmark.end <= deleteOffset) {
6658
+ continue;
6659
+ }
6660
+ if (extmark.start >= deleteOffset + length) {
6661
+ extmark.start -= length;
6662
+ extmark.end -= length;
6663
+ } else if (extmark.start >= deleteOffset && extmark.end <= deleteOffset + length) {
6664
+ toDelete.push(extmark.id);
6665
+ } else if (extmark.start < deleteOffset && extmark.end > deleteOffset + length) {
6666
+ extmark.end -= length;
6667
+ } else if (extmark.start < deleteOffset && extmark.end > deleteOffset) {
6668
+ extmark.end -= Math.min(extmark.end, deleteOffset + length) - deleteOffset;
6669
+ } else if (extmark.start < deleteOffset + length && extmark.end > deleteOffset + length) {
6670
+ const overlap = deleteOffset + length - extmark.start;
6671
+ extmark.start = deleteOffset;
6672
+ extmark.end -= length;
6673
+ }
6674
+ }
6675
+ for (const id of toDelete) {
6676
+ this.deleteExtmarkById(id);
6677
+ }
6678
+ this.updateHighlights();
6679
+ }
6680
+ offsetToPosition(offset) {
6681
+ const result = this.editBuffer.offsetToPosition(offset);
6682
+ if (!result) {
6683
+ return { row: 0, col: 0 };
6684
+ }
6685
+ return result;
6686
+ }
6687
+ positionToOffset(row, col) {
6688
+ return this.editBuffer.positionToOffset(row, col);
6689
+ }
6690
+ updateHighlights() {
6691
+ this.editBuffer.clearAllHighlights();
6692
+ for (const extmark of this.extmarks.values()) {
6693
+ if (extmark.styleId !== undefined) {
6694
+ const startWithoutNewlines = this.offsetToCharOffset(extmark.start);
6695
+ const endWithoutNewlines = this.offsetToCharOffset(extmark.end);
6696
+ this.editBuffer.addHighlightByCharRange({
6697
+ start: startWithoutNewlines,
6698
+ end: endWithoutNewlines,
6699
+ styleId: extmark.styleId,
6700
+ priority: extmark.priority ?? 0,
6701
+ hlRef: extmark.id
6702
+ });
6703
+ }
6704
+ }
6705
+ }
6706
+ offsetToCharOffset(offset) {
6707
+ const text = this.editBuffer.getText();
6708
+ let charOffset = 0;
6709
+ for (let i = 0;i < offset && i < text.length; i++) {
6710
+ if (text[i] !== `
6711
+ `) {
6712
+ charOffset++;
6713
+ }
6714
+ }
6715
+ return charOffset;
6716
+ }
6717
+ create(options) {
6718
+ if (this.destroyed) {
6719
+ throw new Error("ExtmarksController is destroyed");
6720
+ }
6721
+ const id = this.nextId++;
6722
+ const typeId = options.typeId ?? 0;
6723
+ const extmark = {
6724
+ id,
6725
+ start: options.start,
6726
+ end: options.end,
6727
+ virtual: options.virtual ?? false,
6728
+ styleId: options.styleId,
6729
+ priority: options.priority,
6730
+ data: options.data,
6731
+ typeId
6732
+ };
6733
+ this.extmarks.set(id, extmark);
6734
+ if (!this.extmarksByTypeId.has(typeId)) {
6735
+ this.extmarksByTypeId.set(typeId, new Set);
6736
+ }
6737
+ this.extmarksByTypeId.get(typeId).add(id);
6738
+ if (options.metadata !== undefined) {
6739
+ this.metadata.set(id, options.metadata);
6740
+ }
6741
+ this.updateHighlights();
6742
+ return id;
6743
+ }
6744
+ delete(id) {
6745
+ if (this.destroyed) {
6746
+ throw new Error("ExtmarksController is destroyed");
6747
+ }
6748
+ const extmark = this.extmarks.get(id);
6749
+ if (!extmark)
6750
+ return false;
6751
+ this.deleteExtmarkById(id);
6752
+ this.updateHighlights();
6753
+ return true;
6754
+ }
6755
+ get(id) {
6756
+ if (this.destroyed)
6757
+ return null;
6758
+ return this.extmarks.get(id) ?? null;
6759
+ }
6760
+ getAll() {
6761
+ if (this.destroyed)
6762
+ return [];
6763
+ return Array.from(this.extmarks.values());
6764
+ }
6765
+ getVirtual() {
6766
+ if (this.destroyed)
6767
+ return [];
6768
+ return Array.from(this.extmarks.values()).filter((e) => e.virtual);
6769
+ }
6770
+ getAtOffset(offset) {
6771
+ if (this.destroyed)
6772
+ return [];
6773
+ return Array.from(this.extmarks.values()).filter((e) => offset >= e.start && offset < e.end);
6774
+ }
6775
+ getAllForTypeId(typeId) {
6776
+ if (this.destroyed)
6777
+ return [];
6778
+ const ids = this.extmarksByTypeId.get(typeId);
6779
+ if (!ids)
6780
+ return [];
6781
+ return Array.from(ids).map((id) => this.extmarks.get(id)).filter((e) => e !== undefined);
6782
+ }
6783
+ clear() {
6784
+ if (this.destroyed)
6785
+ return;
6786
+ this.extmarks.clear();
6787
+ this.extmarksByTypeId.clear();
6788
+ this.metadata.clear();
6789
+ this.updateHighlights();
6790
+ }
6791
+ saveSnapshot() {
6792
+ this.history.saveSnapshot(this.extmarks, this.nextId);
6793
+ }
6794
+ restoreSnapshot(snapshot) {
6795
+ this.extmarks = new Map(Array.from(snapshot.extmarks.entries()).map(([id, extmark]) => [id, { ...extmark }]));
6796
+ this.nextId = snapshot.nextId;
6797
+ this.updateHighlights();
6798
+ }
6799
+ wrapUndoRedo() {
6800
+ this.editBuffer.undo = () => {
6801
+ if (this.destroyed) {
6802
+ return this.originalUndo();
6803
+ }
6804
+ if (!this.history.canUndo()) {
6805
+ return this.originalUndo();
6806
+ }
6807
+ const currentSnapshot = {
6808
+ extmarks: new Map(Array.from(this.extmarks.entries()).map(([id, extmark]) => [id, { ...extmark }])),
6809
+ nextId: this.nextId
6810
+ };
6811
+ this.history.pushRedo(currentSnapshot);
6812
+ const snapshot = this.history.undo();
6813
+ this.restoreSnapshot(snapshot);
6814
+ return this.originalUndo();
6815
+ };
6816
+ this.editBuffer.redo = () => {
6817
+ if (this.destroyed) {
6818
+ return this.originalRedo();
6819
+ }
6820
+ if (!this.history.canRedo()) {
6821
+ return this.originalRedo();
6822
+ }
6823
+ const currentSnapshot = {
6824
+ extmarks: new Map(Array.from(this.extmarks.entries()).map(([id, extmark]) => [id, { ...extmark }])),
6825
+ nextId: this.nextId
6826
+ };
6827
+ this.history.pushUndo(currentSnapshot);
6828
+ const snapshot = this.history.redo();
6829
+ this.restoreSnapshot(snapshot);
6830
+ return this.originalRedo();
6831
+ };
6832
+ }
6833
+ registerType(typeName) {
6834
+ if (this.destroyed) {
6835
+ throw new Error("ExtmarksController is destroyed");
6836
+ }
6837
+ const existing = this.typeNameToId.get(typeName);
6838
+ if (existing !== undefined) {
6839
+ return existing;
6840
+ }
6841
+ const typeId = this.nextTypeId++;
6842
+ this.typeNameToId.set(typeName, typeId);
6843
+ this.typeIdToName.set(typeId, typeName);
6844
+ return typeId;
6845
+ }
6846
+ getTypeId(typeName) {
6847
+ if (this.destroyed)
6848
+ return null;
6849
+ return this.typeNameToId.get(typeName) ?? null;
6850
+ }
6851
+ getTypeName(typeId) {
6852
+ if (this.destroyed)
6853
+ return null;
6854
+ return this.typeIdToName.get(typeId) ?? null;
6855
+ }
6856
+ getMetadataFor(extmarkId) {
6857
+ if (this.destroyed)
6858
+ return;
6859
+ return this.metadata.get(extmarkId);
6860
+ }
6861
+ destroy() {
6862
+ if (this.destroyed)
6863
+ return;
6864
+ this.editBuffer.moveCursorLeft = this.originalMoveCursorLeft;
6865
+ this.editBuffer.moveCursorRight = this.originalMoveCursorRight;
6866
+ this.editBuffer.setCursorByOffset = this.originalSetCursorByOffset;
6867
+ this.editorView.moveUpVisual = this.originalMoveUpVisual;
6868
+ this.editorView.moveDownVisual = this.originalMoveDownVisual;
6869
+ this.editBuffer.deleteCharBackward = this.originalDeleteCharBackward;
6870
+ this.editBuffer.deleteChar = this.originalDeleteChar;
6871
+ this.editBuffer.insertText = this.originalInsertText;
6872
+ this.editBuffer.insertChar = this.originalInsertChar;
6873
+ this.editBuffer.deleteRange = this.originalDeleteRange;
6874
+ this.editBuffer.setText = this.originalSetText;
6875
+ this.editBuffer.clear = this.originalClear;
6876
+ this.editBuffer.newLine = this.originalNewLine;
6877
+ this.editBuffer.deleteLine = this.originalDeleteLine;
6878
+ this.editorView.deleteSelectedText = this.originalEditorViewDeleteSelectedText;
6879
+ this.editBuffer.undo = this.originalUndo;
6880
+ this.editBuffer.redo = this.originalRedo;
6881
+ this.extmarks.clear();
6882
+ this.extmarksByTypeId.clear();
6883
+ this.metadata.clear();
6884
+ this.typeNameToId.clear();
6885
+ this.typeIdToName.clear();
6886
+ this.history.clear();
6887
+ this.destroyed = true;
6888
+ }
6889
+ }
6890
+ function createExtmarksController(editBuffer, editorView) {
6891
+ return new ExtmarksController(editBuffer, editorView);
6892
+ }
6256
6893
  // src/zig.ts
6257
- import { dlopen, toArrayBuffer as toArrayBuffer2, JSCallback, ptr } from "bun:ffi";
6894
+ import { dlopen, toArrayBuffer as toArrayBuffer4, JSCallback, ptr as ptr3 } from "bun:ffi";
6258
6895
  import { existsSync as existsSync2 } from "fs";
6896
+ import { EventEmitter as EventEmitter4 } from "events";
6259
6897
 
6260
6898
  // src/buffer.ts
6261
6899
  import { toArrayBuffer } from "bun:ffi";
@@ -6411,9 +7049,13 @@ class OptimizedBuffer {
6411
7049
  this._destroyed = true;
6412
7050
  this.lib.destroyOptimizedBuffer(this.bufferPtr);
6413
7051
  }
6414
- drawTextBuffer(textBuffer, x, y, clipRect) {
7052
+ drawTextBuffer(textBufferView, x, y) {
7053
+ this.guard();
7054
+ this.lib.bufferDrawTextBufferView(this.bufferPtr, textBufferView.ptr, x, y);
7055
+ }
7056
+ drawEditorView(editorView, x, y) {
6415
7057
  this.guard();
6416
- this.lib.bufferDrawTextBuffer(this.bufferPtr, textBuffer.ptr, x, y, clipRect);
7058
+ this.lib.bufferDrawEditorView(this.bufferPtr, editorView.ptr, x, y);
6417
7059
  }
6418
7060
  drawSuperSampleBuffer(x, y, pixelDataPtr, pixelDataLength, format, alignedBytesPerRow) {
6419
7061
  this.guard();
@@ -6453,42 +7095,664 @@ class OptimizedBuffer {
6453
7095
  }
6454
7096
  }
6455
7097
 
6456
- // src/zig.ts
6457
- var module = await import(`@opentui/core-${process.platform}-${process.arch}/index.ts`);
6458
- var targetLibPath = module.default;
6459
- if (/\$bunfs/.test(targetLibPath)) {
6460
- targetLibPath = targetLibPath.replace("../", "");
7098
+ // ../../node_modules/.bun/bun-ffi-structs@0.1.0+ca84541ac88a3075/node_modules/bun-ffi-structs/index.js
7099
+ import { ptr, toArrayBuffer as toArrayBuffer2 } from "bun:ffi";
7100
+ function fatalError(...args) {
7101
+ const message = args.join(" ");
7102
+ console.error("FATAL ERROR:", message);
7103
+ throw new Error(message);
7104
+ }
7105
+ var pointerSize = process.arch === "x64" || process.arch === "arm64" ? 8 : 4;
7106
+ var typeSizes = {
7107
+ u8: 1,
7108
+ bool_u8: 1,
7109
+ bool_u32: 4,
7110
+ u16: 2,
7111
+ i16: 2,
7112
+ u32: 4,
7113
+ u64: 8,
7114
+ f32: 4,
7115
+ f64: 8,
7116
+ pointer: pointerSize,
7117
+ i32: 4
7118
+ };
7119
+ var primitiveKeys = Object.keys(typeSizes);
7120
+ function isPrimitiveType(type) {
7121
+ return typeof type === "string" && primitiveKeys.includes(type);
7122
+ }
7123
+ var typeAlignments = { ...typeSizes };
7124
+ var typeGetters = {
7125
+ u8: (view, offset) => view.getUint8(offset),
7126
+ bool_u8: (view, offset) => Boolean(view.getUint8(offset)),
7127
+ bool_u32: (view, offset) => Boolean(view.getUint32(offset, true)),
7128
+ u16: (view, offset) => view.getUint16(offset, true),
7129
+ i16: (view, offset) => view.getInt16(offset, true),
7130
+ u32: (view, offset) => view.getUint32(offset, true),
7131
+ u64: (view, offset) => view.getBigUint64(offset, true),
7132
+ f32: (view, offset) => view.getFloat32(offset, true),
7133
+ f64: (view, offset) => view.getFloat64(offset, true),
7134
+ i32: (view, offset) => view.getInt32(offset, true),
7135
+ pointer: (view, offset) => pointerSize === 8 ? view.getBigUint64(offset, true) : BigInt(view.getUint32(offset, true))
7136
+ };
7137
+ function isObjectPointerDef(type) {
7138
+ return typeof type === "object" && type !== null && type.__type === "objectPointer";
6461
7139
  }
6462
- if (!existsSync2(targetLibPath)) {
6463
- throw new Error(`opentui is not supported on the current platform: ${process.platform}-${process.arch}`);
7140
+ function alignOffset(offset, align) {
7141
+ return offset + (align - 1) & ~(align - 1);
6464
7142
  }
6465
- registerEnvVar({
6466
- name: "OTUI_DEBUG_FFI",
6467
- description: "Enable debug logging for the FFI bindings.",
6468
- type: "boolean",
6469
- default: false
6470
- });
6471
- registerEnvVar({
6472
- name: "OTUI_TRACE_FFI",
6473
- description: "Enable tracing for the FFI bindings.",
6474
- type: "boolean",
6475
- default: false
6476
- });
6477
- function getOpenTUILib(libPath) {
6478
- const resolvedLibPath = libPath || targetLibPath;
6479
- const rawSymbols = dlopen(resolvedLibPath, {
6480
- setLogCallback: {
6481
- args: ["ptr"],
6482
- returns: "void"
6483
- },
6484
- createRenderer: {
6485
- args: ["u32", "u32", "bool"],
6486
- returns: "ptr"
6487
- },
6488
- destroyRenderer: {
6489
- args: ["ptr"],
6490
- returns: "void"
6491
- },
7143
+ function isEnum(type) {
7144
+ return typeof type === "object" && type.__type === "enum";
7145
+ }
7146
+ function isStruct(type) {
7147
+ return typeof type === "object" && type.__type === "struct";
7148
+ }
7149
+ function primitivePackers(type) {
7150
+ let pack;
7151
+ let unpack;
7152
+ switch (type) {
7153
+ case "u8":
7154
+ pack = (view, off, val) => view.setUint8(off, val);
7155
+ unpack = (view, off) => view.getUint8(off);
7156
+ break;
7157
+ case "bool_u8":
7158
+ pack = (view, off, val) => view.setUint8(off, val ? 1 : 0);
7159
+ unpack = (view, off) => Boolean(view.getUint8(off));
7160
+ break;
7161
+ case "bool_u32":
7162
+ pack = (view, off, val) => view.setUint32(off, val ? 1 : 0, true);
7163
+ unpack = (view, off) => Boolean(view.getUint32(off, true));
7164
+ break;
7165
+ case "u16":
7166
+ pack = (view, off, val) => view.setUint16(off, val, true);
7167
+ unpack = (view, off) => view.getUint16(off, true);
7168
+ break;
7169
+ case "i16":
7170
+ pack = (view, off, val) => view.setInt16(off, val, true);
7171
+ unpack = (view, off) => view.getInt16(off, true);
7172
+ break;
7173
+ case "u32":
7174
+ pack = (view, off, val) => view.setUint32(off, val, true);
7175
+ unpack = (view, off) => view.getUint32(off, true);
7176
+ break;
7177
+ case "i32":
7178
+ pack = (view, off, val) => view.setInt32(off, val, true);
7179
+ unpack = (view, off) => view.getInt32(off, true);
7180
+ break;
7181
+ case "u64":
7182
+ pack = (view, off, val) => view.setBigUint64(off, BigInt(val), true);
7183
+ unpack = (view, off) => view.getBigUint64(off, true);
7184
+ break;
7185
+ case "f32":
7186
+ pack = (view, off, val) => view.setFloat32(off, val, true);
7187
+ unpack = (view, off) => view.getFloat32(off, true);
7188
+ break;
7189
+ case "f64":
7190
+ pack = (view, off, val) => view.setFloat64(off, val, true);
7191
+ unpack = (view, off) => view.getFloat64(off, true);
7192
+ break;
7193
+ case "pointer":
7194
+ pack = (view, off, val) => {
7195
+ pointerSize === 8 ? view.setBigUint64(off, val ? BigInt(val) : 0n, true) : view.setUint32(off, val ? Number(val) : 0, true);
7196
+ };
7197
+ unpack = (view, off) => {
7198
+ const bint = pointerSize === 8 ? view.getBigUint64(off, true) : BigInt(view.getUint32(off, true));
7199
+ return Number(bint);
7200
+ };
7201
+ break;
7202
+ default:
7203
+ fatalError(`Unsupported primitive type: ${type}`);
7204
+ }
7205
+ return { pack, unpack };
7206
+ }
7207
+ var { pack: pointerPacker, unpack: pointerUnpacker } = primitivePackers("pointer");
7208
+ function packObjectArray(val) {
7209
+ const buffer = new ArrayBuffer(val.length * pointerSize);
7210
+ const bufferView = new DataView(buffer);
7211
+ for (let i = 0;i < val.length; i++) {
7212
+ const instance = val[i];
7213
+ const ptrValue = instance?.ptr ?? null;
7214
+ pointerPacker(bufferView, i * pointerSize, ptrValue);
7215
+ }
7216
+ return bufferView;
7217
+ }
7218
+ var encoder = new TextEncoder;
7219
+ function defineStruct(fields, structDefOptions) {
7220
+ let offset = 0;
7221
+ let maxAlign = 1;
7222
+ const layout = [];
7223
+ const lengthOfFields = {};
7224
+ const lengthOfRequested = [];
7225
+ const arrayFieldsMetadata = {};
7226
+ for (const [name, typeOrStruct, options = {}] of fields) {
7227
+ if (options.condition && !options.condition()) {
7228
+ continue;
7229
+ }
7230
+ let size = 0, align = 0;
7231
+ let pack;
7232
+ let unpack;
7233
+ let needsLengthOf = false;
7234
+ let lengthOfDef = null;
7235
+ if (isPrimitiveType(typeOrStruct)) {
7236
+ size = typeSizes[typeOrStruct];
7237
+ align = typeAlignments[typeOrStruct];
7238
+ ({ pack, unpack } = primitivePackers(typeOrStruct));
7239
+ } else if (typeof typeOrStruct === "string" && typeOrStruct === "cstring") {
7240
+ size = pointerSize;
7241
+ align = pointerSize;
7242
+ pack = (view, off, val) => {
7243
+ const bufPtr = val ? ptr(encoder.encode(val + "\x00")) : null;
7244
+ pointerPacker(view, off, bufPtr);
7245
+ };
7246
+ unpack = (view, off) => {
7247
+ const ptrVal = pointerUnpacker(view, off);
7248
+ return ptrVal;
7249
+ };
7250
+ } else if (typeof typeOrStruct === "string" && typeOrStruct === "char*") {
7251
+ size = pointerSize;
7252
+ align = pointerSize;
7253
+ pack = (view, off, val) => {
7254
+ const bufPtr = val ? ptr(encoder.encode(val)) : null;
7255
+ pointerPacker(view, off, bufPtr);
7256
+ };
7257
+ unpack = (view, off) => {
7258
+ const ptrVal = pointerUnpacker(view, off);
7259
+ return ptrVal;
7260
+ };
7261
+ } else if (isEnum(typeOrStruct)) {
7262
+ const base = typeOrStruct.type;
7263
+ size = typeSizes[base];
7264
+ align = typeAlignments[base];
7265
+ const { pack: packEnum } = primitivePackers(base);
7266
+ pack = (view, off, val) => {
7267
+ const num = typeOrStruct.to(val);
7268
+ packEnum(view, off, num);
7269
+ };
7270
+ unpack = (view, off) => {
7271
+ const raw = typeGetters[base](view, off);
7272
+ return typeOrStruct.from(raw);
7273
+ };
7274
+ } else if (isStruct(typeOrStruct)) {
7275
+ if (options.asPointer === true) {
7276
+ size = pointerSize;
7277
+ align = pointerSize;
7278
+ pack = (view, off, val, obj, options2) => {
7279
+ if (!val) {
7280
+ pointerPacker(view, off, null);
7281
+ return;
7282
+ }
7283
+ const nestedBuf = typeOrStruct.pack(val, options2);
7284
+ pointerPacker(view, off, ptr(nestedBuf));
7285
+ };
7286
+ unpack = (view, off) => {
7287
+ throw new Error("Not implemented yet");
7288
+ };
7289
+ } else {
7290
+ size = typeOrStruct.size;
7291
+ align = typeOrStruct.align;
7292
+ pack = (view, off, val, obj, options2) => {
7293
+ const nestedBuf = typeOrStruct.pack(val, options2);
7294
+ const nestedView = new Uint8Array(nestedBuf);
7295
+ const dView = new Uint8Array(view.buffer);
7296
+ dView.set(nestedView, off);
7297
+ };
7298
+ unpack = (view, off) => {
7299
+ const slice = view.buffer.slice(off, off + size);
7300
+ return typeOrStruct.unpack(slice);
7301
+ };
7302
+ }
7303
+ } else if (isObjectPointerDef(typeOrStruct)) {
7304
+ size = pointerSize;
7305
+ align = pointerSize;
7306
+ pack = (view, off, value) => {
7307
+ const ptrValue = value?.ptr ?? null;
7308
+ if (ptrValue === undefined) {
7309
+ console.warn(`Field '${name}' expected object with '.ptr' property, but got undefined pointer value from:`, value);
7310
+ pointerPacker(view, off, null);
7311
+ } else {
7312
+ pointerPacker(view, off, ptrValue);
7313
+ }
7314
+ };
7315
+ unpack = (view, off) => {
7316
+ return pointerUnpacker(view, off);
7317
+ };
7318
+ } else if (Array.isArray(typeOrStruct) && typeOrStruct.length === 1 && typeOrStruct[0] !== undefined) {
7319
+ const [def] = typeOrStruct;
7320
+ size = pointerSize;
7321
+ align = pointerSize;
7322
+ let arrayElementSize;
7323
+ if (isEnum(def)) {
7324
+ arrayElementSize = typeSizes[def.type];
7325
+ pack = (view, off, val, obj) => {
7326
+ if (!val || val.length === 0) {
7327
+ pointerPacker(view, off, null);
7328
+ return;
7329
+ }
7330
+ const buffer = new ArrayBuffer(val.length * arrayElementSize);
7331
+ const bufferView = new DataView(buffer);
7332
+ for (let i = 0;i < val.length; i++) {
7333
+ const num = def.to(val[i]);
7334
+ bufferView.setUint32(i * arrayElementSize, num, true);
7335
+ }
7336
+ pointerPacker(view, off, ptr(buffer));
7337
+ };
7338
+ unpack = null;
7339
+ needsLengthOf = true;
7340
+ lengthOfDef = def;
7341
+ } else if (isStruct(def)) {
7342
+ arrayElementSize = def.size;
7343
+ pack = (view, off, val, obj, options2) => {
7344
+ if (!val || val.length === 0) {
7345
+ pointerPacker(view, off, null);
7346
+ return;
7347
+ }
7348
+ const buffer = new ArrayBuffer(val.length * arrayElementSize);
7349
+ const bufferView = new DataView(buffer);
7350
+ for (let i = 0;i < val.length; i++) {
7351
+ def.packInto(val[i], bufferView, i * arrayElementSize, options2);
7352
+ }
7353
+ pointerPacker(view, off, ptr(buffer));
7354
+ };
7355
+ unpack = (view, off) => {
7356
+ throw new Error("Not implemented yet");
7357
+ };
7358
+ } else if (isPrimitiveType(def)) {
7359
+ arrayElementSize = typeSizes[def];
7360
+ const { pack: primitivePack } = primitivePackers(def);
7361
+ pack = (view, off, val) => {
7362
+ if (!val || val.length === 0) {
7363
+ pointerPacker(view, off, null);
7364
+ return;
7365
+ }
7366
+ const buffer = new ArrayBuffer(val.length * arrayElementSize);
7367
+ const bufferView = new DataView(buffer);
7368
+ for (let i = 0;i < val.length; i++) {
7369
+ primitivePack(bufferView, i * arrayElementSize, val[i]);
7370
+ }
7371
+ pointerPacker(view, off, ptr(buffer));
7372
+ };
7373
+ unpack = null;
7374
+ needsLengthOf = true;
7375
+ lengthOfDef = def;
7376
+ } else if (isObjectPointerDef(def)) {
7377
+ arrayElementSize = pointerSize;
7378
+ pack = (view, off, val) => {
7379
+ if (!val || val.length === 0) {
7380
+ pointerPacker(view, off, null);
7381
+ return;
7382
+ }
7383
+ const packedView = packObjectArray(val);
7384
+ pointerPacker(view, off, ptr(packedView.buffer));
7385
+ };
7386
+ unpack = () => {
7387
+ throw new Error("not implemented yet");
7388
+ };
7389
+ } else {
7390
+ throw new Error(`Unsupported array element type for ${name}: ${JSON.stringify(def)}`);
7391
+ }
7392
+ const lengthOfField = Object.values(lengthOfFields).find((f) => f.lengthOf === name);
7393
+ if (lengthOfField && isPrimitiveType(lengthOfField.type)) {
7394
+ const { pack: lengthPack } = primitivePackers(lengthOfField.type);
7395
+ arrayFieldsMetadata[name] = {
7396
+ elementSize: arrayElementSize,
7397
+ arrayOffset: offset,
7398
+ lengthOffset: lengthOfField.offset,
7399
+ lengthPack
7400
+ };
7401
+ }
7402
+ } else {
7403
+ throw new Error(`Unsupported field type for ${name}: ${JSON.stringify(typeOrStruct)}`);
7404
+ }
7405
+ offset = alignOffset(offset, align);
7406
+ if (options.unpackTransform) {
7407
+ const originalUnpack = unpack;
7408
+ unpack = (view, off) => options.unpackTransform(originalUnpack(view, off));
7409
+ }
7410
+ if (options.packTransform) {
7411
+ const originalPack = pack;
7412
+ pack = (view, off, val, obj, packOptions) => originalPack(view, off, options.packTransform(val), obj, packOptions);
7413
+ }
7414
+ if (options.optional) {
7415
+ const originalPack = pack;
7416
+ if (isStruct(typeOrStruct) && !options.asPointer) {
7417
+ pack = (view, off, val, obj, packOptions) => {
7418
+ if (val || options.mapOptionalInline) {
7419
+ originalPack(view, off, val, obj, packOptions);
7420
+ }
7421
+ };
7422
+ } else {
7423
+ pack = (view, off, val, obj, packOptions) => originalPack(view, off, val ?? 0, obj, packOptions);
7424
+ }
7425
+ }
7426
+ if (options.lengthOf) {
7427
+ const originalPack = pack;
7428
+ pack = (view, off, val, obj, packOptions) => {
7429
+ const targetValue = obj[options.lengthOf];
7430
+ let length = 0;
7431
+ if (targetValue) {
7432
+ if (typeof targetValue === "string") {
7433
+ length = Buffer.byteLength(targetValue);
7434
+ } else {
7435
+ length = targetValue.length;
7436
+ }
7437
+ }
7438
+ return originalPack(view, off, length, obj, packOptions);
7439
+ };
7440
+ }
7441
+ let validateFunctions;
7442
+ if (options.validate) {
7443
+ validateFunctions = Array.isArray(options.validate) ? options.validate : [options.validate];
7444
+ }
7445
+ const layoutField = {
7446
+ name,
7447
+ offset,
7448
+ size,
7449
+ align,
7450
+ validate: validateFunctions,
7451
+ optional: !!options.optional || !!options.lengthOf || options.default !== undefined,
7452
+ default: options.default,
7453
+ pack,
7454
+ unpack,
7455
+ type: typeOrStruct,
7456
+ lengthOf: options.lengthOf
7457
+ };
7458
+ layout.push(layoutField);
7459
+ if (options.lengthOf) {
7460
+ lengthOfFields[options.lengthOf] = layoutField;
7461
+ }
7462
+ if (needsLengthOf) {
7463
+ if (!lengthOfDef)
7464
+ fatalError(`Internal error: needsLengthOf=true but lengthOfDef is null for ${name}`);
7465
+ lengthOfRequested.push({ requester: layoutField, def: lengthOfDef });
7466
+ }
7467
+ offset += size;
7468
+ maxAlign = Math.max(maxAlign, align);
7469
+ }
7470
+ for (const { requester, def } of lengthOfRequested) {
7471
+ const lengthOfField = lengthOfFields[requester.name];
7472
+ if (!lengthOfField) {
7473
+ throw new Error(`lengthOf field not found for array field ${requester.name}`);
7474
+ }
7475
+ if (isPrimitiveType(def)) {
7476
+ const elemSize = typeSizes[def];
7477
+ const { unpack: primitiveUnpack } = primitivePackers(def);
7478
+ requester.unpack = (view, off) => {
7479
+ const result = [];
7480
+ const length = lengthOfField.unpack(view, lengthOfField.offset);
7481
+ const ptrAddress = pointerUnpacker(view, off);
7482
+ if (ptrAddress === 0n && length > 0) {
7483
+ throw new Error(`Array field ${requester.name} has null pointer but length ${length}.`);
7484
+ }
7485
+ if (ptrAddress === 0n || length === 0) {
7486
+ return [];
7487
+ }
7488
+ const buffer = toArrayBuffer2(ptrAddress, 0, length * elemSize);
7489
+ const bufferView = new DataView(buffer);
7490
+ for (let i = 0;i < length; i++) {
7491
+ result.push(primitiveUnpack(bufferView, i * elemSize));
7492
+ }
7493
+ return result;
7494
+ };
7495
+ } else {
7496
+ const elemSize = def.type === "u32" ? 4 : 8;
7497
+ requester.unpack = (view, off) => {
7498
+ const result = [];
7499
+ const length = lengthOfField.unpack(view, lengthOfField.offset);
7500
+ const ptrAddress = pointerUnpacker(view, off);
7501
+ if (ptrAddress === 0n && length > 0) {
7502
+ throw new Error(`Array field ${requester.name} has null pointer but length ${length}.`);
7503
+ }
7504
+ if (ptrAddress === 0n || length === 0) {
7505
+ return [];
7506
+ }
7507
+ const buffer = toArrayBuffer2(ptrAddress, 0, length * elemSize);
7508
+ const bufferView = new DataView(buffer);
7509
+ for (let i = 0;i < length; i++) {
7510
+ result.push(def.from(bufferView.getUint32(i * elemSize, true)));
7511
+ }
7512
+ return result;
7513
+ };
7514
+ }
7515
+ }
7516
+ const totalSize = alignOffset(offset, maxAlign);
7517
+ const description = layout.map((f) => ({
7518
+ name: f.name,
7519
+ offset: f.offset,
7520
+ size: f.size,
7521
+ align: f.align,
7522
+ optional: f.optional,
7523
+ type: f.type,
7524
+ lengthOf: f.lengthOf
7525
+ }));
7526
+ const layoutByName = new Map(description.map((f) => [f.name, f]));
7527
+ const arrayFields = new Map(Object.entries(arrayFieldsMetadata));
7528
+ return {
7529
+ __type: "struct",
7530
+ size: totalSize,
7531
+ align: maxAlign,
7532
+ hasMapValue: !!structDefOptions?.mapValue,
7533
+ layoutByName,
7534
+ arrayFields,
7535
+ pack(obj, options) {
7536
+ const buf = new ArrayBuffer(totalSize);
7537
+ const view = new DataView(buf);
7538
+ let mappedObj = obj;
7539
+ if (structDefOptions?.mapValue) {
7540
+ mappedObj = structDefOptions.mapValue(obj);
7541
+ }
7542
+ for (const field of layout) {
7543
+ const value = mappedObj[field.name] ?? field.default;
7544
+ if (!field.optional && value === undefined) {
7545
+ fatalError(`Packing non-optional field '${field.name}' but value is undefined (and no default provided)`);
7546
+ }
7547
+ if (field.validate) {
7548
+ for (const validateFn of field.validate) {
7549
+ validateFn(value, field.name, {
7550
+ hints: options?.validationHints,
7551
+ input: mappedObj
7552
+ });
7553
+ }
7554
+ }
7555
+ field.pack(view, field.offset, value, mappedObj, options);
7556
+ }
7557
+ return view.buffer;
7558
+ },
7559
+ packInto(obj, view, offset2, options) {
7560
+ let mappedObj = obj;
7561
+ if (structDefOptions?.mapValue) {
7562
+ mappedObj = structDefOptions.mapValue(obj);
7563
+ }
7564
+ for (const field of layout) {
7565
+ const value = mappedObj[field.name] ?? field.default;
7566
+ if (!field.optional && value === undefined) {
7567
+ console.warn(`packInto missing value for non-optional field '${field.name}' at offset ${offset2 + field.offset}. Writing default or zero.`);
7568
+ }
7569
+ if (field.validate) {
7570
+ for (const validateFn of field.validate) {
7571
+ validateFn(value, field.name, {
7572
+ hints: options?.validationHints,
7573
+ input: mappedObj
7574
+ });
7575
+ }
7576
+ }
7577
+ field.pack(view, offset2 + field.offset, value, mappedObj, options);
7578
+ }
7579
+ },
7580
+ unpack(buf) {
7581
+ if (buf.byteLength < totalSize) {
7582
+ fatalError(`Buffer size (${buf.byteLength}) is smaller than struct size (${totalSize}) for unpacking.`);
7583
+ }
7584
+ const view = new DataView(buf);
7585
+ const result = structDefOptions?.default ? { ...structDefOptions.default } : {};
7586
+ for (const field of layout) {
7587
+ if (!field.unpack) {
7588
+ continue;
7589
+ }
7590
+ try {
7591
+ result[field.name] = field.unpack(view, field.offset);
7592
+ } catch (e) {
7593
+ console.error(`Error unpacking field '${field.name}' at offset ${field.offset}:`, e);
7594
+ throw e;
7595
+ }
7596
+ }
7597
+ if (structDefOptions?.reduceValue) {
7598
+ return structDefOptions.reduceValue(result);
7599
+ }
7600
+ return result;
7601
+ },
7602
+ packList(objects, options) {
7603
+ if (objects.length === 0) {
7604
+ return new ArrayBuffer(0);
7605
+ }
7606
+ const buffer = new ArrayBuffer(totalSize * objects.length);
7607
+ const view = new DataView(buffer);
7608
+ for (let i = 0;i < objects.length; i++) {
7609
+ let mappedObj = objects[i];
7610
+ if (structDefOptions?.mapValue) {
7611
+ mappedObj = structDefOptions.mapValue(objects[i]);
7612
+ }
7613
+ for (const field of layout) {
7614
+ const value = mappedObj[field.name] ?? field.default;
7615
+ if (!field.optional && value === undefined) {
7616
+ fatalError(`Packing non-optional field '${field.name}' at index ${i} but value is undefined (and no default provided)`);
7617
+ }
7618
+ if (field.validate) {
7619
+ for (const validateFn of field.validate) {
7620
+ validateFn(value, field.name, {
7621
+ hints: options?.validationHints,
7622
+ input: mappedObj
7623
+ });
7624
+ }
7625
+ }
7626
+ field.pack(view, i * totalSize + field.offset, value, mappedObj, options);
7627
+ }
7628
+ }
7629
+ return buffer;
7630
+ },
7631
+ unpackList(buf, count) {
7632
+ if (count === 0) {
7633
+ return [];
7634
+ }
7635
+ const expectedSize = totalSize * count;
7636
+ if (buf.byteLength < expectedSize) {
7637
+ fatalError(`Buffer size (${buf.byteLength}) is smaller than expected size (${expectedSize}) for unpacking ${count} structs.`);
7638
+ }
7639
+ const view = new DataView(buf);
7640
+ const results = [];
7641
+ for (let i = 0;i < count; i++) {
7642
+ const offset2 = i * totalSize;
7643
+ const result = structDefOptions?.default ? { ...structDefOptions.default } : {};
7644
+ for (const field of layout) {
7645
+ if (!field.unpack) {
7646
+ continue;
7647
+ }
7648
+ try {
7649
+ result[field.name] = field.unpack(view, offset2 + field.offset);
7650
+ } catch (e) {
7651
+ console.error(`Error unpacking field '${field.name}' at index ${i}, offset ${offset2 + field.offset}:`, e);
7652
+ throw e;
7653
+ }
7654
+ }
7655
+ if (structDefOptions?.reduceValue) {
7656
+ results.push(structDefOptions.reduceValue(result));
7657
+ } else {
7658
+ results.push(result);
7659
+ }
7660
+ }
7661
+ return results;
7662
+ },
7663
+ describe() {
7664
+ return description;
7665
+ }
7666
+ };
7667
+ }
7668
+
7669
+ // src/zig-structs.ts
7670
+ import { ptr as ptr2, toArrayBuffer as toArrayBuffer3 } from "bun:ffi";
7671
+ var rgbaPackTransform = (rgba) => rgba ? ptr2(rgba.buffer) : null;
7672
+ var rgbaUnpackTransform = (ptr3) => ptr3 ? RGBA.fromArray(new Float32Array(toArrayBuffer3(ptr3))) : undefined;
7673
+ var StyledChunkStruct = defineStruct([
7674
+ ["text", "char*"],
7675
+ ["text_len", "u64", { lengthOf: "text" }],
7676
+ [
7677
+ "fg",
7678
+ "pointer",
7679
+ {
7680
+ optional: true,
7681
+ packTransform: rgbaPackTransform,
7682
+ unpackTransform: rgbaUnpackTransform
7683
+ }
7684
+ ],
7685
+ [
7686
+ "bg",
7687
+ "pointer",
7688
+ {
7689
+ optional: true,
7690
+ packTransform: rgbaPackTransform,
7691
+ unpackTransform: rgbaUnpackTransform
7692
+ }
7693
+ ],
7694
+ ["attributes", "u8", { optional: true }]
7695
+ ]);
7696
+ var HighlightStruct = defineStruct([
7697
+ ["start", "u32"],
7698
+ ["end", "u32"],
7699
+ ["styleId", "u32"],
7700
+ ["priority", "u8", { default: 0 }],
7701
+ ["hlRef", "u16", { default: 0 }]
7702
+ ]);
7703
+ var LogicalCursorStruct = defineStruct([
7704
+ ["row", "u32"],
7705
+ ["col", "u32"],
7706
+ ["offset", "u32"]
7707
+ ]);
7708
+ var VisualCursorStruct = defineStruct([
7709
+ ["visualRow", "u32"],
7710
+ ["visualCol", "u32"],
7711
+ ["logicalRow", "u32"],
7712
+ ["logicalCol", "u32"],
7713
+ ["offset", "u32"]
7714
+ ]);
7715
+
7716
+ // src/zig.ts
7717
+ var module = await import(`@opentui/core-${process.platform}-${process.arch}/index.ts`);
7718
+ var targetLibPath = module.default;
7719
+ if (/\$bunfs/.test(targetLibPath)) {
7720
+ targetLibPath = targetLibPath.replace("../", "");
7721
+ }
7722
+ if (!existsSync2(targetLibPath)) {
7723
+ throw new Error(`opentui is not supported on the current platform: ${process.platform}-${process.arch}`);
7724
+ }
7725
+ registerEnvVar({
7726
+ name: "OTUI_DEBUG_FFI",
7727
+ description: "Enable debug logging for the FFI bindings.",
7728
+ type: "boolean",
7729
+ default: false
7730
+ });
7731
+ registerEnvVar({
7732
+ name: "OTUI_TRACE_FFI",
7733
+ description: "Enable tracing for the FFI bindings.",
7734
+ type: "boolean",
7735
+ default: false
7736
+ });
7737
+ function getOpenTUILib(libPath) {
7738
+ const resolvedLibPath = libPath || targetLibPath;
7739
+ const rawSymbols = dlopen(resolvedLibPath, {
7740
+ setLogCallback: {
7741
+ args: ["ptr"],
7742
+ returns: "void"
7743
+ },
7744
+ setEventCallback: {
7745
+ args: ["ptr"],
7746
+ returns: "void"
7747
+ },
7748
+ createRenderer: {
7749
+ args: ["u32", "u32", "bool"],
7750
+ returns: "ptr"
7751
+ },
7752
+ destroyRenderer: {
7753
+ args: ["ptr"],
7754
+ returns: "void"
7755
+ },
6492
7756
  setUseThread: {
6493
7757
  args: ["ptr", "bool"],
6494
7758
  returns: "void"
@@ -6709,15 +7973,15 @@ function getOpenTUILib(libPath) {
6709
7973
  args: ["ptr"],
6710
7974
  returns: "u32"
6711
7975
  },
6712
- textBufferReset: {
7976
+ textBufferGetByteSize: {
6713
7977
  args: ["ptr"],
6714
- returns: "void"
7978
+ returns: "u32"
6715
7979
  },
6716
- textBufferSetSelection: {
6717
- args: ["ptr", "u32", "u32", "ptr", "ptr"],
7980
+ textBufferReset: {
7981
+ args: ["ptr"],
6718
7982
  returns: "void"
6719
7983
  },
6720
- textBufferResetSelection: {
7984
+ textBufferClear: {
6721
7985
  args: ["ptr"],
6722
7986
  returns: "void"
6723
7987
  },
@@ -6737,74 +8001,414 @@ function getOpenTUILib(libPath) {
6737
8001
  args: ["ptr"],
6738
8002
  returns: "void"
6739
8003
  },
6740
- textBufferWriteChunk: {
6741
- args: ["ptr", "ptr", "u32", "ptr", "ptr", "ptr"],
6742
- returns: "u32"
8004
+ textBufferRegisterMemBuffer: {
8005
+ args: ["ptr", "ptr", "usize", "bool"],
8006
+ returns: "u16"
8007
+ },
8008
+ textBufferReplaceMemBuffer: {
8009
+ args: ["ptr", "u8", "ptr", "usize", "bool"],
8010
+ returns: "bool"
6743
8011
  },
6744
- textBufferFinalizeLineInfo: {
8012
+ textBufferClearMemRegistry: {
6745
8013
  args: ["ptr"],
6746
8014
  returns: "void"
6747
8015
  },
8016
+ textBufferSetTextFromMem: {
8017
+ args: ["ptr", "u8"],
8018
+ returns: "void"
8019
+ },
8020
+ textBufferLoadFile: {
8021
+ args: ["ptr", "ptr", "usize"],
8022
+ returns: "bool"
8023
+ },
8024
+ textBufferSetStyledText: {
8025
+ args: ["ptr", "ptr", "usize"],
8026
+ returns: "void"
8027
+ },
6748
8028
  textBufferGetLineCount: {
6749
8029
  args: ["ptr"],
6750
8030
  returns: "u32"
6751
8031
  },
6752
- textBufferGetLineInfoDirect: {
8032
+ textBufferGetPlainText: {
8033
+ args: ["ptr", "ptr", "usize"],
8034
+ returns: "usize"
8035
+ },
8036
+ textBufferAddHighlightByCharRange: {
8037
+ args: ["ptr", "ptr"],
8038
+ returns: "void"
8039
+ },
8040
+ textBufferAddHighlight: {
8041
+ args: ["ptr", "u32", "ptr"],
8042
+ returns: "void"
8043
+ },
8044
+ textBufferRemoveHighlightsByRef: {
8045
+ args: ["ptr", "u16"],
8046
+ returns: "void"
8047
+ },
8048
+ textBufferClearLineHighlights: {
8049
+ args: ["ptr", "u32"],
8050
+ returns: "void"
8051
+ },
8052
+ textBufferClearAllHighlights: {
8053
+ args: ["ptr"],
8054
+ returns: "void"
8055
+ },
8056
+ textBufferSetSyntaxStyle: {
8057
+ args: ["ptr", "ptr"],
8058
+ returns: "void"
8059
+ },
8060
+ textBufferGetLineHighlightsPtr: {
8061
+ args: ["ptr", "u32", "ptr"],
8062
+ returns: "ptr"
8063
+ },
8064
+ textBufferFreeLineHighlights: {
8065
+ args: ["ptr", "usize"],
8066
+ returns: "void"
8067
+ },
8068
+ createTextBufferView: {
8069
+ args: ["ptr"],
8070
+ returns: "ptr"
8071
+ },
8072
+ destroyTextBufferView: {
8073
+ args: ["ptr"],
8074
+ returns: "void"
8075
+ },
8076
+ textBufferViewSetSelection: {
8077
+ args: ["ptr", "u32", "u32", "ptr", "ptr"],
8078
+ returns: "void"
8079
+ },
8080
+ textBufferViewResetSelection: {
8081
+ args: ["ptr"],
8082
+ returns: "void"
8083
+ },
8084
+ textBufferViewGetSelectionInfo: {
8085
+ args: ["ptr"],
8086
+ returns: "u64"
8087
+ },
8088
+ textBufferViewSetLocalSelection: {
8089
+ args: ["ptr", "i32", "i32", "i32", "i32", "ptr", "ptr"],
8090
+ returns: "bool"
8091
+ },
8092
+ textBufferViewResetLocalSelection: {
8093
+ args: ["ptr"],
8094
+ returns: "void"
8095
+ },
8096
+ textBufferViewSetWrapWidth: {
8097
+ args: ["ptr", "u32"],
8098
+ returns: "void"
8099
+ },
8100
+ textBufferViewSetWrapMode: {
8101
+ args: ["ptr", "u8"],
8102
+ returns: "void"
8103
+ },
8104
+ textBufferViewSetViewportSize: {
8105
+ args: ["ptr", "u32", "u32"],
8106
+ returns: "void"
8107
+ },
8108
+ textBufferViewGetVirtualLineCount: {
8109
+ args: ["ptr"],
8110
+ returns: "u32"
8111
+ },
8112
+ textBufferViewGetLineInfoDirect: {
8113
+ args: ["ptr", "ptr", "ptr"],
8114
+ returns: "u32"
8115
+ },
8116
+ textBufferViewGetLogicalLineInfoDirect: {
6753
8117
  args: ["ptr", "ptr", "ptr"],
6754
8118
  returns: "u32"
6755
8119
  },
6756
- textBufferGetSelectionInfo: {
8120
+ textBufferViewGetSelectedText: {
8121
+ args: ["ptr", "ptr", "usize"],
8122
+ returns: "usize"
8123
+ },
8124
+ textBufferViewGetPlainText: {
8125
+ args: ["ptr", "ptr", "usize"],
8126
+ returns: "usize"
8127
+ },
8128
+ bufferDrawTextBufferView: {
8129
+ args: ["ptr", "ptr", "i32", "i32"],
8130
+ returns: "void"
8131
+ },
8132
+ bufferDrawEditorView: {
8133
+ args: ["ptr", "ptr", "i32", "i32"],
8134
+ returns: "void"
8135
+ },
8136
+ createEditorView: {
8137
+ args: ["ptr", "u32", "u32"],
8138
+ returns: "ptr"
8139
+ },
8140
+ destroyEditorView: {
6757
8141
  args: ["ptr"],
6758
- returns: "u64"
8142
+ returns: "void"
8143
+ },
8144
+ editorViewSetViewportSize: {
8145
+ args: ["ptr", "u32", "u32"],
8146
+ returns: "void"
8147
+ },
8148
+ editorViewGetViewport: {
8149
+ args: ["ptr", "ptr", "ptr", "ptr", "ptr"],
8150
+ returns: "void"
8151
+ },
8152
+ editorViewSetScrollMargin: {
8153
+ args: ["ptr", "f32"],
8154
+ returns: "void"
8155
+ },
8156
+ editorViewSetWrapMode: {
8157
+ args: ["ptr", "u8"],
8158
+ returns: "void"
8159
+ },
8160
+ editorViewGetVirtualLineCount: {
8161
+ args: ["ptr"],
8162
+ returns: "u32"
8163
+ },
8164
+ editorViewGetTotalVirtualLineCount: {
8165
+ args: ["ptr"],
8166
+ returns: "u32"
8167
+ },
8168
+ editorViewGetTextBufferView: {
8169
+ args: ["ptr"],
8170
+ returns: "ptr"
8171
+ },
8172
+ createEditBuffer: {
8173
+ args: ["u8"],
8174
+ returns: "ptr"
8175
+ },
8176
+ destroyEditBuffer: {
8177
+ args: ["ptr"],
8178
+ returns: "void"
8179
+ },
8180
+ editBufferSetText: {
8181
+ args: ["ptr", "ptr", "usize", "bool"],
8182
+ returns: "void"
6759
8183
  },
6760
- textBufferGetSelectedText: {
8184
+ editBufferSetTextFromMem: {
8185
+ args: ["ptr", "u8", "bool"],
8186
+ returns: "void"
8187
+ },
8188
+ editBufferGetText: {
6761
8189
  args: ["ptr", "ptr", "usize"],
6762
8190
  returns: "usize"
6763
8191
  },
6764
- textBufferGetPlainText: {
8192
+ editBufferInsertChar: {
8193
+ args: ["ptr", "ptr", "usize"],
8194
+ returns: "void"
8195
+ },
8196
+ editBufferInsertText: {
8197
+ args: ["ptr", "ptr", "usize"],
8198
+ returns: "void"
8199
+ },
8200
+ editBufferDeleteChar: {
8201
+ args: ["ptr"],
8202
+ returns: "void"
8203
+ },
8204
+ editBufferDeleteCharBackward: {
8205
+ args: ["ptr"],
8206
+ returns: "void"
8207
+ },
8208
+ editBufferDeleteRange: {
8209
+ args: ["ptr", "u32", "u32", "u32", "u32"],
8210
+ returns: "void"
8211
+ },
8212
+ editBufferNewLine: {
8213
+ args: ["ptr"],
8214
+ returns: "void"
8215
+ },
8216
+ editBufferDeleteLine: {
8217
+ args: ["ptr"],
8218
+ returns: "void"
8219
+ },
8220
+ editBufferMoveCursorLeft: {
8221
+ args: ["ptr"],
8222
+ returns: "void"
8223
+ },
8224
+ editBufferMoveCursorRight: {
8225
+ args: ["ptr"],
8226
+ returns: "void"
8227
+ },
8228
+ editBufferMoveCursorUp: {
8229
+ args: ["ptr"],
8230
+ returns: "void"
8231
+ },
8232
+ editBufferMoveCursorDown: {
8233
+ args: ["ptr"],
8234
+ returns: "void"
8235
+ },
8236
+ editBufferGotoLine: {
8237
+ args: ["ptr", "u32"],
8238
+ returns: "void"
8239
+ },
8240
+ editBufferSetCursor: {
8241
+ args: ["ptr", "u32", "u32"],
8242
+ returns: "void"
8243
+ },
8244
+ editBufferSetCursorToLineCol: {
8245
+ args: ["ptr", "u32", "u32"],
8246
+ returns: "void"
8247
+ },
8248
+ editBufferSetCursorByOffset: {
8249
+ args: ["ptr", "u32"],
8250
+ returns: "void"
8251
+ },
8252
+ editBufferGetCursorPosition: {
8253
+ args: ["ptr", "ptr"],
8254
+ returns: "void"
8255
+ },
8256
+ editBufferGetId: {
8257
+ args: ["ptr"],
8258
+ returns: "u16"
8259
+ },
8260
+ editBufferGetTextBuffer: {
8261
+ args: ["ptr"],
8262
+ returns: "ptr"
8263
+ },
8264
+ editBufferDebugLogRope: {
8265
+ args: ["ptr"],
8266
+ returns: "void"
8267
+ },
8268
+ editBufferUndo: {
6765
8269
  args: ["ptr", "ptr", "usize"],
6766
8270
  returns: "usize"
6767
8271
  },
6768
- textBufferSetLocalSelection: {
6769
- args: ["ptr", "i32", "i32", "i32", "i32", "ptr", "ptr"],
8272
+ editBufferRedo: {
8273
+ args: ["ptr", "ptr", "usize"],
8274
+ returns: "usize"
8275
+ },
8276
+ editBufferCanUndo: {
8277
+ args: ["ptr"],
8278
+ returns: "bool"
8279
+ },
8280
+ editBufferCanRedo: {
8281
+ args: ["ptr"],
6770
8282
  returns: "bool"
6771
8283
  },
6772
- textBufferResetLocalSelection: {
8284
+ editBufferClearHistory: {
6773
8285
  args: ["ptr"],
6774
8286
  returns: "void"
6775
8287
  },
6776
- textBufferInsertChunkGroup: {
6777
- args: ["ptr", "usize", "ptr", "u32", "ptr", "ptr", "u8"],
6778
- returns: "u32"
8288
+ editBufferSetPlaceholder: {
8289
+ args: ["ptr", "ptr", "usize"],
8290
+ returns: "void"
6779
8291
  },
6780
- textBufferRemoveChunkGroup: {
6781
- args: ["ptr", "usize"],
8292
+ editBufferSetPlaceholderColor: {
8293
+ args: ["ptr", "ptr"],
8294
+ returns: "void"
8295
+ },
8296
+ editBufferClear: {
8297
+ args: ["ptr"],
8298
+ returns: "void"
8299
+ },
8300
+ editBufferGetNextWordBoundary: {
8301
+ args: ["ptr", "ptr"],
8302
+ returns: "void"
8303
+ },
8304
+ editBufferGetPrevWordBoundary: {
8305
+ args: ["ptr", "ptr"],
8306
+ returns: "void"
8307
+ },
8308
+ editBufferGetEOL: {
8309
+ args: ["ptr", "ptr"],
8310
+ returns: "void"
8311
+ },
8312
+ editBufferOffsetToPosition: {
8313
+ args: ["ptr", "u32", "ptr"],
8314
+ returns: "bool"
8315
+ },
8316
+ editBufferPositionToOffset: {
8317
+ args: ["ptr", "u32", "u32"],
6782
8318
  returns: "u32"
6783
8319
  },
6784
- textBufferReplaceChunkGroup: {
6785
- args: ["ptr", "usize", "ptr", "u32", "ptr", "ptr", "u8"],
8320
+ editBufferGetLineStartOffset: {
8321
+ args: ["ptr", "u32"],
6786
8322
  returns: "u32"
6787
8323
  },
6788
- textBufferGetChunkGroupCount: {
8324
+ editorViewSetSelection: {
8325
+ args: ["ptr", "u32", "u32", "ptr", "ptr"],
8326
+ returns: "void"
8327
+ },
8328
+ editorViewResetSelection: {
8329
+ args: ["ptr"],
8330
+ returns: "void"
8331
+ },
8332
+ editorViewGetSelection: {
8333
+ args: ["ptr"],
8334
+ returns: "u64"
8335
+ },
8336
+ editorViewSetLocalSelection: {
8337
+ args: ["ptr", "i32", "i32", "i32", "i32", "ptr", "ptr"],
8338
+ returns: "bool"
8339
+ },
8340
+ editorViewResetLocalSelection: {
8341
+ args: ["ptr"],
8342
+ returns: "void"
8343
+ },
8344
+ editorViewGetSelectedTextBytes: {
8345
+ args: ["ptr", "ptr", "usize"],
8346
+ returns: "usize"
8347
+ },
8348
+ editorViewGetCursor: {
8349
+ args: ["ptr", "ptr", "ptr"],
8350
+ returns: "void"
8351
+ },
8352
+ editorViewGetText: {
8353
+ args: ["ptr", "ptr", "usize"],
8354
+ returns: "usize"
8355
+ },
8356
+ editorViewGetVisualCursor: {
8357
+ args: ["ptr", "ptr"],
8358
+ returns: "void"
8359
+ },
8360
+ editorViewMoveUpVisual: {
8361
+ args: ["ptr"],
8362
+ returns: "void"
8363
+ },
8364
+ editorViewMoveDownVisual: {
8365
+ args: ["ptr"],
8366
+ returns: "void"
8367
+ },
8368
+ editorViewDeleteSelectedText: {
6789
8369
  args: ["ptr"],
6790
- returns: "usize"
8370
+ returns: "void"
6791
8371
  },
6792
- textBufferSetWrapWidth: {
8372
+ editorViewSetCursorByOffset: {
6793
8373
  args: ["ptr", "u32"],
6794
8374
  returns: "void"
6795
8375
  },
6796
- textBufferSetWrapMode: {
6797
- args: ["ptr", "u8"],
8376
+ editorViewGetNextWordBoundary: {
8377
+ args: ["ptr", "ptr"],
8378
+ returns: "void"
8379
+ },
8380
+ editorViewGetPrevWordBoundary: {
8381
+ args: ["ptr", "ptr"],
8382
+ returns: "void"
8383
+ },
8384
+ editorViewGetEOL: {
8385
+ args: ["ptr", "ptr"],
6798
8386
  returns: "void"
6799
8387
  },
6800
8388
  getArenaAllocatedBytes: {
6801
8389
  args: [],
6802
8390
  returns: "usize"
6803
8391
  },
6804
- bufferDrawTextBuffer: {
6805
- args: ["ptr", "ptr", "i32", "i32", "i32", "i32", "u32", "u32", "bool"],
8392
+ createSyntaxStyle: {
8393
+ args: [],
8394
+ returns: "ptr"
8395
+ },
8396
+ destroySyntaxStyle: {
8397
+ args: ["ptr"],
6806
8398
  returns: "void"
6807
8399
  },
8400
+ syntaxStyleRegister: {
8401
+ args: ["ptr", "ptr", "usize", "ptr", "ptr", "u8"],
8402
+ returns: "u32"
8403
+ },
8404
+ syntaxStyleResolveByName: {
8405
+ args: ["ptr", "ptr", "usize"],
8406
+ returns: "u32"
8407
+ },
8408
+ syntaxStyleGetStyleCount: {
8409
+ args: ["ptr"],
8410
+ returns: "usize"
8411
+ },
6808
8412
  getTerminalCapabilities: {
6809
8413
  args: ["ptr", "ptr"],
6810
8414
  returns: "void"
@@ -6937,9 +8541,13 @@ class FFIRenderLib {
6937
8541
  encoder = new TextEncoder;
6938
8542
  decoder = new TextDecoder;
6939
8543
  logCallbackWrapper;
8544
+ eventCallbackWrapper;
8545
+ _nativeEvents = new EventEmitter4;
8546
+ _anyEventHandlers = [];
6940
8547
  constructor(libPath) {
6941
8548
  this.opentui = getOpenTUILib(libPath);
6942
8549
  this.setupLogging();
8550
+ this.setupEventBus();
6943
8551
  }
6944
8552
  setupLogging() {
6945
8553
  if (this.logCallbackWrapper) {
@@ -6951,7 +8559,7 @@ class FFIRenderLib {
6951
8559
  if (msgLen === 0 || !msgPtr) {
6952
8560
  return;
6953
8561
  }
6954
- const msgBuffer = toArrayBuffer2(msgPtr, 0, msgLen);
8562
+ const msgBuffer = toArrayBuffer4(msgPtr, 0, msgLen);
6955
8563
  const msgBytes = new Uint8Array(msgBuffer);
6956
8564
  const message = this.decoder.decode(msgBytes);
6957
8565
  switch (level) {
@@ -6986,6 +8594,48 @@ class FFIRenderLib {
6986
8594
  setLogCallback(callbackPtr) {
6987
8595
  this.opentui.symbols.setLogCallback(callbackPtr);
6988
8596
  }
8597
+ setupEventBus() {
8598
+ if (this.eventCallbackWrapper) {
8599
+ return;
8600
+ }
8601
+ const eventCallback = new JSCallback((namePtr, nameLenBigInt, dataPtr, dataLenBigInt) => {
8602
+ try {
8603
+ const nameLen = typeof nameLenBigInt === "bigint" ? Number(nameLenBigInt) : nameLenBigInt;
8604
+ const dataLen = typeof dataLenBigInt === "bigint" ? Number(dataLenBigInt) : dataLenBigInt;
8605
+ if (nameLen === 0 || !namePtr) {
8606
+ return;
8607
+ }
8608
+ const nameBuffer = toArrayBuffer4(namePtr, 0, nameLen);
8609
+ const nameBytes = new Uint8Array(nameBuffer);
8610
+ const eventName = this.decoder.decode(nameBytes);
8611
+ let eventData;
8612
+ if (dataLen > 0 && dataPtr) {
8613
+ eventData = toArrayBuffer4(dataPtr, 0, dataLen).slice();
8614
+ } else {
8615
+ eventData = new ArrayBuffer(0);
8616
+ }
8617
+ queueMicrotask(() => {
8618
+ this._nativeEvents.emit(eventName, eventData);
8619
+ for (const handler of this._anyEventHandlers) {
8620
+ handler(eventName, eventData);
8621
+ }
8622
+ });
8623
+ } catch (error) {
8624
+ console.error("Error in native event callback:", error);
8625
+ }
8626
+ }, {
8627
+ args: ["ptr", "usize", "ptr", "usize"],
8628
+ returns: "void"
8629
+ });
8630
+ this.eventCallbackWrapper = eventCallback;
8631
+ if (!eventCallback.ptr) {
8632
+ throw new Error("Failed to create event callback");
8633
+ }
8634
+ this.setEventCallback(eventCallback.ptr);
8635
+ }
8636
+ setEventCallback(callbackPtr) {
8637
+ this.opentui.symbols.setEventCallback(callbackPtr);
8638
+ }
6989
8639
  createRenderer(width, height, options = { testing: false }) {
6990
8640
  return this.opentui.symbols.createRenderer(width, height, options.testing);
6991
8641
  }
@@ -7026,32 +8676,32 @@ class FFIRenderLib {
7026
8676
  return new OptimizedBuffer(this, bufferPtr, width, height, { id: "current buffer" });
7027
8677
  }
7028
8678
  bufferGetCharPtr(buffer) {
7029
- const ptr2 = this.opentui.symbols.bufferGetCharPtr(buffer);
7030
- if (!ptr2) {
8679
+ const ptr4 = this.opentui.symbols.bufferGetCharPtr(buffer);
8680
+ if (!ptr4) {
7031
8681
  throw new Error("Failed to get char pointer");
7032
8682
  }
7033
- return ptr2;
8683
+ return ptr4;
7034
8684
  }
7035
8685
  bufferGetFgPtr(buffer) {
7036
- const ptr2 = this.opentui.symbols.bufferGetFgPtr(buffer);
7037
- if (!ptr2) {
8686
+ const ptr4 = this.opentui.symbols.bufferGetFgPtr(buffer);
8687
+ if (!ptr4) {
7038
8688
  throw new Error("Failed to get fg pointer");
7039
8689
  }
7040
- return ptr2;
8690
+ return ptr4;
7041
8691
  }
7042
8692
  bufferGetBgPtr(buffer) {
7043
- const ptr2 = this.opentui.symbols.bufferGetBgPtr(buffer);
7044
- if (!ptr2) {
8693
+ const ptr4 = this.opentui.symbols.bufferGetBgPtr(buffer);
8694
+ if (!ptr4) {
7045
8695
  throw new Error("Failed to get bg pointer");
7046
8696
  }
7047
- return ptr2;
8697
+ return ptr4;
7048
8698
  }
7049
8699
  bufferGetAttributesPtr(buffer) {
7050
- const ptr2 = this.opentui.symbols.bufferGetAttributesPtr(buffer);
7051
- if (!ptr2) {
8700
+ const ptr4 = this.opentui.symbols.bufferGetAttributesPtr(buffer);
8701
+ if (!ptr4) {
7052
8702
  throw new Error("Failed to get attributes pointer");
7053
8703
  }
7054
- return ptr2;
8704
+ return ptr4;
7055
8705
  }
7056
8706
  bufferGetRespectAlpha(buffer) {
7057
8707
  return this.opentui.symbols.bufferGetRespectAlpha(buffer);
@@ -7131,135 +8781,526 @@ class FFIRenderLib {
7131
8781
  const stylePtr = this.encoder.encode(style);
7132
8782
  this.opentui.symbols.setCursorStyle(renderer, stylePtr, style.length, blinking);
7133
8783
  }
7134
- setCursorColor(renderer, color) {
7135
- this.opentui.symbols.setCursorColor(renderer, color.buffer);
8784
+ setCursorColor(renderer, color) {
8785
+ this.opentui.symbols.setCursorColor(renderer, color.buffer);
8786
+ }
8787
+ render(renderer, force) {
8788
+ this.opentui.symbols.render(renderer, force);
8789
+ }
8790
+ createOptimizedBuffer(width, height, widthMethod, respectAlpha = false, id) {
8791
+ if (Number.isNaN(width) || Number.isNaN(height)) {
8792
+ console.error(new Error(`Invalid dimensions for OptimizedBuffer: ${width}x${height}`).stack);
8793
+ }
8794
+ const widthMethodCode = widthMethod === "wcwidth" ? 0 : 1;
8795
+ const idToUse = id || "unnamed buffer";
8796
+ const idBytes = this.encoder.encode(idToUse);
8797
+ const bufferPtr = this.opentui.symbols.createOptimizedBuffer(width, height, respectAlpha, widthMethodCode, idBytes, idBytes.length);
8798
+ if (!bufferPtr) {
8799
+ throw new Error(`Failed to create optimized buffer: ${width}x${height}`);
8800
+ }
8801
+ return new OptimizedBuffer(this, bufferPtr, width, height, { respectAlpha, id });
8802
+ }
8803
+ destroyOptimizedBuffer(bufferPtr) {
8804
+ this.opentui.symbols.destroyOptimizedBuffer(bufferPtr);
8805
+ }
8806
+ drawFrameBuffer(targetBufferPtr, destX, destY, bufferPtr, sourceX, sourceY, sourceWidth, sourceHeight) {
8807
+ const srcX = sourceX ?? 0;
8808
+ const srcY = sourceY ?? 0;
8809
+ const srcWidth = sourceWidth ?? 0;
8810
+ const srcHeight = sourceHeight ?? 0;
8811
+ this.opentui.symbols.drawFrameBuffer(targetBufferPtr, destX, destY, bufferPtr, srcX, srcY, srcWidth, srcHeight);
8812
+ }
8813
+ setDebugOverlay(renderer, enabled, corner) {
8814
+ this.opentui.symbols.setDebugOverlay(renderer, enabled, corner);
8815
+ }
8816
+ clearTerminal(renderer) {
8817
+ this.opentui.symbols.clearTerminal(renderer);
8818
+ }
8819
+ setTerminalTitle(renderer, title) {
8820
+ const titleBytes = this.encoder.encode(title);
8821
+ this.opentui.symbols.setTerminalTitle(renderer, titleBytes, titleBytes.length);
8822
+ }
8823
+ addToHitGrid(renderer, x, y, width, height, id) {
8824
+ this.opentui.symbols.addToHitGrid(renderer, x, y, width, height, id);
8825
+ }
8826
+ checkHit(renderer, x, y) {
8827
+ return this.opentui.symbols.checkHit(renderer, x, y);
8828
+ }
8829
+ dumpHitGrid(renderer) {
8830
+ this.opentui.symbols.dumpHitGrid(renderer);
8831
+ }
8832
+ dumpBuffers(renderer, timestamp) {
8833
+ const ts = timestamp ?? Date.now();
8834
+ this.opentui.symbols.dumpBuffers(renderer, ts);
8835
+ }
8836
+ dumpStdoutBuffer(renderer, timestamp) {
8837
+ const ts = timestamp ?? Date.now();
8838
+ this.opentui.symbols.dumpStdoutBuffer(renderer, ts);
8839
+ }
8840
+ enableMouse(renderer, enableMovement) {
8841
+ this.opentui.symbols.enableMouse(renderer, enableMovement);
8842
+ }
8843
+ disableMouse(renderer) {
8844
+ this.opentui.symbols.disableMouse(renderer);
8845
+ }
8846
+ enableKittyKeyboard(renderer, flags) {
8847
+ this.opentui.symbols.enableKittyKeyboard(renderer, flags);
8848
+ }
8849
+ disableKittyKeyboard(renderer) {
8850
+ this.opentui.symbols.disableKittyKeyboard(renderer);
8851
+ }
8852
+ setupTerminal(renderer, useAlternateScreen) {
8853
+ this.opentui.symbols.setupTerminal(renderer, useAlternateScreen);
8854
+ }
8855
+ queryPixelResolution(renderer) {
8856
+ this.opentui.symbols.queryPixelResolution(renderer);
8857
+ }
8858
+ createTextBuffer(widthMethod) {
8859
+ const widthMethodCode = widthMethod === "wcwidth" ? 0 : 1;
8860
+ const bufferPtr = this.opentui.symbols.createTextBuffer(widthMethodCode);
8861
+ if (!bufferPtr) {
8862
+ throw new Error(`Failed to create TextBuffer`);
8863
+ }
8864
+ return new TextBuffer(this, bufferPtr);
8865
+ }
8866
+ destroyTextBuffer(buffer) {
8867
+ this.opentui.symbols.destroyTextBuffer(buffer);
8868
+ }
8869
+ textBufferGetLength(buffer) {
8870
+ return this.opentui.symbols.textBufferGetLength(buffer);
8871
+ }
8872
+ textBufferGetByteSize(buffer) {
8873
+ return this.opentui.symbols.textBufferGetByteSize(buffer);
8874
+ }
8875
+ textBufferReset(buffer) {
8876
+ this.opentui.symbols.textBufferReset(buffer);
8877
+ }
8878
+ textBufferClear(buffer) {
8879
+ this.opentui.symbols.textBufferClear(buffer);
8880
+ }
8881
+ textBufferSetDefaultFg(buffer, fg2) {
8882
+ const fgPtr = fg2 ? fg2.buffer : null;
8883
+ this.opentui.symbols.textBufferSetDefaultFg(buffer, fgPtr);
8884
+ }
8885
+ textBufferSetDefaultBg(buffer, bg2) {
8886
+ const bgPtr = bg2 ? bg2.buffer : null;
8887
+ this.opentui.symbols.textBufferSetDefaultBg(buffer, bgPtr);
8888
+ }
8889
+ textBufferSetDefaultAttributes(buffer, attributes) {
8890
+ const attrValue = attributes === null ? null : new Uint8Array([attributes]);
8891
+ this.opentui.symbols.textBufferSetDefaultAttributes(buffer, attrValue);
8892
+ }
8893
+ textBufferResetDefaults(buffer) {
8894
+ this.opentui.symbols.textBufferResetDefaults(buffer);
8895
+ }
8896
+ textBufferRegisterMemBuffer(buffer, bytes, owned = false) {
8897
+ const result = this.opentui.symbols.textBufferRegisterMemBuffer(buffer, bytes, bytes.length, owned);
8898
+ if (result === 65535) {
8899
+ throw new Error("Failed to register memory buffer");
8900
+ }
8901
+ return result;
8902
+ }
8903
+ textBufferReplaceMemBuffer(buffer, memId, bytes, owned = false) {
8904
+ return this.opentui.symbols.textBufferReplaceMemBuffer(buffer, memId, bytes, bytes.length, owned);
8905
+ }
8906
+ textBufferClearMemRegistry(buffer) {
8907
+ this.opentui.symbols.textBufferClearMemRegistry(buffer);
8908
+ }
8909
+ textBufferSetTextFromMem(buffer, memId) {
8910
+ this.opentui.symbols.textBufferSetTextFromMem(buffer, memId);
8911
+ }
8912
+ textBufferLoadFile(buffer, path4) {
8913
+ const pathBytes = this.encoder.encode(path4);
8914
+ return this.opentui.symbols.textBufferLoadFile(buffer, pathBytes, pathBytes.length);
8915
+ }
8916
+ textBufferSetStyledText(buffer, chunks) {
8917
+ const nonEmptyChunks = chunks.filter((c) => c.text.length > 0);
8918
+ if (nonEmptyChunks.length === 0) {
8919
+ this.textBufferClear(buffer);
8920
+ return;
8921
+ }
8922
+ const chunksBuffer = StyledChunkStruct.packList(nonEmptyChunks);
8923
+ this.opentui.symbols.textBufferSetStyledText(buffer, ptr3(chunksBuffer), nonEmptyChunks.length);
8924
+ }
8925
+ textBufferGetLineCount(buffer) {
8926
+ return this.opentui.symbols.textBufferGetLineCount(buffer);
8927
+ }
8928
+ textBufferGetPlainText(buffer, outPtr, maxLen) {
8929
+ const result = this.opentui.symbols.textBufferGetPlainText(buffer, outPtr, maxLen);
8930
+ return typeof result === "bigint" ? Number(result) : result;
8931
+ }
8932
+ getPlainTextBytes(buffer, maxLength) {
8933
+ const outBuffer = new Uint8Array(maxLength);
8934
+ const actualLen = this.textBufferGetPlainText(buffer, ptr3(outBuffer), maxLength);
8935
+ if (actualLen === 0) {
8936
+ return null;
8937
+ }
8938
+ return outBuffer.slice(0, actualLen);
8939
+ }
8940
+ createTextBufferView(textBuffer) {
8941
+ const viewPtr = this.opentui.symbols.createTextBufferView(textBuffer);
8942
+ if (!viewPtr) {
8943
+ throw new Error("Failed to create TextBufferView");
8944
+ }
8945
+ return viewPtr;
8946
+ }
8947
+ destroyTextBufferView(view) {
8948
+ this.opentui.symbols.destroyTextBufferView(view);
8949
+ }
8950
+ textBufferViewSetSelection(view, start, end, bgColor, fgColor) {
8951
+ const bg2 = bgColor ? bgColor.buffer : null;
8952
+ const fg2 = fgColor ? fgColor.buffer : null;
8953
+ this.opentui.symbols.textBufferViewSetSelection(view, start, end, bg2, fg2);
8954
+ }
8955
+ textBufferViewResetSelection(view) {
8956
+ this.opentui.symbols.textBufferViewResetSelection(view);
8957
+ }
8958
+ textBufferViewGetSelection(view) {
8959
+ const packedInfo = this.textBufferViewGetSelectionInfo(view);
8960
+ if (packedInfo === 0xffff_ffff_ffff_ffffn) {
8961
+ return null;
8962
+ }
8963
+ const start = Number(packedInfo >> 32n);
8964
+ const end = Number(packedInfo & 0xffff_ffffn);
8965
+ return { start, end };
8966
+ }
8967
+ textBufferViewGetSelectionInfo(view) {
8968
+ return this.opentui.symbols.textBufferViewGetSelectionInfo(view);
8969
+ }
8970
+ textBufferViewSetLocalSelection(view, anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
8971
+ const bg2 = bgColor ? bgColor.buffer : null;
8972
+ const fg2 = fgColor ? fgColor.buffer : null;
8973
+ return this.opentui.symbols.textBufferViewSetLocalSelection(view, anchorX, anchorY, focusX, focusY, bg2, fg2);
8974
+ }
8975
+ textBufferViewResetLocalSelection(view) {
8976
+ this.opentui.symbols.textBufferViewResetLocalSelection(view);
8977
+ }
8978
+ textBufferViewSetWrapWidth(view, width) {
8979
+ this.opentui.symbols.textBufferViewSetWrapWidth(view, width);
8980
+ }
8981
+ textBufferViewSetWrapMode(view, mode) {
8982
+ const modeValue = mode === "none" ? 0 : mode === "char" ? 1 : 2;
8983
+ this.opentui.symbols.textBufferViewSetWrapMode(view, modeValue);
8984
+ }
8985
+ textBufferViewSetViewportSize(view, width, height) {
8986
+ this.opentui.symbols.textBufferViewSetViewportSize(view, width, height);
8987
+ }
8988
+ textBufferViewGetLineInfo(view) {
8989
+ const lineCount = this.textBufferViewGetLineCount(view);
8990
+ if (lineCount === 0) {
8991
+ return { lineStarts: [], lineWidths: [], maxLineWidth: 0 };
8992
+ }
8993
+ const lineStarts = new Uint32Array(lineCount);
8994
+ const lineWidths = new Uint32Array(lineCount);
8995
+ const maxLineWidth = this.textBufferViewGetLineInfoDirect(view, ptr3(lineStarts), ptr3(lineWidths));
8996
+ return {
8997
+ maxLineWidth,
8998
+ lineStarts: Array.from(lineStarts),
8999
+ lineWidths: Array.from(lineWidths)
9000
+ };
9001
+ }
9002
+ textBufferViewGetLogicalLineInfo(view) {
9003
+ const lineCount = this.textBufferViewGetLineCount(view);
9004
+ if (lineCount === 0) {
9005
+ return { lineStarts: [], lineWidths: [], maxLineWidth: 0 };
9006
+ }
9007
+ const lineStarts = new Uint32Array(lineCount);
9008
+ const lineWidths = new Uint32Array(lineCount);
9009
+ const maxLineWidth = this.textBufferViewGetLogicalLineInfoDirect(view, ptr3(lineStarts), ptr3(lineWidths));
9010
+ return {
9011
+ maxLineWidth,
9012
+ lineStarts: Array.from(lineStarts),
9013
+ lineWidths: Array.from(lineWidths)
9014
+ };
9015
+ }
9016
+ textBufferViewGetLineCount(view) {
9017
+ return this.opentui.symbols.textBufferViewGetVirtualLineCount(view);
9018
+ }
9019
+ textBufferViewGetLineInfoDirect(view, lineStartsPtr, lineWidthsPtr) {
9020
+ return this.opentui.symbols.textBufferViewGetLineInfoDirect(view, lineStartsPtr, lineWidthsPtr);
9021
+ }
9022
+ textBufferViewGetLogicalLineInfoDirect(view, lineStartsPtr, lineWidthsPtr) {
9023
+ return this.opentui.symbols.textBufferViewGetLogicalLineInfoDirect(view, lineStartsPtr, lineWidthsPtr);
9024
+ }
9025
+ textBufferViewGetSelectedText(view, outPtr, maxLen) {
9026
+ const result = this.opentui.symbols.textBufferViewGetSelectedText(view, outPtr, maxLen);
9027
+ return typeof result === "bigint" ? Number(result) : result;
9028
+ }
9029
+ textBufferViewGetPlainText(view, outPtr, maxLen) {
9030
+ const result = this.opentui.symbols.textBufferViewGetPlainText(view, outPtr, maxLen);
9031
+ return typeof result === "bigint" ? Number(result) : result;
9032
+ }
9033
+ textBufferViewGetSelectedTextBytes(view, maxLength) {
9034
+ const outBuffer = new Uint8Array(maxLength);
9035
+ const actualLen = this.textBufferViewGetSelectedText(view, ptr3(outBuffer), maxLength);
9036
+ if (actualLen === 0) {
9037
+ return null;
9038
+ }
9039
+ return outBuffer.slice(0, actualLen);
9040
+ }
9041
+ textBufferViewGetPlainTextBytes(view, maxLength) {
9042
+ const outBuffer = new Uint8Array(maxLength);
9043
+ const actualLen = this.textBufferViewGetPlainText(view, ptr3(outBuffer), maxLength);
9044
+ if (actualLen === 0) {
9045
+ return null;
9046
+ }
9047
+ return outBuffer.slice(0, actualLen);
9048
+ }
9049
+ textBufferAddHighlightByCharRange(buffer, highlight) {
9050
+ const packedHighlight = HighlightStruct.pack(highlight);
9051
+ this.opentui.symbols.textBufferAddHighlightByCharRange(buffer, ptr3(packedHighlight));
9052
+ }
9053
+ textBufferAddHighlight(buffer, lineIdx, highlight) {
9054
+ const packedHighlight = HighlightStruct.pack(highlight);
9055
+ this.opentui.symbols.textBufferAddHighlight(buffer, lineIdx, ptr3(packedHighlight));
9056
+ }
9057
+ textBufferRemoveHighlightsByRef(buffer, hlRef) {
9058
+ this.opentui.symbols.textBufferRemoveHighlightsByRef(buffer, hlRef);
9059
+ }
9060
+ textBufferClearLineHighlights(buffer, lineIdx) {
9061
+ this.opentui.symbols.textBufferClearLineHighlights(buffer, lineIdx);
9062
+ }
9063
+ textBufferClearAllHighlights(buffer) {
9064
+ this.opentui.symbols.textBufferClearAllHighlights(buffer);
9065
+ }
9066
+ textBufferSetSyntaxStyle(buffer, style) {
9067
+ this.opentui.symbols.textBufferSetSyntaxStyle(buffer, style);
9068
+ }
9069
+ textBufferGetLineHighlights(buffer, lineIdx) {
9070
+ const outCountBuf = new BigUint64Array(1);
9071
+ const nativePtr = this.opentui.symbols.textBufferGetLineHighlightsPtr(buffer, lineIdx, ptr3(outCountBuf));
9072
+ if (!nativePtr)
9073
+ return [];
9074
+ const count = Number(outCountBuf[0]);
9075
+ const byteLen = count * HighlightStruct.size;
9076
+ const raw = toArrayBuffer4(nativePtr, 0, byteLen);
9077
+ const results = HighlightStruct.unpackList(raw, count);
9078
+ this.opentui.symbols.textBufferFreeLineHighlights(nativePtr, count);
9079
+ return results;
9080
+ }
9081
+ getArenaAllocatedBytes() {
9082
+ const result = this.opentui.symbols.getArenaAllocatedBytes();
9083
+ return typeof result === "bigint" ? Number(result) : result;
9084
+ }
9085
+ bufferDrawTextBufferView(buffer, view, x, y) {
9086
+ this.opentui.symbols.bufferDrawTextBufferView(buffer, view, x, y);
9087
+ }
9088
+ bufferDrawEditorView(buffer, view, x, y) {
9089
+ this.opentui.symbols.bufferDrawEditorView(buffer, view, x, y);
9090
+ }
9091
+ createEditorView(editBufferPtr, viewportWidth, viewportHeight) {
9092
+ const viewPtr = this.opentui.symbols.createEditorView(editBufferPtr, viewportWidth, viewportHeight);
9093
+ if (!viewPtr) {
9094
+ throw new Error("Failed to create EditorView");
9095
+ }
9096
+ return viewPtr;
9097
+ }
9098
+ destroyEditorView(view) {
9099
+ this.opentui.symbols.destroyEditorView(view);
9100
+ }
9101
+ editorViewSetViewportSize(view, width, height) {
9102
+ this.opentui.symbols.editorViewSetViewportSize(view, width, height);
9103
+ }
9104
+ editorViewGetViewport(view) {
9105
+ const x = new Uint32Array(1);
9106
+ const y = new Uint32Array(1);
9107
+ const width = new Uint32Array(1);
9108
+ const height = new Uint32Array(1);
9109
+ this.opentui.symbols.editorViewGetViewport(view, ptr3(x), ptr3(y), ptr3(width), ptr3(height));
9110
+ return {
9111
+ offsetX: x[0],
9112
+ offsetY: y[0],
9113
+ width: width[0],
9114
+ height: height[0]
9115
+ };
9116
+ }
9117
+ editorViewSetScrollMargin(view, margin) {
9118
+ this.opentui.symbols.editorViewSetScrollMargin(view, margin);
9119
+ }
9120
+ editorViewSetWrapMode(view, mode) {
9121
+ const modeValue = mode === "none" ? 0 : mode === "char" ? 1 : 2;
9122
+ this.opentui.symbols.editorViewSetWrapMode(view, modeValue);
9123
+ }
9124
+ editorViewGetVirtualLineCount(view) {
9125
+ return this.opentui.symbols.editorViewGetVirtualLineCount(view);
7136
9126
  }
7137
- render(renderer, force) {
7138
- this.opentui.symbols.render(renderer, force);
9127
+ editorViewGetTotalVirtualLineCount(view) {
9128
+ return this.opentui.symbols.editorViewGetTotalVirtualLineCount(view);
7139
9129
  }
7140
- createOptimizedBuffer(width, height, widthMethod, respectAlpha = false, id) {
7141
- if (Number.isNaN(width) || Number.isNaN(height)) {
7142
- console.error(new Error(`Invalid dimensions for OptimizedBuffer: ${width}x${height}`).stack);
9130
+ editorViewGetTextBufferView(view) {
9131
+ const result = this.opentui.symbols.editorViewGetTextBufferView(view);
9132
+ if (!result) {
9133
+ throw new Error("Failed to get TextBufferView from EditorView");
7143
9134
  }
9135
+ return result;
9136
+ }
9137
+ createEditBuffer(widthMethod) {
7144
9138
  const widthMethodCode = widthMethod === "wcwidth" ? 0 : 1;
7145
- const idToUse = id || "unnamed buffer";
7146
- const idBytes = this.encoder.encode(idToUse);
7147
- const bufferPtr = this.opentui.symbols.createOptimizedBuffer(width, height, respectAlpha, widthMethodCode, idBytes, idBytes.length);
9139
+ const bufferPtr = this.opentui.symbols.createEditBuffer(widthMethodCode);
7148
9140
  if (!bufferPtr) {
7149
- throw new Error(`Failed to create optimized buffer: ${width}x${height}`);
9141
+ throw new Error("Failed to create EditBuffer");
7150
9142
  }
7151
- return new OptimizedBuffer(this, bufferPtr, width, height, { respectAlpha, id });
9143
+ return bufferPtr;
7152
9144
  }
7153
- destroyOptimizedBuffer(bufferPtr) {
7154
- this.opentui.symbols.destroyOptimizedBuffer(bufferPtr);
9145
+ destroyEditBuffer(buffer) {
9146
+ this.opentui.symbols.destroyEditBuffer(buffer);
7155
9147
  }
7156
- drawFrameBuffer(targetBufferPtr, destX, destY, bufferPtr, sourceX, sourceY, sourceWidth, sourceHeight) {
7157
- const srcX = sourceX ?? 0;
7158
- const srcY = sourceY ?? 0;
7159
- const srcWidth = sourceWidth ?? 0;
7160
- const srcHeight = sourceHeight ?? 0;
7161
- this.opentui.symbols.drawFrameBuffer(targetBufferPtr, destX, destY, bufferPtr, srcX, srcY, srcWidth, srcHeight);
9148
+ editBufferSetText(buffer, textBytes, retainHistory = true) {
9149
+ this.opentui.symbols.editBufferSetText(buffer, textBytes, textBytes.length, retainHistory);
7162
9150
  }
7163
- setDebugOverlay(renderer, enabled, corner) {
7164
- this.opentui.symbols.setDebugOverlay(renderer, enabled, corner);
9151
+ editBufferSetTextFromMem(buffer, memId, retainHistory = true) {
9152
+ this.opentui.symbols.editBufferSetTextFromMem(buffer, memId, retainHistory);
7165
9153
  }
7166
- clearTerminal(renderer) {
7167
- this.opentui.symbols.clearTerminal(renderer);
9154
+ editBufferGetText(buffer, maxLength) {
9155
+ const outBuffer = new Uint8Array(maxLength);
9156
+ const actualLen = this.opentui.symbols.editBufferGetText(buffer, ptr3(outBuffer), maxLength);
9157
+ const len = typeof actualLen === "bigint" ? Number(actualLen) : actualLen;
9158
+ if (len === 0)
9159
+ return null;
9160
+ return outBuffer.slice(0, len);
7168
9161
  }
7169
- setTerminalTitle(renderer, title) {
7170
- const titleBytes = this.encoder.encode(title);
7171
- this.opentui.symbols.setTerminalTitle(renderer, titleBytes, titleBytes.length);
9162
+ editBufferInsertChar(buffer, char) {
9163
+ const charBytes = this.encoder.encode(char);
9164
+ this.opentui.symbols.editBufferInsertChar(buffer, charBytes, charBytes.length);
7172
9165
  }
7173
- addToHitGrid(renderer, x, y, width, height, id) {
7174
- this.opentui.symbols.addToHitGrid(renderer, x, y, width, height, id);
9166
+ editBufferInsertText(buffer, text) {
9167
+ const textBytes = this.encoder.encode(text);
9168
+ this.opentui.symbols.editBufferInsertText(buffer, textBytes, textBytes.length);
7175
9169
  }
7176
- checkHit(renderer, x, y) {
7177
- return this.opentui.symbols.checkHit(renderer, x, y);
9170
+ editBufferDeleteChar(buffer) {
9171
+ this.opentui.symbols.editBufferDeleteChar(buffer);
7178
9172
  }
7179
- dumpHitGrid(renderer) {
7180
- this.opentui.symbols.dumpHitGrid(renderer);
9173
+ editBufferDeleteCharBackward(buffer) {
9174
+ this.opentui.symbols.editBufferDeleteCharBackward(buffer);
7181
9175
  }
7182
- dumpBuffers(renderer, timestamp) {
7183
- const ts = timestamp ?? Date.now();
7184
- this.opentui.symbols.dumpBuffers(renderer, ts);
9176
+ editBufferDeleteRange(buffer, startLine, startCol, endLine, endCol) {
9177
+ this.opentui.symbols.editBufferDeleteRange(buffer, startLine, startCol, endLine, endCol);
7185
9178
  }
7186
- dumpStdoutBuffer(renderer, timestamp) {
7187
- const ts = timestamp ?? Date.now();
7188
- this.opentui.symbols.dumpStdoutBuffer(renderer, ts);
9179
+ editBufferNewLine(buffer) {
9180
+ this.opentui.symbols.editBufferNewLine(buffer);
7189
9181
  }
7190
- enableMouse(renderer, enableMovement) {
7191
- this.opentui.symbols.enableMouse(renderer, enableMovement);
9182
+ editBufferDeleteLine(buffer) {
9183
+ this.opentui.symbols.editBufferDeleteLine(buffer);
7192
9184
  }
7193
- disableMouse(renderer) {
7194
- this.opentui.symbols.disableMouse(renderer);
9185
+ editBufferMoveCursorLeft(buffer) {
9186
+ this.opentui.symbols.editBufferMoveCursorLeft(buffer);
7195
9187
  }
7196
- enableKittyKeyboard(renderer, flags) {
7197
- this.opentui.symbols.enableKittyKeyboard(renderer, flags);
9188
+ editBufferMoveCursorRight(buffer) {
9189
+ this.opentui.symbols.editBufferMoveCursorRight(buffer);
7198
9190
  }
7199
- disableKittyKeyboard(renderer) {
7200
- this.opentui.symbols.disableKittyKeyboard(renderer);
9191
+ editBufferMoveCursorUp(buffer) {
9192
+ this.opentui.symbols.editBufferMoveCursorUp(buffer);
7201
9193
  }
7202
- setupTerminal(renderer, useAlternateScreen) {
7203
- this.opentui.symbols.setupTerminal(renderer, useAlternateScreen);
9194
+ editBufferMoveCursorDown(buffer) {
9195
+ this.opentui.symbols.editBufferMoveCursorDown(buffer);
7204
9196
  }
7205
- queryPixelResolution(renderer) {
7206
- this.opentui.symbols.queryPixelResolution(renderer);
9197
+ editBufferGotoLine(buffer, line) {
9198
+ this.opentui.symbols.editBufferGotoLine(buffer, line);
7207
9199
  }
7208
- createTextBuffer(widthMethod) {
7209
- const widthMethodCode = widthMethod === "wcwidth" ? 0 : 1;
7210
- const bufferPtr = this.opentui.symbols.createTextBuffer(widthMethodCode);
7211
- if (!bufferPtr) {
7212
- throw new Error(`Failed to create TextBuffer`);
9200
+ editBufferSetCursor(buffer, line, byteOffset) {
9201
+ this.opentui.symbols.editBufferSetCursor(buffer, line, byteOffset);
9202
+ }
9203
+ editBufferSetCursorToLineCol(buffer, line, col) {
9204
+ this.opentui.symbols.editBufferSetCursorToLineCol(buffer, line, col);
9205
+ }
9206
+ editBufferSetCursorByOffset(buffer, offset) {
9207
+ this.opentui.symbols.editBufferSetCursorByOffset(buffer, offset);
9208
+ }
9209
+ editBufferGetCursorPosition(buffer) {
9210
+ const cursorBuffer = new ArrayBuffer(LogicalCursorStruct.size);
9211
+ this.opentui.symbols.editBufferGetCursorPosition(buffer, ptr3(cursorBuffer));
9212
+ return LogicalCursorStruct.unpack(cursorBuffer);
9213
+ }
9214
+ editBufferGetId(buffer) {
9215
+ return this.opentui.symbols.editBufferGetId(buffer);
9216
+ }
9217
+ editBufferGetTextBuffer(buffer) {
9218
+ const result = this.opentui.symbols.editBufferGetTextBuffer(buffer);
9219
+ if (!result) {
9220
+ throw new Error("Failed to get TextBuffer from EditBuffer");
7213
9221
  }
7214
- return new TextBuffer(this, bufferPtr);
9222
+ return result;
7215
9223
  }
7216
- destroyTextBuffer(buffer) {
7217
- this.opentui.symbols.destroyTextBuffer(buffer);
9224
+ editBufferDebugLogRope(buffer) {
9225
+ this.opentui.symbols.editBufferDebugLogRope(buffer);
7218
9226
  }
7219
- textBufferGetLength(buffer) {
7220
- return this.opentui.symbols.textBufferGetLength(buffer);
9227
+ editBufferUndo(buffer, maxLength) {
9228
+ const outBuffer = new Uint8Array(maxLength);
9229
+ const actualLen = this.opentui.symbols.editBufferUndo(buffer, ptr3(outBuffer), maxLength);
9230
+ const len = typeof actualLen === "bigint" ? Number(actualLen) : actualLen;
9231
+ if (len === 0)
9232
+ return null;
9233
+ return outBuffer.slice(0, len);
7221
9234
  }
7222
- textBufferReset(buffer) {
7223
- this.opentui.symbols.textBufferReset(buffer);
9235
+ editBufferRedo(buffer, maxLength) {
9236
+ const outBuffer = new Uint8Array(maxLength);
9237
+ const actualLen = this.opentui.symbols.editBufferRedo(buffer, ptr3(outBuffer), maxLength);
9238
+ const len = typeof actualLen === "bigint" ? Number(actualLen) : actualLen;
9239
+ if (len === 0)
9240
+ return null;
9241
+ return outBuffer.slice(0, len);
7224
9242
  }
7225
- textBufferSetSelection(buffer, start, end, bgColor, fgColor) {
7226
- const bg2 = bgColor ? bgColor.buffer : null;
7227
- const fg2 = fgColor ? fgColor.buffer : null;
7228
- this.opentui.symbols.textBufferSetSelection(buffer, start, end, bg2, fg2);
9243
+ editBufferCanUndo(buffer) {
9244
+ return this.opentui.symbols.editBufferCanUndo(buffer);
7229
9245
  }
7230
- textBufferResetSelection(buffer) {
7231
- this.opentui.symbols.textBufferResetSelection(buffer);
9246
+ editBufferCanRedo(buffer) {
9247
+ return this.opentui.symbols.editBufferCanRedo(buffer);
7232
9248
  }
7233
- textBufferSetDefaultFg(buffer, fg2) {
7234
- const fgPtr = fg2 ? fg2.buffer : null;
7235
- this.opentui.symbols.textBufferSetDefaultFg(buffer, fgPtr);
9249
+ editBufferClearHistory(buffer) {
9250
+ this.opentui.symbols.editBufferClearHistory(buffer);
7236
9251
  }
7237
- textBufferSetDefaultBg(buffer, bg2) {
7238
- const bgPtr = bg2 ? bg2.buffer : null;
7239
- this.opentui.symbols.textBufferSetDefaultBg(buffer, bgPtr);
9252
+ editBufferSetPlaceholder(buffer, text) {
9253
+ if (text === null) {
9254
+ this.opentui.symbols.editBufferSetPlaceholder(buffer, null, 0);
9255
+ } else {
9256
+ const textBytes = this.encoder.encode(text);
9257
+ this.opentui.symbols.editBufferSetPlaceholder(buffer, textBytes, textBytes.length);
9258
+ }
7240
9259
  }
7241
- textBufferSetDefaultAttributes(buffer, attributes) {
7242
- const attrValue = attributes === null ? null : new Uint8Array([attributes]);
7243
- this.opentui.symbols.textBufferSetDefaultAttributes(buffer, attrValue);
9260
+ editBufferSetPlaceholderColor(buffer, color) {
9261
+ this.opentui.symbols.editBufferSetPlaceholderColor(buffer, color.buffer);
7244
9262
  }
7245
- textBufferResetDefaults(buffer) {
7246
- this.opentui.symbols.textBufferResetDefaults(buffer);
9263
+ editBufferClear(buffer) {
9264
+ this.opentui.symbols.editBufferClear(buffer);
7247
9265
  }
7248
- textBufferWriteChunk(buffer, textBytes, fg2, bg2, attributes) {
7249
- const attrValue = attributes === null ? null : new Uint8Array([attributes]);
7250
- return this.opentui.symbols.textBufferWriteChunk(buffer, textBytes, textBytes.length, fg2 ? fg2.buffer : null, bg2 ? bg2.buffer : null, attrValue);
9266
+ editBufferGetNextWordBoundary(buffer) {
9267
+ const cursorBuffer = new ArrayBuffer(LogicalCursorStruct.size);
9268
+ this.opentui.symbols.editBufferGetNextWordBoundary(buffer, ptr3(cursorBuffer));
9269
+ return LogicalCursorStruct.unpack(cursorBuffer);
7251
9270
  }
7252
- textBufferFinalizeLineInfo(buffer) {
7253
- this.opentui.symbols.textBufferFinalizeLineInfo(buffer);
9271
+ editBufferGetPrevWordBoundary(buffer) {
9272
+ const cursorBuffer = new ArrayBuffer(LogicalCursorStruct.size);
9273
+ this.opentui.symbols.editBufferGetPrevWordBoundary(buffer, ptr3(cursorBuffer));
9274
+ return LogicalCursorStruct.unpack(cursorBuffer);
7254
9275
  }
7255
- textBufferGetLineCount(buffer) {
7256
- return this.opentui.symbols.textBufferGetLineCount(buffer);
9276
+ editBufferGetEOL(buffer) {
9277
+ const cursorBuffer = new ArrayBuffer(LogicalCursorStruct.size);
9278
+ this.opentui.symbols.editBufferGetEOL(buffer, ptr3(cursorBuffer));
9279
+ return LogicalCursorStruct.unpack(cursorBuffer);
9280
+ }
9281
+ editBufferOffsetToPosition(buffer, offset) {
9282
+ const cursorBuffer = new ArrayBuffer(LogicalCursorStruct.size);
9283
+ const success = this.opentui.symbols.editBufferOffsetToPosition(buffer, offset, ptr3(cursorBuffer));
9284
+ if (!success)
9285
+ return null;
9286
+ return LogicalCursorStruct.unpack(cursorBuffer);
9287
+ }
9288
+ editBufferPositionToOffset(buffer, row, col) {
9289
+ return this.opentui.symbols.editBufferPositionToOffset(buffer, row, col);
9290
+ }
9291
+ editBufferGetLineStartOffset(buffer, row) {
9292
+ return this.opentui.symbols.editBufferGetLineStartOffset(buffer, row);
9293
+ }
9294
+ editorViewSetSelection(view, start, end, bgColor, fgColor) {
9295
+ const bg2 = bgColor ? bgColor.buffer : null;
9296
+ const fg2 = fgColor ? fgColor.buffer : null;
9297
+ this.opentui.symbols.editorViewSetSelection(view, start, end, bg2, fg2);
7257
9298
  }
7258
- textBufferGetLineInfoDirect(buffer, lineStartsPtr, lineWidthsPtr) {
7259
- return this.opentui.symbols.textBufferGetLineInfoDirect(buffer, lineStartsPtr, lineWidthsPtr);
9299
+ editorViewResetSelection(view) {
9300
+ this.opentui.symbols.editorViewResetSelection(view);
7260
9301
  }
7261
- textBufferGetSelection(buffer) {
7262
- const packedInfo = this.textBufferGetSelectionInfo(buffer);
9302
+ editorViewGetSelection(view) {
9303
+ const packedInfo = this.opentui.symbols.editorViewGetSelection(view);
7263
9304
  if (packedInfo === 0xffff_ffff_ffff_ffffn) {
7264
9305
  return null;
7265
9306
  }
@@ -7267,92 +9308,67 @@ class FFIRenderLib {
7267
9308
  const end = Number(packedInfo & 0xffff_ffffn);
7268
9309
  return { start, end };
7269
9310
  }
7270
- textBufferGetSelectionInfo(buffer) {
7271
- return this.opentui.symbols.textBufferGetSelectionInfo(buffer);
7272
- }
7273
- textBufferGetSelectedText(buffer, outPtr, maxLen) {
7274
- const result = this.opentui.symbols.textBufferGetSelectedText(buffer, outPtr, maxLen);
7275
- return typeof result === "bigint" ? Number(result) : result;
9311
+ editorViewSetLocalSelection(view, anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
9312
+ const bg2 = bgColor ? bgColor.buffer : null;
9313
+ const fg2 = fgColor ? fgColor.buffer : null;
9314
+ return this.opentui.symbols.editorViewSetLocalSelection(view, anchorX, anchorY, focusX, focusY, bg2, fg2);
7276
9315
  }
7277
- textBufferGetPlainText(buffer, outPtr, maxLen) {
7278
- const result = this.opentui.symbols.textBufferGetPlainText(buffer, outPtr, maxLen);
7279
- return typeof result === "bigint" ? Number(result) : result;
9316
+ editorViewResetLocalSelection(view) {
9317
+ this.opentui.symbols.editorViewResetLocalSelection(view);
7280
9318
  }
7281
- getSelectedTextBytes(buffer, maxLength) {
9319
+ editorViewGetSelectedTextBytes(view, maxLength) {
7282
9320
  const outBuffer = new Uint8Array(maxLength);
7283
- const actualLen = this.textBufferGetSelectedText(buffer, ptr(outBuffer), maxLength);
7284
- if (actualLen === 0) {
9321
+ const actualLen = this.opentui.symbols.editorViewGetSelectedTextBytes(view, ptr3(outBuffer), maxLength);
9322
+ const len = typeof actualLen === "bigint" ? Number(actualLen) : actualLen;
9323
+ if (len === 0)
7285
9324
  return null;
7286
- }
7287
- return outBuffer.slice(0, actualLen);
9325
+ return outBuffer.slice(0, len);
7288
9326
  }
7289
- getPlainTextBytes(buffer, maxLength) {
9327
+ editorViewGetCursor(view) {
9328
+ const row = new Uint32Array(1);
9329
+ const col = new Uint32Array(1);
9330
+ this.opentui.symbols.editorViewGetCursor(view, ptr3(row), ptr3(col));
9331
+ return { row: row[0], col: col[0] };
9332
+ }
9333
+ editorViewGetText(view, maxLength) {
7290
9334
  const outBuffer = new Uint8Array(maxLength);
7291
- const actualLen = this.textBufferGetPlainText(buffer, ptr(outBuffer), maxLength);
7292
- if (actualLen === 0) {
9335
+ const actualLen = this.opentui.symbols.editorViewGetText(view, ptr3(outBuffer), maxLength);
9336
+ const len = typeof actualLen === "bigint" ? Number(actualLen) : actualLen;
9337
+ if (len === 0)
7293
9338
  return null;
7294
- }
7295
- return outBuffer.slice(0, actualLen);
7296
- }
7297
- textBufferSetLocalSelection(buffer, anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
7298
- const bg2 = bgColor ? bgColor.buffer : null;
7299
- const fg2 = fgColor ? fgColor.buffer : null;
7300
- return this.opentui.symbols.textBufferSetLocalSelection(buffer, anchorX, anchorY, focusX, focusY, bg2, fg2);
7301
- }
7302
- textBufferResetLocalSelection(buffer) {
7303
- this.opentui.symbols.textBufferResetLocalSelection(buffer);
7304
- }
7305
- textBufferInsertChunkGroup(buffer, index, textBytes, fg2, bg2, attributes) {
7306
- const fgPtr = fg2 ? fg2.buffer : null;
7307
- const bgPtr = bg2 ? bg2.buffer : null;
7308
- const attr = attributes ?? 255;
7309
- return this.opentui.symbols.textBufferInsertChunkGroup(buffer, index, textBytes, textBytes.length, fgPtr, bgPtr, attr);
9339
+ return outBuffer.slice(0, len);
7310
9340
  }
7311
- textBufferRemoveChunkGroup(buffer, index) {
7312
- return this.opentui.symbols.textBufferRemoveChunkGroup(buffer, index);
9341
+ editorViewGetVisualCursor(view) {
9342
+ const cursorBuffer = new ArrayBuffer(VisualCursorStruct.size);
9343
+ this.opentui.symbols.editorViewGetVisualCursor(view, ptr3(cursorBuffer));
9344
+ return VisualCursorStruct.unpack(cursorBuffer);
7313
9345
  }
7314
- textBufferReplaceChunkGroup(buffer, index, textBytes, fg2, bg2, attributes) {
7315
- const fgPtr = fg2 ? fg2.buffer : null;
7316
- const bgPtr = bg2 ? bg2.buffer : null;
7317
- const attr = attributes ?? 255;
7318
- return this.opentui.symbols.textBufferReplaceChunkGroup(buffer, index, textBytes, textBytes.length, fgPtr, bgPtr, attr);
9346
+ editorViewMoveUpVisual(view) {
9347
+ this.opentui.symbols.editorViewMoveUpVisual(view);
7319
9348
  }
7320
- textBufferGetChunkGroupCount(buffer) {
7321
- const result = this.opentui.symbols.textBufferGetChunkGroupCount(buffer);
7322
- return typeof result === "bigint" ? Number(result) : result;
9349
+ editorViewMoveDownVisual(view) {
9350
+ this.opentui.symbols.editorViewMoveDownVisual(view);
7323
9351
  }
7324
- textBufferSetWrapWidth(buffer, width) {
7325
- this.opentui.symbols.textBufferSetWrapWidth(buffer, width);
9352
+ editorViewDeleteSelectedText(view) {
9353
+ this.opentui.symbols.editorViewDeleteSelectedText(view);
7326
9354
  }
7327
- textBufferSetWrapMode(buffer, mode) {
7328
- const modeValue = mode === "char" ? 0 : 1;
7329
- this.opentui.symbols.textBufferSetWrapMode(buffer, modeValue);
9355
+ editorViewSetCursorByOffset(view, offset) {
9356
+ this.opentui.symbols.editorViewSetCursorByOffset(view, offset);
7330
9357
  }
7331
- getArenaAllocatedBytes() {
7332
- const result = this.opentui.symbols.getArenaAllocatedBytes();
7333
- return typeof result === "bigint" ? Number(result) : result;
9358
+ editorViewGetNextWordBoundary(view) {
9359
+ const cursorBuffer = new ArrayBuffer(VisualCursorStruct.size);
9360
+ this.opentui.symbols.editorViewGetNextWordBoundary(view, ptr3(cursorBuffer));
9361
+ return VisualCursorStruct.unpack(cursorBuffer);
7334
9362
  }
7335
- textBufferGetLineInfo(buffer) {
7336
- const lineCount = this.textBufferGetLineCount(buffer);
7337
- if (lineCount === 0) {
7338
- return { lineStarts: [], lineWidths: [], maxLineWidth: 0 };
7339
- }
7340
- const lineStarts = new Uint32Array(lineCount);
7341
- const lineWidths = new Uint32Array(lineCount);
7342
- const maxLineWidth = this.textBufferGetLineInfoDirect(buffer, ptr(lineStarts), ptr(lineWidths));
7343
- return {
7344
- maxLineWidth,
7345
- lineStarts: Array.from(lineStarts),
7346
- lineWidths: Array.from(lineWidths)
7347
- };
9363
+ editorViewGetPrevWordBoundary(view) {
9364
+ const cursorBuffer = new ArrayBuffer(VisualCursorStruct.size);
9365
+ this.opentui.symbols.editorViewGetPrevWordBoundary(view, ptr3(cursorBuffer));
9366
+ return VisualCursorStruct.unpack(cursorBuffer);
7348
9367
  }
7349
- bufferDrawTextBuffer(buffer, textBuffer, x, y, clipRect) {
7350
- const hasClipRect = clipRect !== undefined && clipRect !== null;
7351
- const clipX = clipRect?.x ?? 0;
7352
- const clipY = clipRect?.y ?? 0;
7353
- const clipWidth = clipRect?.width ?? 0;
7354
- const clipHeight = clipRect?.height ?? 0;
7355
- this.opentui.symbols.bufferDrawTextBuffer(buffer, textBuffer, x, y, clipX, clipY, clipWidth, clipHeight, hasClipRect);
9368
+ editorViewGetEOL(view) {
9369
+ const cursorBuffer = new ArrayBuffer(VisualCursorStruct.size);
9370
+ this.opentui.symbols.editorViewGetEOL(view, ptr3(cursorBuffer));
9371
+ return VisualCursorStruct.unpack(cursorBuffer);
7356
9372
  }
7357
9373
  bufferPushScissorRect(buffer, x, y, width, height) {
7358
9374
  this.opentui.symbols.bufferPushScissorRect(buffer, x, y, width, height);
@@ -7388,6 +9404,43 @@ class FFIRenderLib {
7388
9404
  const responseBytes = this.encoder.encode(response);
7389
9405
  this.opentui.symbols.processCapabilityResponse(renderer, responseBytes, responseBytes.length);
7390
9406
  }
9407
+ createSyntaxStyle() {
9408
+ const stylePtr = this.opentui.symbols.createSyntaxStyle();
9409
+ if (!stylePtr) {
9410
+ throw new Error("Failed to create SyntaxStyle");
9411
+ }
9412
+ return stylePtr;
9413
+ }
9414
+ destroySyntaxStyle(style) {
9415
+ this.opentui.symbols.destroySyntaxStyle(style);
9416
+ }
9417
+ syntaxStyleRegister(style, name, fg2, bg2, attributes) {
9418
+ const nameBytes = this.encoder.encode(name);
9419
+ const fgPtr = fg2 ? fg2.buffer : null;
9420
+ const bgPtr = bg2 ? bg2.buffer : null;
9421
+ return this.opentui.symbols.syntaxStyleRegister(style, nameBytes, nameBytes.length, fgPtr, bgPtr, attributes);
9422
+ }
9423
+ syntaxStyleResolveByName(style, name) {
9424
+ const nameBytes = this.encoder.encode(name);
9425
+ const id = this.opentui.symbols.syntaxStyleResolveByName(style, nameBytes, nameBytes.length);
9426
+ return id === 0 ? null : id;
9427
+ }
9428
+ syntaxStyleGetStyleCount(style) {
9429
+ const result = this.opentui.symbols.syntaxStyleGetStyleCount(style);
9430
+ return typeof result === "bigint" ? Number(result) : result;
9431
+ }
9432
+ onNativeEvent(name, handler) {
9433
+ this._nativeEvents.on(name, handler);
9434
+ }
9435
+ onceNativeEvent(name, handler) {
9436
+ this._nativeEvents.once(name, handler);
9437
+ }
9438
+ offNativeEvent(name, handler) {
9439
+ this._nativeEvents.off(name, handler);
9440
+ }
9441
+ onAnyNativeEvent(handler) {
9442
+ this._anyEventHandlers.push(handler);
9443
+ }
7391
9444
  }
7392
9445
  var opentuiLibPath;
7393
9446
  var opentuiLib;
@@ -7416,11 +9469,15 @@ class TextBuffer {
7416
9469
  lib;
7417
9470
  bufferPtr;
7418
9471
  _length = 0;
9472
+ _byteSize = 0;
7419
9473
  _lineInfo;
7420
9474
  _destroyed = false;
7421
- constructor(lib, ptr2) {
9475
+ _syntaxStyle;
9476
+ _textBytes;
9477
+ _memId;
9478
+ constructor(lib, ptr4) {
7422
9479
  this.lib = lib;
7423
- this.bufferPtr = ptr2;
9480
+ this.bufferPtr = ptr4;
7424
9481
  }
7425
9482
  static create(widthMethod) {
7426
9483
  const lib = resolveRenderLib();
@@ -7430,17 +9487,42 @@ class TextBuffer {
7430
9487
  if (this._destroyed)
7431
9488
  throw new Error("TextBuffer is destroyed");
7432
9489
  }
7433
- setStyledText(text) {
9490
+ setText(text) {
7434
9491
  this.guard();
7435
- this.lib.textBufferReset(this.bufferPtr);
7436
- this._length = 0;
9492
+ this._textBytes = this.lib.encoder.encode(text);
9493
+ if (this._memId === undefined) {
9494
+ this._memId = this.lib.textBufferRegisterMemBuffer(this.bufferPtr, this._textBytes, false);
9495
+ } else {
9496
+ this.lib.textBufferReplaceMemBuffer(this.bufferPtr, this._memId, this._textBytes, false);
9497
+ }
9498
+ this.lib.textBufferSetTextFromMem(this.bufferPtr, this._memId);
9499
+ this._length = this.lib.textBufferGetLength(this.bufferPtr);
9500
+ this._byteSize = this.lib.textBufferGetByteSize(this.bufferPtr);
7437
9501
  this._lineInfo = undefined;
7438
- for (const chunk of text.chunks) {
7439
- const textBytes = this.lib.encoder.encode(chunk.text);
7440
- this.lib.textBufferWriteChunk(this.bufferPtr, textBytes, chunk.fg || null, chunk.bg || null, chunk.attributes ?? null);
9502
+ }
9503
+ loadFile(path4) {
9504
+ this.guard();
9505
+ const success = this.lib.textBufferLoadFile(this.bufferPtr, path4);
9506
+ if (!success) {
9507
+ throw new Error(`Failed to load file: ${path4}`);
7441
9508
  }
7442
- this.lib.textBufferFinalizeLineInfo(this.bufferPtr);
7443
9509
  this._length = this.lib.textBufferGetLength(this.bufferPtr);
9510
+ this._byteSize = this.lib.textBufferGetByteSize(this.bufferPtr);
9511
+ this._lineInfo = undefined;
9512
+ this._textBytes = undefined;
9513
+ }
9514
+ setStyledText(text) {
9515
+ this.guard();
9516
+ const chunks = text.chunks.map((chunk) => ({
9517
+ text: chunk.text,
9518
+ fg: chunk.fg || null,
9519
+ bg: chunk.bg || null,
9520
+ attributes: chunk.attributes ?? 0
9521
+ }));
9522
+ this.lib.textBufferSetStyledText(this.bufferPtr, chunks);
9523
+ this._length = this.lib.textBufferGetLength(this.bufferPtr);
9524
+ this._byteSize = this.lib.textBufferGetByteSize(this.bufferPtr);
9525
+ this._lineInfo = undefined;
7444
9526
  }
7445
9527
  setDefaultFg(fg2) {
7446
9528
  this.guard();
@@ -7462,97 +9544,72 @@ class TextBuffer {
7462
9544
  this.guard();
7463
9545
  return this._length;
7464
9546
  }
7465
- get ptr() {
9547
+ get byteSize() {
7466
9548
  this.guard();
7467
- return this.bufferPtr;
9549
+ return this._byteSize;
7468
9550
  }
7469
- getSelectedText() {
9551
+ get ptr() {
7470
9552
  this.guard();
7471
- if (this._length === 0)
7472
- return "";
7473
- const selectedBytes = this.lib.getSelectedTextBytes(this.bufferPtr, this.length * 4);
7474
- if (!selectedBytes)
7475
- return "";
7476
- return this.lib.decoder.decode(selectedBytes);
9553
+ return this.bufferPtr;
7477
9554
  }
7478
9555
  getPlainText() {
7479
9556
  this.guard();
7480
- if (this._length === 0)
9557
+ if (this._byteSize === 0)
7481
9558
  return "";
7482
- const plainBytes = this.lib.getPlainTextBytes(this.bufferPtr, this.length * 4);
9559
+ const plainBytes = this.lib.getPlainTextBytes(this.bufferPtr, this._byteSize);
7483
9560
  if (!plainBytes)
7484
9561
  return "";
7485
9562
  return this.lib.decoder.decode(plainBytes);
7486
9563
  }
7487
- get lineInfo() {
7488
- this.guard();
7489
- if (!this._lineInfo) {
7490
- this._lineInfo = this.lib.textBufferGetLineInfo(this.bufferPtr);
7491
- }
7492
- return this._lineInfo;
7493
- }
7494
- setSelection(start, end, bgColor, fgColor) {
7495
- this.guard();
7496
- this.lib.textBufferSetSelection(this.bufferPtr, start, end, bgColor || null, fgColor || null);
7497
- }
7498
- resetSelection() {
7499
- this.guard();
7500
- this.lib.textBufferResetSelection(this.bufferPtr);
7501
- }
7502
- setLocalSelection(anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
7503
- this.guard();
7504
- return this.lib.textBufferSetLocalSelection(this.bufferPtr, anchorX, anchorY, focusX, focusY, bgColor || null, fgColor || null);
7505
- }
7506
- resetLocalSelection() {
7507
- this.guard();
7508
- this.lib.textBufferResetLocalSelection(this.bufferPtr);
7509
- }
7510
- getSelection() {
9564
+ addHighlightByCharRange(highlight) {
7511
9565
  this.guard();
7512
- return this.lib.textBufferGetSelection(this.bufferPtr);
9566
+ this.lib.textBufferAddHighlightByCharRange(this.bufferPtr, highlight);
7513
9567
  }
7514
- hasSelection() {
9568
+ addHighlight(lineIdx, highlight) {
7515
9569
  this.guard();
7516
- return this.getSelection() !== null;
9570
+ this.lib.textBufferAddHighlight(this.bufferPtr, lineIdx, highlight);
7517
9571
  }
7518
- insertChunkGroup(index, text, fg2, bg2, attributes) {
9572
+ removeHighlightsByRef(hlRef) {
7519
9573
  this.guard();
7520
- const textBytes = this.lib.encoder.encode(text);
7521
- this.insertEncodedChunkGroup(index, textBytes, fg2, bg2, attributes);
9574
+ this.lib.textBufferRemoveHighlightsByRef(this.bufferPtr, hlRef);
7522
9575
  }
7523
- insertEncodedChunkGroup(index, textBytes, fg2, bg2, attributes) {
9576
+ clearLineHighlights(lineIdx) {
7524
9577
  this.guard();
7525
- this._length = this.lib.textBufferInsertChunkGroup(this.bufferPtr, index, textBytes, fg2 || null, bg2 || null, attributes ?? null);
7526
- this._lineInfo = undefined;
9578
+ this.lib.textBufferClearLineHighlights(this.bufferPtr, lineIdx);
7527
9579
  }
7528
- removeChunkGroup(index) {
9580
+ clearAllHighlights() {
7529
9581
  this.guard();
7530
- this._length = this.lib.textBufferRemoveChunkGroup(this.bufferPtr, index);
7531
- this._lineInfo = undefined;
9582
+ this.lib.textBufferClearAllHighlights(this.bufferPtr);
7532
9583
  }
7533
- replaceChunkGroup(index, text, fg2, bg2, attributes) {
9584
+ getLineHighlights(lineIdx) {
7534
9585
  this.guard();
7535
- const textBytes = this.lib.encoder.encode(text);
7536
- this.replaceEncodedChunkGroup(index, textBytes, fg2, bg2, attributes);
9586
+ return this.lib.textBufferGetLineHighlights(this.bufferPtr, lineIdx);
7537
9587
  }
7538
- replaceEncodedChunkGroup(index, textBytes, fg2, bg2, attributes) {
9588
+ setSyntaxStyle(style) {
7539
9589
  this.guard();
7540
- this._length = this.lib.textBufferReplaceChunkGroup(this.bufferPtr, index, textBytes, fg2 || null, bg2 || null, attributes ?? null);
7541
- this._lineInfo = undefined;
9590
+ this._syntaxStyle = style ?? undefined;
9591
+ this.lib.textBufferSetSyntaxStyle(this.bufferPtr, style?.ptr ?? null);
7542
9592
  }
7543
- get chunkGroupCount() {
9593
+ getSyntaxStyle() {
7544
9594
  this.guard();
7545
- return this.lib.textBufferGetChunkGroupCount(this.bufferPtr);
9595
+ return this._syntaxStyle ?? null;
7546
9596
  }
7547
- setWrapWidth(width) {
9597
+ clear() {
7548
9598
  this.guard();
7549
- this.lib.textBufferSetWrapWidth(this.bufferPtr, width ?? 0);
9599
+ this.lib.textBufferClear(this.bufferPtr);
9600
+ this._length = 0;
9601
+ this._byteSize = 0;
7550
9602
  this._lineInfo = undefined;
9603
+ this._textBytes = undefined;
7551
9604
  }
7552
- setWrapMode(mode) {
9605
+ reset() {
7553
9606
  this.guard();
7554
- this.lib.textBufferSetWrapMode(this.bufferPtr, mode);
9607
+ this.lib.textBufferReset(this.bufferPtr);
9608
+ this._length = 0;
9609
+ this._byteSize = 0;
7555
9610
  this._lineInfo = undefined;
9611
+ this._textBytes = undefined;
9612
+ this._memId = undefined;
7556
9613
  }
7557
9614
  destroy() {
7558
9615
  if (this._destroyed)
@@ -7563,7 +9620,7 @@ class TextBuffer {
7563
9620
  }
7564
9621
 
7565
9622
  // src/Renderable.ts
7566
- import { EventEmitter as EventEmitter4 } from "events";
9623
+ import { EventEmitter as EventEmitter5 } from "events";
7567
9624
 
7568
9625
  // src/lib/renderable.validations.ts
7569
9626
  function validateOptions(id, options) {
@@ -7656,7 +9713,7 @@ function isRenderable(obj) {
7656
9713
  return !!obj?.[BrandedRenderable];
7657
9714
  }
7658
9715
 
7659
- class BaseRenderable extends EventEmitter4 {
9716
+ class BaseRenderable extends EventEmitter5 {
7660
9717
  [BrandedRenderable] = true;
7661
9718
  static renderableNumber = 1;
7662
9719
  _id;
@@ -7728,6 +9785,7 @@ class Renderable extends BaseRenderable {
7728
9785
  _positionType = "relative";
7729
9786
  _overflow = "visible";
7730
9787
  _position = {};
9788
+ _flexShrink = 1;
7731
9789
  renderableMapById = new Map;
7732
9790
  _childrenInLayoutOrder = [];
7733
9791
  _childrenInZIndexOrder = [];
@@ -7974,6 +10032,10 @@ class Renderable extends BaseRenderable {
7974
10032
  if (isDimensionType(value)) {
7975
10033
  this._width = value;
7976
10034
  this.yogaNode.setWidth(value);
10035
+ if (typeof value === "number" && this._flexShrink === 1) {
10036
+ this._flexShrink = 0;
10037
+ this.yogaNode.setFlexShrink(0);
10038
+ }
7977
10039
  this.requestRender();
7978
10040
  }
7979
10041
  }
@@ -7984,6 +10046,10 @@ class Renderable extends BaseRenderable {
7984
10046
  if (isDimensionType(value)) {
7985
10047
  this._height = value;
7986
10048
  this.yogaNode.setHeight(value);
10049
+ if (typeof value === "number" && this._flexShrink === 1) {
10050
+ this._flexShrink = 0;
10051
+ this.yogaNode.setFlexShrink(0);
10052
+ }
7987
10053
  this.requestRender();
7988
10054
  }
7989
10055
  }
@@ -8038,9 +10104,13 @@ class Renderable extends BaseRenderable {
8038
10104
  node.setFlexGrow(0);
8039
10105
  }
8040
10106
  if (options.flexShrink !== undefined) {
10107
+ this._flexShrink = options.flexShrink;
8041
10108
  node.setFlexShrink(options.flexShrink);
8042
10109
  } else {
8043
- node.setFlexShrink(1);
10110
+ const hasExplicitWidth = typeof options.width === "number";
10111
+ const hasExplicitHeight = typeof options.height === "number";
10112
+ this._flexShrink = hasExplicitWidth || hasExplicitHeight ? 0 : 1;
10113
+ node.setFlexShrink(this._flexShrink);
8044
10114
  }
8045
10115
  if (options.flexDirection !== undefined) {
8046
10116
  node.setFlexDirection(parseFlexDirection(options.flexDirection));
@@ -8185,11 +10255,17 @@ class Renderable extends BaseRenderable {
8185
10255
  this.requestRender();
8186
10256
  }
8187
10257
  set flexGrow(grow) {
8188
- this.yogaNode.setFlexGrow(grow);
10258
+ if (grow == null) {
10259
+ this.yogaNode.setFlexGrow(0);
10260
+ } else {
10261
+ this.yogaNode.setFlexGrow(grow);
10262
+ }
8189
10263
  this.requestRender();
8190
10264
  }
8191
10265
  set flexShrink(shrink) {
8192
- this.yogaNode.setFlexShrink(shrink);
10266
+ const value = shrink == null ? 1 : shrink;
10267
+ this._flexShrink = value;
10268
+ this.yogaNode.setFlexShrink(value);
8193
10269
  this.requestRender();
8194
10270
  }
8195
10271
  set flexDirection(direction) {
@@ -8390,34 +10466,31 @@ class Renderable extends BaseRenderable {
8390
10466
  }
8391
10467
  return -1;
8392
10468
  }
8393
- if (this.renderableMapById.has(renderable.id)) {
8394
- console.warn(`A renderable with id ${renderable.id} already exists in ${this.id}, removing it`);
8395
- this.remove(renderable.id);
10469
+ const anchorRenderable = index !== undefined ? this._childrenInLayoutOrder[index] : undefined;
10470
+ if (anchorRenderable) {
10471
+ return this.insertBefore(renderable, anchorRenderable);
8396
10472
  }
8397
- this.replaceParent(renderable);
8398
- const childLayoutNode = renderable.getLayoutNode();
8399
- let insertedIndex;
8400
- if (index !== undefined) {
8401
- insertedIndex = Math.max(0, Math.min(index, this._childrenInLayoutOrder.length));
8402
- this._childrenInLayoutOrder.splice(index, 0, renderable);
8403
- this._forceLayoutUpdateFor = this._childrenInLayoutOrder.slice(index);
8404
- this.yogaNode.insertChild(childLayoutNode, insertedIndex);
10473
+ if (renderable.parent === this) {
10474
+ this.yogaNode.removeChild(renderable.getLayoutNode());
10475
+ this._childrenInLayoutOrder.splice(this._childrenInLayoutOrder.indexOf(renderable), 1);
8405
10476
  } else {
8406
- insertedIndex = this._childrenInLayoutOrder.length;
8407
- this._childrenInLayoutOrder.push(renderable);
8408
- this.yogaNode.insertChild(childLayoutNode, insertedIndex);
8409
- }
8410
- this.needsZIndexSort = true;
8411
- this.childrenPrimarySortDirty = true;
8412
- this.renderableMapById.set(renderable.id, renderable);
8413
- this._childrenInZIndexOrder.push(renderable);
8414
- if (typeof renderable.onLifecyclePass === "function") {
8415
- this._ctx.registerLifecyclePass(renderable);
10477
+ this.replaceParent(renderable);
10478
+ this.needsZIndexSort = true;
10479
+ this.renderableMapById.set(renderable.id, renderable);
10480
+ this._childrenInZIndexOrder.push(renderable);
10481
+ if (typeof renderable.onLifecyclePass === "function") {
10482
+ this._ctx.registerLifecyclePass(renderable);
10483
+ }
10484
+ if (renderable._liveCount > 0) {
10485
+ this.propagateLiveCount(renderable._liveCount);
10486
+ }
8416
10487
  }
8417
10488
  this._newChildren.push(renderable);
8418
- if (renderable._liveCount > 0) {
8419
- this.propagateLiveCount(renderable._liveCount);
8420
- }
10489
+ const childLayoutNode = renderable.getLayoutNode();
10490
+ const insertedIndex = this._childrenInLayoutOrder.length;
10491
+ this._childrenInLayoutOrder.push(renderable);
10492
+ this.yogaNode.insertChild(childLayoutNode, insertedIndex);
10493
+ this.childrenPrimarySortDirty = true;
8421
10494
  this.requestRender();
8422
10495
  return insertedIndex;
8423
10496
  }
@@ -8472,6 +10545,7 @@ class Renderable extends BaseRenderable {
8472
10545
  this._forceLayoutUpdateFor = this._childrenInLayoutOrder.slice(insertedIndex);
8473
10546
  this._childrenInLayoutOrder.splice(insertedIndex, 0, renderable);
8474
10547
  this.yogaNode.insertChild(renderable.getLayoutNode(), insertedIndex);
10548
+ this.requestRender();
8475
10549
  return insertedIndex;
8476
10550
  }
8477
10551
  getRenderable(id) {
@@ -8960,7 +11034,7 @@ function delegate(mapping, vnode) {
8960
11034
  }
8961
11035
 
8962
11036
  // src/console.ts
8963
- import { EventEmitter as EventEmitter6 } from "events";
11037
+ import { EventEmitter as EventEmitter7 } from "events";
8964
11038
  import { Console } from "console";
8965
11039
  import fs from "fs";
8966
11040
  import path4 from "path";
@@ -8968,9 +11042,9 @@ import util2 from "util";
8968
11042
 
8969
11043
  // src/lib/output.capture.ts
8970
11044
  import { Writable } from "stream";
8971
- import { EventEmitter as EventEmitter5 } from "events";
11045
+ import { EventEmitter as EventEmitter6 } from "events";
8972
11046
 
8973
- class Capture extends EventEmitter5 {
11047
+ class Capture extends EventEmitter6 {
8974
11048
  output = [];
8975
11049
  constructor() {
8976
11050
  super();
@@ -9046,11 +11120,12 @@ registerEnvVar({
9046
11120
  default: false
9047
11121
  });
9048
11122
 
9049
- class TerminalConsoleCache extends EventEmitter6 {
11123
+ class TerminalConsoleCache extends EventEmitter7 {
9050
11124
  _cachedLogs = [];
9051
11125
  MAX_CACHE_SIZE = 1000;
9052
11126
  _collectCallerInfo = false;
9053
11127
  _cachingEnabled = true;
11128
+ _originalConsole = null;
9054
11129
  get cachedLogs() {
9055
11130
  return this._cachedLogs;
9056
11131
  }
@@ -9058,6 +11133,9 @@ class TerminalConsoleCache extends EventEmitter6 {
9058
11133
  super();
9059
11134
  }
9060
11135
  activate() {
11136
+ if (!this._originalConsole) {
11137
+ this._originalConsole = global.console;
11138
+ }
9061
11139
  this.setupConsoleCapture();
9062
11140
  this.overrideConsoleMethods();
9063
11141
  }
@@ -9107,8 +11185,9 @@ class TerminalConsoleCache extends EventEmitter6 {
9107
11185
  this.restoreOriginalConsole();
9108
11186
  }
9109
11187
  restoreOriginalConsole() {
9110
- const originalNodeConsole = __require("console");
9111
- global.console = originalNodeConsole;
11188
+ if (this._originalConsole) {
11189
+ global.console = this._originalConsole;
11190
+ }
9112
11191
  this.setupConsoleCapture();
9113
11192
  }
9114
11193
  addLogEntry(level, ...args) {
@@ -9167,7 +11246,7 @@ var DEFAULT_CONSOLE_OPTIONS = {
9167
11246
  };
9168
11247
  var INDENT_WIDTH = 2;
9169
11248
 
9170
- class TerminalConsole extends EventEmitter6 {
11249
+ class TerminalConsole extends EventEmitter7 {
9171
11250
  isVisible = false;
9172
11251
  isFocused = false;
9173
11252
  renderer;
@@ -9627,7 +11706,7 @@ class TerminalConsole extends EventEmitter6 {
9627
11706
  }
9628
11707
 
9629
11708
  // src/renderer.ts
9630
- import { EventEmitter as EventEmitter7 } from "events";
11709
+ import { EventEmitter as EventEmitter8 } from "events";
9631
11710
 
9632
11711
  // src/lib/objects-in-viewport.ts
9633
11712
  function getObjectsInViewport(viewport, objects, direction = "column", padding = 10, minTriggerSize = 16) {
@@ -9663,24 +11742,39 @@ function getObjectsInViewport(viewport, objects, direction = "column", padding =
9663
11742
  }
9664
11743
  const visibleChildren = [];
9665
11744
  if (candidate === -1) {
9666
- return visibleChildren;
11745
+ candidate = lo > 0 ? lo - 1 : 0;
9667
11746
  }
11747
+ const maxLookBehind = 50;
9668
11748
  let left = candidate;
11749
+ let gapCount = 0;
9669
11750
  while (left - 1 >= 0) {
9670
11751
  const prev = children[left - 1];
9671
- if ((isRow ? prev.x + prev.width : prev.y + prev.height) < vpStart)
9672
- break;
11752
+ const prevEnd = isRow ? prev.x + prev.width : prev.y + prev.height;
11753
+ if (prevEnd <= vpStart) {
11754
+ gapCount++;
11755
+ if (gapCount >= maxLookBehind) {
11756
+ break;
11757
+ }
11758
+ } else {
11759
+ gapCount = 0;
11760
+ }
9673
11761
  left--;
9674
11762
  }
9675
11763
  let right = candidate + 1;
9676
11764
  while (right < totalChildren) {
9677
11765
  const next = children[right];
9678
- if ((isRow ? next.x : next.y) > vpEnd)
11766
+ if ((isRow ? next.x : next.y) >= vpEnd)
9679
11767
  break;
9680
11768
  right++;
9681
11769
  }
9682
11770
  for (let i = left;i < right; i++) {
9683
11771
  const child = children[i];
11772
+ const start = isRow ? child.x : child.y;
11773
+ const end = isRow ? child.x + child.width : child.y + child.height;
11774
+ if (end <= vpStart)
11775
+ continue;
11776
+ if (start >= vpEnd)
11777
+ break;
9684
11778
  if (isRow) {
9685
11779
  const childBottom = child.y + child.height;
9686
11780
  if (childBottom < viewportTop)
@@ -9838,7 +11932,7 @@ var RendererControlState;
9838
11932
  RendererControlState2["EXPLICIT_STOPPED"] = "explicit_stopped";
9839
11933
  })(RendererControlState ||= {});
9840
11934
 
9841
- class CliRenderer extends EventEmitter7 {
11935
+ class CliRenderer extends EventEmitter8 {
9842
11936
  static animationFrameId = 0;
9843
11937
  lib;
9844
11938
  rendererPtr;
@@ -9866,7 +11960,7 @@ class CliRenderer extends EventEmitter7 {
9866
11960
  frameTimes = [];
9867
11961
  maxStatSamples = 300;
9868
11962
  postProcessFns = [];
9869
- backgroundColor = RGBA.fromHex("#000000");
11963
+ backgroundColor = RGBA.fromInts(0, 0, 0, 0);
9870
11964
  waitingForPixelResolution = false;
9871
11965
  rendering = false;
9872
11966
  renderingNative = false;
@@ -9930,30 +12024,10 @@ class CliRenderer extends EventEmitter7 {
9930
12024
  _currentFocusedRenderable = null;
9931
12025
  lifecyclePasses = new Set;
9932
12026
  handleError = ((error) => {
9933
- this.stop();
9934
- this.destroy();
9935
- new Promise((resolve4) => {
9936
- setTimeout(() => {
9937
- resolve4(true);
9938
- }, 100);
9939
- }).then(() => {
9940
- this.realStdoutWrite.call(this.stdout, `
9941
- `.repeat(this._terminalHeight));
9942
- this.realStdoutWrite.call(this.stdout, `
9943
- === FATAL ERROR OCCURRED ===
9944
- `);
9945
- this.dumpOutputCache();
9946
- this.realStdoutWrite.call(this.stdout, `
9947
- Error details:
9948
- `);
9949
- this.realStdoutWrite.call(this.stdout, error.message || "unknown error");
9950
- this.realStdoutWrite.call(this.stdout, `
9951
- `);
9952
- this.realStdoutWrite.call(this.stdout, error.stack || error.toString());
9953
- this.realStdoutWrite.call(this.stdout, `
9954
- `);
9955
- process.exit(1);
9956
- });
12027
+ console.error(error);
12028
+ if (true) {
12029
+ this.console.show();
12030
+ }
9957
12031
  }).bind(this);
9958
12032
  dumpOutputCache(optionalMessage = "") {
9959
12033
  const cachedLogs = this.console.getCachedLogs();
@@ -9978,8 +12052,10 @@ Captured output:
9978
12052
  exitHandler = (() => {
9979
12053
  this.destroy();
9980
12054
  if (env.OTUI_DUMP_CAPTURES) {
9981
- this.dumpOutputCache(`=== CAPTURED OUTPUT ===
12055
+ Bun.sleep(100).then(() => {
12056
+ this.dumpOutputCache(`=== CAPTURED OUTPUT ===
9982
12057
  `);
12058
+ });
9983
12059
  }
9984
12060
  }).bind(this);
9985
12061
  warningHandler = ((warning) => {
@@ -10088,7 +12164,7 @@ Captured output:
10088
12164
  }
10089
12165
  get widthMethod() {
10090
12166
  const caps = this.capabilities;
10091
- return caps?.unicode === "unicode" ? "unicode" : "wcwidth";
12167
+ return caps?.unicode === "wcwidth" ? "wcwidth" : "unicode";
10092
12168
  }
10093
12169
  writeOut(chunk, encoding, callback) {
10094
12170
  return this.realStdoutWrite.call(this.stdout, chunk, encoding, callback);
@@ -10496,7 +12572,7 @@ Captured output:
10496
12572
  this.renderOffset = height - this._splitHeight;
10497
12573
  this.width = width;
10498
12574
  this.height = this._splitHeight;
10499
- this.currentRenderBuffer.clear(RGBA.fromHex("#000000"));
12575
+ this.currentRenderBuffer.clear(this.backgroundColor);
10500
12576
  this.lib.setRenderOffset(this.rendererPtr, this.renderOffset);
10501
12577
  } else {
10502
12578
  this.width = width;
@@ -10854,10 +12930,12 @@ Captured output:
10854
12930
  }
10855
12931
  this.selectionContainers = [];
10856
12932
  }
10857
- startSelection(startRenderable, x, y) {
12933
+ startSelection(renderable, x, y) {
12934
+ if (!renderable.selectable)
12935
+ return;
10858
12936
  this.clearSelection();
10859
- this.selectionContainers.push(startRenderable.parent || this.root);
10860
- this.currentSelection = new Selection(startRenderable, { x, y }, { x, y });
12937
+ this.selectionContainers.push(renderable.parent || this.root);
12938
+ this.currentSelection = new Selection(renderable, { x, y }, { x, y });
10861
12939
  this.notifySelectablesOfSelectionChange();
10862
12940
  }
10863
12941
  updateSelection(currentRenderable, x, y) {
@@ -10937,7 +13015,7 @@ Captured output:
10937
13015
  }
10938
13016
  }
10939
13017
 
10940
- export { __toESM, __commonJS, __export, __require, Edge, Gutter, exports_src, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, nonAlphanumericKeys, parseKeypress, ANSI, 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, convertThemeToStyles, SyntaxStyle, 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, 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 };
13018
+ export { __toESM, __commonJS, __export, __require, Edge, Gutter, exports_src, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, nonAlphanumericKeys, parseKeypress, ANSI, 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 };
10941
13019
 
10942
- //# debugId=A4D3177124AD469F64756E2164756E21
10943
- //# sourceMappingURL=index-kqk5knmb.js.map
13020
+ //# debugId=EBFFB34D1CBF336764756E2164756E21
13021
+ //# sourceMappingURL=index-g5xctwrm.js.map