@opentui/core 0.0.0-20251010-2eed09fd → 0.0.0-20251026-8b7fde6b

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 +77 -0
  7. package/editor-view.d.ts +55 -0
  8. package/{index-kqk5knmb.js → index-hgxcxzxa.js} +2557 -469
  9. package/index-hgxcxzxa.js.map +55 -0
  10. package/index.d.ts +4 -0
  11. package/index.js +3527 -2025
  12. package/index.js.map +19 -12
  13. package/lib/extmarks-history.d.ts +17 -0
  14. package/lib/extmarks.d.ts +80 -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 +6 -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 +147 -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,719 @@ function getTreeSitterClient() {
6253
6216
  return client2;
6254
6217
  });
6255
6218
  }
6219
+
6220
+ // src/lib/extmarks.ts
6221
+ import { EventEmitter as EventEmitter4 } from "events";
6222
+
6223
+ // src/lib/extmarks-history.ts
6224
+ class ExtmarksHistory {
6225
+ undoStack = [];
6226
+ redoStack = [];
6227
+ saveSnapshot(extmarks, nextId) {
6228
+ const snapshot = {
6229
+ extmarks: new Map(Array.from(extmarks.entries()).map(([id, extmark]) => [id, { ...extmark }])),
6230
+ nextId
6231
+ };
6232
+ this.undoStack.push(snapshot);
6233
+ this.redoStack = [];
6234
+ }
6235
+ undo() {
6236
+ if (this.undoStack.length === 0)
6237
+ return null;
6238
+ return this.undoStack.pop();
6239
+ }
6240
+ redo() {
6241
+ if (this.redoStack.length === 0)
6242
+ return null;
6243
+ return this.redoStack.pop();
6244
+ }
6245
+ pushRedo(snapshot) {
6246
+ this.redoStack.push(snapshot);
6247
+ }
6248
+ pushUndo(snapshot) {
6249
+ this.undoStack.push(snapshot);
6250
+ }
6251
+ clear() {
6252
+ this.undoStack = [];
6253
+ this.redoStack = [];
6254
+ }
6255
+ canUndo() {
6256
+ return this.undoStack.length > 0;
6257
+ }
6258
+ canRedo() {
6259
+ return this.redoStack.length > 0;
6260
+ }
6261
+ }
6262
+
6263
+ // src/lib/extmarks.ts
6264
+ class ExtmarksController extends EventEmitter4 {
6265
+ editBuffer;
6266
+ editorView;
6267
+ extmarks = new Map;
6268
+ nextId = 1;
6269
+ destroyed = false;
6270
+ history = new ExtmarksHistory;
6271
+ originalMoveCursorLeft;
6272
+ originalMoveCursorRight;
6273
+ originalSetCursorByOffset;
6274
+ originalMoveUpVisual;
6275
+ originalMoveDownVisual;
6276
+ originalDeleteCharBackward;
6277
+ originalDeleteChar;
6278
+ originalInsertText;
6279
+ originalInsertChar;
6280
+ originalDeleteRange;
6281
+ originalSetText;
6282
+ originalClear;
6283
+ originalNewLine;
6284
+ originalDeleteLine;
6285
+ originalEditorViewDeleteSelectedText;
6286
+ originalUndo;
6287
+ originalRedo;
6288
+ constructor(editBuffer, editorView) {
6289
+ super();
6290
+ this.editBuffer = editBuffer;
6291
+ this.editorView = editorView;
6292
+ this.originalMoveCursorLeft = editBuffer.moveCursorLeft.bind(editBuffer);
6293
+ this.originalMoveCursorRight = editBuffer.moveCursorRight.bind(editBuffer);
6294
+ this.originalSetCursorByOffset = editBuffer.setCursorByOffset.bind(editBuffer);
6295
+ this.originalMoveUpVisual = editorView.moveUpVisual.bind(editorView);
6296
+ this.originalMoveDownVisual = editorView.moveDownVisual.bind(editorView);
6297
+ this.originalDeleteCharBackward = editBuffer.deleteCharBackward.bind(editBuffer);
6298
+ this.originalDeleteChar = editBuffer.deleteChar.bind(editBuffer);
6299
+ this.originalInsertText = editBuffer.insertText.bind(editBuffer);
6300
+ this.originalInsertChar = editBuffer.insertChar.bind(editBuffer);
6301
+ this.originalDeleteRange = editBuffer.deleteRange.bind(editBuffer);
6302
+ this.originalSetText = editBuffer.setText.bind(editBuffer);
6303
+ this.originalClear = editBuffer.clear.bind(editBuffer);
6304
+ this.originalNewLine = editBuffer.newLine.bind(editBuffer);
6305
+ this.originalDeleteLine = editBuffer.deleteLine.bind(editBuffer);
6306
+ this.originalEditorViewDeleteSelectedText = editorView.deleteSelectedText.bind(editorView);
6307
+ this.originalUndo = editBuffer.undo.bind(editBuffer);
6308
+ this.originalRedo = editBuffer.redo.bind(editBuffer);
6309
+ this.wrapCursorMovement();
6310
+ this.wrapDeletion();
6311
+ this.wrapInsertion();
6312
+ this.wrapEditorViewDeleteSelectedText();
6313
+ this.wrapUndoRedo();
6314
+ this.setupContentChangeListener();
6315
+ }
6316
+ wrapCursorMovement() {
6317
+ this.editBuffer.moveCursorLeft = () => {
6318
+ if (this.destroyed) {
6319
+ this.originalMoveCursorLeft();
6320
+ return;
6321
+ }
6322
+ const currentOffset = this.editorView.getVisualCursor().offset;
6323
+ const hasSelection = this.editorView.hasSelection();
6324
+ if (hasSelection) {
6325
+ this.originalMoveCursorLeft();
6326
+ return;
6327
+ }
6328
+ const targetOffset = currentOffset - 1;
6329
+ if (targetOffset < 0) {
6330
+ this.originalMoveCursorLeft();
6331
+ return;
6332
+ }
6333
+ const virtualExtmark = this.findVirtualExtmarkContaining(targetOffset);
6334
+ if (virtualExtmark && currentOffset >= virtualExtmark.end) {
6335
+ this.editBuffer.setCursorByOffset(virtualExtmark.start - 1);
6336
+ return;
6337
+ }
6338
+ this.originalMoveCursorLeft();
6339
+ };
6340
+ this.editBuffer.moveCursorRight = () => {
6341
+ if (this.destroyed) {
6342
+ this.originalMoveCursorRight();
6343
+ return;
6344
+ }
6345
+ const currentOffset = this.editorView.getVisualCursor().offset;
6346
+ const hasSelection = this.editorView.hasSelection();
6347
+ if (hasSelection) {
6348
+ this.originalMoveCursorRight();
6349
+ return;
6350
+ }
6351
+ const targetOffset = currentOffset + 1;
6352
+ const textLength = this.editBuffer.getText().length;
6353
+ if (targetOffset > textLength) {
6354
+ this.originalMoveCursorRight();
6355
+ return;
6356
+ }
6357
+ const virtualExtmark = this.findVirtualExtmarkContaining(targetOffset);
6358
+ if (virtualExtmark && currentOffset <= virtualExtmark.start) {
6359
+ this.editBuffer.setCursorByOffset(virtualExtmark.end);
6360
+ return;
6361
+ }
6362
+ this.originalMoveCursorRight();
6363
+ };
6364
+ this.editorView.moveUpVisual = () => {
6365
+ if (this.destroyed) {
6366
+ this.originalMoveUpVisual();
6367
+ return;
6368
+ }
6369
+ const hasSelection = this.editorView.hasSelection();
6370
+ if (hasSelection) {
6371
+ this.originalMoveUpVisual();
6372
+ return;
6373
+ }
6374
+ const currentOffset = this.editorView.getVisualCursor().offset;
6375
+ this.originalMoveUpVisual();
6376
+ const newOffset = this.editorView.getVisualCursor().offset;
6377
+ const virtualExtmark = this.findVirtualExtmarkContaining(newOffset);
6378
+ if (virtualExtmark) {
6379
+ const distanceToStart = newOffset - virtualExtmark.start;
6380
+ const distanceToEnd = virtualExtmark.end - newOffset;
6381
+ if (distanceToStart < distanceToEnd) {
6382
+ this.editorView.setCursorByOffset(virtualExtmark.start - 1);
6383
+ } else {
6384
+ this.editorView.setCursorByOffset(virtualExtmark.end);
6385
+ }
6386
+ }
6387
+ };
6388
+ this.editorView.moveDownVisual = () => {
6389
+ if (this.destroyed) {
6390
+ this.originalMoveDownVisual();
6391
+ return;
6392
+ }
6393
+ const hasSelection = this.editorView.hasSelection();
6394
+ if (hasSelection) {
6395
+ this.originalMoveDownVisual();
6396
+ return;
6397
+ }
6398
+ const currentOffset = this.editorView.getVisualCursor().offset;
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.extmarks.delete(virtualExtmark.id);
6466
+ this.originalDeleteRange(startCursor.row, startCursor.col, endCursor.row, endCursor.col);
6467
+ this.adjustExtmarksAfterDeletion(deleteOffset, deleteLength);
6468
+ this.emit("extmark-deleted", {
6469
+ extmark: virtualExtmark,
6470
+ trigger: "backspace"
6471
+ });
6472
+ this.updateHighlights();
6473
+ return;
6474
+ }
6475
+ this.originalDeleteCharBackward();
6476
+ this.adjustExtmarksAfterDeletion(targetOffset, 1);
6477
+ };
6478
+ this.editBuffer.deleteChar = () => {
6479
+ if (this.destroyed) {
6480
+ this.originalDeleteChar();
6481
+ return;
6482
+ }
6483
+ this.saveSnapshot();
6484
+ const currentOffset = this.editorView.getVisualCursor().offset;
6485
+ const textLength = this.editBuffer.getText().length;
6486
+ const hadSelection = this.editorView.hasSelection();
6487
+ if (currentOffset >= textLength) {
6488
+ this.originalDeleteChar();
6489
+ return;
6490
+ }
6491
+ if (hadSelection) {
6492
+ this.originalDeleteChar();
6493
+ return;
6494
+ }
6495
+ const targetOffset = currentOffset;
6496
+ const virtualExtmark = this.findVirtualExtmarkContaining(targetOffset);
6497
+ if (virtualExtmark && currentOffset === virtualExtmark.start) {
6498
+ const startCursor = this.offsetToPosition(virtualExtmark.start);
6499
+ const endCursor = this.offsetToPosition(virtualExtmark.end);
6500
+ const deleteOffset = virtualExtmark.start;
6501
+ const deleteLength = virtualExtmark.end - virtualExtmark.start;
6502
+ this.extmarks.delete(virtualExtmark.id);
6503
+ this.originalDeleteRange(startCursor.row, startCursor.col, endCursor.row, endCursor.col);
6504
+ this.adjustExtmarksAfterDeletion(deleteOffset, deleteLength);
6505
+ this.emit("extmark-deleted", {
6506
+ extmark: virtualExtmark,
6507
+ trigger: "delete"
6508
+ });
6509
+ this.updateHighlights();
6510
+ return;
6511
+ }
6512
+ this.originalDeleteChar();
6513
+ this.adjustExtmarksAfterDeletion(targetOffset, 1);
6514
+ };
6515
+ this.editBuffer.deleteRange = (startLine, startCol, endLine, endCol) => {
6516
+ if (this.destroyed) {
6517
+ this.originalDeleteRange(startLine, startCol, endLine, endCol);
6518
+ return;
6519
+ }
6520
+ this.saveSnapshot();
6521
+ const startOffset = this.positionToOffset(startLine, startCol);
6522
+ const endOffset = this.positionToOffset(endLine, endCol);
6523
+ const length = endOffset - startOffset;
6524
+ this.originalDeleteRange(startLine, startCol, endLine, endCol);
6525
+ this.adjustExtmarksAfterDeletion(startOffset, length);
6526
+ };
6527
+ this.editBuffer.deleteLine = () => {
6528
+ if (this.destroyed) {
6529
+ this.originalDeleteLine();
6530
+ return;
6531
+ }
6532
+ this.saveSnapshot();
6533
+ const text = this.editBuffer.getText();
6534
+ const currentOffset = this.editorView.getVisualCursor().offset;
6535
+ let lineStart = 0;
6536
+ for (let i = currentOffset - 1;i >= 0; i--) {
6537
+ if (text[i] === `
6538
+ `) {
6539
+ lineStart = i + 1;
6540
+ break;
6541
+ }
6542
+ }
6543
+ let lineEnd = text.length;
6544
+ for (let i = currentOffset;i < text.length; i++) {
6545
+ if (text[i] === `
6546
+ `) {
6547
+ lineEnd = i + 1;
6548
+ break;
6549
+ }
6550
+ }
6551
+ const deleteLength = lineEnd - lineStart;
6552
+ this.originalDeleteLine();
6553
+ this.adjustExtmarksAfterDeletion(lineStart, deleteLength);
6554
+ };
6555
+ }
6556
+ wrapInsertion() {
6557
+ this.editBuffer.insertText = (text) => {
6558
+ if (this.destroyed) {
6559
+ this.originalInsertText(text);
6560
+ return;
6561
+ }
6562
+ this.saveSnapshot();
6563
+ const currentOffset = this.editorView.getVisualCursor().offset;
6564
+ this.originalInsertText(text);
6565
+ this.adjustExtmarksAfterInsertion(currentOffset, text.length);
6566
+ };
6567
+ this.editBuffer.insertChar = (char) => {
6568
+ if (this.destroyed) {
6569
+ this.originalInsertChar(char);
6570
+ return;
6571
+ }
6572
+ this.saveSnapshot();
6573
+ const currentOffset = this.editorView.getVisualCursor().offset;
6574
+ this.originalInsertChar(char);
6575
+ this.adjustExtmarksAfterInsertion(currentOffset, 1);
6576
+ };
6577
+ this.editBuffer.setText = (text, opts) => {
6578
+ if (this.destroyed) {
6579
+ this.originalSetText(text, opts);
6580
+ return;
6581
+ }
6582
+ if (opts?.history !== false) {
6583
+ this.saveSnapshot();
6584
+ }
6585
+ this.clear();
6586
+ this.originalSetText(text, opts);
6587
+ };
6588
+ this.editBuffer.clear = () => {
6589
+ if (this.destroyed) {
6590
+ this.originalClear();
6591
+ return;
6592
+ }
6593
+ this.saveSnapshot();
6594
+ this.clear();
6595
+ this.originalClear();
6596
+ };
6597
+ this.editBuffer.newLine = () => {
6598
+ if (this.destroyed) {
6599
+ this.originalNewLine();
6600
+ return;
6601
+ }
6602
+ this.saveSnapshot();
6603
+ const currentOffset = this.editorView.getVisualCursor().offset;
6604
+ this.originalNewLine();
6605
+ this.adjustExtmarksAfterInsertion(currentOffset, 1);
6606
+ };
6607
+ }
6608
+ wrapEditorViewDeleteSelectedText() {
6609
+ this.editorView.deleteSelectedText = () => {
6610
+ if (this.destroyed) {
6611
+ this.originalEditorViewDeleteSelectedText();
6612
+ return;
6613
+ }
6614
+ this.saveSnapshot();
6615
+ const selection = this.editorView.getSelection();
6616
+ if (!selection) {
6617
+ this.originalEditorViewDeleteSelectedText();
6618
+ return;
6619
+ }
6620
+ const deleteOffset = Math.min(selection.start, selection.end);
6621
+ const deleteLength = Math.abs(selection.end - selection.start);
6622
+ this.originalEditorViewDeleteSelectedText();
6623
+ if (deleteLength > 0) {
6624
+ this.adjustExtmarksAfterDeletion(deleteOffset, deleteLength);
6625
+ }
6626
+ };
6627
+ }
6628
+ setupContentChangeListener() {
6629
+ this.editBuffer.on("content-changed", () => {
6630
+ if (this.destroyed)
6631
+ return;
6632
+ this.updateHighlights();
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
+ this.emit("extmark-updated", extmark);
6649
+ } else if (extmark.end > insertOffset) {
6650
+ extmark.end += length;
6651
+ this.emit("extmark-updated", extmark);
6652
+ }
6653
+ }
6654
+ this.updateHighlights();
6655
+ }
6656
+ adjustExtmarksAfterDeletion(deleteOffset, length) {
6657
+ const toDelete = [];
6658
+ for (const extmark of this.extmarks.values()) {
6659
+ if (extmark.end <= deleteOffset) {
6660
+ continue;
6661
+ }
6662
+ if (extmark.start >= deleteOffset + length) {
6663
+ extmark.start -= length;
6664
+ extmark.end -= length;
6665
+ this.emit("extmark-updated", extmark);
6666
+ } else if (extmark.start >= deleteOffset && extmark.end <= deleteOffset + length) {
6667
+ toDelete.push(extmark.id);
6668
+ } else if (extmark.start < deleteOffset && extmark.end > deleteOffset + length) {
6669
+ extmark.end -= length;
6670
+ this.emit("extmark-updated", extmark);
6671
+ } else if (extmark.start < deleteOffset && extmark.end > deleteOffset) {
6672
+ extmark.end -= Math.min(extmark.end, deleteOffset + length) - deleteOffset;
6673
+ this.emit("extmark-updated", extmark);
6674
+ } else if (extmark.start < deleteOffset + length && extmark.end > deleteOffset + length) {
6675
+ const overlap = deleteOffset + length - extmark.start;
6676
+ extmark.start = deleteOffset;
6677
+ extmark.end -= length;
6678
+ this.emit("extmark-updated", extmark);
6679
+ }
6680
+ }
6681
+ for (const id of toDelete) {
6682
+ const extmark = this.extmarks.get(id);
6683
+ if (extmark) {
6684
+ this.extmarks.delete(id);
6685
+ this.emit("extmark-deleted", {
6686
+ extmark,
6687
+ trigger: "manual"
6688
+ });
6689
+ }
6690
+ }
6691
+ this.updateHighlights();
6692
+ }
6693
+ offsetToPosition(offset) {
6694
+ const text = this.editBuffer.getText();
6695
+ let currentOffset = 0;
6696
+ let row = 0;
6697
+ let col = 0;
6698
+ for (let i = 0;i < text.length && currentOffset < offset; i++) {
6699
+ if (text[i] === `
6700
+ `) {
6701
+ row++;
6702
+ col = 0;
6703
+ } else {
6704
+ col++;
6705
+ }
6706
+ currentOffset++;
6707
+ }
6708
+ return { row, col };
6709
+ }
6710
+ positionToOffset(row, col) {
6711
+ const text = this.editBuffer.getText();
6712
+ let currentRow = 0;
6713
+ let offset = 0;
6714
+ for (let i = 0;i < text.length; i++) {
6715
+ if (currentRow === row && offset - this.getLineStartOffset(row) === col) {
6716
+ return offset;
6717
+ }
6718
+ if (text[i] === `
6719
+ `) {
6720
+ currentRow++;
6721
+ }
6722
+ offset++;
6723
+ }
6724
+ return offset;
6725
+ }
6726
+ getLineStartOffset(targetRow) {
6727
+ const text = this.editBuffer.getText();
6728
+ let row = 0;
6729
+ let offset = 0;
6730
+ for (let i = 0;i < text.length; i++) {
6731
+ if (row === targetRow) {
6732
+ return offset;
6733
+ }
6734
+ if (text[i] === `
6735
+ `) {
6736
+ row++;
6737
+ offset = i + 1;
6738
+ }
6739
+ }
6740
+ return offset;
6741
+ }
6742
+ updateHighlights() {
6743
+ this.editBuffer.clearAllHighlights();
6744
+ for (const extmark of this.extmarks.values()) {
6745
+ if (extmark.styleId !== undefined) {
6746
+ const startWithoutNewlines = this.offsetToCharOffset(extmark.start);
6747
+ const endWithoutNewlines = this.offsetToCharOffset(extmark.end);
6748
+ this.editBuffer.addHighlightByCharRange({
6749
+ start: startWithoutNewlines,
6750
+ end: endWithoutNewlines,
6751
+ styleId: extmark.styleId,
6752
+ priority: extmark.priority ?? 0,
6753
+ hlRef: extmark.id
6754
+ });
6755
+ }
6756
+ }
6757
+ }
6758
+ offsetToCharOffset(offset) {
6759
+ const text = this.editBuffer.getText();
6760
+ let charOffset = 0;
6761
+ for (let i = 0;i < offset && i < text.length; i++) {
6762
+ if (text[i] !== `
6763
+ `) {
6764
+ charOffset++;
6765
+ }
6766
+ }
6767
+ return charOffset;
6768
+ }
6769
+ create(options) {
6770
+ if (this.destroyed) {
6771
+ throw new Error("ExtmarksController is destroyed");
6772
+ }
6773
+ const id = this.nextId++;
6774
+ const extmark = {
6775
+ id,
6776
+ start: options.start,
6777
+ end: options.end,
6778
+ virtual: options.virtual ?? false,
6779
+ styleId: options.styleId,
6780
+ priority: options.priority,
6781
+ data: options.data
6782
+ };
6783
+ this.extmarks.set(id, extmark);
6784
+ this.updateHighlights();
6785
+ return id;
6786
+ }
6787
+ update(id, options) {
6788
+ if (this.destroyed) {
6789
+ throw new Error("ExtmarksController is destroyed");
6790
+ }
6791
+ const extmark = this.extmarks.get(id);
6792
+ if (!extmark)
6793
+ return false;
6794
+ if (options.start !== undefined)
6795
+ extmark.start = options.start;
6796
+ if (options.end !== undefined)
6797
+ extmark.end = options.end;
6798
+ if (options.virtual !== undefined)
6799
+ extmark.virtual = options.virtual;
6800
+ if (options.styleId !== undefined)
6801
+ extmark.styleId = options.styleId;
6802
+ if (options.priority !== undefined)
6803
+ extmark.priority = options.priority;
6804
+ if (options.data !== undefined)
6805
+ extmark.data = options.data;
6806
+ this.emit("extmark-updated", extmark);
6807
+ this.updateHighlights();
6808
+ return true;
6809
+ }
6810
+ delete(id) {
6811
+ if (this.destroyed) {
6812
+ throw new Error("ExtmarksController is destroyed");
6813
+ }
6814
+ const extmark = this.extmarks.get(id);
6815
+ if (!extmark)
6816
+ return false;
6817
+ this.extmarks.delete(id);
6818
+ this.emit("extmark-deleted", {
6819
+ extmark,
6820
+ trigger: "manual"
6821
+ });
6822
+ this.updateHighlights();
6823
+ return true;
6824
+ }
6825
+ get(id) {
6826
+ if (this.destroyed)
6827
+ return null;
6828
+ return this.extmarks.get(id) ?? null;
6829
+ }
6830
+ getAll() {
6831
+ if (this.destroyed)
6832
+ return [];
6833
+ return Array.from(this.extmarks.values());
6834
+ }
6835
+ getVirtual() {
6836
+ if (this.destroyed)
6837
+ return [];
6838
+ return Array.from(this.extmarks.values()).filter((e) => e.virtual);
6839
+ }
6840
+ getAtOffset(offset) {
6841
+ if (this.destroyed)
6842
+ return [];
6843
+ return Array.from(this.extmarks.values()).filter((e) => offset >= e.start && offset < e.end);
6844
+ }
6845
+ clear() {
6846
+ if (this.destroyed)
6847
+ return;
6848
+ for (const extmark of this.extmarks.values()) {
6849
+ this.emit("extmark-deleted", {
6850
+ extmark,
6851
+ trigger: "manual"
6852
+ });
6853
+ }
6854
+ this.extmarks.clear();
6855
+ this.updateHighlights();
6856
+ }
6857
+ saveSnapshot() {
6858
+ this.history.saveSnapshot(this.extmarks, this.nextId);
6859
+ }
6860
+ restoreSnapshot(snapshot) {
6861
+ this.extmarks = new Map(Array.from(snapshot.extmarks.entries()).map(([id, extmark]) => [id, { ...extmark }]));
6862
+ this.nextId = snapshot.nextId;
6863
+ this.updateHighlights();
6864
+ }
6865
+ wrapUndoRedo() {
6866
+ this.editBuffer.undo = () => {
6867
+ if (this.destroyed) {
6868
+ return this.originalUndo();
6869
+ }
6870
+ if (!this.history.canUndo()) {
6871
+ return this.originalUndo();
6872
+ }
6873
+ const currentSnapshot = {
6874
+ extmarks: new Map(Array.from(this.extmarks.entries()).map(([id, extmark]) => [id, { ...extmark }])),
6875
+ nextId: this.nextId
6876
+ };
6877
+ this.history.pushRedo(currentSnapshot);
6878
+ const snapshot = this.history.undo();
6879
+ this.restoreSnapshot(snapshot);
6880
+ return this.originalUndo();
6881
+ };
6882
+ this.editBuffer.redo = () => {
6883
+ if (this.destroyed) {
6884
+ return this.originalRedo();
6885
+ }
6886
+ if (!this.history.canRedo()) {
6887
+ return this.originalRedo();
6888
+ }
6889
+ const currentSnapshot = {
6890
+ extmarks: new Map(Array.from(this.extmarks.entries()).map(([id, extmark]) => [id, { ...extmark }])),
6891
+ nextId: this.nextId
6892
+ };
6893
+ this.history.pushUndo(currentSnapshot);
6894
+ const snapshot = this.history.redo();
6895
+ this.restoreSnapshot(snapshot);
6896
+ return this.originalRedo();
6897
+ };
6898
+ }
6899
+ destroy() {
6900
+ if (this.destroyed)
6901
+ return;
6902
+ this.editBuffer.moveCursorLeft = this.originalMoveCursorLeft;
6903
+ this.editBuffer.moveCursorRight = this.originalMoveCursorRight;
6904
+ this.editBuffer.setCursorByOffset = this.originalSetCursorByOffset;
6905
+ this.editorView.moveUpVisual = this.originalMoveUpVisual;
6906
+ this.editorView.moveDownVisual = this.originalMoveDownVisual;
6907
+ this.editBuffer.deleteCharBackward = this.originalDeleteCharBackward;
6908
+ this.editBuffer.deleteChar = this.originalDeleteChar;
6909
+ this.editBuffer.insertText = this.originalInsertText;
6910
+ this.editBuffer.insertChar = this.originalInsertChar;
6911
+ this.editBuffer.deleteRange = this.originalDeleteRange;
6912
+ this.editBuffer.setText = this.originalSetText;
6913
+ this.editBuffer.clear = this.originalClear;
6914
+ this.editBuffer.newLine = this.originalNewLine;
6915
+ this.editBuffer.deleteLine = this.originalDeleteLine;
6916
+ this.editorView.deleteSelectedText = this.originalEditorViewDeleteSelectedText;
6917
+ this.editBuffer.undo = this.originalUndo;
6918
+ this.editBuffer.redo = this.originalRedo;
6919
+ this.extmarks.clear();
6920
+ this.history.clear();
6921
+ this.destroyed = true;
6922
+ this.removeAllListeners();
6923
+ }
6924
+ }
6925
+ function createExtmarksController(editBuffer, editorView) {
6926
+ return new ExtmarksController(editBuffer, editorView);
6927
+ }
6256
6928
  // src/zig.ts
6257
- import { dlopen, toArrayBuffer as toArrayBuffer2, JSCallback, ptr } from "bun:ffi";
6929
+ import { dlopen, toArrayBuffer as toArrayBuffer4, JSCallback, ptr as ptr3 } from "bun:ffi";
6258
6930
  import { existsSync as existsSync2 } from "fs";
6931
+ import { EventEmitter as EventEmitter5 } from "events";
6259
6932
 
6260
6933
  // src/buffer.ts
6261
6934
  import { toArrayBuffer } from "bun:ffi";
@@ -6411,9 +7084,13 @@ class OptimizedBuffer {
6411
7084
  this._destroyed = true;
6412
7085
  this.lib.destroyOptimizedBuffer(this.bufferPtr);
6413
7086
  }
6414
- drawTextBuffer(textBuffer, x, y, clipRect) {
7087
+ drawTextBuffer(textBufferView, x, y) {
7088
+ this.guard();
7089
+ this.lib.bufferDrawTextBufferView(this.bufferPtr, textBufferView.ptr, x, y);
7090
+ }
7091
+ drawEditorView(editorView, x, y) {
6415
7092
  this.guard();
6416
- this.lib.bufferDrawTextBuffer(this.bufferPtr, textBuffer.ptr, x, y, clipRect);
7093
+ this.lib.bufferDrawEditorView(this.bufferPtr, editorView.ptr, x, y);
6417
7094
  }
6418
7095
  drawSuperSampleBuffer(x, y, pixelDataPtr, pixelDataLength, format, alignedBytesPerRow) {
6419
7096
  this.guard();
@@ -6453,10 +7130,628 @@ class OptimizedBuffer {
6453
7130
  }
6454
7131
  }
6455
7132
 
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)) {
7133
+ // ../../node_modules/.bun/bun-ffi-structs@0.1.0+ca84541ac88a3075/node_modules/bun-ffi-structs/index.js
7134
+ import { ptr, toArrayBuffer as toArrayBuffer2 } from "bun:ffi";
7135
+ function fatalError(...args) {
7136
+ const message = args.join(" ");
7137
+ console.error("FATAL ERROR:", message);
7138
+ throw new Error(message);
7139
+ }
7140
+ var pointerSize = process.arch === "x64" || process.arch === "arm64" ? 8 : 4;
7141
+ var typeSizes = {
7142
+ u8: 1,
7143
+ bool_u8: 1,
7144
+ bool_u32: 4,
7145
+ u16: 2,
7146
+ i16: 2,
7147
+ u32: 4,
7148
+ u64: 8,
7149
+ f32: 4,
7150
+ f64: 8,
7151
+ pointer: pointerSize,
7152
+ i32: 4
7153
+ };
7154
+ var primitiveKeys = Object.keys(typeSizes);
7155
+ function isPrimitiveType(type) {
7156
+ return typeof type === "string" && primitiveKeys.includes(type);
7157
+ }
7158
+ var typeAlignments = { ...typeSizes };
7159
+ var typeGetters = {
7160
+ u8: (view, offset) => view.getUint8(offset),
7161
+ bool_u8: (view, offset) => Boolean(view.getUint8(offset)),
7162
+ bool_u32: (view, offset) => Boolean(view.getUint32(offset, true)),
7163
+ u16: (view, offset) => view.getUint16(offset, true),
7164
+ i16: (view, offset) => view.getInt16(offset, true),
7165
+ u32: (view, offset) => view.getUint32(offset, true),
7166
+ u64: (view, offset) => view.getBigUint64(offset, true),
7167
+ f32: (view, offset) => view.getFloat32(offset, true),
7168
+ f64: (view, offset) => view.getFloat64(offset, true),
7169
+ i32: (view, offset) => view.getInt32(offset, true),
7170
+ pointer: (view, offset) => pointerSize === 8 ? view.getBigUint64(offset, true) : BigInt(view.getUint32(offset, true))
7171
+ };
7172
+ function isObjectPointerDef(type) {
7173
+ return typeof type === "object" && type !== null && type.__type === "objectPointer";
7174
+ }
7175
+ function alignOffset(offset, align) {
7176
+ return offset + (align - 1) & ~(align - 1);
7177
+ }
7178
+ function isEnum(type) {
7179
+ return typeof type === "object" && type.__type === "enum";
7180
+ }
7181
+ function isStruct(type) {
7182
+ return typeof type === "object" && type.__type === "struct";
7183
+ }
7184
+ function primitivePackers(type) {
7185
+ let pack;
7186
+ let unpack;
7187
+ switch (type) {
7188
+ case "u8":
7189
+ pack = (view, off, val) => view.setUint8(off, val);
7190
+ unpack = (view, off) => view.getUint8(off);
7191
+ break;
7192
+ case "bool_u8":
7193
+ pack = (view, off, val) => view.setUint8(off, val ? 1 : 0);
7194
+ unpack = (view, off) => Boolean(view.getUint8(off));
7195
+ break;
7196
+ case "bool_u32":
7197
+ pack = (view, off, val) => view.setUint32(off, val ? 1 : 0, true);
7198
+ unpack = (view, off) => Boolean(view.getUint32(off, true));
7199
+ break;
7200
+ case "u16":
7201
+ pack = (view, off, val) => view.setUint16(off, val, true);
7202
+ unpack = (view, off) => view.getUint16(off, true);
7203
+ break;
7204
+ case "i16":
7205
+ pack = (view, off, val) => view.setInt16(off, val, true);
7206
+ unpack = (view, off) => view.getInt16(off, true);
7207
+ break;
7208
+ case "u32":
7209
+ pack = (view, off, val) => view.setUint32(off, val, true);
7210
+ unpack = (view, off) => view.getUint32(off, true);
7211
+ break;
7212
+ case "i32":
7213
+ pack = (view, off, val) => view.setInt32(off, val, true);
7214
+ unpack = (view, off) => view.getInt32(off, true);
7215
+ break;
7216
+ case "u64":
7217
+ pack = (view, off, val) => view.setBigUint64(off, BigInt(val), true);
7218
+ unpack = (view, off) => view.getBigUint64(off, true);
7219
+ break;
7220
+ case "f32":
7221
+ pack = (view, off, val) => view.setFloat32(off, val, true);
7222
+ unpack = (view, off) => view.getFloat32(off, true);
7223
+ break;
7224
+ case "f64":
7225
+ pack = (view, off, val) => view.setFloat64(off, val, true);
7226
+ unpack = (view, off) => view.getFloat64(off, true);
7227
+ break;
7228
+ case "pointer":
7229
+ pack = (view, off, val) => {
7230
+ pointerSize === 8 ? view.setBigUint64(off, val ? BigInt(val) : 0n, true) : view.setUint32(off, val ? Number(val) : 0, true);
7231
+ };
7232
+ unpack = (view, off) => {
7233
+ const bint = pointerSize === 8 ? view.getBigUint64(off, true) : BigInt(view.getUint32(off, true));
7234
+ return Number(bint);
7235
+ };
7236
+ break;
7237
+ default:
7238
+ fatalError(`Unsupported primitive type: ${type}`);
7239
+ }
7240
+ return { pack, unpack };
7241
+ }
7242
+ var { pack: pointerPacker, unpack: pointerUnpacker } = primitivePackers("pointer");
7243
+ function packObjectArray(val) {
7244
+ const buffer = new ArrayBuffer(val.length * pointerSize);
7245
+ const bufferView = new DataView(buffer);
7246
+ for (let i = 0;i < val.length; i++) {
7247
+ const instance = val[i];
7248
+ const ptrValue = instance?.ptr ?? null;
7249
+ pointerPacker(bufferView, i * pointerSize, ptrValue);
7250
+ }
7251
+ return bufferView;
7252
+ }
7253
+ var encoder = new TextEncoder;
7254
+ function defineStruct(fields, structDefOptions) {
7255
+ let offset = 0;
7256
+ let maxAlign = 1;
7257
+ const layout = [];
7258
+ const lengthOfFields = {};
7259
+ const lengthOfRequested = [];
7260
+ const arrayFieldsMetadata = {};
7261
+ for (const [name, typeOrStruct, options = {}] of fields) {
7262
+ if (options.condition && !options.condition()) {
7263
+ continue;
7264
+ }
7265
+ let size = 0, align = 0;
7266
+ let pack;
7267
+ let unpack;
7268
+ let needsLengthOf = false;
7269
+ let lengthOfDef = null;
7270
+ if (isPrimitiveType(typeOrStruct)) {
7271
+ size = typeSizes[typeOrStruct];
7272
+ align = typeAlignments[typeOrStruct];
7273
+ ({ pack, unpack } = primitivePackers(typeOrStruct));
7274
+ } else if (typeof typeOrStruct === "string" && typeOrStruct === "cstring") {
7275
+ size = pointerSize;
7276
+ align = pointerSize;
7277
+ pack = (view, off, val) => {
7278
+ const bufPtr = val ? ptr(encoder.encode(val + "\x00")) : null;
7279
+ pointerPacker(view, off, bufPtr);
7280
+ };
7281
+ unpack = (view, off) => {
7282
+ const ptrVal = pointerUnpacker(view, off);
7283
+ return ptrVal;
7284
+ };
7285
+ } else if (typeof typeOrStruct === "string" && typeOrStruct === "char*") {
7286
+ size = pointerSize;
7287
+ align = pointerSize;
7288
+ pack = (view, off, val) => {
7289
+ const bufPtr = val ? ptr(encoder.encode(val)) : null;
7290
+ pointerPacker(view, off, bufPtr);
7291
+ };
7292
+ unpack = (view, off) => {
7293
+ const ptrVal = pointerUnpacker(view, off);
7294
+ return ptrVal;
7295
+ };
7296
+ } else if (isEnum(typeOrStruct)) {
7297
+ const base = typeOrStruct.type;
7298
+ size = typeSizes[base];
7299
+ align = typeAlignments[base];
7300
+ const { pack: packEnum } = primitivePackers(base);
7301
+ pack = (view, off, val) => {
7302
+ const num = typeOrStruct.to(val);
7303
+ packEnum(view, off, num);
7304
+ };
7305
+ unpack = (view, off) => {
7306
+ const raw = typeGetters[base](view, off);
7307
+ return typeOrStruct.from(raw);
7308
+ };
7309
+ } else if (isStruct(typeOrStruct)) {
7310
+ if (options.asPointer === true) {
7311
+ size = pointerSize;
7312
+ align = pointerSize;
7313
+ pack = (view, off, val, obj, options2) => {
7314
+ if (!val) {
7315
+ pointerPacker(view, off, null);
7316
+ return;
7317
+ }
7318
+ const nestedBuf = typeOrStruct.pack(val, options2);
7319
+ pointerPacker(view, off, ptr(nestedBuf));
7320
+ };
7321
+ unpack = (view, off) => {
7322
+ throw new Error("Not implemented yet");
7323
+ };
7324
+ } else {
7325
+ size = typeOrStruct.size;
7326
+ align = typeOrStruct.align;
7327
+ pack = (view, off, val, obj, options2) => {
7328
+ const nestedBuf = typeOrStruct.pack(val, options2);
7329
+ const nestedView = new Uint8Array(nestedBuf);
7330
+ const dView = new Uint8Array(view.buffer);
7331
+ dView.set(nestedView, off);
7332
+ };
7333
+ unpack = (view, off) => {
7334
+ const slice = view.buffer.slice(off, off + size);
7335
+ return typeOrStruct.unpack(slice);
7336
+ };
7337
+ }
7338
+ } else if (isObjectPointerDef(typeOrStruct)) {
7339
+ size = pointerSize;
7340
+ align = pointerSize;
7341
+ pack = (view, off, value) => {
7342
+ const ptrValue = value?.ptr ?? null;
7343
+ if (ptrValue === undefined) {
7344
+ console.warn(`Field '${name}' expected object with '.ptr' property, but got undefined pointer value from:`, value);
7345
+ pointerPacker(view, off, null);
7346
+ } else {
7347
+ pointerPacker(view, off, ptrValue);
7348
+ }
7349
+ };
7350
+ unpack = (view, off) => {
7351
+ return pointerUnpacker(view, off);
7352
+ };
7353
+ } else if (Array.isArray(typeOrStruct) && typeOrStruct.length === 1 && typeOrStruct[0] !== undefined) {
7354
+ const [def] = typeOrStruct;
7355
+ size = pointerSize;
7356
+ align = pointerSize;
7357
+ let arrayElementSize;
7358
+ if (isEnum(def)) {
7359
+ arrayElementSize = typeSizes[def.type];
7360
+ pack = (view, off, val, obj) => {
7361
+ if (!val || val.length === 0) {
7362
+ pointerPacker(view, off, null);
7363
+ return;
7364
+ }
7365
+ const buffer = new ArrayBuffer(val.length * arrayElementSize);
7366
+ const bufferView = new DataView(buffer);
7367
+ for (let i = 0;i < val.length; i++) {
7368
+ const num = def.to(val[i]);
7369
+ bufferView.setUint32(i * arrayElementSize, num, true);
7370
+ }
7371
+ pointerPacker(view, off, ptr(buffer));
7372
+ };
7373
+ unpack = null;
7374
+ needsLengthOf = true;
7375
+ lengthOfDef = def;
7376
+ } else if (isStruct(def)) {
7377
+ arrayElementSize = def.size;
7378
+ pack = (view, off, val, obj, options2) => {
7379
+ if (!val || val.length === 0) {
7380
+ pointerPacker(view, off, null);
7381
+ return;
7382
+ }
7383
+ const buffer = new ArrayBuffer(val.length * arrayElementSize);
7384
+ const bufferView = new DataView(buffer);
7385
+ for (let i = 0;i < val.length; i++) {
7386
+ def.packInto(val[i], bufferView, i * arrayElementSize, options2);
7387
+ }
7388
+ pointerPacker(view, off, ptr(buffer));
7389
+ };
7390
+ unpack = (view, off) => {
7391
+ throw new Error("Not implemented yet");
7392
+ };
7393
+ } else if (isPrimitiveType(def)) {
7394
+ arrayElementSize = typeSizes[def];
7395
+ const { pack: primitivePack } = primitivePackers(def);
7396
+ pack = (view, off, val) => {
7397
+ if (!val || val.length === 0) {
7398
+ pointerPacker(view, off, null);
7399
+ return;
7400
+ }
7401
+ const buffer = new ArrayBuffer(val.length * arrayElementSize);
7402
+ const bufferView = new DataView(buffer);
7403
+ for (let i = 0;i < val.length; i++) {
7404
+ primitivePack(bufferView, i * arrayElementSize, val[i]);
7405
+ }
7406
+ pointerPacker(view, off, ptr(buffer));
7407
+ };
7408
+ unpack = null;
7409
+ needsLengthOf = true;
7410
+ lengthOfDef = def;
7411
+ } else if (isObjectPointerDef(def)) {
7412
+ arrayElementSize = pointerSize;
7413
+ pack = (view, off, val) => {
7414
+ if (!val || val.length === 0) {
7415
+ pointerPacker(view, off, null);
7416
+ return;
7417
+ }
7418
+ const packedView = packObjectArray(val);
7419
+ pointerPacker(view, off, ptr(packedView.buffer));
7420
+ };
7421
+ unpack = () => {
7422
+ throw new Error("not implemented yet");
7423
+ };
7424
+ } else {
7425
+ throw new Error(`Unsupported array element type for ${name}: ${JSON.stringify(def)}`);
7426
+ }
7427
+ const lengthOfField = Object.values(lengthOfFields).find((f) => f.lengthOf === name);
7428
+ if (lengthOfField && isPrimitiveType(lengthOfField.type)) {
7429
+ const { pack: lengthPack } = primitivePackers(lengthOfField.type);
7430
+ arrayFieldsMetadata[name] = {
7431
+ elementSize: arrayElementSize,
7432
+ arrayOffset: offset,
7433
+ lengthOffset: lengthOfField.offset,
7434
+ lengthPack
7435
+ };
7436
+ }
7437
+ } else {
7438
+ throw new Error(`Unsupported field type for ${name}: ${JSON.stringify(typeOrStruct)}`);
7439
+ }
7440
+ offset = alignOffset(offset, align);
7441
+ if (options.unpackTransform) {
7442
+ const originalUnpack = unpack;
7443
+ unpack = (view, off) => options.unpackTransform(originalUnpack(view, off));
7444
+ }
7445
+ if (options.packTransform) {
7446
+ const originalPack = pack;
7447
+ pack = (view, off, val, obj, packOptions) => originalPack(view, off, options.packTransform(val), obj, packOptions);
7448
+ }
7449
+ if (options.optional) {
7450
+ const originalPack = pack;
7451
+ if (isStruct(typeOrStruct) && !options.asPointer) {
7452
+ pack = (view, off, val, obj, packOptions) => {
7453
+ if (val || options.mapOptionalInline) {
7454
+ originalPack(view, off, val, obj, packOptions);
7455
+ }
7456
+ };
7457
+ } else {
7458
+ pack = (view, off, val, obj, packOptions) => originalPack(view, off, val ?? 0, obj, packOptions);
7459
+ }
7460
+ }
7461
+ if (options.lengthOf) {
7462
+ const originalPack = pack;
7463
+ pack = (view, off, val, obj, packOptions) => {
7464
+ const targetValue = obj[options.lengthOf];
7465
+ let length = 0;
7466
+ if (targetValue) {
7467
+ if (typeof targetValue === "string") {
7468
+ length = Buffer.byteLength(targetValue);
7469
+ } else {
7470
+ length = targetValue.length;
7471
+ }
7472
+ }
7473
+ return originalPack(view, off, length, obj, packOptions);
7474
+ };
7475
+ }
7476
+ let validateFunctions;
7477
+ if (options.validate) {
7478
+ validateFunctions = Array.isArray(options.validate) ? options.validate : [options.validate];
7479
+ }
7480
+ const layoutField = {
7481
+ name,
7482
+ offset,
7483
+ size,
7484
+ align,
7485
+ validate: validateFunctions,
7486
+ optional: !!options.optional || !!options.lengthOf || options.default !== undefined,
7487
+ default: options.default,
7488
+ pack,
7489
+ unpack,
7490
+ type: typeOrStruct,
7491
+ lengthOf: options.lengthOf
7492
+ };
7493
+ layout.push(layoutField);
7494
+ if (options.lengthOf) {
7495
+ lengthOfFields[options.lengthOf] = layoutField;
7496
+ }
7497
+ if (needsLengthOf) {
7498
+ if (!lengthOfDef)
7499
+ fatalError(`Internal error: needsLengthOf=true but lengthOfDef is null for ${name}`);
7500
+ lengthOfRequested.push({ requester: layoutField, def: lengthOfDef });
7501
+ }
7502
+ offset += size;
7503
+ maxAlign = Math.max(maxAlign, align);
7504
+ }
7505
+ for (const { requester, def } of lengthOfRequested) {
7506
+ const lengthOfField = lengthOfFields[requester.name];
7507
+ if (!lengthOfField) {
7508
+ throw new Error(`lengthOf field not found for array field ${requester.name}`);
7509
+ }
7510
+ if (isPrimitiveType(def)) {
7511
+ const elemSize = typeSizes[def];
7512
+ const { unpack: primitiveUnpack } = primitivePackers(def);
7513
+ requester.unpack = (view, off) => {
7514
+ const result = [];
7515
+ const length = lengthOfField.unpack(view, lengthOfField.offset);
7516
+ const ptrAddress = pointerUnpacker(view, off);
7517
+ if (ptrAddress === 0n && length > 0) {
7518
+ throw new Error(`Array field ${requester.name} has null pointer but length ${length}.`);
7519
+ }
7520
+ if (ptrAddress === 0n || length === 0) {
7521
+ return [];
7522
+ }
7523
+ const buffer = toArrayBuffer2(ptrAddress, 0, length * elemSize);
7524
+ const bufferView = new DataView(buffer);
7525
+ for (let i = 0;i < length; i++) {
7526
+ result.push(primitiveUnpack(bufferView, i * elemSize));
7527
+ }
7528
+ return result;
7529
+ };
7530
+ } else {
7531
+ const elemSize = def.type === "u32" ? 4 : 8;
7532
+ requester.unpack = (view, off) => {
7533
+ const result = [];
7534
+ const length = lengthOfField.unpack(view, lengthOfField.offset);
7535
+ const ptrAddress = pointerUnpacker(view, off);
7536
+ if (ptrAddress === 0n && length > 0) {
7537
+ throw new Error(`Array field ${requester.name} has null pointer but length ${length}.`);
7538
+ }
7539
+ if (ptrAddress === 0n || length === 0) {
7540
+ return [];
7541
+ }
7542
+ const buffer = toArrayBuffer2(ptrAddress, 0, length * elemSize);
7543
+ const bufferView = new DataView(buffer);
7544
+ for (let i = 0;i < length; i++) {
7545
+ result.push(def.from(bufferView.getUint32(i * elemSize, true)));
7546
+ }
7547
+ return result;
7548
+ };
7549
+ }
7550
+ }
7551
+ const totalSize = alignOffset(offset, maxAlign);
7552
+ const description = layout.map((f) => ({
7553
+ name: f.name,
7554
+ offset: f.offset,
7555
+ size: f.size,
7556
+ align: f.align,
7557
+ optional: f.optional,
7558
+ type: f.type,
7559
+ lengthOf: f.lengthOf
7560
+ }));
7561
+ const layoutByName = new Map(description.map((f) => [f.name, f]));
7562
+ const arrayFields = new Map(Object.entries(arrayFieldsMetadata));
7563
+ return {
7564
+ __type: "struct",
7565
+ size: totalSize,
7566
+ align: maxAlign,
7567
+ hasMapValue: !!structDefOptions?.mapValue,
7568
+ layoutByName,
7569
+ arrayFields,
7570
+ pack(obj, options) {
7571
+ const buf = new ArrayBuffer(totalSize);
7572
+ const view = new DataView(buf);
7573
+ let mappedObj = obj;
7574
+ if (structDefOptions?.mapValue) {
7575
+ mappedObj = structDefOptions.mapValue(obj);
7576
+ }
7577
+ for (const field of layout) {
7578
+ const value = mappedObj[field.name] ?? field.default;
7579
+ if (!field.optional && value === undefined) {
7580
+ fatalError(`Packing non-optional field '${field.name}' but value is undefined (and no default provided)`);
7581
+ }
7582
+ if (field.validate) {
7583
+ for (const validateFn of field.validate) {
7584
+ validateFn(value, field.name, {
7585
+ hints: options?.validationHints,
7586
+ input: mappedObj
7587
+ });
7588
+ }
7589
+ }
7590
+ field.pack(view, field.offset, value, mappedObj, options);
7591
+ }
7592
+ return view.buffer;
7593
+ },
7594
+ packInto(obj, view, offset2, options) {
7595
+ let mappedObj = obj;
7596
+ if (structDefOptions?.mapValue) {
7597
+ mappedObj = structDefOptions.mapValue(obj);
7598
+ }
7599
+ for (const field of layout) {
7600
+ const value = mappedObj[field.name] ?? field.default;
7601
+ if (!field.optional && value === undefined) {
7602
+ console.warn(`packInto missing value for non-optional field '${field.name}' at offset ${offset2 + field.offset}. Writing default or zero.`);
7603
+ }
7604
+ if (field.validate) {
7605
+ for (const validateFn of field.validate) {
7606
+ validateFn(value, field.name, {
7607
+ hints: options?.validationHints,
7608
+ input: mappedObj
7609
+ });
7610
+ }
7611
+ }
7612
+ field.pack(view, offset2 + field.offset, value, mappedObj, options);
7613
+ }
7614
+ },
7615
+ unpack(buf) {
7616
+ if (buf.byteLength < totalSize) {
7617
+ fatalError(`Buffer size (${buf.byteLength}) is smaller than struct size (${totalSize}) for unpacking.`);
7618
+ }
7619
+ const view = new DataView(buf);
7620
+ const result = structDefOptions?.default ? { ...structDefOptions.default } : {};
7621
+ for (const field of layout) {
7622
+ if (!field.unpack) {
7623
+ continue;
7624
+ }
7625
+ try {
7626
+ result[field.name] = field.unpack(view, field.offset);
7627
+ } catch (e) {
7628
+ console.error(`Error unpacking field '${field.name}' at offset ${field.offset}:`, e);
7629
+ throw e;
7630
+ }
7631
+ }
7632
+ if (structDefOptions?.reduceValue) {
7633
+ return structDefOptions.reduceValue(result);
7634
+ }
7635
+ return result;
7636
+ },
7637
+ packList(objects, options) {
7638
+ if (objects.length === 0) {
7639
+ return new ArrayBuffer(0);
7640
+ }
7641
+ const buffer = new ArrayBuffer(totalSize * objects.length);
7642
+ const view = new DataView(buffer);
7643
+ for (let i = 0;i < objects.length; i++) {
7644
+ let mappedObj = objects[i];
7645
+ if (structDefOptions?.mapValue) {
7646
+ mappedObj = structDefOptions.mapValue(objects[i]);
7647
+ }
7648
+ for (const field of layout) {
7649
+ const value = mappedObj[field.name] ?? field.default;
7650
+ if (!field.optional && value === undefined) {
7651
+ fatalError(`Packing non-optional field '${field.name}' at index ${i} but value is undefined (and no default provided)`);
7652
+ }
7653
+ if (field.validate) {
7654
+ for (const validateFn of field.validate) {
7655
+ validateFn(value, field.name, {
7656
+ hints: options?.validationHints,
7657
+ input: mappedObj
7658
+ });
7659
+ }
7660
+ }
7661
+ field.pack(view, i * totalSize + field.offset, value, mappedObj, options);
7662
+ }
7663
+ }
7664
+ return buffer;
7665
+ },
7666
+ unpackList(buf, count) {
7667
+ if (count === 0) {
7668
+ return [];
7669
+ }
7670
+ const expectedSize = totalSize * count;
7671
+ if (buf.byteLength < expectedSize) {
7672
+ fatalError(`Buffer size (${buf.byteLength}) is smaller than expected size (${expectedSize}) for unpacking ${count} structs.`);
7673
+ }
7674
+ const view = new DataView(buf);
7675
+ const results = [];
7676
+ for (let i = 0;i < count; i++) {
7677
+ const offset2 = i * totalSize;
7678
+ const result = structDefOptions?.default ? { ...structDefOptions.default } : {};
7679
+ for (const field of layout) {
7680
+ if (!field.unpack) {
7681
+ continue;
7682
+ }
7683
+ try {
7684
+ result[field.name] = field.unpack(view, offset2 + field.offset);
7685
+ } catch (e) {
7686
+ console.error(`Error unpacking field '${field.name}' at index ${i}, offset ${offset2 + field.offset}:`, e);
7687
+ throw e;
7688
+ }
7689
+ }
7690
+ if (structDefOptions?.reduceValue) {
7691
+ results.push(structDefOptions.reduceValue(result));
7692
+ } else {
7693
+ results.push(result);
7694
+ }
7695
+ }
7696
+ return results;
7697
+ },
7698
+ describe() {
7699
+ return description;
7700
+ }
7701
+ };
7702
+ }
7703
+
7704
+ // src/zig-structs.ts
7705
+ import { ptr as ptr2, toArrayBuffer as toArrayBuffer3 } from "bun:ffi";
7706
+ var rgbaPackTransform = (rgba) => rgba ? ptr2(rgba.buffer) : null;
7707
+ var rgbaUnpackTransform = (ptr3) => ptr3 ? RGBA.fromArray(new Float32Array(toArrayBuffer3(ptr3))) : undefined;
7708
+ var StyledChunkStruct = defineStruct([
7709
+ ["text", "char*"],
7710
+ ["text_len", "u64", { lengthOf: "text" }],
7711
+ [
7712
+ "fg",
7713
+ "pointer",
7714
+ {
7715
+ optional: true,
7716
+ packTransform: rgbaPackTransform,
7717
+ unpackTransform: rgbaUnpackTransform
7718
+ }
7719
+ ],
7720
+ [
7721
+ "bg",
7722
+ "pointer",
7723
+ {
7724
+ optional: true,
7725
+ packTransform: rgbaPackTransform,
7726
+ unpackTransform: rgbaUnpackTransform
7727
+ }
7728
+ ],
7729
+ ["attributes", "u8", { optional: true }]
7730
+ ]);
7731
+ var HighlightStruct = defineStruct([
7732
+ ["start", "u32"],
7733
+ ["end", "u32"],
7734
+ ["styleId", "u32"],
7735
+ ["priority", "u8", { default: 0 }],
7736
+ ["hlRef", "u16", { default: 0 }]
7737
+ ]);
7738
+ var LogicalCursorStruct = defineStruct([
7739
+ ["row", "u32"],
7740
+ ["col", "u32"],
7741
+ ["offset", "u32"]
7742
+ ]);
7743
+ var VisualCursorStruct = defineStruct([
7744
+ ["visualRow", "u32"],
7745
+ ["visualCol", "u32"],
7746
+ ["logicalRow", "u32"],
7747
+ ["logicalCol", "u32"],
7748
+ ["offset", "u32"]
7749
+ ]);
7750
+
7751
+ // src/zig.ts
7752
+ var module = await import(`@opentui/core-${process.platform}-${process.arch}/index.ts`);
7753
+ var targetLibPath = module.default;
7754
+ if (/\$bunfs/.test(targetLibPath)) {
6460
7755
  targetLibPath = targetLibPath.replace("../", "");
6461
7756
  }
6462
7757
  if (!existsSync2(targetLibPath)) {
@@ -6481,6 +7776,10 @@ function getOpenTUILib(libPath) {
6481
7776
  args: ["ptr"],
6482
7777
  returns: "void"
6483
7778
  },
7779
+ setEventCallback: {
7780
+ args: ["ptr"],
7781
+ returns: "void"
7782
+ },
6484
7783
  createRenderer: {
6485
7784
  args: ["u32", "u32", "bool"],
6486
7785
  returns: "ptr"
@@ -6709,15 +8008,15 @@ function getOpenTUILib(libPath) {
6709
8008
  args: ["ptr"],
6710
8009
  returns: "u32"
6711
8010
  },
6712
- textBufferReset: {
8011
+ textBufferGetByteSize: {
6713
8012
  args: ["ptr"],
6714
- returns: "void"
8013
+ returns: "u32"
6715
8014
  },
6716
- textBufferSetSelection: {
6717
- args: ["ptr", "u32", "u32", "ptr", "ptr"],
8015
+ textBufferReset: {
8016
+ args: ["ptr"],
6718
8017
  returns: "void"
6719
8018
  },
6720
- textBufferResetSelection: {
8019
+ textBufferClear: {
6721
8020
  args: ["ptr"],
6722
8021
  returns: "void"
6723
8022
  },
@@ -6737,74 +8036,402 @@ function getOpenTUILib(libPath) {
6737
8036
  args: ["ptr"],
6738
8037
  returns: "void"
6739
8038
  },
6740
- textBufferWriteChunk: {
6741
- args: ["ptr", "ptr", "u32", "ptr", "ptr", "ptr"],
6742
- returns: "u32"
8039
+ textBufferRegisterMemBuffer: {
8040
+ args: ["ptr", "ptr", "usize", "bool"],
8041
+ returns: "u16"
6743
8042
  },
6744
- textBufferFinalizeLineInfo: {
8043
+ textBufferReplaceMemBuffer: {
8044
+ args: ["ptr", "u8", "ptr", "usize", "bool"],
8045
+ returns: "bool"
8046
+ },
8047
+ textBufferClearMemRegistry: {
6745
8048
  args: ["ptr"],
6746
8049
  returns: "void"
6747
8050
  },
8051
+ textBufferSetTextFromMem: {
8052
+ args: ["ptr", "u8"],
8053
+ returns: "void"
8054
+ },
8055
+ textBufferLoadFile: {
8056
+ args: ["ptr", "ptr", "usize"],
8057
+ returns: "bool"
8058
+ },
8059
+ textBufferSetStyledText: {
8060
+ args: ["ptr", "ptr", "usize"],
8061
+ returns: "void"
8062
+ },
6748
8063
  textBufferGetLineCount: {
6749
8064
  args: ["ptr"],
6750
8065
  returns: "u32"
6751
8066
  },
6752
- textBufferGetLineInfoDirect: {
6753
- args: ["ptr", "ptr", "ptr"],
6754
- returns: "u32"
8067
+ textBufferGetPlainText: {
8068
+ args: ["ptr", "ptr", "usize"],
8069
+ returns: "usize"
8070
+ },
8071
+ textBufferAddHighlightByCharRange: {
8072
+ args: ["ptr", "ptr"],
8073
+ returns: "void"
8074
+ },
8075
+ textBufferAddHighlight: {
8076
+ args: ["ptr", "u32", "ptr"],
8077
+ returns: "void"
6755
8078
  },
6756
- textBufferGetSelectionInfo: {
8079
+ textBufferRemoveHighlightsByRef: {
8080
+ args: ["ptr", "u16"],
8081
+ returns: "void"
8082
+ },
8083
+ textBufferClearLineHighlights: {
8084
+ args: ["ptr", "u32"],
8085
+ returns: "void"
8086
+ },
8087
+ textBufferClearAllHighlights: {
8088
+ args: ["ptr"],
8089
+ returns: "void"
8090
+ },
8091
+ textBufferSetSyntaxStyle: {
8092
+ args: ["ptr", "ptr"],
8093
+ returns: "void"
8094
+ },
8095
+ textBufferGetLineHighlightsPtr: {
8096
+ args: ["ptr", "u32", "ptr"],
8097
+ returns: "ptr"
8098
+ },
8099
+ textBufferFreeLineHighlights: {
8100
+ args: ["ptr", "usize"],
8101
+ returns: "void"
8102
+ },
8103
+ createTextBufferView: {
8104
+ args: ["ptr"],
8105
+ returns: "ptr"
8106
+ },
8107
+ destroyTextBufferView: {
8108
+ args: ["ptr"],
8109
+ returns: "void"
8110
+ },
8111
+ textBufferViewSetSelection: {
8112
+ args: ["ptr", "u32", "u32", "ptr", "ptr"],
8113
+ returns: "void"
8114
+ },
8115
+ textBufferViewResetSelection: {
8116
+ args: ["ptr"],
8117
+ returns: "void"
8118
+ },
8119
+ textBufferViewGetSelectionInfo: {
6757
8120
  args: ["ptr"],
6758
8121
  returns: "u64"
6759
8122
  },
6760
- textBufferGetSelectedText: {
8123
+ textBufferViewSetLocalSelection: {
8124
+ args: ["ptr", "i32", "i32", "i32", "i32", "ptr", "ptr"],
8125
+ returns: "bool"
8126
+ },
8127
+ textBufferViewResetLocalSelection: {
8128
+ args: ["ptr"],
8129
+ returns: "void"
8130
+ },
8131
+ textBufferViewSetWrapWidth: {
8132
+ args: ["ptr", "u32"],
8133
+ returns: "void"
8134
+ },
8135
+ textBufferViewSetWrapMode: {
8136
+ args: ["ptr", "u8"],
8137
+ returns: "void"
8138
+ },
8139
+ textBufferViewSetViewportSize: {
8140
+ args: ["ptr", "u32", "u32"],
8141
+ returns: "void"
8142
+ },
8143
+ textBufferViewGetVirtualLineCount: {
8144
+ args: ["ptr"],
8145
+ returns: "u32"
8146
+ },
8147
+ textBufferViewGetLineInfoDirect: {
8148
+ args: ["ptr", "ptr", "ptr"],
8149
+ returns: "u32"
8150
+ },
8151
+ textBufferViewGetLogicalLineInfoDirect: {
8152
+ args: ["ptr", "ptr", "ptr"],
8153
+ returns: "u32"
8154
+ },
8155
+ textBufferViewGetSelectedText: {
6761
8156
  args: ["ptr", "ptr", "usize"],
6762
8157
  returns: "usize"
6763
8158
  },
6764
- textBufferGetPlainText: {
8159
+ textBufferViewGetPlainText: {
6765
8160
  args: ["ptr", "ptr", "usize"],
6766
8161
  returns: "usize"
6767
8162
  },
6768
- textBufferSetLocalSelection: {
6769
- args: ["ptr", "i32", "i32", "i32", "i32", "ptr", "ptr"],
6770
- returns: "bool"
8163
+ bufferDrawTextBufferView: {
8164
+ args: ["ptr", "ptr", "i32", "i32"],
8165
+ returns: "void"
8166
+ },
8167
+ bufferDrawEditorView: {
8168
+ args: ["ptr", "ptr", "i32", "i32"],
8169
+ returns: "void"
8170
+ },
8171
+ createEditorView: {
8172
+ args: ["ptr", "u32", "u32"],
8173
+ returns: "ptr"
6771
8174
  },
6772
- textBufferResetLocalSelection: {
8175
+ destroyEditorView: {
6773
8176
  args: ["ptr"],
6774
8177
  returns: "void"
6775
8178
  },
6776
- textBufferInsertChunkGroup: {
6777
- args: ["ptr", "usize", "ptr", "u32", "ptr", "ptr", "u8"],
6778
- returns: "u32"
8179
+ editorViewSetViewportSize: {
8180
+ args: ["ptr", "u32", "u32"],
8181
+ returns: "void"
6779
8182
  },
6780
- textBufferRemoveChunkGroup: {
6781
- args: ["ptr", "usize"],
8183
+ editorViewGetViewport: {
8184
+ args: ["ptr", "ptr", "ptr", "ptr", "ptr"],
8185
+ returns: "void"
8186
+ },
8187
+ editorViewSetScrollMargin: {
8188
+ args: ["ptr", "f32"],
8189
+ returns: "void"
8190
+ },
8191
+ editorViewSetWrapMode: {
8192
+ args: ["ptr", "u8"],
8193
+ returns: "void"
8194
+ },
8195
+ editorViewGetVirtualLineCount: {
8196
+ args: ["ptr"],
6782
8197
  returns: "u32"
6783
8198
  },
6784
- textBufferReplaceChunkGroup: {
6785
- args: ["ptr", "usize", "ptr", "u32", "ptr", "ptr", "u8"],
8199
+ editorViewGetTotalVirtualLineCount: {
8200
+ args: ["ptr"],
6786
8201
  returns: "u32"
6787
8202
  },
6788
- textBufferGetChunkGroupCount: {
8203
+ editorViewGetTextBufferView: {
8204
+ args: ["ptr"],
8205
+ returns: "ptr"
8206
+ },
8207
+ createEditBuffer: {
8208
+ args: ["u8"],
8209
+ returns: "ptr"
8210
+ },
8211
+ destroyEditBuffer: {
6789
8212
  args: ["ptr"],
8213
+ returns: "void"
8214
+ },
8215
+ editBufferSetText: {
8216
+ args: ["ptr", "ptr", "usize", "bool"],
8217
+ returns: "void"
8218
+ },
8219
+ editBufferSetTextFromMem: {
8220
+ args: ["ptr", "u8", "bool"],
8221
+ returns: "void"
8222
+ },
8223
+ editBufferGetText: {
8224
+ args: ["ptr", "ptr", "usize"],
6790
8225
  returns: "usize"
6791
8226
  },
6792
- textBufferSetWrapWidth: {
6793
- args: ["ptr", "u32"],
8227
+ editBufferInsertChar: {
8228
+ args: ["ptr", "ptr", "usize"],
8229
+ returns: "void"
8230
+ },
8231
+ editBufferInsertText: {
8232
+ args: ["ptr", "ptr", "usize"],
8233
+ returns: "void"
8234
+ },
8235
+ editBufferDeleteChar: {
8236
+ args: ["ptr"],
8237
+ returns: "void"
8238
+ },
8239
+ editBufferDeleteCharBackward: {
8240
+ args: ["ptr"],
8241
+ returns: "void"
8242
+ },
8243
+ editBufferDeleteRange: {
8244
+ args: ["ptr", "u32", "u32", "u32", "u32"],
8245
+ returns: "void"
8246
+ },
8247
+ editBufferNewLine: {
8248
+ args: ["ptr"],
8249
+ returns: "void"
8250
+ },
8251
+ editBufferDeleteLine: {
8252
+ args: ["ptr"],
8253
+ returns: "void"
8254
+ },
8255
+ editBufferMoveCursorLeft: {
8256
+ args: ["ptr"],
8257
+ returns: "void"
8258
+ },
8259
+ editBufferMoveCursorRight: {
8260
+ args: ["ptr"],
8261
+ returns: "void"
8262
+ },
8263
+ editBufferMoveCursorUp: {
8264
+ args: ["ptr"],
8265
+ returns: "void"
8266
+ },
8267
+ editBufferMoveCursorDown: {
8268
+ args: ["ptr"],
8269
+ returns: "void"
8270
+ },
8271
+ editBufferGotoLine: {
8272
+ args: ["ptr", "u32"],
8273
+ returns: "void"
8274
+ },
8275
+ editBufferSetCursor: {
8276
+ args: ["ptr", "u32", "u32"],
8277
+ returns: "void"
8278
+ },
8279
+ editBufferSetCursorToLineCol: {
8280
+ args: ["ptr", "u32", "u32"],
8281
+ returns: "void"
8282
+ },
8283
+ editBufferSetCursorByOffset: {
8284
+ args: ["ptr", "u32"],
8285
+ returns: "void"
8286
+ },
8287
+ editBufferGetCursorPosition: {
8288
+ args: ["ptr", "ptr"],
8289
+ returns: "void"
8290
+ },
8291
+ editBufferGetId: {
8292
+ args: ["ptr"],
8293
+ returns: "u16"
8294
+ },
8295
+ editBufferGetTextBuffer: {
8296
+ args: ["ptr"],
8297
+ returns: "ptr"
8298
+ },
8299
+ editBufferDebugLogRope: {
8300
+ args: ["ptr"],
8301
+ returns: "void"
8302
+ },
8303
+ editBufferUndo: {
8304
+ args: ["ptr", "ptr", "usize"],
8305
+ returns: "usize"
8306
+ },
8307
+ editBufferRedo: {
8308
+ args: ["ptr", "ptr", "usize"],
8309
+ returns: "usize"
8310
+ },
8311
+ editBufferCanUndo: {
8312
+ args: ["ptr"],
8313
+ returns: "bool"
8314
+ },
8315
+ editBufferCanRedo: {
8316
+ args: ["ptr"],
8317
+ returns: "bool"
8318
+ },
8319
+ editBufferClearHistory: {
8320
+ args: ["ptr"],
8321
+ returns: "void"
8322
+ },
8323
+ editBufferSetPlaceholder: {
8324
+ args: ["ptr", "ptr", "usize"],
8325
+ returns: "void"
8326
+ },
8327
+ editBufferSetPlaceholderColor: {
8328
+ args: ["ptr", "ptr"],
8329
+ returns: "void"
8330
+ },
8331
+ editBufferClear: {
8332
+ args: ["ptr"],
8333
+ returns: "void"
8334
+ },
8335
+ editBufferGetNextWordBoundary: {
8336
+ args: ["ptr", "ptr"],
8337
+ returns: "void"
8338
+ },
8339
+ editBufferGetPrevWordBoundary: {
8340
+ args: ["ptr", "ptr"],
8341
+ returns: "void"
8342
+ },
8343
+ editBufferGetEOL: {
8344
+ args: ["ptr", "ptr"],
8345
+ returns: "void"
8346
+ },
8347
+ editorViewSetSelection: {
8348
+ args: ["ptr", "u32", "u32", "ptr", "ptr"],
8349
+ returns: "void"
8350
+ },
8351
+ editorViewResetSelection: {
8352
+ args: ["ptr"],
8353
+ returns: "void"
8354
+ },
8355
+ editorViewGetSelection: {
8356
+ args: ["ptr"],
8357
+ returns: "u64"
8358
+ },
8359
+ editorViewSetLocalSelection: {
8360
+ args: ["ptr", "i32", "i32", "i32", "i32", "ptr", "ptr"],
8361
+ returns: "bool"
8362
+ },
8363
+ editorViewResetLocalSelection: {
8364
+ args: ["ptr"],
8365
+ returns: "void"
8366
+ },
8367
+ editorViewGetSelectedTextBytes: {
8368
+ args: ["ptr", "ptr", "usize"],
8369
+ returns: "usize"
8370
+ },
8371
+ editorViewGetCursor: {
8372
+ args: ["ptr", "ptr", "ptr"],
8373
+ returns: "void"
8374
+ },
8375
+ editorViewGetText: {
8376
+ args: ["ptr", "ptr", "usize"],
8377
+ returns: "usize"
8378
+ },
8379
+ editorViewGetVisualCursor: {
8380
+ args: ["ptr", "ptr"],
8381
+ returns: "void"
8382
+ },
8383
+ editorViewMoveUpVisual: {
8384
+ args: ["ptr"],
8385
+ returns: "void"
8386
+ },
8387
+ editorViewMoveDownVisual: {
8388
+ args: ["ptr"],
8389
+ returns: "void"
8390
+ },
8391
+ editorViewDeleteSelectedText: {
8392
+ args: ["ptr"],
8393
+ returns: "void"
8394
+ },
8395
+ editorViewSetCursorByOffset: {
8396
+ args: ["ptr", "u32"],
8397
+ returns: "void"
8398
+ },
8399
+ editorViewGetNextWordBoundary: {
8400
+ args: ["ptr", "ptr"],
8401
+ returns: "void"
8402
+ },
8403
+ editorViewGetPrevWordBoundary: {
8404
+ args: ["ptr", "ptr"],
6794
8405
  returns: "void"
6795
8406
  },
6796
- textBufferSetWrapMode: {
6797
- args: ["ptr", "u8"],
8407
+ editorViewGetEOL: {
8408
+ args: ["ptr", "ptr"],
6798
8409
  returns: "void"
6799
8410
  },
6800
8411
  getArenaAllocatedBytes: {
6801
8412
  args: [],
6802
8413
  returns: "usize"
6803
8414
  },
6804
- bufferDrawTextBuffer: {
6805
- args: ["ptr", "ptr", "i32", "i32", "i32", "i32", "u32", "u32", "bool"],
8415
+ createSyntaxStyle: {
8416
+ args: [],
8417
+ returns: "ptr"
8418
+ },
8419
+ destroySyntaxStyle: {
8420
+ args: ["ptr"],
6806
8421
  returns: "void"
6807
8422
  },
8423
+ syntaxStyleRegister: {
8424
+ args: ["ptr", "ptr", "usize", "ptr", "ptr", "u8"],
8425
+ returns: "u32"
8426
+ },
8427
+ syntaxStyleResolveByName: {
8428
+ args: ["ptr", "ptr", "usize"],
8429
+ returns: "u32"
8430
+ },
8431
+ syntaxStyleGetStyleCount: {
8432
+ args: ["ptr"],
8433
+ returns: "usize"
8434
+ },
6808
8435
  getTerminalCapabilities: {
6809
8436
  args: ["ptr", "ptr"],
6810
8437
  returns: "void"
@@ -6937,9 +8564,13 @@ class FFIRenderLib {
6937
8564
  encoder = new TextEncoder;
6938
8565
  decoder = new TextDecoder;
6939
8566
  logCallbackWrapper;
8567
+ eventCallbackWrapper;
8568
+ _nativeEvents = new EventEmitter5;
8569
+ _anyEventHandlers = [];
6940
8570
  constructor(libPath) {
6941
8571
  this.opentui = getOpenTUILib(libPath);
6942
8572
  this.setupLogging();
8573
+ this.setupEventBus();
6943
8574
  }
6944
8575
  setupLogging() {
6945
8576
  if (this.logCallbackWrapper) {
@@ -6951,7 +8582,7 @@ class FFIRenderLib {
6951
8582
  if (msgLen === 0 || !msgPtr) {
6952
8583
  return;
6953
8584
  }
6954
- const msgBuffer = toArrayBuffer2(msgPtr, 0, msgLen);
8585
+ const msgBuffer = toArrayBuffer4(msgPtr, 0, msgLen);
6955
8586
  const msgBytes = new Uint8Array(msgBuffer);
6956
8587
  const message = this.decoder.decode(msgBytes);
6957
8588
  switch (level) {
@@ -6986,6 +8617,48 @@ class FFIRenderLib {
6986
8617
  setLogCallback(callbackPtr) {
6987
8618
  this.opentui.symbols.setLogCallback(callbackPtr);
6988
8619
  }
8620
+ setupEventBus() {
8621
+ if (this.eventCallbackWrapper) {
8622
+ return;
8623
+ }
8624
+ const eventCallback = new JSCallback((namePtr, nameLenBigInt, dataPtr, dataLenBigInt) => {
8625
+ try {
8626
+ const nameLen = typeof nameLenBigInt === "bigint" ? Number(nameLenBigInt) : nameLenBigInt;
8627
+ const dataLen = typeof dataLenBigInt === "bigint" ? Number(dataLenBigInt) : dataLenBigInt;
8628
+ if (nameLen === 0 || !namePtr) {
8629
+ return;
8630
+ }
8631
+ const nameBuffer = toArrayBuffer4(namePtr, 0, nameLen);
8632
+ const nameBytes = new Uint8Array(nameBuffer);
8633
+ const eventName = this.decoder.decode(nameBytes);
8634
+ let eventData;
8635
+ if (dataLen > 0 && dataPtr) {
8636
+ eventData = toArrayBuffer4(dataPtr, 0, dataLen).slice();
8637
+ } else {
8638
+ eventData = new ArrayBuffer(0);
8639
+ }
8640
+ queueMicrotask(() => {
8641
+ this._nativeEvents.emit(eventName, eventData);
8642
+ for (const handler of this._anyEventHandlers) {
8643
+ handler(eventName, eventData);
8644
+ }
8645
+ });
8646
+ } catch (error) {
8647
+ console.error("Error in native event callback:", error);
8648
+ }
8649
+ }, {
8650
+ args: ["ptr", "usize", "ptr", "usize"],
8651
+ returns: "void"
8652
+ });
8653
+ this.eventCallbackWrapper = eventCallback;
8654
+ if (!eventCallback.ptr) {
8655
+ throw new Error("Failed to create event callback");
8656
+ }
8657
+ this.setEventCallback(eventCallback.ptr);
8658
+ }
8659
+ setEventCallback(callbackPtr) {
8660
+ this.opentui.symbols.setEventCallback(callbackPtr);
8661
+ }
6989
8662
  createRenderer(width, height, options = { testing: false }) {
6990
8663
  return this.opentui.symbols.createRenderer(width, height, options.testing);
6991
8664
  }
@@ -7026,32 +8699,32 @@ class FFIRenderLib {
7026
8699
  return new OptimizedBuffer(this, bufferPtr, width, height, { id: "current buffer" });
7027
8700
  }
7028
8701
  bufferGetCharPtr(buffer) {
7029
- const ptr2 = this.opentui.symbols.bufferGetCharPtr(buffer);
7030
- if (!ptr2) {
8702
+ const ptr4 = this.opentui.symbols.bufferGetCharPtr(buffer);
8703
+ if (!ptr4) {
7031
8704
  throw new Error("Failed to get char pointer");
7032
8705
  }
7033
- return ptr2;
8706
+ return ptr4;
7034
8707
  }
7035
8708
  bufferGetFgPtr(buffer) {
7036
- const ptr2 = this.opentui.symbols.bufferGetFgPtr(buffer);
7037
- if (!ptr2) {
8709
+ const ptr4 = this.opentui.symbols.bufferGetFgPtr(buffer);
8710
+ if (!ptr4) {
7038
8711
  throw new Error("Failed to get fg pointer");
7039
8712
  }
7040
- return ptr2;
8713
+ return ptr4;
7041
8714
  }
7042
8715
  bufferGetBgPtr(buffer) {
7043
- const ptr2 = this.opentui.symbols.bufferGetBgPtr(buffer);
7044
- if (!ptr2) {
8716
+ const ptr4 = this.opentui.symbols.bufferGetBgPtr(buffer);
8717
+ if (!ptr4) {
7045
8718
  throw new Error("Failed to get bg pointer");
7046
8719
  }
7047
- return ptr2;
8720
+ return ptr4;
7048
8721
  }
7049
8722
  bufferGetAttributesPtr(buffer) {
7050
- const ptr2 = this.opentui.symbols.bufferGetAttributesPtr(buffer);
7051
- if (!ptr2) {
8723
+ const ptr4 = this.opentui.symbols.bufferGetAttributesPtr(buffer);
8724
+ if (!ptr4) {
7052
8725
  throw new Error("Failed to get attributes pointer");
7053
8726
  }
7054
- return ptr2;
8727
+ return ptr4;
7055
8728
  }
7056
8729
  bufferGetRespectAlpha(buffer) {
7057
8730
  return this.opentui.symbols.bufferGetRespectAlpha(buffer);
@@ -7124,142 +8797,520 @@ class FFIRenderLib {
7124
8797
  resizeRenderer(renderer, width, height) {
7125
8798
  this.opentui.symbols.resizeRenderer(renderer, width, height);
7126
8799
  }
7127
- setCursorPosition(renderer, x, y, visible) {
7128
- this.opentui.symbols.setCursorPosition(renderer, x, y, visible);
8800
+ setCursorPosition(renderer, x, y, visible) {
8801
+ this.opentui.symbols.setCursorPosition(renderer, x, y, visible);
8802
+ }
8803
+ setCursorStyle(renderer, style, blinking) {
8804
+ const stylePtr = this.encoder.encode(style);
8805
+ this.opentui.symbols.setCursorStyle(renderer, stylePtr, style.length, blinking);
8806
+ }
8807
+ setCursorColor(renderer, color) {
8808
+ this.opentui.symbols.setCursorColor(renderer, color.buffer);
8809
+ }
8810
+ render(renderer, force) {
8811
+ this.opentui.symbols.render(renderer, force);
8812
+ }
8813
+ createOptimizedBuffer(width, height, widthMethod, respectAlpha = false, id) {
8814
+ if (Number.isNaN(width) || Number.isNaN(height)) {
8815
+ console.error(new Error(`Invalid dimensions for OptimizedBuffer: ${width}x${height}`).stack);
8816
+ }
8817
+ const widthMethodCode = widthMethod === "wcwidth" ? 0 : 1;
8818
+ const idToUse = id || "unnamed buffer";
8819
+ const idBytes = this.encoder.encode(idToUse);
8820
+ const bufferPtr = this.opentui.symbols.createOptimizedBuffer(width, height, respectAlpha, widthMethodCode, idBytes, idBytes.length);
8821
+ if (!bufferPtr) {
8822
+ throw new Error(`Failed to create optimized buffer: ${width}x${height}`);
8823
+ }
8824
+ return new OptimizedBuffer(this, bufferPtr, width, height, { respectAlpha, id });
8825
+ }
8826
+ destroyOptimizedBuffer(bufferPtr) {
8827
+ this.opentui.symbols.destroyOptimizedBuffer(bufferPtr);
8828
+ }
8829
+ drawFrameBuffer(targetBufferPtr, destX, destY, bufferPtr, sourceX, sourceY, sourceWidth, sourceHeight) {
8830
+ const srcX = sourceX ?? 0;
8831
+ const srcY = sourceY ?? 0;
8832
+ const srcWidth = sourceWidth ?? 0;
8833
+ const srcHeight = sourceHeight ?? 0;
8834
+ this.opentui.symbols.drawFrameBuffer(targetBufferPtr, destX, destY, bufferPtr, srcX, srcY, srcWidth, srcHeight);
8835
+ }
8836
+ setDebugOverlay(renderer, enabled, corner) {
8837
+ this.opentui.symbols.setDebugOverlay(renderer, enabled, corner);
8838
+ }
8839
+ clearTerminal(renderer) {
8840
+ this.opentui.symbols.clearTerminal(renderer);
8841
+ }
8842
+ setTerminalTitle(renderer, title) {
8843
+ const titleBytes = this.encoder.encode(title);
8844
+ this.opentui.symbols.setTerminalTitle(renderer, titleBytes, titleBytes.length);
8845
+ }
8846
+ addToHitGrid(renderer, x, y, width, height, id) {
8847
+ this.opentui.symbols.addToHitGrid(renderer, x, y, width, height, id);
8848
+ }
8849
+ checkHit(renderer, x, y) {
8850
+ return this.opentui.symbols.checkHit(renderer, x, y);
8851
+ }
8852
+ dumpHitGrid(renderer) {
8853
+ this.opentui.symbols.dumpHitGrid(renderer);
8854
+ }
8855
+ dumpBuffers(renderer, timestamp) {
8856
+ const ts = timestamp ?? Date.now();
8857
+ this.opentui.symbols.dumpBuffers(renderer, ts);
8858
+ }
8859
+ dumpStdoutBuffer(renderer, timestamp) {
8860
+ const ts = timestamp ?? Date.now();
8861
+ this.opentui.symbols.dumpStdoutBuffer(renderer, ts);
8862
+ }
8863
+ enableMouse(renderer, enableMovement) {
8864
+ this.opentui.symbols.enableMouse(renderer, enableMovement);
8865
+ }
8866
+ disableMouse(renderer) {
8867
+ this.opentui.symbols.disableMouse(renderer);
8868
+ }
8869
+ enableKittyKeyboard(renderer, flags) {
8870
+ this.opentui.symbols.enableKittyKeyboard(renderer, flags);
8871
+ }
8872
+ disableKittyKeyboard(renderer) {
8873
+ this.opentui.symbols.disableKittyKeyboard(renderer);
8874
+ }
8875
+ setupTerminal(renderer, useAlternateScreen) {
8876
+ this.opentui.symbols.setupTerminal(renderer, useAlternateScreen);
8877
+ }
8878
+ queryPixelResolution(renderer) {
8879
+ this.opentui.symbols.queryPixelResolution(renderer);
8880
+ }
8881
+ createTextBuffer(widthMethod) {
8882
+ const widthMethodCode = widthMethod === "wcwidth" ? 0 : 1;
8883
+ const bufferPtr = this.opentui.symbols.createTextBuffer(widthMethodCode);
8884
+ if (!bufferPtr) {
8885
+ throw new Error(`Failed to create TextBuffer`);
8886
+ }
8887
+ return new TextBuffer(this, bufferPtr);
8888
+ }
8889
+ destroyTextBuffer(buffer) {
8890
+ this.opentui.symbols.destroyTextBuffer(buffer);
8891
+ }
8892
+ textBufferGetLength(buffer) {
8893
+ return this.opentui.symbols.textBufferGetLength(buffer);
8894
+ }
8895
+ textBufferGetByteSize(buffer) {
8896
+ return this.opentui.symbols.textBufferGetByteSize(buffer);
8897
+ }
8898
+ textBufferReset(buffer) {
8899
+ this.opentui.symbols.textBufferReset(buffer);
8900
+ }
8901
+ textBufferClear(buffer) {
8902
+ this.opentui.symbols.textBufferClear(buffer);
8903
+ }
8904
+ textBufferSetDefaultFg(buffer, fg2) {
8905
+ const fgPtr = fg2 ? fg2.buffer : null;
8906
+ this.opentui.symbols.textBufferSetDefaultFg(buffer, fgPtr);
8907
+ }
8908
+ textBufferSetDefaultBg(buffer, bg2) {
8909
+ const bgPtr = bg2 ? bg2.buffer : null;
8910
+ this.opentui.symbols.textBufferSetDefaultBg(buffer, bgPtr);
8911
+ }
8912
+ textBufferSetDefaultAttributes(buffer, attributes) {
8913
+ const attrValue = attributes === null ? null : new Uint8Array([attributes]);
8914
+ this.opentui.symbols.textBufferSetDefaultAttributes(buffer, attrValue);
8915
+ }
8916
+ textBufferResetDefaults(buffer) {
8917
+ this.opentui.symbols.textBufferResetDefaults(buffer);
8918
+ }
8919
+ textBufferRegisterMemBuffer(buffer, bytes, owned = false) {
8920
+ const result = this.opentui.symbols.textBufferRegisterMemBuffer(buffer, bytes, bytes.length, owned);
8921
+ if (result === 65535) {
8922
+ throw new Error("Failed to register memory buffer");
8923
+ }
8924
+ return result;
8925
+ }
8926
+ textBufferReplaceMemBuffer(buffer, memId, bytes, owned = false) {
8927
+ return this.opentui.symbols.textBufferReplaceMemBuffer(buffer, memId, bytes, bytes.length, owned);
8928
+ }
8929
+ textBufferClearMemRegistry(buffer) {
8930
+ this.opentui.symbols.textBufferClearMemRegistry(buffer);
8931
+ }
8932
+ textBufferSetTextFromMem(buffer, memId) {
8933
+ this.opentui.symbols.textBufferSetTextFromMem(buffer, memId);
8934
+ }
8935
+ textBufferLoadFile(buffer, path4) {
8936
+ const pathBytes = this.encoder.encode(path4);
8937
+ return this.opentui.symbols.textBufferLoadFile(buffer, pathBytes, pathBytes.length);
8938
+ }
8939
+ textBufferSetStyledText(buffer, chunks) {
8940
+ const nonEmptyChunks = chunks.filter((c) => c.text.length > 0);
8941
+ if (nonEmptyChunks.length === 0) {
8942
+ this.textBufferClear(buffer);
8943
+ return;
8944
+ }
8945
+ const chunksBuffer = StyledChunkStruct.packList(nonEmptyChunks);
8946
+ this.opentui.symbols.textBufferSetStyledText(buffer, ptr3(chunksBuffer), nonEmptyChunks.length);
8947
+ }
8948
+ textBufferGetLineCount(buffer) {
8949
+ return this.opentui.symbols.textBufferGetLineCount(buffer);
8950
+ }
8951
+ textBufferGetPlainText(buffer, outPtr, maxLen) {
8952
+ const result = this.opentui.symbols.textBufferGetPlainText(buffer, outPtr, maxLen);
8953
+ return typeof result === "bigint" ? Number(result) : result;
8954
+ }
8955
+ getPlainTextBytes(buffer, maxLength) {
8956
+ const outBuffer = new Uint8Array(maxLength);
8957
+ const actualLen = this.textBufferGetPlainText(buffer, ptr3(outBuffer), maxLength);
8958
+ if (actualLen === 0) {
8959
+ return null;
8960
+ }
8961
+ return outBuffer.slice(0, actualLen);
8962
+ }
8963
+ createTextBufferView(textBuffer) {
8964
+ const viewPtr = this.opentui.symbols.createTextBufferView(textBuffer);
8965
+ if (!viewPtr) {
8966
+ throw new Error("Failed to create TextBufferView");
8967
+ }
8968
+ return viewPtr;
8969
+ }
8970
+ destroyTextBufferView(view) {
8971
+ this.opentui.symbols.destroyTextBufferView(view);
8972
+ }
8973
+ textBufferViewSetSelection(view, start, end, bgColor, fgColor) {
8974
+ const bg2 = bgColor ? bgColor.buffer : null;
8975
+ const fg2 = fgColor ? fgColor.buffer : null;
8976
+ this.opentui.symbols.textBufferViewSetSelection(view, start, end, bg2, fg2);
8977
+ }
8978
+ textBufferViewResetSelection(view) {
8979
+ this.opentui.symbols.textBufferViewResetSelection(view);
8980
+ }
8981
+ textBufferViewGetSelection(view) {
8982
+ const packedInfo = this.textBufferViewGetSelectionInfo(view);
8983
+ if (packedInfo === 0xffff_ffff_ffff_ffffn) {
8984
+ return null;
8985
+ }
8986
+ const start = Number(packedInfo >> 32n);
8987
+ const end = Number(packedInfo & 0xffff_ffffn);
8988
+ return { start, end };
8989
+ }
8990
+ textBufferViewGetSelectionInfo(view) {
8991
+ return this.opentui.symbols.textBufferViewGetSelectionInfo(view);
8992
+ }
8993
+ textBufferViewSetLocalSelection(view, anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
8994
+ const bg2 = bgColor ? bgColor.buffer : null;
8995
+ const fg2 = fgColor ? fgColor.buffer : null;
8996
+ return this.opentui.symbols.textBufferViewSetLocalSelection(view, anchorX, anchorY, focusX, focusY, bg2, fg2);
8997
+ }
8998
+ textBufferViewResetLocalSelection(view) {
8999
+ this.opentui.symbols.textBufferViewResetLocalSelection(view);
9000
+ }
9001
+ textBufferViewSetWrapWidth(view, width) {
9002
+ this.opentui.symbols.textBufferViewSetWrapWidth(view, width);
9003
+ }
9004
+ textBufferViewSetWrapMode(view, mode) {
9005
+ const modeValue = mode === "none" ? 0 : mode === "char" ? 1 : 2;
9006
+ this.opentui.symbols.textBufferViewSetWrapMode(view, modeValue);
9007
+ }
9008
+ textBufferViewSetViewportSize(view, width, height) {
9009
+ this.opentui.symbols.textBufferViewSetViewportSize(view, width, height);
9010
+ }
9011
+ textBufferViewGetLineInfo(view) {
9012
+ const lineCount = this.textBufferViewGetLineCount(view);
9013
+ if (lineCount === 0) {
9014
+ return { lineStarts: [], lineWidths: [], maxLineWidth: 0 };
9015
+ }
9016
+ const lineStarts = new Uint32Array(lineCount);
9017
+ const lineWidths = new Uint32Array(lineCount);
9018
+ const maxLineWidth = this.textBufferViewGetLineInfoDirect(view, ptr3(lineStarts), ptr3(lineWidths));
9019
+ return {
9020
+ maxLineWidth,
9021
+ lineStarts: Array.from(lineStarts),
9022
+ lineWidths: Array.from(lineWidths)
9023
+ };
9024
+ }
9025
+ textBufferViewGetLogicalLineInfo(view) {
9026
+ const lineCount = this.textBufferViewGetLineCount(view);
9027
+ if (lineCount === 0) {
9028
+ return { lineStarts: [], lineWidths: [], maxLineWidth: 0 };
9029
+ }
9030
+ const lineStarts = new Uint32Array(lineCount);
9031
+ const lineWidths = new Uint32Array(lineCount);
9032
+ const maxLineWidth = this.textBufferViewGetLogicalLineInfoDirect(view, ptr3(lineStarts), ptr3(lineWidths));
9033
+ return {
9034
+ maxLineWidth,
9035
+ lineStarts: Array.from(lineStarts),
9036
+ lineWidths: Array.from(lineWidths)
9037
+ };
9038
+ }
9039
+ textBufferViewGetLineCount(view) {
9040
+ return this.opentui.symbols.textBufferViewGetVirtualLineCount(view);
9041
+ }
9042
+ textBufferViewGetLineInfoDirect(view, lineStartsPtr, lineWidthsPtr) {
9043
+ return this.opentui.symbols.textBufferViewGetLineInfoDirect(view, lineStartsPtr, lineWidthsPtr);
9044
+ }
9045
+ textBufferViewGetLogicalLineInfoDirect(view, lineStartsPtr, lineWidthsPtr) {
9046
+ return this.opentui.symbols.textBufferViewGetLogicalLineInfoDirect(view, lineStartsPtr, lineWidthsPtr);
9047
+ }
9048
+ textBufferViewGetSelectedText(view, outPtr, maxLen) {
9049
+ const result = this.opentui.symbols.textBufferViewGetSelectedText(view, outPtr, maxLen);
9050
+ return typeof result === "bigint" ? Number(result) : result;
9051
+ }
9052
+ textBufferViewGetPlainText(view, outPtr, maxLen) {
9053
+ const result = this.opentui.symbols.textBufferViewGetPlainText(view, outPtr, maxLen);
9054
+ return typeof result === "bigint" ? Number(result) : result;
9055
+ }
9056
+ textBufferViewGetSelectedTextBytes(view, maxLength) {
9057
+ const outBuffer = new Uint8Array(maxLength);
9058
+ const actualLen = this.textBufferViewGetSelectedText(view, ptr3(outBuffer), maxLength);
9059
+ if (actualLen === 0) {
9060
+ return null;
9061
+ }
9062
+ return outBuffer.slice(0, actualLen);
9063
+ }
9064
+ textBufferViewGetPlainTextBytes(view, maxLength) {
9065
+ const outBuffer = new Uint8Array(maxLength);
9066
+ const actualLen = this.textBufferViewGetPlainText(view, ptr3(outBuffer), maxLength);
9067
+ if (actualLen === 0) {
9068
+ return null;
9069
+ }
9070
+ return outBuffer.slice(0, actualLen);
9071
+ }
9072
+ textBufferAddHighlightByCharRange(buffer, highlight) {
9073
+ const packedHighlight = HighlightStruct.pack(highlight);
9074
+ this.opentui.symbols.textBufferAddHighlightByCharRange(buffer, ptr3(packedHighlight));
9075
+ }
9076
+ textBufferAddHighlight(buffer, lineIdx, highlight) {
9077
+ const packedHighlight = HighlightStruct.pack(highlight);
9078
+ this.opentui.symbols.textBufferAddHighlight(buffer, lineIdx, ptr3(packedHighlight));
9079
+ }
9080
+ textBufferRemoveHighlightsByRef(buffer, hlRef) {
9081
+ this.opentui.symbols.textBufferRemoveHighlightsByRef(buffer, hlRef);
9082
+ }
9083
+ textBufferClearLineHighlights(buffer, lineIdx) {
9084
+ this.opentui.symbols.textBufferClearLineHighlights(buffer, lineIdx);
9085
+ }
9086
+ textBufferClearAllHighlights(buffer) {
9087
+ this.opentui.symbols.textBufferClearAllHighlights(buffer);
9088
+ }
9089
+ textBufferSetSyntaxStyle(buffer, style) {
9090
+ this.opentui.symbols.textBufferSetSyntaxStyle(buffer, style);
9091
+ }
9092
+ textBufferGetLineHighlights(buffer, lineIdx) {
9093
+ const outCountBuf = new BigUint64Array(1);
9094
+ const nativePtr = this.opentui.symbols.textBufferGetLineHighlightsPtr(buffer, lineIdx, ptr3(outCountBuf));
9095
+ if (!nativePtr)
9096
+ return [];
9097
+ const count = Number(outCountBuf[0]);
9098
+ const byteLen = count * HighlightStruct.size;
9099
+ const raw = toArrayBuffer4(nativePtr, 0, byteLen);
9100
+ const results = HighlightStruct.unpackList(raw, count);
9101
+ this.opentui.symbols.textBufferFreeLineHighlights(nativePtr, count);
9102
+ return results;
9103
+ }
9104
+ getArenaAllocatedBytes() {
9105
+ const result = this.opentui.symbols.getArenaAllocatedBytes();
9106
+ return typeof result === "bigint" ? Number(result) : result;
9107
+ }
9108
+ bufferDrawTextBufferView(buffer, view, x, y) {
9109
+ this.opentui.symbols.bufferDrawTextBufferView(buffer, view, x, y);
9110
+ }
9111
+ bufferDrawEditorView(buffer, view, x, y) {
9112
+ this.opentui.symbols.bufferDrawEditorView(buffer, view, x, y);
9113
+ }
9114
+ createEditorView(editBufferPtr, viewportWidth, viewportHeight) {
9115
+ const viewPtr = this.opentui.symbols.createEditorView(editBufferPtr, viewportWidth, viewportHeight);
9116
+ if (!viewPtr) {
9117
+ throw new Error("Failed to create EditorView");
9118
+ }
9119
+ return viewPtr;
9120
+ }
9121
+ destroyEditorView(view) {
9122
+ this.opentui.symbols.destroyEditorView(view);
9123
+ }
9124
+ editorViewSetViewportSize(view, width, height) {
9125
+ this.opentui.symbols.editorViewSetViewportSize(view, width, height);
9126
+ }
9127
+ editorViewGetViewport(view) {
9128
+ const x = new Uint32Array(1);
9129
+ const y = new Uint32Array(1);
9130
+ const width = new Uint32Array(1);
9131
+ const height = new Uint32Array(1);
9132
+ this.opentui.symbols.editorViewGetViewport(view, ptr3(x), ptr3(y), ptr3(width), ptr3(height));
9133
+ return {
9134
+ offsetX: x[0],
9135
+ offsetY: y[0],
9136
+ width: width[0],
9137
+ height: height[0]
9138
+ };
9139
+ }
9140
+ editorViewSetScrollMargin(view, margin) {
9141
+ this.opentui.symbols.editorViewSetScrollMargin(view, margin);
7129
9142
  }
7130
- setCursorStyle(renderer, style, blinking) {
7131
- const stylePtr = this.encoder.encode(style);
7132
- this.opentui.symbols.setCursorStyle(renderer, stylePtr, style.length, blinking);
9143
+ editorViewSetWrapMode(view, mode) {
9144
+ const modeValue = mode === "none" ? 0 : mode === "char" ? 1 : 2;
9145
+ this.opentui.symbols.editorViewSetWrapMode(view, modeValue);
7133
9146
  }
7134
- setCursorColor(renderer, color) {
7135
- this.opentui.symbols.setCursorColor(renderer, color.buffer);
9147
+ editorViewGetVirtualLineCount(view) {
9148
+ return this.opentui.symbols.editorViewGetVirtualLineCount(view);
7136
9149
  }
7137
- render(renderer, force) {
7138
- this.opentui.symbols.render(renderer, force);
9150
+ editorViewGetTotalVirtualLineCount(view) {
9151
+ return this.opentui.symbols.editorViewGetTotalVirtualLineCount(view);
7139
9152
  }
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);
9153
+ editorViewGetTextBufferView(view) {
9154
+ const result = this.opentui.symbols.editorViewGetTextBufferView(view);
9155
+ if (!result) {
9156
+ throw new Error("Failed to get TextBufferView from EditorView");
7143
9157
  }
9158
+ return result;
9159
+ }
9160
+ createEditBuffer(widthMethod) {
7144
9161
  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);
9162
+ const bufferPtr = this.opentui.symbols.createEditBuffer(widthMethodCode);
7148
9163
  if (!bufferPtr) {
7149
- throw new Error(`Failed to create optimized buffer: ${width}x${height}`);
9164
+ throw new Error("Failed to create EditBuffer");
7150
9165
  }
7151
- return new OptimizedBuffer(this, bufferPtr, width, height, { respectAlpha, id });
9166
+ return bufferPtr;
7152
9167
  }
7153
- destroyOptimizedBuffer(bufferPtr) {
7154
- this.opentui.symbols.destroyOptimizedBuffer(bufferPtr);
9168
+ destroyEditBuffer(buffer) {
9169
+ this.opentui.symbols.destroyEditBuffer(buffer);
7155
9170
  }
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);
9171
+ editBufferSetText(buffer, textBytes, retainHistory = true) {
9172
+ this.opentui.symbols.editBufferSetText(buffer, textBytes, textBytes.length, retainHistory);
7162
9173
  }
7163
- setDebugOverlay(renderer, enabled, corner) {
7164
- this.opentui.symbols.setDebugOverlay(renderer, enabled, corner);
9174
+ editBufferSetTextFromMem(buffer, memId, retainHistory = true) {
9175
+ this.opentui.symbols.editBufferSetTextFromMem(buffer, memId, retainHistory);
7165
9176
  }
7166
- clearTerminal(renderer) {
7167
- this.opentui.symbols.clearTerminal(renderer);
9177
+ editBufferGetText(buffer, maxLength) {
9178
+ const outBuffer = new Uint8Array(maxLength);
9179
+ const actualLen = this.opentui.symbols.editBufferGetText(buffer, ptr3(outBuffer), maxLength);
9180
+ const len = typeof actualLen === "bigint" ? Number(actualLen) : actualLen;
9181
+ if (len === 0)
9182
+ return null;
9183
+ return outBuffer.slice(0, len);
7168
9184
  }
7169
- setTerminalTitle(renderer, title) {
7170
- const titleBytes = this.encoder.encode(title);
7171
- this.opentui.symbols.setTerminalTitle(renderer, titleBytes, titleBytes.length);
9185
+ editBufferInsertChar(buffer, char) {
9186
+ const charBytes = this.encoder.encode(char);
9187
+ this.opentui.symbols.editBufferInsertChar(buffer, charBytes, charBytes.length);
7172
9188
  }
7173
- addToHitGrid(renderer, x, y, width, height, id) {
7174
- this.opentui.symbols.addToHitGrid(renderer, x, y, width, height, id);
9189
+ editBufferInsertText(buffer, text) {
9190
+ const textBytes = this.encoder.encode(text);
9191
+ this.opentui.symbols.editBufferInsertText(buffer, textBytes, textBytes.length);
7175
9192
  }
7176
- checkHit(renderer, x, y) {
7177
- return this.opentui.symbols.checkHit(renderer, x, y);
9193
+ editBufferDeleteChar(buffer) {
9194
+ this.opentui.symbols.editBufferDeleteChar(buffer);
7178
9195
  }
7179
- dumpHitGrid(renderer) {
7180
- this.opentui.symbols.dumpHitGrid(renderer);
9196
+ editBufferDeleteCharBackward(buffer) {
9197
+ this.opentui.symbols.editBufferDeleteCharBackward(buffer);
7181
9198
  }
7182
- dumpBuffers(renderer, timestamp) {
7183
- const ts = timestamp ?? Date.now();
7184
- this.opentui.symbols.dumpBuffers(renderer, ts);
9199
+ editBufferDeleteRange(buffer, startLine, startCol, endLine, endCol) {
9200
+ this.opentui.symbols.editBufferDeleteRange(buffer, startLine, startCol, endLine, endCol);
7185
9201
  }
7186
- dumpStdoutBuffer(renderer, timestamp) {
7187
- const ts = timestamp ?? Date.now();
7188
- this.opentui.symbols.dumpStdoutBuffer(renderer, ts);
9202
+ editBufferNewLine(buffer) {
9203
+ this.opentui.symbols.editBufferNewLine(buffer);
7189
9204
  }
7190
- enableMouse(renderer, enableMovement) {
7191
- this.opentui.symbols.enableMouse(renderer, enableMovement);
9205
+ editBufferDeleteLine(buffer) {
9206
+ this.opentui.symbols.editBufferDeleteLine(buffer);
7192
9207
  }
7193
- disableMouse(renderer) {
7194
- this.opentui.symbols.disableMouse(renderer);
9208
+ editBufferMoveCursorLeft(buffer) {
9209
+ this.opentui.symbols.editBufferMoveCursorLeft(buffer);
7195
9210
  }
7196
- enableKittyKeyboard(renderer, flags) {
7197
- this.opentui.symbols.enableKittyKeyboard(renderer, flags);
9211
+ editBufferMoveCursorRight(buffer) {
9212
+ this.opentui.symbols.editBufferMoveCursorRight(buffer);
7198
9213
  }
7199
- disableKittyKeyboard(renderer) {
7200
- this.opentui.symbols.disableKittyKeyboard(renderer);
9214
+ editBufferMoveCursorUp(buffer) {
9215
+ this.opentui.symbols.editBufferMoveCursorUp(buffer);
7201
9216
  }
7202
- setupTerminal(renderer, useAlternateScreen) {
7203
- this.opentui.symbols.setupTerminal(renderer, useAlternateScreen);
9217
+ editBufferMoveCursorDown(buffer) {
9218
+ this.opentui.symbols.editBufferMoveCursorDown(buffer);
7204
9219
  }
7205
- queryPixelResolution(renderer) {
7206
- this.opentui.symbols.queryPixelResolution(renderer);
9220
+ editBufferGotoLine(buffer, line) {
9221
+ this.opentui.symbols.editBufferGotoLine(buffer, line);
7207
9222
  }
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`);
9223
+ editBufferSetCursor(buffer, line, byteOffset) {
9224
+ this.opentui.symbols.editBufferSetCursor(buffer, line, byteOffset);
9225
+ }
9226
+ editBufferSetCursorToLineCol(buffer, line, col) {
9227
+ this.opentui.symbols.editBufferSetCursorToLineCol(buffer, line, col);
9228
+ }
9229
+ editBufferSetCursorByOffset(buffer, offset) {
9230
+ this.opentui.symbols.editBufferSetCursorByOffset(buffer, offset);
9231
+ }
9232
+ editBufferGetCursorPosition(buffer) {
9233
+ const cursorBuffer = new ArrayBuffer(LogicalCursorStruct.size);
9234
+ this.opentui.symbols.editBufferGetCursorPosition(buffer, ptr3(cursorBuffer));
9235
+ return LogicalCursorStruct.unpack(cursorBuffer);
9236
+ }
9237
+ editBufferGetId(buffer) {
9238
+ return this.opentui.symbols.editBufferGetId(buffer);
9239
+ }
9240
+ editBufferGetTextBuffer(buffer) {
9241
+ const result = this.opentui.symbols.editBufferGetTextBuffer(buffer);
9242
+ if (!result) {
9243
+ throw new Error("Failed to get TextBuffer from EditBuffer");
7213
9244
  }
7214
- return new TextBuffer(this, bufferPtr);
9245
+ return result;
7215
9246
  }
7216
- destroyTextBuffer(buffer) {
7217
- this.opentui.symbols.destroyTextBuffer(buffer);
9247
+ editBufferDebugLogRope(buffer) {
9248
+ this.opentui.symbols.editBufferDebugLogRope(buffer);
7218
9249
  }
7219
- textBufferGetLength(buffer) {
7220
- return this.opentui.symbols.textBufferGetLength(buffer);
9250
+ editBufferUndo(buffer, maxLength) {
9251
+ const outBuffer = new Uint8Array(maxLength);
9252
+ const actualLen = this.opentui.symbols.editBufferUndo(buffer, ptr3(outBuffer), maxLength);
9253
+ const len = typeof actualLen === "bigint" ? Number(actualLen) : actualLen;
9254
+ if (len === 0)
9255
+ return null;
9256
+ return outBuffer.slice(0, len);
7221
9257
  }
7222
- textBufferReset(buffer) {
7223
- this.opentui.symbols.textBufferReset(buffer);
9258
+ editBufferRedo(buffer, maxLength) {
9259
+ const outBuffer = new Uint8Array(maxLength);
9260
+ const actualLen = this.opentui.symbols.editBufferRedo(buffer, ptr3(outBuffer), maxLength);
9261
+ const len = typeof actualLen === "bigint" ? Number(actualLen) : actualLen;
9262
+ if (len === 0)
9263
+ return null;
9264
+ return outBuffer.slice(0, len);
7224
9265
  }
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);
9266
+ editBufferCanUndo(buffer) {
9267
+ return this.opentui.symbols.editBufferCanUndo(buffer);
7229
9268
  }
7230
- textBufferResetSelection(buffer) {
7231
- this.opentui.symbols.textBufferResetSelection(buffer);
9269
+ editBufferCanRedo(buffer) {
9270
+ return this.opentui.symbols.editBufferCanRedo(buffer);
7232
9271
  }
7233
- textBufferSetDefaultFg(buffer, fg2) {
7234
- const fgPtr = fg2 ? fg2.buffer : null;
7235
- this.opentui.symbols.textBufferSetDefaultFg(buffer, fgPtr);
9272
+ editBufferClearHistory(buffer) {
9273
+ this.opentui.symbols.editBufferClearHistory(buffer);
7236
9274
  }
7237
- textBufferSetDefaultBg(buffer, bg2) {
7238
- const bgPtr = bg2 ? bg2.buffer : null;
7239
- this.opentui.symbols.textBufferSetDefaultBg(buffer, bgPtr);
9275
+ editBufferSetPlaceholder(buffer, text) {
9276
+ if (text === null) {
9277
+ this.opentui.symbols.editBufferSetPlaceholder(buffer, null, 0);
9278
+ } else {
9279
+ const textBytes = this.encoder.encode(text);
9280
+ this.opentui.symbols.editBufferSetPlaceholder(buffer, textBytes, textBytes.length);
9281
+ }
7240
9282
  }
7241
- textBufferSetDefaultAttributes(buffer, attributes) {
7242
- const attrValue = attributes === null ? null : new Uint8Array([attributes]);
7243
- this.opentui.symbols.textBufferSetDefaultAttributes(buffer, attrValue);
9283
+ editBufferSetPlaceholderColor(buffer, color) {
9284
+ this.opentui.symbols.editBufferSetPlaceholderColor(buffer, color.buffer);
7244
9285
  }
7245
- textBufferResetDefaults(buffer) {
7246
- this.opentui.symbols.textBufferResetDefaults(buffer);
9286
+ editBufferClear(buffer) {
9287
+ this.opentui.symbols.editBufferClear(buffer);
7247
9288
  }
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);
9289
+ editBufferGetNextWordBoundary(buffer) {
9290
+ const cursorBuffer = new ArrayBuffer(LogicalCursorStruct.size);
9291
+ this.opentui.symbols.editBufferGetNextWordBoundary(buffer, ptr3(cursorBuffer));
9292
+ return LogicalCursorStruct.unpack(cursorBuffer);
7251
9293
  }
7252
- textBufferFinalizeLineInfo(buffer) {
7253
- this.opentui.symbols.textBufferFinalizeLineInfo(buffer);
9294
+ editBufferGetPrevWordBoundary(buffer) {
9295
+ const cursorBuffer = new ArrayBuffer(LogicalCursorStruct.size);
9296
+ this.opentui.symbols.editBufferGetPrevWordBoundary(buffer, ptr3(cursorBuffer));
9297
+ return LogicalCursorStruct.unpack(cursorBuffer);
7254
9298
  }
7255
- textBufferGetLineCount(buffer) {
7256
- return this.opentui.symbols.textBufferGetLineCount(buffer);
9299
+ editBufferGetEOL(buffer) {
9300
+ const cursorBuffer = new ArrayBuffer(LogicalCursorStruct.size);
9301
+ this.opentui.symbols.editBufferGetEOL(buffer, ptr3(cursorBuffer));
9302
+ return LogicalCursorStruct.unpack(cursorBuffer);
9303
+ }
9304
+ editorViewSetSelection(view, start, end, bgColor, fgColor) {
9305
+ const bg2 = bgColor ? bgColor.buffer : null;
9306
+ const fg2 = fgColor ? fgColor.buffer : null;
9307
+ this.opentui.symbols.editorViewSetSelection(view, start, end, bg2, fg2);
7257
9308
  }
7258
- textBufferGetLineInfoDirect(buffer, lineStartsPtr, lineWidthsPtr) {
7259
- return this.opentui.symbols.textBufferGetLineInfoDirect(buffer, lineStartsPtr, lineWidthsPtr);
9309
+ editorViewResetSelection(view) {
9310
+ this.opentui.symbols.editorViewResetSelection(view);
7260
9311
  }
7261
- textBufferGetSelection(buffer) {
7262
- const packedInfo = this.textBufferGetSelectionInfo(buffer);
9312
+ editorViewGetSelection(view) {
9313
+ const packedInfo = this.opentui.symbols.editorViewGetSelection(view);
7263
9314
  if (packedInfo === 0xffff_ffff_ffff_ffffn) {
7264
9315
  return null;
7265
9316
  }
@@ -7267,92 +9318,67 @@ class FFIRenderLib {
7267
9318
  const end = Number(packedInfo & 0xffff_ffffn);
7268
9319
  return { start, end };
7269
9320
  }
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;
9321
+ editorViewSetLocalSelection(view, anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
9322
+ const bg2 = bgColor ? bgColor.buffer : null;
9323
+ const fg2 = fgColor ? fgColor.buffer : null;
9324
+ return this.opentui.symbols.editorViewSetLocalSelection(view, anchorX, anchorY, focusX, focusY, bg2, fg2);
7276
9325
  }
7277
- textBufferGetPlainText(buffer, outPtr, maxLen) {
7278
- const result = this.opentui.symbols.textBufferGetPlainText(buffer, outPtr, maxLen);
7279
- return typeof result === "bigint" ? Number(result) : result;
9326
+ editorViewResetLocalSelection(view) {
9327
+ this.opentui.symbols.editorViewResetLocalSelection(view);
7280
9328
  }
7281
- getSelectedTextBytes(buffer, maxLength) {
9329
+ editorViewGetSelectedTextBytes(view, maxLength) {
7282
9330
  const outBuffer = new Uint8Array(maxLength);
7283
- const actualLen = this.textBufferGetSelectedText(buffer, ptr(outBuffer), maxLength);
7284
- if (actualLen === 0) {
9331
+ const actualLen = this.opentui.symbols.editorViewGetSelectedTextBytes(view, ptr3(outBuffer), maxLength);
9332
+ const len = typeof actualLen === "bigint" ? Number(actualLen) : actualLen;
9333
+ if (len === 0)
7285
9334
  return null;
7286
- }
7287
- return outBuffer.slice(0, actualLen);
9335
+ return outBuffer.slice(0, len);
7288
9336
  }
7289
- getPlainTextBytes(buffer, maxLength) {
9337
+ editorViewGetCursor(view) {
9338
+ const row = new Uint32Array(1);
9339
+ const col = new Uint32Array(1);
9340
+ this.opentui.symbols.editorViewGetCursor(view, ptr3(row), ptr3(col));
9341
+ return { row: row[0], col: col[0] };
9342
+ }
9343
+ editorViewGetText(view, maxLength) {
7290
9344
  const outBuffer = new Uint8Array(maxLength);
7291
- const actualLen = this.textBufferGetPlainText(buffer, ptr(outBuffer), maxLength);
7292
- if (actualLen === 0) {
9345
+ const actualLen = this.opentui.symbols.editorViewGetText(view, ptr3(outBuffer), maxLength);
9346
+ const len = typeof actualLen === "bigint" ? Number(actualLen) : actualLen;
9347
+ if (len === 0)
7293
9348
  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);
9349
+ return outBuffer.slice(0, len);
7310
9350
  }
7311
- textBufferRemoveChunkGroup(buffer, index) {
7312
- return this.opentui.symbols.textBufferRemoveChunkGroup(buffer, index);
9351
+ editorViewGetVisualCursor(view) {
9352
+ const cursorBuffer = new ArrayBuffer(VisualCursorStruct.size);
9353
+ this.opentui.symbols.editorViewGetVisualCursor(view, ptr3(cursorBuffer));
9354
+ return VisualCursorStruct.unpack(cursorBuffer);
7313
9355
  }
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);
9356
+ editorViewMoveUpVisual(view) {
9357
+ this.opentui.symbols.editorViewMoveUpVisual(view);
7319
9358
  }
7320
- textBufferGetChunkGroupCount(buffer) {
7321
- const result = this.opentui.symbols.textBufferGetChunkGroupCount(buffer);
7322
- return typeof result === "bigint" ? Number(result) : result;
9359
+ editorViewMoveDownVisual(view) {
9360
+ this.opentui.symbols.editorViewMoveDownVisual(view);
7323
9361
  }
7324
- textBufferSetWrapWidth(buffer, width) {
7325
- this.opentui.symbols.textBufferSetWrapWidth(buffer, width);
9362
+ editorViewDeleteSelectedText(view) {
9363
+ this.opentui.symbols.editorViewDeleteSelectedText(view);
7326
9364
  }
7327
- textBufferSetWrapMode(buffer, mode) {
7328
- const modeValue = mode === "char" ? 0 : 1;
7329
- this.opentui.symbols.textBufferSetWrapMode(buffer, modeValue);
9365
+ editorViewSetCursorByOffset(view, offset) {
9366
+ this.opentui.symbols.editorViewSetCursorByOffset(view, offset);
7330
9367
  }
7331
- getArenaAllocatedBytes() {
7332
- const result = this.opentui.symbols.getArenaAllocatedBytes();
7333
- return typeof result === "bigint" ? Number(result) : result;
9368
+ editorViewGetNextWordBoundary(view) {
9369
+ const cursorBuffer = new ArrayBuffer(VisualCursorStruct.size);
9370
+ this.opentui.symbols.editorViewGetNextWordBoundary(view, ptr3(cursorBuffer));
9371
+ return VisualCursorStruct.unpack(cursorBuffer);
7334
9372
  }
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
- };
9373
+ editorViewGetPrevWordBoundary(view) {
9374
+ const cursorBuffer = new ArrayBuffer(VisualCursorStruct.size);
9375
+ this.opentui.symbols.editorViewGetPrevWordBoundary(view, ptr3(cursorBuffer));
9376
+ return VisualCursorStruct.unpack(cursorBuffer);
7348
9377
  }
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);
9378
+ editorViewGetEOL(view) {
9379
+ const cursorBuffer = new ArrayBuffer(VisualCursorStruct.size);
9380
+ this.opentui.symbols.editorViewGetEOL(view, ptr3(cursorBuffer));
9381
+ return VisualCursorStruct.unpack(cursorBuffer);
7356
9382
  }
7357
9383
  bufferPushScissorRect(buffer, x, y, width, height) {
7358
9384
  this.opentui.symbols.bufferPushScissorRect(buffer, x, y, width, height);
@@ -7388,6 +9414,43 @@ class FFIRenderLib {
7388
9414
  const responseBytes = this.encoder.encode(response);
7389
9415
  this.opentui.symbols.processCapabilityResponse(renderer, responseBytes, responseBytes.length);
7390
9416
  }
9417
+ createSyntaxStyle() {
9418
+ const stylePtr = this.opentui.symbols.createSyntaxStyle();
9419
+ if (!stylePtr) {
9420
+ throw new Error("Failed to create SyntaxStyle");
9421
+ }
9422
+ return stylePtr;
9423
+ }
9424
+ destroySyntaxStyle(style) {
9425
+ this.opentui.symbols.destroySyntaxStyle(style);
9426
+ }
9427
+ syntaxStyleRegister(style, name, fg2, bg2, attributes) {
9428
+ const nameBytes = this.encoder.encode(name);
9429
+ const fgPtr = fg2 ? fg2.buffer : null;
9430
+ const bgPtr = bg2 ? bg2.buffer : null;
9431
+ return this.opentui.symbols.syntaxStyleRegister(style, nameBytes, nameBytes.length, fgPtr, bgPtr, attributes);
9432
+ }
9433
+ syntaxStyleResolveByName(style, name) {
9434
+ const nameBytes = this.encoder.encode(name);
9435
+ const id = this.opentui.symbols.syntaxStyleResolveByName(style, nameBytes, nameBytes.length);
9436
+ return id === 0 ? null : id;
9437
+ }
9438
+ syntaxStyleGetStyleCount(style) {
9439
+ const result = this.opentui.symbols.syntaxStyleGetStyleCount(style);
9440
+ return typeof result === "bigint" ? Number(result) : result;
9441
+ }
9442
+ onNativeEvent(name, handler) {
9443
+ this._nativeEvents.on(name, handler);
9444
+ }
9445
+ onceNativeEvent(name, handler) {
9446
+ this._nativeEvents.once(name, handler);
9447
+ }
9448
+ offNativeEvent(name, handler) {
9449
+ this._nativeEvents.off(name, handler);
9450
+ }
9451
+ onAnyNativeEvent(handler) {
9452
+ this._anyEventHandlers.push(handler);
9453
+ }
7391
9454
  }
7392
9455
  var opentuiLibPath;
7393
9456
  var opentuiLib;
@@ -7416,11 +9479,15 @@ class TextBuffer {
7416
9479
  lib;
7417
9480
  bufferPtr;
7418
9481
  _length = 0;
9482
+ _byteSize = 0;
7419
9483
  _lineInfo;
7420
9484
  _destroyed = false;
7421
- constructor(lib, ptr2) {
9485
+ _syntaxStyle;
9486
+ _textBytes;
9487
+ _memId;
9488
+ constructor(lib, ptr4) {
7422
9489
  this.lib = lib;
7423
- this.bufferPtr = ptr2;
9490
+ this.bufferPtr = ptr4;
7424
9491
  }
7425
9492
  static create(widthMethod) {
7426
9493
  const lib = resolveRenderLib();
@@ -7430,17 +9497,42 @@ class TextBuffer {
7430
9497
  if (this._destroyed)
7431
9498
  throw new Error("TextBuffer is destroyed");
7432
9499
  }
7433
- setStyledText(text) {
9500
+ setText(text) {
7434
9501
  this.guard();
7435
- this.lib.textBufferReset(this.bufferPtr);
7436
- this._length = 0;
9502
+ this._textBytes = this.lib.encoder.encode(text);
9503
+ if (this._memId === undefined) {
9504
+ this._memId = this.lib.textBufferRegisterMemBuffer(this.bufferPtr, this._textBytes, false);
9505
+ } else {
9506
+ this.lib.textBufferReplaceMemBuffer(this.bufferPtr, this._memId, this._textBytes, false);
9507
+ }
9508
+ this.lib.textBufferSetTextFromMem(this.bufferPtr, this._memId);
9509
+ this._length = this.lib.textBufferGetLength(this.bufferPtr);
9510
+ this._byteSize = this.lib.textBufferGetByteSize(this.bufferPtr);
7437
9511
  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);
9512
+ }
9513
+ loadFile(path4) {
9514
+ this.guard();
9515
+ const success = this.lib.textBufferLoadFile(this.bufferPtr, path4);
9516
+ if (!success) {
9517
+ throw new Error(`Failed to load file: ${path4}`);
7441
9518
  }
7442
- this.lib.textBufferFinalizeLineInfo(this.bufferPtr);
7443
9519
  this._length = this.lib.textBufferGetLength(this.bufferPtr);
9520
+ this._byteSize = this.lib.textBufferGetByteSize(this.bufferPtr);
9521
+ this._lineInfo = undefined;
9522
+ this._textBytes = undefined;
9523
+ }
9524
+ setStyledText(text) {
9525
+ this.guard();
9526
+ const chunks = text.chunks.map((chunk) => ({
9527
+ text: chunk.text,
9528
+ fg: chunk.fg || null,
9529
+ bg: chunk.bg || null,
9530
+ attributes: chunk.attributes ?? 0
9531
+ }));
9532
+ this.lib.textBufferSetStyledText(this.bufferPtr, chunks);
9533
+ this._length = this.lib.textBufferGetLength(this.bufferPtr);
9534
+ this._byteSize = this.lib.textBufferGetByteSize(this.bufferPtr);
9535
+ this._lineInfo = undefined;
7444
9536
  }
7445
9537
  setDefaultFg(fg2) {
7446
9538
  this.guard();
@@ -7462,97 +9554,72 @@ class TextBuffer {
7462
9554
  this.guard();
7463
9555
  return this._length;
7464
9556
  }
7465
- get ptr() {
9557
+ get byteSize() {
7466
9558
  this.guard();
7467
- return this.bufferPtr;
9559
+ return this._byteSize;
7468
9560
  }
7469
- getSelectedText() {
9561
+ get ptr() {
7470
9562
  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);
9563
+ return this.bufferPtr;
7477
9564
  }
7478
9565
  getPlainText() {
7479
9566
  this.guard();
7480
- if (this._length === 0)
9567
+ if (this._byteSize === 0)
7481
9568
  return "";
7482
- const plainBytes = this.lib.getPlainTextBytes(this.bufferPtr, this.length * 4);
9569
+ const plainBytes = this.lib.getPlainTextBytes(this.bufferPtr, this._byteSize);
7483
9570
  if (!plainBytes)
7484
9571
  return "";
7485
9572
  return this.lib.decoder.decode(plainBytes);
7486
9573
  }
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() {
9574
+ addHighlightByCharRange(highlight) {
7499
9575
  this.guard();
7500
- this.lib.textBufferResetSelection(this.bufferPtr);
9576
+ this.lib.textBufferAddHighlightByCharRange(this.bufferPtr, highlight);
7501
9577
  }
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() {
7511
- this.guard();
7512
- return this.lib.textBufferGetSelection(this.bufferPtr);
7513
- }
7514
- hasSelection() {
9578
+ addHighlight(lineIdx, highlight) {
7515
9579
  this.guard();
7516
- return this.getSelection() !== null;
9580
+ this.lib.textBufferAddHighlight(this.bufferPtr, lineIdx, highlight);
7517
9581
  }
7518
- insertChunkGroup(index, text, fg2, bg2, attributes) {
9582
+ removeHighlightsByRef(hlRef) {
7519
9583
  this.guard();
7520
- const textBytes = this.lib.encoder.encode(text);
7521
- this.insertEncodedChunkGroup(index, textBytes, fg2, bg2, attributes);
9584
+ this.lib.textBufferRemoveHighlightsByRef(this.bufferPtr, hlRef);
7522
9585
  }
7523
- insertEncodedChunkGroup(index, textBytes, fg2, bg2, attributes) {
9586
+ clearLineHighlights(lineIdx) {
7524
9587
  this.guard();
7525
- this._length = this.lib.textBufferInsertChunkGroup(this.bufferPtr, index, textBytes, fg2 || null, bg2 || null, attributes ?? null);
7526
- this._lineInfo = undefined;
9588
+ this.lib.textBufferClearLineHighlights(this.bufferPtr, lineIdx);
7527
9589
  }
7528
- removeChunkGroup(index) {
9590
+ clearAllHighlights() {
7529
9591
  this.guard();
7530
- this._length = this.lib.textBufferRemoveChunkGroup(this.bufferPtr, index);
7531
- this._lineInfo = undefined;
9592
+ this.lib.textBufferClearAllHighlights(this.bufferPtr);
7532
9593
  }
7533
- replaceChunkGroup(index, text, fg2, bg2, attributes) {
9594
+ getLineHighlights(lineIdx) {
7534
9595
  this.guard();
7535
- const textBytes = this.lib.encoder.encode(text);
7536
- this.replaceEncodedChunkGroup(index, textBytes, fg2, bg2, attributes);
9596
+ return this.lib.textBufferGetLineHighlights(this.bufferPtr, lineIdx);
7537
9597
  }
7538
- replaceEncodedChunkGroup(index, textBytes, fg2, bg2, attributes) {
9598
+ setSyntaxStyle(style) {
7539
9599
  this.guard();
7540
- this._length = this.lib.textBufferReplaceChunkGroup(this.bufferPtr, index, textBytes, fg2 || null, bg2 || null, attributes ?? null);
7541
- this._lineInfo = undefined;
9600
+ this._syntaxStyle = style ?? undefined;
9601
+ this.lib.textBufferSetSyntaxStyle(this.bufferPtr, style?.ptr ?? null);
7542
9602
  }
7543
- get chunkGroupCount() {
9603
+ getSyntaxStyle() {
7544
9604
  this.guard();
7545
- return this.lib.textBufferGetChunkGroupCount(this.bufferPtr);
9605
+ return this._syntaxStyle ?? null;
7546
9606
  }
7547
- setWrapWidth(width) {
9607
+ clear() {
7548
9608
  this.guard();
7549
- this.lib.textBufferSetWrapWidth(this.bufferPtr, width ?? 0);
9609
+ this.lib.textBufferClear(this.bufferPtr);
9610
+ this._length = 0;
9611
+ this._byteSize = 0;
7550
9612
  this._lineInfo = undefined;
9613
+ this._textBytes = undefined;
7551
9614
  }
7552
- setWrapMode(mode) {
9615
+ reset() {
7553
9616
  this.guard();
7554
- this.lib.textBufferSetWrapMode(this.bufferPtr, mode);
9617
+ this.lib.textBufferReset(this.bufferPtr);
9618
+ this._length = 0;
9619
+ this._byteSize = 0;
7555
9620
  this._lineInfo = undefined;
9621
+ this._textBytes = undefined;
9622
+ this._memId = undefined;
7556
9623
  }
7557
9624
  destroy() {
7558
9625
  if (this._destroyed)
@@ -7563,7 +9630,7 @@ class TextBuffer {
7563
9630
  }
7564
9631
 
7565
9632
  // src/Renderable.ts
7566
- import { EventEmitter as EventEmitter4 } from "events";
9633
+ import { EventEmitter as EventEmitter6 } from "events";
7567
9634
 
7568
9635
  // src/lib/renderable.validations.ts
7569
9636
  function validateOptions(id, options) {
@@ -7656,7 +9723,7 @@ function isRenderable(obj) {
7656
9723
  return !!obj?.[BrandedRenderable];
7657
9724
  }
7658
9725
 
7659
- class BaseRenderable extends EventEmitter4 {
9726
+ class BaseRenderable extends EventEmitter6 {
7660
9727
  [BrandedRenderable] = true;
7661
9728
  static renderableNumber = 1;
7662
9729
  _id;
@@ -7728,6 +9795,7 @@ class Renderable extends BaseRenderable {
7728
9795
  _positionType = "relative";
7729
9796
  _overflow = "visible";
7730
9797
  _position = {};
9798
+ _flexShrink = 1;
7731
9799
  renderableMapById = new Map;
7732
9800
  _childrenInLayoutOrder = [];
7733
9801
  _childrenInZIndexOrder = [];
@@ -7974,6 +10042,10 @@ class Renderable extends BaseRenderable {
7974
10042
  if (isDimensionType(value)) {
7975
10043
  this._width = value;
7976
10044
  this.yogaNode.setWidth(value);
10045
+ if (typeof value === "number" && this._flexShrink === 1) {
10046
+ this._flexShrink = 0;
10047
+ this.yogaNode.setFlexShrink(0);
10048
+ }
7977
10049
  this.requestRender();
7978
10050
  }
7979
10051
  }
@@ -7984,6 +10056,10 @@ class Renderable extends BaseRenderable {
7984
10056
  if (isDimensionType(value)) {
7985
10057
  this._height = value;
7986
10058
  this.yogaNode.setHeight(value);
10059
+ if (typeof value === "number" && this._flexShrink === 1) {
10060
+ this._flexShrink = 0;
10061
+ this.yogaNode.setFlexShrink(0);
10062
+ }
7987
10063
  this.requestRender();
7988
10064
  }
7989
10065
  }
@@ -8038,9 +10114,13 @@ class Renderable extends BaseRenderable {
8038
10114
  node.setFlexGrow(0);
8039
10115
  }
8040
10116
  if (options.flexShrink !== undefined) {
10117
+ this._flexShrink = options.flexShrink;
8041
10118
  node.setFlexShrink(options.flexShrink);
8042
10119
  } else {
8043
- node.setFlexShrink(1);
10120
+ const hasExplicitWidth = typeof options.width === "number";
10121
+ const hasExplicitHeight = typeof options.height === "number";
10122
+ this._flexShrink = hasExplicitWidth || hasExplicitHeight ? 0 : 1;
10123
+ node.setFlexShrink(this._flexShrink);
8044
10124
  }
8045
10125
  if (options.flexDirection !== undefined) {
8046
10126
  node.setFlexDirection(parseFlexDirection(options.flexDirection));
@@ -8185,11 +10265,17 @@ class Renderable extends BaseRenderable {
8185
10265
  this.requestRender();
8186
10266
  }
8187
10267
  set flexGrow(grow) {
8188
- this.yogaNode.setFlexGrow(grow);
10268
+ if (grow == null) {
10269
+ this.yogaNode.setFlexGrow(0);
10270
+ } else {
10271
+ this.yogaNode.setFlexGrow(grow);
10272
+ }
8189
10273
  this.requestRender();
8190
10274
  }
8191
10275
  set flexShrink(shrink) {
8192
- this.yogaNode.setFlexShrink(shrink);
10276
+ const value = shrink == null ? 1 : shrink;
10277
+ this._flexShrink = value;
10278
+ this.yogaNode.setFlexShrink(value);
8193
10279
  this.requestRender();
8194
10280
  }
8195
10281
  set flexDirection(direction) {
@@ -8390,34 +10476,31 @@ class Renderable extends BaseRenderable {
8390
10476
  }
8391
10477
  return -1;
8392
10478
  }
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);
10479
+ const anchorRenderable = index !== undefined ? this._childrenInLayoutOrder[index] : undefined;
10480
+ if (anchorRenderable) {
10481
+ return this.insertBefore(renderable, anchorRenderable);
8396
10482
  }
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);
10483
+ if (renderable.parent === this) {
10484
+ this.yogaNode.removeChild(renderable.getLayoutNode());
10485
+ this._childrenInLayoutOrder.splice(this._childrenInLayoutOrder.indexOf(renderable), 1);
8405
10486
  } 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);
10487
+ this.replaceParent(renderable);
10488
+ this.needsZIndexSort = true;
10489
+ this.renderableMapById.set(renderable.id, renderable);
10490
+ this._childrenInZIndexOrder.push(renderable);
10491
+ if (typeof renderable.onLifecyclePass === "function") {
10492
+ this._ctx.registerLifecyclePass(renderable);
10493
+ }
10494
+ if (renderable._liveCount > 0) {
10495
+ this.propagateLiveCount(renderable._liveCount);
10496
+ }
8416
10497
  }
8417
10498
  this._newChildren.push(renderable);
8418
- if (renderable._liveCount > 0) {
8419
- this.propagateLiveCount(renderable._liveCount);
8420
- }
10499
+ const childLayoutNode = renderable.getLayoutNode();
10500
+ const insertedIndex = this._childrenInLayoutOrder.length;
10501
+ this._childrenInLayoutOrder.push(renderable);
10502
+ this.yogaNode.insertChild(childLayoutNode, insertedIndex);
10503
+ this.childrenPrimarySortDirty = true;
8421
10504
  this.requestRender();
8422
10505
  return insertedIndex;
8423
10506
  }
@@ -8472,6 +10555,7 @@ class Renderable extends BaseRenderable {
8472
10555
  this._forceLayoutUpdateFor = this._childrenInLayoutOrder.slice(insertedIndex);
8473
10556
  this._childrenInLayoutOrder.splice(insertedIndex, 0, renderable);
8474
10557
  this.yogaNode.insertChild(renderable.getLayoutNode(), insertedIndex);
10558
+ this.requestRender();
8475
10559
  return insertedIndex;
8476
10560
  }
8477
10561
  getRenderable(id) {
@@ -8960,7 +11044,7 @@ function delegate(mapping, vnode) {
8960
11044
  }
8961
11045
 
8962
11046
  // src/console.ts
8963
- import { EventEmitter as EventEmitter6 } from "events";
11047
+ import { EventEmitter as EventEmitter8 } from "events";
8964
11048
  import { Console } from "console";
8965
11049
  import fs from "fs";
8966
11050
  import path4 from "path";
@@ -8968,9 +11052,9 @@ import util2 from "util";
8968
11052
 
8969
11053
  // src/lib/output.capture.ts
8970
11054
  import { Writable } from "stream";
8971
- import { EventEmitter as EventEmitter5 } from "events";
11055
+ import { EventEmitter as EventEmitter7 } from "events";
8972
11056
 
8973
- class Capture extends EventEmitter5 {
11057
+ class Capture extends EventEmitter7 {
8974
11058
  output = [];
8975
11059
  constructor() {
8976
11060
  super();
@@ -9046,11 +11130,12 @@ registerEnvVar({
9046
11130
  default: false
9047
11131
  });
9048
11132
 
9049
- class TerminalConsoleCache extends EventEmitter6 {
11133
+ class TerminalConsoleCache extends EventEmitter8 {
9050
11134
  _cachedLogs = [];
9051
11135
  MAX_CACHE_SIZE = 1000;
9052
11136
  _collectCallerInfo = false;
9053
11137
  _cachingEnabled = true;
11138
+ _originalConsole = null;
9054
11139
  get cachedLogs() {
9055
11140
  return this._cachedLogs;
9056
11141
  }
@@ -9058,6 +11143,9 @@ class TerminalConsoleCache extends EventEmitter6 {
9058
11143
  super();
9059
11144
  }
9060
11145
  activate() {
11146
+ if (!this._originalConsole) {
11147
+ this._originalConsole = global.console;
11148
+ }
9061
11149
  this.setupConsoleCapture();
9062
11150
  this.overrideConsoleMethods();
9063
11151
  }
@@ -9107,8 +11195,9 @@ class TerminalConsoleCache extends EventEmitter6 {
9107
11195
  this.restoreOriginalConsole();
9108
11196
  }
9109
11197
  restoreOriginalConsole() {
9110
- const originalNodeConsole = __require("console");
9111
- global.console = originalNodeConsole;
11198
+ if (this._originalConsole) {
11199
+ global.console = this._originalConsole;
11200
+ }
9112
11201
  this.setupConsoleCapture();
9113
11202
  }
9114
11203
  addLogEntry(level, ...args) {
@@ -9167,7 +11256,7 @@ var DEFAULT_CONSOLE_OPTIONS = {
9167
11256
  };
9168
11257
  var INDENT_WIDTH = 2;
9169
11258
 
9170
- class TerminalConsole extends EventEmitter6 {
11259
+ class TerminalConsole extends EventEmitter8 {
9171
11260
  isVisible = false;
9172
11261
  isFocused = false;
9173
11262
  renderer;
@@ -9627,7 +11716,7 @@ class TerminalConsole extends EventEmitter6 {
9627
11716
  }
9628
11717
 
9629
11718
  // src/renderer.ts
9630
- import { EventEmitter as EventEmitter7 } from "events";
11719
+ import { EventEmitter as EventEmitter9 } from "events";
9631
11720
 
9632
11721
  // src/lib/objects-in-viewport.ts
9633
11722
  function getObjectsInViewport(viewport, objects, direction = "column", padding = 10, minTriggerSize = 16) {
@@ -9663,24 +11752,39 @@ function getObjectsInViewport(viewport, objects, direction = "column", padding =
9663
11752
  }
9664
11753
  const visibleChildren = [];
9665
11754
  if (candidate === -1) {
9666
- return visibleChildren;
11755
+ candidate = lo > 0 ? lo - 1 : 0;
9667
11756
  }
11757
+ const maxLookBehind = 50;
9668
11758
  let left = candidate;
11759
+ let gapCount = 0;
9669
11760
  while (left - 1 >= 0) {
9670
11761
  const prev = children[left - 1];
9671
- if ((isRow ? prev.x + prev.width : prev.y + prev.height) < vpStart)
9672
- break;
11762
+ const prevEnd = isRow ? prev.x + prev.width : prev.y + prev.height;
11763
+ if (prevEnd <= vpStart) {
11764
+ gapCount++;
11765
+ if (gapCount >= maxLookBehind) {
11766
+ break;
11767
+ }
11768
+ } else {
11769
+ gapCount = 0;
11770
+ }
9673
11771
  left--;
9674
11772
  }
9675
11773
  let right = candidate + 1;
9676
11774
  while (right < totalChildren) {
9677
11775
  const next = children[right];
9678
- if ((isRow ? next.x : next.y) > vpEnd)
11776
+ if ((isRow ? next.x : next.y) >= vpEnd)
9679
11777
  break;
9680
11778
  right++;
9681
11779
  }
9682
11780
  for (let i = left;i < right; i++) {
9683
11781
  const child = children[i];
11782
+ const start = isRow ? child.x : child.y;
11783
+ const end = isRow ? child.x + child.width : child.y + child.height;
11784
+ if (end <= vpStart)
11785
+ continue;
11786
+ if (start >= vpEnd)
11787
+ break;
9684
11788
  if (isRow) {
9685
11789
  const childBottom = child.y + child.height;
9686
11790
  if (childBottom < viewportTop)
@@ -9838,7 +11942,7 @@ var RendererControlState;
9838
11942
  RendererControlState2["EXPLICIT_STOPPED"] = "explicit_stopped";
9839
11943
  })(RendererControlState ||= {});
9840
11944
 
9841
- class CliRenderer extends EventEmitter7 {
11945
+ class CliRenderer extends EventEmitter9 {
9842
11946
  static animationFrameId = 0;
9843
11947
  lib;
9844
11948
  rendererPtr;
@@ -9930,30 +12034,10 @@ class CliRenderer extends EventEmitter7 {
9930
12034
  _currentFocusedRenderable = null;
9931
12035
  lifecyclePasses = new Set;
9932
12036
  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
- });
12037
+ console.error(error);
12038
+ if (true) {
12039
+ this.console.show();
12040
+ }
9957
12041
  }).bind(this);
9958
12042
  dumpOutputCache(optionalMessage = "") {
9959
12043
  const cachedLogs = this.console.getCachedLogs();
@@ -9978,8 +12062,10 @@ Captured output:
9978
12062
  exitHandler = (() => {
9979
12063
  this.destroy();
9980
12064
  if (env.OTUI_DUMP_CAPTURES) {
9981
- this.dumpOutputCache(`=== CAPTURED OUTPUT ===
12065
+ Bun.sleep(100).then(() => {
12066
+ this.dumpOutputCache(`=== CAPTURED OUTPUT ===
9982
12067
  `);
12068
+ });
9983
12069
  }
9984
12070
  }).bind(this);
9985
12071
  warningHandler = ((warning) => {
@@ -10088,7 +12174,7 @@ Captured output:
10088
12174
  }
10089
12175
  get widthMethod() {
10090
12176
  const caps = this.capabilities;
10091
- return caps?.unicode === "unicode" ? "unicode" : "wcwidth";
12177
+ return caps?.unicode === "wcwidth" ? "wcwidth" : "unicode";
10092
12178
  }
10093
12179
  writeOut(chunk, encoding, callback) {
10094
12180
  return this.realStdoutWrite.call(this.stdout, chunk, encoding, callback);
@@ -10854,10 +12940,12 @@ Captured output:
10854
12940
  }
10855
12941
  this.selectionContainers = [];
10856
12942
  }
10857
- startSelection(startRenderable, x, y) {
12943
+ startSelection(renderable, x, y) {
12944
+ if (!renderable.selectable)
12945
+ return;
10858
12946
  this.clearSelection();
10859
- this.selectionContainers.push(startRenderable.parent || this.root);
10860
- this.currentSelection = new Selection(startRenderable, { x, y }, { x, y });
12947
+ this.selectionContainers.push(renderable.parent || this.root);
12948
+ this.currentSelection = new Selection(renderable, { x, y }, { x, y });
10861
12949
  this.notifySelectablesOfSelectionChange();
10862
12950
  }
10863
12951
  updateSelection(currentRenderable, x, y) {
@@ -10937,7 +13025,7 @@ Captured output:
10937
13025
  }
10938
13026
  }
10939
13027
 
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 };
13028
+ 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
13029
 
10942
- //# debugId=A4D3177124AD469F64756E2164756E21
10943
- //# sourceMappingURL=index-kqk5knmb.js.map
13030
+ //# debugId=73F3B7C93A2E540464756E2164756E21
13031
+ //# sourceMappingURL=index-hgxcxzxa.js.map