@opentui/core 0.1.28 → 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/3d.js +1 -1
- package/3d.js.map +1 -1
- package/README.md +10 -0
- package/Renderable.d.ts +25 -24
- package/buffer.d.ts +4 -7
- package/edit-buffer.d.ts +80 -0
- package/editor-view.d.ts +53 -0
- package/{index-phjxdb6g.js → index-0qmm1k4p.js} +1709 -323
- package/{index-phjxdb6g.js.map → index-0qmm1k4p.js.map} +18 -17
- package/index.d.ts +4 -0
- package/index.js +1505 -65
- package/index.js.map +13 -6
- package/lib/hast-styled-text.d.ts +2 -3
- package/lib/index.d.ts +0 -1
- package/lib/keymapping.d.ts +10 -0
- package/lib/objects-in-viewport.d.ts +14 -0
- package/lib/tree-sitter/index.d.ts +0 -2
- package/lib/tree-sitter-styled-text.d.ts +1 -1
- package/lib/yoga.options.d.ts +6 -6
- package/package.json +8 -7
- package/renderables/Code.d.ts +1 -1
- package/renderables/EditBufferRenderable.d.ts +113 -0
- package/renderables/Text.d.ts +0 -3
- package/renderables/TextBufferRenderable.d.ts +8 -14
- package/renderables/Textarea.d.ts +87 -0
- package/renderables/index.d.ts +1 -0
- package/renderer.d.ts +6 -2
- package/{lib/syntax-style.d.ts → syntax-style.d.ts} +21 -5
- package/testing/mock-keys.d.ts +37 -2
- package/testing.js +52 -6
- package/testing.js.map +3 -3
- package/text-buffer-view.d.ts +31 -0
- package/text-buffer.d.ts +28 -21
- package/types.d.ts +10 -0
- package/zig-structs.d.ts +22 -0
- package/zig.d.ts +145 -23
- package/lib/word-jumps.d.ts +0 -2
|
@@ -2406,18 +2406,22 @@ function hexToRgb(hex) {
|
|
|
2406
2406
|
hex = hex.replace(/^#/, "");
|
|
2407
2407
|
if (hex.length === 3) {
|
|
2408
2408
|
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
|
|
2409
|
+
} else if (hex.length === 4) {
|
|
2410
|
+
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3];
|
|
2409
2411
|
}
|
|
2410
|
-
if (!/^[0-9A-Fa-f]{6}$/.test(hex)) {
|
|
2412
|
+
if (!/^[0-9A-Fa-f]{6}$/.test(hex) && !/^[0-9A-Fa-f]{8}$/.test(hex)) {
|
|
2411
2413
|
console.warn(`Invalid hex color: ${hex}, defaulting to magenta`);
|
|
2412
2414
|
return RGBA.fromValues(1, 0, 1, 1);
|
|
2413
2415
|
}
|
|
2414
2416
|
const r = parseInt(hex.substring(0, 2), 16) / 255;
|
|
2415
2417
|
const g = parseInt(hex.substring(2, 4), 16) / 255;
|
|
2416
2418
|
const b = parseInt(hex.substring(4, 6), 16) / 255;
|
|
2417
|
-
|
|
2419
|
+
const a = hex.length === 8 ? parseInt(hex.substring(6, 8), 16) / 255 : 1;
|
|
2420
|
+
return RGBA.fromValues(r, g, b, a);
|
|
2418
2421
|
}
|
|
2419
2422
|
function rgbToHex(rgb) {
|
|
2420
|
-
|
|
2423
|
+
const components = rgb.a === 1 ? [rgb.r, rgb.g, rgb.b] : [rgb.r, rgb.g, rgb.b, rgb.a];
|
|
2424
|
+
return "#" + components.map((x) => {
|
|
2421
2425
|
const hex = Math.floor(Math.max(0, Math.min(1, x) * 255)).toString(16);
|
|
2422
2426
|
return hex.length === 1 ? "0" + hex : hex;
|
|
2423
2427
|
}).join("");
|
|
@@ -4299,104 +4303,6 @@ function t(strings, ...values) {
|
|
|
4299
4303
|
return new StyledText(chunks);
|
|
4300
4304
|
}
|
|
4301
4305
|
|
|
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
4306
|
// src/lib/hast-styled-text.ts
|
|
4401
4307
|
function hastToTextChunks(node, syntaxStyle, parentStyles = []) {
|
|
4402
4308
|
const chunks = [];
|
|
@@ -4480,6 +4386,9 @@ class MacOSScrollAccel {
|
|
|
4480
4386
|
|
|
4481
4387
|
// src/lib/yoga.options.ts
|
|
4482
4388
|
function parseAlign(value) {
|
|
4389
|
+
if (value == null) {
|
|
4390
|
+
return Align.Auto;
|
|
4391
|
+
}
|
|
4483
4392
|
switch (value.toLowerCase()) {
|
|
4484
4393
|
case "auto":
|
|
4485
4394
|
return Align.Auto;
|
|
@@ -4504,6 +4413,9 @@ function parseAlign(value) {
|
|
|
4504
4413
|
}
|
|
4505
4414
|
}
|
|
4506
4415
|
function parseBoxSizing(value) {
|
|
4416
|
+
if (value == null) {
|
|
4417
|
+
return BoxSizing.BorderBox;
|
|
4418
|
+
}
|
|
4507
4419
|
switch (value.toLowerCase()) {
|
|
4508
4420
|
case "border-box":
|
|
4509
4421
|
return BoxSizing.BorderBox;
|
|
@@ -4514,6 +4426,9 @@ function parseBoxSizing(value) {
|
|
|
4514
4426
|
}
|
|
4515
4427
|
}
|
|
4516
4428
|
function parseDimension(value) {
|
|
4429
|
+
if (value == null) {
|
|
4430
|
+
return Dimension.Width;
|
|
4431
|
+
}
|
|
4517
4432
|
switch (value.toLowerCase()) {
|
|
4518
4433
|
case "width":
|
|
4519
4434
|
return Dimension.Width;
|
|
@@ -4524,6 +4439,9 @@ function parseDimension(value) {
|
|
|
4524
4439
|
}
|
|
4525
4440
|
}
|
|
4526
4441
|
function parseDirection(value) {
|
|
4442
|
+
if (value == null) {
|
|
4443
|
+
return Direction.LTR;
|
|
4444
|
+
}
|
|
4527
4445
|
switch (value.toLowerCase()) {
|
|
4528
4446
|
case "inherit":
|
|
4529
4447
|
return Direction.Inherit;
|
|
@@ -4536,6 +4454,9 @@ function parseDirection(value) {
|
|
|
4536
4454
|
}
|
|
4537
4455
|
}
|
|
4538
4456
|
function parseDisplay(value) {
|
|
4457
|
+
if (value == null) {
|
|
4458
|
+
return Display.Flex;
|
|
4459
|
+
}
|
|
4539
4460
|
switch (value.toLowerCase()) {
|
|
4540
4461
|
case "flex":
|
|
4541
4462
|
return Display.Flex;
|
|
@@ -4548,6 +4469,9 @@ function parseDisplay(value) {
|
|
|
4548
4469
|
}
|
|
4549
4470
|
}
|
|
4550
4471
|
function parseEdge(value) {
|
|
4472
|
+
if (value == null) {
|
|
4473
|
+
return Edge.All;
|
|
4474
|
+
}
|
|
4551
4475
|
switch (value.toLowerCase()) {
|
|
4552
4476
|
case "left":
|
|
4553
4477
|
return Edge.Left;
|
|
@@ -4572,6 +4496,9 @@ function parseEdge(value) {
|
|
|
4572
4496
|
}
|
|
4573
4497
|
}
|
|
4574
4498
|
function parseFlexDirection(value) {
|
|
4499
|
+
if (value == null) {
|
|
4500
|
+
return FlexDirection.Column;
|
|
4501
|
+
}
|
|
4575
4502
|
switch (value.toLowerCase()) {
|
|
4576
4503
|
case "column":
|
|
4577
4504
|
return FlexDirection.Column;
|
|
@@ -4586,6 +4513,9 @@ function parseFlexDirection(value) {
|
|
|
4586
4513
|
}
|
|
4587
4514
|
}
|
|
4588
4515
|
function parseGutter(value) {
|
|
4516
|
+
if (value == null) {
|
|
4517
|
+
return Gutter.All;
|
|
4518
|
+
}
|
|
4589
4519
|
switch (value.toLowerCase()) {
|
|
4590
4520
|
case "column":
|
|
4591
4521
|
return Gutter.Column;
|
|
@@ -4598,6 +4528,9 @@ function parseGutter(value) {
|
|
|
4598
4528
|
}
|
|
4599
4529
|
}
|
|
4600
4530
|
function parseJustify(value) {
|
|
4531
|
+
if (value == null) {
|
|
4532
|
+
return Justify.FlexStart;
|
|
4533
|
+
}
|
|
4601
4534
|
switch (value.toLowerCase()) {
|
|
4602
4535
|
case "flex-start":
|
|
4603
4536
|
return Justify.FlexStart;
|
|
@@ -4616,6 +4549,9 @@ function parseJustify(value) {
|
|
|
4616
4549
|
}
|
|
4617
4550
|
}
|
|
4618
4551
|
function parseLogLevel(value) {
|
|
4552
|
+
if (value == null) {
|
|
4553
|
+
return LogLevel.Info;
|
|
4554
|
+
}
|
|
4619
4555
|
switch (value.toLowerCase()) {
|
|
4620
4556
|
case "error":
|
|
4621
4557
|
return LogLevel.Error;
|
|
@@ -4634,6 +4570,9 @@ function parseLogLevel(value) {
|
|
|
4634
4570
|
}
|
|
4635
4571
|
}
|
|
4636
4572
|
function parseMeasureMode(value) {
|
|
4573
|
+
if (value == null) {
|
|
4574
|
+
return MeasureMode.Undefined;
|
|
4575
|
+
}
|
|
4637
4576
|
switch (value.toLowerCase()) {
|
|
4638
4577
|
case "undefined":
|
|
4639
4578
|
return MeasureMode.Undefined;
|
|
@@ -4646,6 +4585,9 @@ function parseMeasureMode(value) {
|
|
|
4646
4585
|
}
|
|
4647
4586
|
}
|
|
4648
4587
|
function parseOverflow(value) {
|
|
4588
|
+
if (value == null) {
|
|
4589
|
+
return Overflow.Visible;
|
|
4590
|
+
}
|
|
4649
4591
|
switch (value.toLowerCase()) {
|
|
4650
4592
|
case "visible":
|
|
4651
4593
|
return Overflow.Visible;
|
|
@@ -4658,6 +4600,9 @@ function parseOverflow(value) {
|
|
|
4658
4600
|
}
|
|
4659
4601
|
}
|
|
4660
4602
|
function parsePositionType(value) {
|
|
4603
|
+
if (value == null) {
|
|
4604
|
+
return PositionType.Relative;
|
|
4605
|
+
}
|
|
4661
4606
|
switch (value.toLowerCase()) {
|
|
4662
4607
|
case "static":
|
|
4663
4608
|
return PositionType.Static;
|
|
@@ -4670,6 +4615,9 @@ function parsePositionType(value) {
|
|
|
4670
4615
|
}
|
|
4671
4616
|
}
|
|
4672
4617
|
function parseUnit(value) {
|
|
4618
|
+
if (value == null) {
|
|
4619
|
+
return Unit.Point;
|
|
4620
|
+
}
|
|
4673
4621
|
switch (value.toLowerCase()) {
|
|
4674
4622
|
case "undefined":
|
|
4675
4623
|
return Unit.Undefined;
|
|
@@ -4684,6 +4632,9 @@ function parseUnit(value) {
|
|
|
4684
4632
|
}
|
|
4685
4633
|
}
|
|
4686
4634
|
function parseWrap(value) {
|
|
4635
|
+
if (value == null) {
|
|
4636
|
+
return Wrap.NoWrap;
|
|
4637
|
+
}
|
|
4687
4638
|
switch (value.toLowerCase()) {
|
|
4688
4639
|
case "no-wrap":
|
|
4689
4640
|
return Wrap.NoWrap;
|
|
@@ -6254,8 +6205,9 @@ function getTreeSitterClient() {
|
|
|
6254
6205
|
});
|
|
6255
6206
|
}
|
|
6256
6207
|
// src/zig.ts
|
|
6257
|
-
import { dlopen, toArrayBuffer as
|
|
6208
|
+
import { dlopen, toArrayBuffer as toArrayBuffer4, JSCallback, ptr as ptr3 } from "bun:ffi";
|
|
6258
6209
|
import { existsSync as existsSync2 } from "fs";
|
|
6210
|
+
import { EventEmitter as EventEmitter4 } from "events";
|
|
6259
6211
|
|
|
6260
6212
|
// src/buffer.ts
|
|
6261
6213
|
import { toArrayBuffer } from "bun:ffi";
|
|
@@ -6411,9 +6363,13 @@ class OptimizedBuffer {
|
|
|
6411
6363
|
this._destroyed = true;
|
|
6412
6364
|
this.lib.destroyOptimizedBuffer(this.bufferPtr);
|
|
6413
6365
|
}
|
|
6414
|
-
drawTextBuffer(
|
|
6366
|
+
drawTextBuffer(textBufferView, x, y) {
|
|
6367
|
+
this.guard();
|
|
6368
|
+
this.lib.bufferDrawTextBufferView(this.bufferPtr, textBufferView.ptr, x, y);
|
|
6369
|
+
}
|
|
6370
|
+
drawEditorView(editorView, x, y) {
|
|
6415
6371
|
this.guard();
|
|
6416
|
-
this.lib.
|
|
6372
|
+
this.lib.bufferDrawEditorView(this.bufferPtr, editorView.ptr, x, y);
|
|
6417
6373
|
}
|
|
6418
6374
|
drawSuperSampleBuffer(x, y, pixelDataPtr, pixelDataLength, format, alignedBytesPerRow) {
|
|
6419
6375
|
this.guard();
|
|
@@ -6453,6 +6409,624 @@ class OptimizedBuffer {
|
|
|
6453
6409
|
}
|
|
6454
6410
|
}
|
|
6455
6411
|
|
|
6412
|
+
// ../../node_modules/.bun/bun-ffi-structs@0.1.0+ca84541ac88a3075/node_modules/bun-ffi-structs/index.js
|
|
6413
|
+
import { ptr, toArrayBuffer as toArrayBuffer2 } from "bun:ffi";
|
|
6414
|
+
function fatalError(...args) {
|
|
6415
|
+
const message = args.join(" ");
|
|
6416
|
+
console.error("FATAL ERROR:", message);
|
|
6417
|
+
throw new Error(message);
|
|
6418
|
+
}
|
|
6419
|
+
var pointerSize = process.arch === "x64" || process.arch === "arm64" ? 8 : 4;
|
|
6420
|
+
var typeSizes = {
|
|
6421
|
+
u8: 1,
|
|
6422
|
+
bool_u8: 1,
|
|
6423
|
+
bool_u32: 4,
|
|
6424
|
+
u16: 2,
|
|
6425
|
+
i16: 2,
|
|
6426
|
+
u32: 4,
|
|
6427
|
+
u64: 8,
|
|
6428
|
+
f32: 4,
|
|
6429
|
+
f64: 8,
|
|
6430
|
+
pointer: pointerSize,
|
|
6431
|
+
i32: 4
|
|
6432
|
+
};
|
|
6433
|
+
var primitiveKeys = Object.keys(typeSizes);
|
|
6434
|
+
function isPrimitiveType(type) {
|
|
6435
|
+
return typeof type === "string" && primitiveKeys.includes(type);
|
|
6436
|
+
}
|
|
6437
|
+
var typeAlignments = { ...typeSizes };
|
|
6438
|
+
var typeGetters = {
|
|
6439
|
+
u8: (view, offset) => view.getUint8(offset),
|
|
6440
|
+
bool_u8: (view, offset) => Boolean(view.getUint8(offset)),
|
|
6441
|
+
bool_u32: (view, offset) => Boolean(view.getUint32(offset, true)),
|
|
6442
|
+
u16: (view, offset) => view.getUint16(offset, true),
|
|
6443
|
+
i16: (view, offset) => view.getInt16(offset, true),
|
|
6444
|
+
u32: (view, offset) => view.getUint32(offset, true),
|
|
6445
|
+
u64: (view, offset) => view.getBigUint64(offset, true),
|
|
6446
|
+
f32: (view, offset) => view.getFloat32(offset, true),
|
|
6447
|
+
f64: (view, offset) => view.getFloat64(offset, true),
|
|
6448
|
+
i32: (view, offset) => view.getInt32(offset, true),
|
|
6449
|
+
pointer: (view, offset) => pointerSize === 8 ? view.getBigUint64(offset, true) : BigInt(view.getUint32(offset, true))
|
|
6450
|
+
};
|
|
6451
|
+
function isObjectPointerDef(type) {
|
|
6452
|
+
return typeof type === "object" && type !== null && type.__type === "objectPointer";
|
|
6453
|
+
}
|
|
6454
|
+
function alignOffset(offset, align) {
|
|
6455
|
+
return offset + (align - 1) & ~(align - 1);
|
|
6456
|
+
}
|
|
6457
|
+
function isEnum(type) {
|
|
6458
|
+
return typeof type === "object" && type.__type === "enum";
|
|
6459
|
+
}
|
|
6460
|
+
function isStruct(type) {
|
|
6461
|
+
return typeof type === "object" && type.__type === "struct";
|
|
6462
|
+
}
|
|
6463
|
+
function primitivePackers(type) {
|
|
6464
|
+
let pack;
|
|
6465
|
+
let unpack;
|
|
6466
|
+
switch (type) {
|
|
6467
|
+
case "u8":
|
|
6468
|
+
pack = (view, off, val) => view.setUint8(off, val);
|
|
6469
|
+
unpack = (view, off) => view.getUint8(off);
|
|
6470
|
+
break;
|
|
6471
|
+
case "bool_u8":
|
|
6472
|
+
pack = (view, off, val) => view.setUint8(off, val ? 1 : 0);
|
|
6473
|
+
unpack = (view, off) => Boolean(view.getUint8(off));
|
|
6474
|
+
break;
|
|
6475
|
+
case "bool_u32":
|
|
6476
|
+
pack = (view, off, val) => view.setUint32(off, val ? 1 : 0, true);
|
|
6477
|
+
unpack = (view, off) => Boolean(view.getUint32(off, true));
|
|
6478
|
+
break;
|
|
6479
|
+
case "u16":
|
|
6480
|
+
pack = (view, off, val) => view.setUint16(off, val, true);
|
|
6481
|
+
unpack = (view, off) => view.getUint16(off, true);
|
|
6482
|
+
break;
|
|
6483
|
+
case "i16":
|
|
6484
|
+
pack = (view, off, val) => view.setInt16(off, val, true);
|
|
6485
|
+
unpack = (view, off) => view.getInt16(off, true);
|
|
6486
|
+
break;
|
|
6487
|
+
case "u32":
|
|
6488
|
+
pack = (view, off, val) => view.setUint32(off, val, true);
|
|
6489
|
+
unpack = (view, off) => view.getUint32(off, true);
|
|
6490
|
+
break;
|
|
6491
|
+
case "i32":
|
|
6492
|
+
pack = (view, off, val) => view.setInt32(off, val, true);
|
|
6493
|
+
unpack = (view, off) => view.getInt32(off, true);
|
|
6494
|
+
break;
|
|
6495
|
+
case "u64":
|
|
6496
|
+
pack = (view, off, val) => view.setBigUint64(off, BigInt(val), true);
|
|
6497
|
+
unpack = (view, off) => view.getBigUint64(off, true);
|
|
6498
|
+
break;
|
|
6499
|
+
case "f32":
|
|
6500
|
+
pack = (view, off, val) => view.setFloat32(off, val, true);
|
|
6501
|
+
unpack = (view, off) => view.getFloat32(off, true);
|
|
6502
|
+
break;
|
|
6503
|
+
case "f64":
|
|
6504
|
+
pack = (view, off, val) => view.setFloat64(off, val, true);
|
|
6505
|
+
unpack = (view, off) => view.getFloat64(off, true);
|
|
6506
|
+
break;
|
|
6507
|
+
case "pointer":
|
|
6508
|
+
pack = (view, off, val) => {
|
|
6509
|
+
pointerSize === 8 ? view.setBigUint64(off, val ? BigInt(val) : 0n, true) : view.setUint32(off, val ? Number(val) : 0, true);
|
|
6510
|
+
};
|
|
6511
|
+
unpack = (view, off) => {
|
|
6512
|
+
const bint = pointerSize === 8 ? view.getBigUint64(off, true) : BigInt(view.getUint32(off, true));
|
|
6513
|
+
return Number(bint);
|
|
6514
|
+
};
|
|
6515
|
+
break;
|
|
6516
|
+
default:
|
|
6517
|
+
fatalError(`Unsupported primitive type: ${type}`);
|
|
6518
|
+
}
|
|
6519
|
+
return { pack, unpack };
|
|
6520
|
+
}
|
|
6521
|
+
var { pack: pointerPacker, unpack: pointerUnpacker } = primitivePackers("pointer");
|
|
6522
|
+
function packObjectArray(val) {
|
|
6523
|
+
const buffer = new ArrayBuffer(val.length * pointerSize);
|
|
6524
|
+
const bufferView = new DataView(buffer);
|
|
6525
|
+
for (let i = 0;i < val.length; i++) {
|
|
6526
|
+
const instance = val[i];
|
|
6527
|
+
const ptrValue = instance?.ptr ?? null;
|
|
6528
|
+
pointerPacker(bufferView, i * pointerSize, ptrValue);
|
|
6529
|
+
}
|
|
6530
|
+
return bufferView;
|
|
6531
|
+
}
|
|
6532
|
+
var encoder = new TextEncoder;
|
|
6533
|
+
function defineStruct(fields, structDefOptions) {
|
|
6534
|
+
let offset = 0;
|
|
6535
|
+
let maxAlign = 1;
|
|
6536
|
+
const layout = [];
|
|
6537
|
+
const lengthOfFields = {};
|
|
6538
|
+
const lengthOfRequested = [];
|
|
6539
|
+
const arrayFieldsMetadata = {};
|
|
6540
|
+
for (const [name, typeOrStruct, options = {}] of fields) {
|
|
6541
|
+
if (options.condition && !options.condition()) {
|
|
6542
|
+
continue;
|
|
6543
|
+
}
|
|
6544
|
+
let size = 0, align = 0;
|
|
6545
|
+
let pack;
|
|
6546
|
+
let unpack;
|
|
6547
|
+
let needsLengthOf = false;
|
|
6548
|
+
let lengthOfDef = null;
|
|
6549
|
+
if (isPrimitiveType(typeOrStruct)) {
|
|
6550
|
+
size = typeSizes[typeOrStruct];
|
|
6551
|
+
align = typeAlignments[typeOrStruct];
|
|
6552
|
+
({ pack, unpack } = primitivePackers(typeOrStruct));
|
|
6553
|
+
} else if (typeof typeOrStruct === "string" && typeOrStruct === "cstring") {
|
|
6554
|
+
size = pointerSize;
|
|
6555
|
+
align = pointerSize;
|
|
6556
|
+
pack = (view, off, val) => {
|
|
6557
|
+
const bufPtr = val ? ptr(encoder.encode(val + "\x00")) : null;
|
|
6558
|
+
pointerPacker(view, off, bufPtr);
|
|
6559
|
+
};
|
|
6560
|
+
unpack = (view, off) => {
|
|
6561
|
+
const ptrVal = pointerUnpacker(view, off);
|
|
6562
|
+
return ptrVal;
|
|
6563
|
+
};
|
|
6564
|
+
} else if (typeof typeOrStruct === "string" && typeOrStruct === "char*") {
|
|
6565
|
+
size = pointerSize;
|
|
6566
|
+
align = pointerSize;
|
|
6567
|
+
pack = (view, off, val) => {
|
|
6568
|
+
const bufPtr = val ? ptr(encoder.encode(val)) : null;
|
|
6569
|
+
pointerPacker(view, off, bufPtr);
|
|
6570
|
+
};
|
|
6571
|
+
unpack = (view, off) => {
|
|
6572
|
+
const ptrVal = pointerUnpacker(view, off);
|
|
6573
|
+
return ptrVal;
|
|
6574
|
+
};
|
|
6575
|
+
} else if (isEnum(typeOrStruct)) {
|
|
6576
|
+
const base = typeOrStruct.type;
|
|
6577
|
+
size = typeSizes[base];
|
|
6578
|
+
align = typeAlignments[base];
|
|
6579
|
+
const { pack: packEnum } = primitivePackers(base);
|
|
6580
|
+
pack = (view, off, val) => {
|
|
6581
|
+
const num = typeOrStruct.to(val);
|
|
6582
|
+
packEnum(view, off, num);
|
|
6583
|
+
};
|
|
6584
|
+
unpack = (view, off) => {
|
|
6585
|
+
const raw = typeGetters[base](view, off);
|
|
6586
|
+
return typeOrStruct.from(raw);
|
|
6587
|
+
};
|
|
6588
|
+
} else if (isStruct(typeOrStruct)) {
|
|
6589
|
+
if (options.asPointer === true) {
|
|
6590
|
+
size = pointerSize;
|
|
6591
|
+
align = pointerSize;
|
|
6592
|
+
pack = (view, off, val, obj, options2) => {
|
|
6593
|
+
if (!val) {
|
|
6594
|
+
pointerPacker(view, off, null);
|
|
6595
|
+
return;
|
|
6596
|
+
}
|
|
6597
|
+
const nestedBuf = typeOrStruct.pack(val, options2);
|
|
6598
|
+
pointerPacker(view, off, ptr(nestedBuf));
|
|
6599
|
+
};
|
|
6600
|
+
unpack = (view, off) => {
|
|
6601
|
+
throw new Error("Not implemented yet");
|
|
6602
|
+
};
|
|
6603
|
+
} else {
|
|
6604
|
+
size = typeOrStruct.size;
|
|
6605
|
+
align = typeOrStruct.align;
|
|
6606
|
+
pack = (view, off, val, obj, options2) => {
|
|
6607
|
+
const nestedBuf = typeOrStruct.pack(val, options2);
|
|
6608
|
+
const nestedView = new Uint8Array(nestedBuf);
|
|
6609
|
+
const dView = new Uint8Array(view.buffer);
|
|
6610
|
+
dView.set(nestedView, off);
|
|
6611
|
+
};
|
|
6612
|
+
unpack = (view, off) => {
|
|
6613
|
+
const slice = view.buffer.slice(off, off + size);
|
|
6614
|
+
return typeOrStruct.unpack(slice);
|
|
6615
|
+
};
|
|
6616
|
+
}
|
|
6617
|
+
} else if (isObjectPointerDef(typeOrStruct)) {
|
|
6618
|
+
size = pointerSize;
|
|
6619
|
+
align = pointerSize;
|
|
6620
|
+
pack = (view, off, value) => {
|
|
6621
|
+
const ptrValue = value?.ptr ?? null;
|
|
6622
|
+
if (ptrValue === undefined) {
|
|
6623
|
+
console.warn(`Field '${name}' expected object with '.ptr' property, but got undefined pointer value from:`, value);
|
|
6624
|
+
pointerPacker(view, off, null);
|
|
6625
|
+
} else {
|
|
6626
|
+
pointerPacker(view, off, ptrValue);
|
|
6627
|
+
}
|
|
6628
|
+
};
|
|
6629
|
+
unpack = (view, off) => {
|
|
6630
|
+
return pointerUnpacker(view, off);
|
|
6631
|
+
};
|
|
6632
|
+
} else if (Array.isArray(typeOrStruct) && typeOrStruct.length === 1 && typeOrStruct[0] !== undefined) {
|
|
6633
|
+
const [def] = typeOrStruct;
|
|
6634
|
+
size = pointerSize;
|
|
6635
|
+
align = pointerSize;
|
|
6636
|
+
let arrayElementSize;
|
|
6637
|
+
if (isEnum(def)) {
|
|
6638
|
+
arrayElementSize = typeSizes[def.type];
|
|
6639
|
+
pack = (view, off, val, obj) => {
|
|
6640
|
+
if (!val || val.length === 0) {
|
|
6641
|
+
pointerPacker(view, off, null);
|
|
6642
|
+
return;
|
|
6643
|
+
}
|
|
6644
|
+
const buffer = new ArrayBuffer(val.length * arrayElementSize);
|
|
6645
|
+
const bufferView = new DataView(buffer);
|
|
6646
|
+
for (let i = 0;i < val.length; i++) {
|
|
6647
|
+
const num = def.to(val[i]);
|
|
6648
|
+
bufferView.setUint32(i * arrayElementSize, num, true);
|
|
6649
|
+
}
|
|
6650
|
+
pointerPacker(view, off, ptr(buffer));
|
|
6651
|
+
};
|
|
6652
|
+
unpack = null;
|
|
6653
|
+
needsLengthOf = true;
|
|
6654
|
+
lengthOfDef = def;
|
|
6655
|
+
} else if (isStruct(def)) {
|
|
6656
|
+
arrayElementSize = def.size;
|
|
6657
|
+
pack = (view, off, val, obj, options2) => {
|
|
6658
|
+
if (!val || val.length === 0) {
|
|
6659
|
+
pointerPacker(view, off, null);
|
|
6660
|
+
return;
|
|
6661
|
+
}
|
|
6662
|
+
const buffer = new ArrayBuffer(val.length * arrayElementSize);
|
|
6663
|
+
const bufferView = new DataView(buffer);
|
|
6664
|
+
for (let i = 0;i < val.length; i++) {
|
|
6665
|
+
def.packInto(val[i], bufferView, i * arrayElementSize, options2);
|
|
6666
|
+
}
|
|
6667
|
+
pointerPacker(view, off, ptr(buffer));
|
|
6668
|
+
};
|
|
6669
|
+
unpack = (view, off) => {
|
|
6670
|
+
throw new Error("Not implemented yet");
|
|
6671
|
+
};
|
|
6672
|
+
} else if (isPrimitiveType(def)) {
|
|
6673
|
+
arrayElementSize = typeSizes[def];
|
|
6674
|
+
const { pack: primitivePack } = primitivePackers(def);
|
|
6675
|
+
pack = (view, off, val) => {
|
|
6676
|
+
if (!val || val.length === 0) {
|
|
6677
|
+
pointerPacker(view, off, null);
|
|
6678
|
+
return;
|
|
6679
|
+
}
|
|
6680
|
+
const buffer = new ArrayBuffer(val.length * arrayElementSize);
|
|
6681
|
+
const bufferView = new DataView(buffer);
|
|
6682
|
+
for (let i = 0;i < val.length; i++) {
|
|
6683
|
+
primitivePack(bufferView, i * arrayElementSize, val[i]);
|
|
6684
|
+
}
|
|
6685
|
+
pointerPacker(view, off, ptr(buffer));
|
|
6686
|
+
};
|
|
6687
|
+
unpack = null;
|
|
6688
|
+
needsLengthOf = true;
|
|
6689
|
+
lengthOfDef = def;
|
|
6690
|
+
} else if (isObjectPointerDef(def)) {
|
|
6691
|
+
arrayElementSize = pointerSize;
|
|
6692
|
+
pack = (view, off, val) => {
|
|
6693
|
+
if (!val || val.length === 0) {
|
|
6694
|
+
pointerPacker(view, off, null);
|
|
6695
|
+
return;
|
|
6696
|
+
}
|
|
6697
|
+
const packedView = packObjectArray(val);
|
|
6698
|
+
pointerPacker(view, off, ptr(packedView.buffer));
|
|
6699
|
+
};
|
|
6700
|
+
unpack = () => {
|
|
6701
|
+
throw new Error("not implemented yet");
|
|
6702
|
+
};
|
|
6703
|
+
} else {
|
|
6704
|
+
throw new Error(`Unsupported array element type for ${name}: ${JSON.stringify(def)}`);
|
|
6705
|
+
}
|
|
6706
|
+
const lengthOfField = Object.values(lengthOfFields).find((f) => f.lengthOf === name);
|
|
6707
|
+
if (lengthOfField && isPrimitiveType(lengthOfField.type)) {
|
|
6708
|
+
const { pack: lengthPack } = primitivePackers(lengthOfField.type);
|
|
6709
|
+
arrayFieldsMetadata[name] = {
|
|
6710
|
+
elementSize: arrayElementSize,
|
|
6711
|
+
arrayOffset: offset,
|
|
6712
|
+
lengthOffset: lengthOfField.offset,
|
|
6713
|
+
lengthPack
|
|
6714
|
+
};
|
|
6715
|
+
}
|
|
6716
|
+
} else {
|
|
6717
|
+
throw new Error(`Unsupported field type for ${name}: ${JSON.stringify(typeOrStruct)}`);
|
|
6718
|
+
}
|
|
6719
|
+
offset = alignOffset(offset, align);
|
|
6720
|
+
if (options.unpackTransform) {
|
|
6721
|
+
const originalUnpack = unpack;
|
|
6722
|
+
unpack = (view, off) => options.unpackTransform(originalUnpack(view, off));
|
|
6723
|
+
}
|
|
6724
|
+
if (options.packTransform) {
|
|
6725
|
+
const originalPack = pack;
|
|
6726
|
+
pack = (view, off, val, obj, packOptions) => originalPack(view, off, options.packTransform(val), obj, packOptions);
|
|
6727
|
+
}
|
|
6728
|
+
if (options.optional) {
|
|
6729
|
+
const originalPack = pack;
|
|
6730
|
+
if (isStruct(typeOrStruct) && !options.asPointer) {
|
|
6731
|
+
pack = (view, off, val, obj, packOptions) => {
|
|
6732
|
+
if (val || options.mapOptionalInline) {
|
|
6733
|
+
originalPack(view, off, val, obj, packOptions);
|
|
6734
|
+
}
|
|
6735
|
+
};
|
|
6736
|
+
} else {
|
|
6737
|
+
pack = (view, off, val, obj, packOptions) => originalPack(view, off, val ?? 0, obj, packOptions);
|
|
6738
|
+
}
|
|
6739
|
+
}
|
|
6740
|
+
if (options.lengthOf) {
|
|
6741
|
+
const originalPack = pack;
|
|
6742
|
+
pack = (view, off, val, obj, packOptions) => {
|
|
6743
|
+
const targetValue = obj[options.lengthOf];
|
|
6744
|
+
let length = 0;
|
|
6745
|
+
if (targetValue) {
|
|
6746
|
+
if (typeof targetValue === "string") {
|
|
6747
|
+
length = Buffer.byteLength(targetValue);
|
|
6748
|
+
} else {
|
|
6749
|
+
length = targetValue.length;
|
|
6750
|
+
}
|
|
6751
|
+
}
|
|
6752
|
+
return originalPack(view, off, length, obj, packOptions);
|
|
6753
|
+
};
|
|
6754
|
+
}
|
|
6755
|
+
let validateFunctions;
|
|
6756
|
+
if (options.validate) {
|
|
6757
|
+
validateFunctions = Array.isArray(options.validate) ? options.validate : [options.validate];
|
|
6758
|
+
}
|
|
6759
|
+
const layoutField = {
|
|
6760
|
+
name,
|
|
6761
|
+
offset,
|
|
6762
|
+
size,
|
|
6763
|
+
align,
|
|
6764
|
+
validate: validateFunctions,
|
|
6765
|
+
optional: !!options.optional || !!options.lengthOf || options.default !== undefined,
|
|
6766
|
+
default: options.default,
|
|
6767
|
+
pack,
|
|
6768
|
+
unpack,
|
|
6769
|
+
type: typeOrStruct,
|
|
6770
|
+
lengthOf: options.lengthOf
|
|
6771
|
+
};
|
|
6772
|
+
layout.push(layoutField);
|
|
6773
|
+
if (options.lengthOf) {
|
|
6774
|
+
lengthOfFields[options.lengthOf] = layoutField;
|
|
6775
|
+
}
|
|
6776
|
+
if (needsLengthOf) {
|
|
6777
|
+
if (!lengthOfDef)
|
|
6778
|
+
fatalError(`Internal error: needsLengthOf=true but lengthOfDef is null for ${name}`);
|
|
6779
|
+
lengthOfRequested.push({ requester: layoutField, def: lengthOfDef });
|
|
6780
|
+
}
|
|
6781
|
+
offset += size;
|
|
6782
|
+
maxAlign = Math.max(maxAlign, align);
|
|
6783
|
+
}
|
|
6784
|
+
for (const { requester, def } of lengthOfRequested) {
|
|
6785
|
+
const lengthOfField = lengthOfFields[requester.name];
|
|
6786
|
+
if (!lengthOfField) {
|
|
6787
|
+
throw new Error(`lengthOf field not found for array field ${requester.name}`);
|
|
6788
|
+
}
|
|
6789
|
+
if (isPrimitiveType(def)) {
|
|
6790
|
+
const elemSize = typeSizes[def];
|
|
6791
|
+
const { unpack: primitiveUnpack } = primitivePackers(def);
|
|
6792
|
+
requester.unpack = (view, off) => {
|
|
6793
|
+
const result = [];
|
|
6794
|
+
const length = lengthOfField.unpack(view, lengthOfField.offset);
|
|
6795
|
+
const ptrAddress = pointerUnpacker(view, off);
|
|
6796
|
+
if (ptrAddress === 0n && length > 0) {
|
|
6797
|
+
throw new Error(`Array field ${requester.name} has null pointer but length ${length}.`);
|
|
6798
|
+
}
|
|
6799
|
+
if (ptrAddress === 0n || length === 0) {
|
|
6800
|
+
return [];
|
|
6801
|
+
}
|
|
6802
|
+
const buffer = toArrayBuffer2(ptrAddress, 0, length * elemSize);
|
|
6803
|
+
const bufferView = new DataView(buffer);
|
|
6804
|
+
for (let i = 0;i < length; i++) {
|
|
6805
|
+
result.push(primitiveUnpack(bufferView, i * elemSize));
|
|
6806
|
+
}
|
|
6807
|
+
return result;
|
|
6808
|
+
};
|
|
6809
|
+
} else {
|
|
6810
|
+
const elemSize = def.type === "u32" ? 4 : 8;
|
|
6811
|
+
requester.unpack = (view, off) => {
|
|
6812
|
+
const result = [];
|
|
6813
|
+
const length = lengthOfField.unpack(view, lengthOfField.offset);
|
|
6814
|
+
const ptrAddress = pointerUnpacker(view, off);
|
|
6815
|
+
if (ptrAddress === 0n && length > 0) {
|
|
6816
|
+
throw new Error(`Array field ${requester.name} has null pointer but length ${length}.`);
|
|
6817
|
+
}
|
|
6818
|
+
if (ptrAddress === 0n || length === 0) {
|
|
6819
|
+
return [];
|
|
6820
|
+
}
|
|
6821
|
+
const buffer = toArrayBuffer2(ptrAddress, 0, length * elemSize);
|
|
6822
|
+
const bufferView = new DataView(buffer);
|
|
6823
|
+
for (let i = 0;i < length; i++) {
|
|
6824
|
+
result.push(def.from(bufferView.getUint32(i * elemSize, true)));
|
|
6825
|
+
}
|
|
6826
|
+
return result;
|
|
6827
|
+
};
|
|
6828
|
+
}
|
|
6829
|
+
}
|
|
6830
|
+
const totalSize = alignOffset(offset, maxAlign);
|
|
6831
|
+
const description = layout.map((f) => ({
|
|
6832
|
+
name: f.name,
|
|
6833
|
+
offset: f.offset,
|
|
6834
|
+
size: f.size,
|
|
6835
|
+
align: f.align,
|
|
6836
|
+
optional: f.optional,
|
|
6837
|
+
type: f.type,
|
|
6838
|
+
lengthOf: f.lengthOf
|
|
6839
|
+
}));
|
|
6840
|
+
const layoutByName = new Map(description.map((f) => [f.name, f]));
|
|
6841
|
+
const arrayFields = new Map(Object.entries(arrayFieldsMetadata));
|
|
6842
|
+
return {
|
|
6843
|
+
__type: "struct",
|
|
6844
|
+
size: totalSize,
|
|
6845
|
+
align: maxAlign,
|
|
6846
|
+
hasMapValue: !!structDefOptions?.mapValue,
|
|
6847
|
+
layoutByName,
|
|
6848
|
+
arrayFields,
|
|
6849
|
+
pack(obj, options) {
|
|
6850
|
+
const buf = new ArrayBuffer(totalSize);
|
|
6851
|
+
const view = new DataView(buf);
|
|
6852
|
+
let mappedObj = obj;
|
|
6853
|
+
if (structDefOptions?.mapValue) {
|
|
6854
|
+
mappedObj = structDefOptions.mapValue(obj);
|
|
6855
|
+
}
|
|
6856
|
+
for (const field of layout) {
|
|
6857
|
+
const value = mappedObj[field.name] ?? field.default;
|
|
6858
|
+
if (!field.optional && value === undefined) {
|
|
6859
|
+
fatalError(`Packing non-optional field '${field.name}' but value is undefined (and no default provided)`);
|
|
6860
|
+
}
|
|
6861
|
+
if (field.validate) {
|
|
6862
|
+
for (const validateFn of field.validate) {
|
|
6863
|
+
validateFn(value, field.name, {
|
|
6864
|
+
hints: options?.validationHints,
|
|
6865
|
+
input: mappedObj
|
|
6866
|
+
});
|
|
6867
|
+
}
|
|
6868
|
+
}
|
|
6869
|
+
field.pack(view, field.offset, value, mappedObj, options);
|
|
6870
|
+
}
|
|
6871
|
+
return view.buffer;
|
|
6872
|
+
},
|
|
6873
|
+
packInto(obj, view, offset2, options) {
|
|
6874
|
+
let mappedObj = obj;
|
|
6875
|
+
if (structDefOptions?.mapValue) {
|
|
6876
|
+
mappedObj = structDefOptions.mapValue(obj);
|
|
6877
|
+
}
|
|
6878
|
+
for (const field of layout) {
|
|
6879
|
+
const value = mappedObj[field.name] ?? field.default;
|
|
6880
|
+
if (!field.optional && value === undefined) {
|
|
6881
|
+
console.warn(`packInto missing value for non-optional field '${field.name}' at offset ${offset2 + field.offset}. Writing default or zero.`);
|
|
6882
|
+
}
|
|
6883
|
+
if (field.validate) {
|
|
6884
|
+
for (const validateFn of field.validate) {
|
|
6885
|
+
validateFn(value, field.name, {
|
|
6886
|
+
hints: options?.validationHints,
|
|
6887
|
+
input: mappedObj
|
|
6888
|
+
});
|
|
6889
|
+
}
|
|
6890
|
+
}
|
|
6891
|
+
field.pack(view, offset2 + field.offset, value, mappedObj, options);
|
|
6892
|
+
}
|
|
6893
|
+
},
|
|
6894
|
+
unpack(buf) {
|
|
6895
|
+
if (buf.byteLength < totalSize) {
|
|
6896
|
+
fatalError(`Buffer size (${buf.byteLength}) is smaller than struct size (${totalSize}) for unpacking.`);
|
|
6897
|
+
}
|
|
6898
|
+
const view = new DataView(buf);
|
|
6899
|
+
const result = structDefOptions?.default ? { ...structDefOptions.default } : {};
|
|
6900
|
+
for (const field of layout) {
|
|
6901
|
+
if (!field.unpack) {
|
|
6902
|
+
continue;
|
|
6903
|
+
}
|
|
6904
|
+
try {
|
|
6905
|
+
result[field.name] = field.unpack(view, field.offset);
|
|
6906
|
+
} catch (e) {
|
|
6907
|
+
console.error(`Error unpacking field '${field.name}' at offset ${field.offset}:`, e);
|
|
6908
|
+
throw e;
|
|
6909
|
+
}
|
|
6910
|
+
}
|
|
6911
|
+
if (structDefOptions?.reduceValue) {
|
|
6912
|
+
return structDefOptions.reduceValue(result);
|
|
6913
|
+
}
|
|
6914
|
+
return result;
|
|
6915
|
+
},
|
|
6916
|
+
packList(objects, options) {
|
|
6917
|
+
if (objects.length === 0) {
|
|
6918
|
+
return new ArrayBuffer(0);
|
|
6919
|
+
}
|
|
6920
|
+
const buffer = new ArrayBuffer(totalSize * objects.length);
|
|
6921
|
+
const view = new DataView(buffer);
|
|
6922
|
+
for (let i = 0;i < objects.length; i++) {
|
|
6923
|
+
let mappedObj = objects[i];
|
|
6924
|
+
if (structDefOptions?.mapValue) {
|
|
6925
|
+
mappedObj = structDefOptions.mapValue(objects[i]);
|
|
6926
|
+
}
|
|
6927
|
+
for (const field of layout) {
|
|
6928
|
+
const value = mappedObj[field.name] ?? field.default;
|
|
6929
|
+
if (!field.optional && value === undefined) {
|
|
6930
|
+
fatalError(`Packing non-optional field '${field.name}' at index ${i} but value is undefined (and no default provided)`);
|
|
6931
|
+
}
|
|
6932
|
+
if (field.validate) {
|
|
6933
|
+
for (const validateFn of field.validate) {
|
|
6934
|
+
validateFn(value, field.name, {
|
|
6935
|
+
hints: options?.validationHints,
|
|
6936
|
+
input: mappedObj
|
|
6937
|
+
});
|
|
6938
|
+
}
|
|
6939
|
+
}
|
|
6940
|
+
field.pack(view, i * totalSize + field.offset, value, mappedObj, options);
|
|
6941
|
+
}
|
|
6942
|
+
}
|
|
6943
|
+
return buffer;
|
|
6944
|
+
},
|
|
6945
|
+
unpackList(buf, count) {
|
|
6946
|
+
if (count === 0) {
|
|
6947
|
+
return [];
|
|
6948
|
+
}
|
|
6949
|
+
const expectedSize = totalSize * count;
|
|
6950
|
+
if (buf.byteLength < expectedSize) {
|
|
6951
|
+
fatalError(`Buffer size (${buf.byteLength}) is smaller than expected size (${expectedSize}) for unpacking ${count} structs.`);
|
|
6952
|
+
}
|
|
6953
|
+
const view = new DataView(buf);
|
|
6954
|
+
const results = [];
|
|
6955
|
+
for (let i = 0;i < count; i++) {
|
|
6956
|
+
const offset2 = i * totalSize;
|
|
6957
|
+
const result = structDefOptions?.default ? { ...structDefOptions.default } : {};
|
|
6958
|
+
for (const field of layout) {
|
|
6959
|
+
if (!field.unpack) {
|
|
6960
|
+
continue;
|
|
6961
|
+
}
|
|
6962
|
+
try {
|
|
6963
|
+
result[field.name] = field.unpack(view, offset2 + field.offset);
|
|
6964
|
+
} catch (e) {
|
|
6965
|
+
console.error(`Error unpacking field '${field.name}' at index ${i}, offset ${offset2 + field.offset}:`, e);
|
|
6966
|
+
throw e;
|
|
6967
|
+
}
|
|
6968
|
+
}
|
|
6969
|
+
if (structDefOptions?.reduceValue) {
|
|
6970
|
+
results.push(structDefOptions.reduceValue(result));
|
|
6971
|
+
} else {
|
|
6972
|
+
results.push(result);
|
|
6973
|
+
}
|
|
6974
|
+
}
|
|
6975
|
+
return results;
|
|
6976
|
+
},
|
|
6977
|
+
describe() {
|
|
6978
|
+
return description;
|
|
6979
|
+
}
|
|
6980
|
+
};
|
|
6981
|
+
}
|
|
6982
|
+
|
|
6983
|
+
// src/zig-structs.ts
|
|
6984
|
+
import { ptr as ptr2, toArrayBuffer as toArrayBuffer3 } from "bun:ffi";
|
|
6985
|
+
var rgbaPackTransform = (rgba) => rgba ? ptr2(rgba.buffer) : null;
|
|
6986
|
+
var rgbaUnpackTransform = (ptr3) => ptr3 ? RGBA.fromArray(new Float32Array(toArrayBuffer3(ptr3))) : undefined;
|
|
6987
|
+
var StyledChunkStruct = defineStruct([
|
|
6988
|
+
["text", "char*"],
|
|
6989
|
+
["text_len", "u64", { lengthOf: "text" }],
|
|
6990
|
+
[
|
|
6991
|
+
"fg",
|
|
6992
|
+
"pointer",
|
|
6993
|
+
{
|
|
6994
|
+
optional: true,
|
|
6995
|
+
packTransform: rgbaPackTransform,
|
|
6996
|
+
unpackTransform: rgbaUnpackTransform
|
|
6997
|
+
}
|
|
6998
|
+
],
|
|
6999
|
+
[
|
|
7000
|
+
"bg",
|
|
7001
|
+
"pointer",
|
|
7002
|
+
{
|
|
7003
|
+
optional: true,
|
|
7004
|
+
packTransform: rgbaPackTransform,
|
|
7005
|
+
unpackTransform: rgbaUnpackTransform
|
|
7006
|
+
}
|
|
7007
|
+
],
|
|
7008
|
+
["attributes", "u8", { optional: true }]
|
|
7009
|
+
]);
|
|
7010
|
+
var HighlightStruct = defineStruct([
|
|
7011
|
+
["start", "u32"],
|
|
7012
|
+
["end", "u32"],
|
|
7013
|
+
["styleId", "u32"],
|
|
7014
|
+
["priority", "u8", { default: 0 }],
|
|
7015
|
+
["hlRef", "u16", { default: 0 }]
|
|
7016
|
+
]);
|
|
7017
|
+
var LogicalCursorStruct = defineStruct([
|
|
7018
|
+
["row", "u32"],
|
|
7019
|
+
["col", "u32"],
|
|
7020
|
+
["offset", "u32"]
|
|
7021
|
+
]);
|
|
7022
|
+
var VisualCursorStruct = defineStruct([
|
|
7023
|
+
["visualRow", "u32"],
|
|
7024
|
+
["visualCol", "u32"],
|
|
7025
|
+
["logicalRow", "u32"],
|
|
7026
|
+
["logicalCol", "u32"],
|
|
7027
|
+
["offset", "u32"]
|
|
7028
|
+
]);
|
|
7029
|
+
|
|
6456
7030
|
// src/zig.ts
|
|
6457
7031
|
var module = await import(`@opentui/core-${process.platform}-${process.arch}/index.ts`);
|
|
6458
7032
|
var targetLibPath = module.default;
|
|
@@ -6481,6 +7055,10 @@ function getOpenTUILib(libPath) {
|
|
|
6481
7055
|
args: ["ptr"],
|
|
6482
7056
|
returns: "void"
|
|
6483
7057
|
},
|
|
7058
|
+
setEventCallback: {
|
|
7059
|
+
args: ["ptr"],
|
|
7060
|
+
returns: "void"
|
|
7061
|
+
},
|
|
6484
7062
|
createRenderer: {
|
|
6485
7063
|
args: ["u32", "u32", "bool"],
|
|
6486
7064
|
returns: "ptr"
|
|
@@ -6709,15 +7287,15 @@ function getOpenTUILib(libPath) {
|
|
|
6709
7287
|
args: ["ptr"],
|
|
6710
7288
|
returns: "u32"
|
|
6711
7289
|
},
|
|
6712
|
-
|
|
7290
|
+
textBufferGetByteSize: {
|
|
6713
7291
|
args: ["ptr"],
|
|
6714
|
-
returns: "
|
|
7292
|
+
returns: "u32"
|
|
6715
7293
|
},
|
|
6716
|
-
|
|
6717
|
-
args: ["ptr"
|
|
7294
|
+
textBufferReset: {
|
|
7295
|
+
args: ["ptr"],
|
|
6718
7296
|
returns: "void"
|
|
6719
7297
|
},
|
|
6720
|
-
|
|
7298
|
+
textBufferClear: {
|
|
6721
7299
|
args: ["ptr"],
|
|
6722
7300
|
returns: "void"
|
|
6723
7301
|
},
|
|
@@ -6737,76 +7315,400 @@ function getOpenTUILib(libPath) {
|
|
|
6737
7315
|
args: ["ptr"],
|
|
6738
7316
|
returns: "void"
|
|
6739
7317
|
},
|
|
6740
|
-
|
|
6741
|
-
args: ["ptr", "ptr", "
|
|
6742
|
-
returns: "
|
|
7318
|
+
textBufferRegisterMemBuffer: {
|
|
7319
|
+
args: ["ptr", "ptr", "usize", "bool"],
|
|
7320
|
+
returns: "u16"
|
|
6743
7321
|
},
|
|
6744
|
-
|
|
6745
|
-
args: ["ptr"],
|
|
6746
|
-
returns: "
|
|
7322
|
+
textBufferReplaceMemBuffer: {
|
|
7323
|
+
args: ["ptr", "u8", "ptr", "usize", "bool"],
|
|
7324
|
+
returns: "bool"
|
|
6747
7325
|
},
|
|
6748
|
-
|
|
7326
|
+
textBufferClearMemRegistry: {
|
|
6749
7327
|
args: ["ptr"],
|
|
6750
|
-
returns: "
|
|
7328
|
+
returns: "void"
|
|
6751
7329
|
},
|
|
6752
|
-
|
|
6753
|
-
args: ["ptr", "
|
|
6754
|
-
returns: "
|
|
7330
|
+
textBufferSetTextFromMem: {
|
|
7331
|
+
args: ["ptr", "u8"],
|
|
7332
|
+
returns: "void"
|
|
6755
7333
|
},
|
|
6756
|
-
|
|
6757
|
-
args: ["ptr"],
|
|
6758
|
-
returns: "
|
|
7334
|
+
textBufferLoadFile: {
|
|
7335
|
+
args: ["ptr", "ptr", "usize"],
|
|
7336
|
+
returns: "bool"
|
|
6759
7337
|
},
|
|
6760
|
-
|
|
7338
|
+
textBufferSetStyledText: {
|
|
6761
7339
|
args: ["ptr", "ptr", "usize"],
|
|
6762
|
-
returns: "
|
|
7340
|
+
returns: "void"
|
|
7341
|
+
},
|
|
7342
|
+
textBufferGetLineCount: {
|
|
7343
|
+
args: ["ptr"],
|
|
7344
|
+
returns: "u32"
|
|
6763
7345
|
},
|
|
6764
7346
|
textBufferGetPlainText: {
|
|
6765
7347
|
args: ["ptr", "ptr", "usize"],
|
|
6766
7348
|
returns: "usize"
|
|
6767
7349
|
},
|
|
6768
|
-
|
|
6769
|
-
args: ["ptr", "
|
|
6770
|
-
returns: "
|
|
7350
|
+
textBufferAddHighlightByCharRange: {
|
|
7351
|
+
args: ["ptr", "ptr"],
|
|
7352
|
+
returns: "void"
|
|
7353
|
+
},
|
|
7354
|
+
textBufferAddHighlight: {
|
|
7355
|
+
args: ["ptr", "u32", "ptr"],
|
|
7356
|
+
returns: "void"
|
|
7357
|
+
},
|
|
7358
|
+
textBufferRemoveHighlightsByRef: {
|
|
7359
|
+
args: ["ptr", "u16"],
|
|
7360
|
+
returns: "void"
|
|
7361
|
+
},
|
|
7362
|
+
textBufferClearLineHighlights: {
|
|
7363
|
+
args: ["ptr", "u32"],
|
|
7364
|
+
returns: "void"
|
|
6771
7365
|
},
|
|
6772
|
-
|
|
7366
|
+
textBufferClearAllHighlights: {
|
|
6773
7367
|
args: ["ptr"],
|
|
6774
7368
|
returns: "void"
|
|
6775
7369
|
},
|
|
6776
|
-
|
|
6777
|
-
args: ["ptr", "
|
|
6778
|
-
returns: "
|
|
7370
|
+
textBufferSetSyntaxStyle: {
|
|
7371
|
+
args: ["ptr", "ptr"],
|
|
7372
|
+
returns: "void"
|
|
6779
7373
|
},
|
|
6780
|
-
|
|
7374
|
+
textBufferGetLineHighlightsPtr: {
|
|
7375
|
+
args: ["ptr", "u32", "ptr"],
|
|
7376
|
+
returns: "ptr"
|
|
7377
|
+
},
|
|
7378
|
+
textBufferFreeLineHighlights: {
|
|
6781
7379
|
args: ["ptr", "usize"],
|
|
6782
|
-
returns: "
|
|
7380
|
+
returns: "void"
|
|
6783
7381
|
},
|
|
6784
|
-
|
|
6785
|
-
args: ["ptr"
|
|
6786
|
-
returns: "
|
|
7382
|
+
createTextBufferView: {
|
|
7383
|
+
args: ["ptr"],
|
|
7384
|
+
returns: "ptr"
|
|
6787
7385
|
},
|
|
6788
|
-
|
|
7386
|
+
destroyTextBufferView: {
|
|
6789
7387
|
args: ["ptr"],
|
|
6790
|
-
returns: "
|
|
7388
|
+
returns: "void"
|
|
7389
|
+
},
|
|
7390
|
+
textBufferViewSetSelection: {
|
|
7391
|
+
args: ["ptr", "u32", "u32", "ptr", "ptr"],
|
|
7392
|
+
returns: "void"
|
|
6791
7393
|
},
|
|
6792
|
-
|
|
7394
|
+
textBufferViewResetSelection: {
|
|
7395
|
+
args: ["ptr"],
|
|
7396
|
+
returns: "void"
|
|
7397
|
+
},
|
|
7398
|
+
textBufferViewGetSelectionInfo: {
|
|
7399
|
+
args: ["ptr"],
|
|
7400
|
+
returns: "u64"
|
|
7401
|
+
},
|
|
7402
|
+
textBufferViewSetLocalSelection: {
|
|
7403
|
+
args: ["ptr", "i32", "i32", "i32", "i32", "ptr", "ptr"],
|
|
7404
|
+
returns: "bool"
|
|
7405
|
+
},
|
|
7406
|
+
textBufferViewResetLocalSelection: {
|
|
7407
|
+
args: ["ptr"],
|
|
7408
|
+
returns: "void"
|
|
7409
|
+
},
|
|
7410
|
+
textBufferViewSetWrapWidth: {
|
|
6793
7411
|
args: ["ptr", "u32"],
|
|
6794
7412
|
returns: "void"
|
|
6795
7413
|
},
|
|
6796
|
-
|
|
7414
|
+
textBufferViewSetWrapMode: {
|
|
6797
7415
|
args: ["ptr", "u8"],
|
|
6798
7416
|
returns: "void"
|
|
6799
7417
|
},
|
|
6800
|
-
|
|
6801
|
-
args: [],
|
|
7418
|
+
textBufferViewSetViewportSize: {
|
|
7419
|
+
args: ["ptr", "u32", "u32"],
|
|
7420
|
+
returns: "void"
|
|
7421
|
+
},
|
|
7422
|
+
textBufferViewGetVirtualLineCount: {
|
|
7423
|
+
args: ["ptr"],
|
|
7424
|
+
returns: "u32"
|
|
7425
|
+
},
|
|
7426
|
+
textBufferViewGetLineInfoDirect: {
|
|
7427
|
+
args: ["ptr", "ptr", "ptr"],
|
|
7428
|
+
returns: "u32"
|
|
7429
|
+
},
|
|
7430
|
+
textBufferViewGetLogicalLineInfoDirect: {
|
|
7431
|
+
args: ["ptr", "ptr", "ptr"],
|
|
7432
|
+
returns: "u32"
|
|
7433
|
+
},
|
|
7434
|
+
textBufferViewGetSelectedText: {
|
|
7435
|
+
args: ["ptr", "ptr", "usize"],
|
|
7436
|
+
returns: "usize"
|
|
7437
|
+
},
|
|
7438
|
+
textBufferViewGetPlainText: {
|
|
7439
|
+
args: ["ptr", "ptr", "usize"],
|
|
6802
7440
|
returns: "usize"
|
|
6803
7441
|
},
|
|
6804
|
-
|
|
6805
|
-
args: ["ptr", "ptr", "i32", "i32"
|
|
7442
|
+
bufferDrawTextBufferView: {
|
|
7443
|
+
args: ["ptr", "ptr", "i32", "i32"],
|
|
6806
7444
|
returns: "void"
|
|
6807
7445
|
},
|
|
6808
|
-
|
|
6809
|
-
args: ["ptr", "ptr"],
|
|
7446
|
+
bufferDrawEditorView: {
|
|
7447
|
+
args: ["ptr", "ptr", "i32", "i32"],
|
|
7448
|
+
returns: "void"
|
|
7449
|
+
},
|
|
7450
|
+
createEditorView: {
|
|
7451
|
+
args: ["ptr", "u32", "u32"],
|
|
7452
|
+
returns: "ptr"
|
|
7453
|
+
},
|
|
7454
|
+
destroyEditorView: {
|
|
7455
|
+
args: ["ptr"],
|
|
7456
|
+
returns: "void"
|
|
7457
|
+
},
|
|
7458
|
+
editorViewSetViewportSize: {
|
|
7459
|
+
args: ["ptr", "u32", "u32"],
|
|
7460
|
+
returns: "void"
|
|
7461
|
+
},
|
|
7462
|
+
editorViewGetViewport: {
|
|
7463
|
+
args: ["ptr", "ptr", "ptr", "ptr", "ptr"],
|
|
7464
|
+
returns: "void"
|
|
7465
|
+
},
|
|
7466
|
+
editorViewSetScrollMargin: {
|
|
7467
|
+
args: ["ptr", "f32"],
|
|
7468
|
+
returns: "void"
|
|
7469
|
+
},
|
|
7470
|
+
editorViewSetWrapMode: {
|
|
7471
|
+
args: ["ptr", "u8"],
|
|
7472
|
+
returns: "void"
|
|
7473
|
+
},
|
|
7474
|
+
editorViewGetVirtualLineCount: {
|
|
7475
|
+
args: ["ptr"],
|
|
7476
|
+
returns: "u32"
|
|
7477
|
+
},
|
|
7478
|
+
editorViewGetTotalVirtualLineCount: {
|
|
7479
|
+
args: ["ptr"],
|
|
7480
|
+
returns: "u32"
|
|
7481
|
+
},
|
|
7482
|
+
editorViewGetTextBufferView: {
|
|
7483
|
+
args: ["ptr"],
|
|
7484
|
+
returns: "ptr"
|
|
7485
|
+
},
|
|
7486
|
+
createEditBuffer: {
|
|
7487
|
+
args: ["u8"],
|
|
7488
|
+
returns: "ptr"
|
|
7489
|
+
},
|
|
7490
|
+
destroyEditBuffer: {
|
|
7491
|
+
args: ["ptr"],
|
|
7492
|
+
returns: "void"
|
|
7493
|
+
},
|
|
7494
|
+
editBufferSetText: {
|
|
7495
|
+
args: ["ptr", "ptr", "usize", "bool"],
|
|
7496
|
+
returns: "void"
|
|
7497
|
+
},
|
|
7498
|
+
editBufferSetTextFromMem: {
|
|
7499
|
+
args: ["ptr", "u8", "bool"],
|
|
7500
|
+
returns: "void"
|
|
7501
|
+
},
|
|
7502
|
+
editBufferGetText: {
|
|
7503
|
+
args: ["ptr", "ptr", "usize"],
|
|
7504
|
+
returns: "usize"
|
|
7505
|
+
},
|
|
7506
|
+
editBufferInsertChar: {
|
|
7507
|
+
args: ["ptr", "ptr", "usize"],
|
|
7508
|
+
returns: "void"
|
|
7509
|
+
},
|
|
7510
|
+
editBufferInsertText: {
|
|
7511
|
+
args: ["ptr", "ptr", "usize"],
|
|
7512
|
+
returns: "void"
|
|
7513
|
+
},
|
|
7514
|
+
editBufferDeleteChar: {
|
|
7515
|
+
args: ["ptr"],
|
|
7516
|
+
returns: "void"
|
|
7517
|
+
},
|
|
7518
|
+
editBufferDeleteCharBackward: {
|
|
7519
|
+
args: ["ptr"],
|
|
7520
|
+
returns: "void"
|
|
7521
|
+
},
|
|
7522
|
+
editBufferDeleteRange: {
|
|
7523
|
+
args: ["ptr", "u32", "u32", "u32", "u32"],
|
|
7524
|
+
returns: "void"
|
|
7525
|
+
},
|
|
7526
|
+
editBufferNewLine: {
|
|
7527
|
+
args: ["ptr"],
|
|
7528
|
+
returns: "void"
|
|
7529
|
+
},
|
|
7530
|
+
editBufferDeleteLine: {
|
|
7531
|
+
args: ["ptr"],
|
|
7532
|
+
returns: "void"
|
|
7533
|
+
},
|
|
7534
|
+
editBufferMoveCursorLeft: {
|
|
7535
|
+
args: ["ptr"],
|
|
7536
|
+
returns: "void"
|
|
7537
|
+
},
|
|
7538
|
+
editBufferMoveCursorRight: {
|
|
7539
|
+
args: ["ptr"],
|
|
7540
|
+
returns: "void"
|
|
7541
|
+
},
|
|
7542
|
+
editBufferMoveCursorUp: {
|
|
7543
|
+
args: ["ptr"],
|
|
7544
|
+
returns: "void"
|
|
7545
|
+
},
|
|
7546
|
+
editBufferMoveCursorDown: {
|
|
7547
|
+
args: ["ptr"],
|
|
7548
|
+
returns: "void"
|
|
7549
|
+
},
|
|
7550
|
+
editBufferGotoLine: {
|
|
7551
|
+
args: ["ptr", "u32"],
|
|
7552
|
+
returns: "void"
|
|
7553
|
+
},
|
|
7554
|
+
editBufferSetCursor: {
|
|
7555
|
+
args: ["ptr", "u32", "u32"],
|
|
7556
|
+
returns: "void"
|
|
7557
|
+
},
|
|
7558
|
+
editBufferSetCursorToLineCol: {
|
|
7559
|
+
args: ["ptr", "u32", "u32"],
|
|
7560
|
+
returns: "void"
|
|
7561
|
+
},
|
|
7562
|
+
editBufferSetCursorByOffset: {
|
|
7563
|
+
args: ["ptr", "u32"],
|
|
7564
|
+
returns: "void"
|
|
7565
|
+
},
|
|
7566
|
+
editBufferGetCursorPosition: {
|
|
7567
|
+
args: ["ptr", "ptr", "ptr", "ptr"],
|
|
7568
|
+
returns: "void"
|
|
7569
|
+
},
|
|
7570
|
+
editBufferGetId: {
|
|
7571
|
+
args: ["ptr"],
|
|
7572
|
+
returns: "u16"
|
|
7573
|
+
},
|
|
7574
|
+
editBufferGetTextBuffer: {
|
|
7575
|
+
args: ["ptr"],
|
|
7576
|
+
returns: "ptr"
|
|
7577
|
+
},
|
|
7578
|
+
editBufferDebugLogRope: {
|
|
7579
|
+
args: ["ptr"],
|
|
7580
|
+
returns: "void"
|
|
7581
|
+
},
|
|
7582
|
+
editBufferUndo: {
|
|
7583
|
+
args: ["ptr", "ptr", "usize"],
|
|
7584
|
+
returns: "usize"
|
|
7585
|
+
},
|
|
7586
|
+
editBufferRedo: {
|
|
7587
|
+
args: ["ptr", "ptr", "usize"],
|
|
7588
|
+
returns: "usize"
|
|
7589
|
+
},
|
|
7590
|
+
editBufferCanUndo: {
|
|
7591
|
+
args: ["ptr"],
|
|
7592
|
+
returns: "bool"
|
|
7593
|
+
},
|
|
7594
|
+
editBufferCanRedo: {
|
|
7595
|
+
args: ["ptr"],
|
|
7596
|
+
returns: "bool"
|
|
7597
|
+
},
|
|
7598
|
+
editBufferClearHistory: {
|
|
7599
|
+
args: ["ptr"],
|
|
7600
|
+
returns: "void"
|
|
7601
|
+
},
|
|
7602
|
+
editBufferSetPlaceholder: {
|
|
7603
|
+
args: ["ptr", "ptr", "usize"],
|
|
7604
|
+
returns: "void"
|
|
7605
|
+
},
|
|
7606
|
+
editBufferSetPlaceholderColor: {
|
|
7607
|
+
args: ["ptr", "ptr"],
|
|
7608
|
+
returns: "void"
|
|
7609
|
+
},
|
|
7610
|
+
editBufferGetNextWordBoundary: {
|
|
7611
|
+
args: ["ptr", "ptr"],
|
|
7612
|
+
returns: "void"
|
|
7613
|
+
},
|
|
7614
|
+
editBufferGetPrevWordBoundary: {
|
|
7615
|
+
args: ["ptr", "ptr"],
|
|
7616
|
+
returns: "void"
|
|
7617
|
+
},
|
|
7618
|
+
editBufferGetEOL: {
|
|
7619
|
+
args: ["ptr", "ptr"],
|
|
7620
|
+
returns: "void"
|
|
7621
|
+
},
|
|
7622
|
+
editorViewSetSelection: {
|
|
7623
|
+
args: ["ptr", "u32", "u32", "ptr", "ptr"],
|
|
7624
|
+
returns: "void"
|
|
7625
|
+
},
|
|
7626
|
+
editorViewResetSelection: {
|
|
7627
|
+
args: ["ptr"],
|
|
7628
|
+
returns: "void"
|
|
7629
|
+
},
|
|
7630
|
+
editorViewGetSelection: {
|
|
7631
|
+
args: ["ptr"],
|
|
7632
|
+
returns: "u64"
|
|
7633
|
+
},
|
|
7634
|
+
editorViewSetLocalSelection: {
|
|
7635
|
+
args: ["ptr", "i32", "i32", "i32", "i32", "ptr", "ptr"],
|
|
7636
|
+
returns: "bool"
|
|
7637
|
+
},
|
|
7638
|
+
editorViewResetLocalSelection: {
|
|
7639
|
+
args: ["ptr"],
|
|
7640
|
+
returns: "void"
|
|
7641
|
+
},
|
|
7642
|
+
editorViewGetSelectedTextBytes: {
|
|
7643
|
+
args: ["ptr", "ptr", "usize"],
|
|
7644
|
+
returns: "usize"
|
|
7645
|
+
},
|
|
7646
|
+
editorViewGetCursor: {
|
|
7647
|
+
args: ["ptr", "ptr", "ptr"],
|
|
7648
|
+
returns: "void"
|
|
7649
|
+
},
|
|
7650
|
+
editorViewGetText: {
|
|
7651
|
+
args: ["ptr", "ptr", "usize"],
|
|
7652
|
+
returns: "usize"
|
|
7653
|
+
},
|
|
7654
|
+
editorViewGetVisualCursor: {
|
|
7655
|
+
args: ["ptr", "ptr"],
|
|
7656
|
+
returns: "void"
|
|
7657
|
+
},
|
|
7658
|
+
editorViewMoveUpVisual: {
|
|
7659
|
+
args: ["ptr"],
|
|
7660
|
+
returns: "void"
|
|
7661
|
+
},
|
|
7662
|
+
editorViewMoveDownVisual: {
|
|
7663
|
+
args: ["ptr"],
|
|
7664
|
+
returns: "void"
|
|
7665
|
+
},
|
|
7666
|
+
editorViewDeleteSelectedText: {
|
|
7667
|
+
args: ["ptr"],
|
|
7668
|
+
returns: "void"
|
|
7669
|
+
},
|
|
7670
|
+
editorViewSetCursorByOffset: {
|
|
7671
|
+
args: ["ptr", "u32"],
|
|
7672
|
+
returns: "void"
|
|
7673
|
+
},
|
|
7674
|
+
editorViewGetNextWordBoundary: {
|
|
7675
|
+
args: ["ptr", "ptr"],
|
|
7676
|
+
returns: "void"
|
|
7677
|
+
},
|
|
7678
|
+
editorViewGetPrevWordBoundary: {
|
|
7679
|
+
args: ["ptr", "ptr"],
|
|
7680
|
+
returns: "void"
|
|
7681
|
+
},
|
|
7682
|
+
editorViewGetEOL: {
|
|
7683
|
+
args: ["ptr", "ptr"],
|
|
7684
|
+
returns: "void"
|
|
7685
|
+
},
|
|
7686
|
+
getArenaAllocatedBytes: {
|
|
7687
|
+
args: [],
|
|
7688
|
+
returns: "usize"
|
|
7689
|
+
},
|
|
7690
|
+
createSyntaxStyle: {
|
|
7691
|
+
args: [],
|
|
7692
|
+
returns: "ptr"
|
|
7693
|
+
},
|
|
7694
|
+
destroySyntaxStyle: {
|
|
7695
|
+
args: ["ptr"],
|
|
7696
|
+
returns: "void"
|
|
7697
|
+
},
|
|
7698
|
+
syntaxStyleRegister: {
|
|
7699
|
+
args: ["ptr", "ptr", "usize", "ptr", "ptr", "u8"],
|
|
7700
|
+
returns: "u32"
|
|
7701
|
+
},
|
|
7702
|
+
syntaxStyleResolveByName: {
|
|
7703
|
+
args: ["ptr", "ptr", "usize"],
|
|
7704
|
+
returns: "u32"
|
|
7705
|
+
},
|
|
7706
|
+
syntaxStyleGetStyleCount: {
|
|
7707
|
+
args: ["ptr"],
|
|
7708
|
+
returns: "usize"
|
|
7709
|
+
},
|
|
7710
|
+
getTerminalCapabilities: {
|
|
7711
|
+
args: ["ptr", "ptr"],
|
|
6810
7712
|
returns: "void"
|
|
6811
7713
|
},
|
|
6812
7714
|
processCapabilityResponse: {
|
|
@@ -6937,9 +7839,13 @@ class FFIRenderLib {
|
|
|
6937
7839
|
encoder = new TextEncoder;
|
|
6938
7840
|
decoder = new TextDecoder;
|
|
6939
7841
|
logCallbackWrapper;
|
|
7842
|
+
eventCallbackWrapper;
|
|
7843
|
+
_nativeEvents = new EventEmitter4;
|
|
7844
|
+
_anyEventHandlers = [];
|
|
6940
7845
|
constructor(libPath) {
|
|
6941
7846
|
this.opentui = getOpenTUILib(libPath);
|
|
6942
7847
|
this.setupLogging();
|
|
7848
|
+
this.setupEventBus();
|
|
6943
7849
|
}
|
|
6944
7850
|
setupLogging() {
|
|
6945
7851
|
if (this.logCallbackWrapper) {
|
|
@@ -6951,7 +7857,7 @@ class FFIRenderLib {
|
|
|
6951
7857
|
if (msgLen === 0 || !msgPtr) {
|
|
6952
7858
|
return;
|
|
6953
7859
|
}
|
|
6954
|
-
const msgBuffer =
|
|
7860
|
+
const msgBuffer = toArrayBuffer4(msgPtr, 0, msgLen);
|
|
6955
7861
|
const msgBytes = new Uint8Array(msgBuffer);
|
|
6956
7862
|
const message = this.decoder.decode(msgBytes);
|
|
6957
7863
|
switch (level) {
|
|
@@ -6986,6 +7892,48 @@ class FFIRenderLib {
|
|
|
6986
7892
|
setLogCallback(callbackPtr) {
|
|
6987
7893
|
this.opentui.symbols.setLogCallback(callbackPtr);
|
|
6988
7894
|
}
|
|
7895
|
+
setupEventBus() {
|
|
7896
|
+
if (this.eventCallbackWrapper) {
|
|
7897
|
+
return;
|
|
7898
|
+
}
|
|
7899
|
+
const eventCallback = new JSCallback((namePtr, nameLenBigInt, dataPtr, dataLenBigInt) => {
|
|
7900
|
+
try {
|
|
7901
|
+
const nameLen = typeof nameLenBigInt === "bigint" ? Number(nameLenBigInt) : nameLenBigInt;
|
|
7902
|
+
const dataLen = typeof dataLenBigInt === "bigint" ? Number(dataLenBigInt) : dataLenBigInt;
|
|
7903
|
+
if (nameLen === 0 || !namePtr) {
|
|
7904
|
+
return;
|
|
7905
|
+
}
|
|
7906
|
+
const nameBuffer = toArrayBuffer4(namePtr, 0, nameLen);
|
|
7907
|
+
const nameBytes = new Uint8Array(nameBuffer);
|
|
7908
|
+
const eventName = this.decoder.decode(nameBytes);
|
|
7909
|
+
let eventData;
|
|
7910
|
+
if (dataLen > 0 && dataPtr) {
|
|
7911
|
+
eventData = toArrayBuffer4(dataPtr, 0, dataLen).slice();
|
|
7912
|
+
} else {
|
|
7913
|
+
eventData = new ArrayBuffer(0);
|
|
7914
|
+
}
|
|
7915
|
+
queueMicrotask(() => {
|
|
7916
|
+
this._nativeEvents.emit(eventName, eventData);
|
|
7917
|
+
for (const handler of this._anyEventHandlers) {
|
|
7918
|
+
handler(eventName, eventData);
|
|
7919
|
+
}
|
|
7920
|
+
});
|
|
7921
|
+
} catch (error) {
|
|
7922
|
+
console.error("Error in native event callback:", error);
|
|
7923
|
+
}
|
|
7924
|
+
}, {
|
|
7925
|
+
args: ["ptr", "usize", "ptr", "usize"],
|
|
7926
|
+
returns: "void"
|
|
7927
|
+
});
|
|
7928
|
+
this.eventCallbackWrapper = eventCallback;
|
|
7929
|
+
if (!eventCallback.ptr) {
|
|
7930
|
+
throw new Error("Failed to create event callback");
|
|
7931
|
+
}
|
|
7932
|
+
this.setEventCallback(eventCallback.ptr);
|
|
7933
|
+
}
|
|
7934
|
+
setEventCallback(callbackPtr) {
|
|
7935
|
+
this.opentui.symbols.setEventCallback(callbackPtr);
|
|
7936
|
+
}
|
|
6989
7937
|
createRenderer(width, height, options = { testing: false }) {
|
|
6990
7938
|
return this.opentui.symbols.createRenderer(width, height, options.testing);
|
|
6991
7939
|
}
|
|
@@ -7026,32 +7974,32 @@ class FFIRenderLib {
|
|
|
7026
7974
|
return new OptimizedBuffer(this, bufferPtr, width, height, { id: "current buffer" });
|
|
7027
7975
|
}
|
|
7028
7976
|
bufferGetCharPtr(buffer) {
|
|
7029
|
-
const
|
|
7030
|
-
if (!
|
|
7977
|
+
const ptr4 = this.opentui.symbols.bufferGetCharPtr(buffer);
|
|
7978
|
+
if (!ptr4) {
|
|
7031
7979
|
throw new Error("Failed to get char pointer");
|
|
7032
7980
|
}
|
|
7033
|
-
return
|
|
7981
|
+
return ptr4;
|
|
7034
7982
|
}
|
|
7035
7983
|
bufferGetFgPtr(buffer) {
|
|
7036
|
-
const
|
|
7037
|
-
if (!
|
|
7984
|
+
const ptr4 = this.opentui.symbols.bufferGetFgPtr(buffer);
|
|
7985
|
+
if (!ptr4) {
|
|
7038
7986
|
throw new Error("Failed to get fg pointer");
|
|
7039
7987
|
}
|
|
7040
|
-
return
|
|
7988
|
+
return ptr4;
|
|
7041
7989
|
}
|
|
7042
7990
|
bufferGetBgPtr(buffer) {
|
|
7043
|
-
const
|
|
7044
|
-
if (!
|
|
7991
|
+
const ptr4 = this.opentui.symbols.bufferGetBgPtr(buffer);
|
|
7992
|
+
if (!ptr4) {
|
|
7045
7993
|
throw new Error("Failed to get bg pointer");
|
|
7046
7994
|
}
|
|
7047
|
-
return
|
|
7995
|
+
return ptr4;
|
|
7048
7996
|
}
|
|
7049
7997
|
bufferGetAttributesPtr(buffer) {
|
|
7050
|
-
const
|
|
7051
|
-
if (!
|
|
7998
|
+
const ptr4 = this.opentui.symbols.bufferGetAttributesPtr(buffer);
|
|
7999
|
+
if (!ptr4) {
|
|
7052
8000
|
throw new Error("Failed to get attributes pointer");
|
|
7053
8001
|
}
|
|
7054
|
-
return
|
|
8002
|
+
return ptr4;
|
|
7055
8003
|
}
|
|
7056
8004
|
bufferGetRespectAlpha(buffer) {
|
|
7057
8005
|
return this.opentui.symbols.bufferGetRespectAlpha(buffer);
|
|
@@ -7219,16 +8167,14 @@ class FFIRenderLib {
|
|
|
7219
8167
|
textBufferGetLength(buffer) {
|
|
7220
8168
|
return this.opentui.symbols.textBufferGetLength(buffer);
|
|
7221
8169
|
}
|
|
8170
|
+
textBufferGetByteSize(buffer) {
|
|
8171
|
+
return this.opentui.symbols.textBufferGetByteSize(buffer);
|
|
8172
|
+
}
|
|
7222
8173
|
textBufferReset(buffer) {
|
|
7223
8174
|
this.opentui.symbols.textBufferReset(buffer);
|
|
7224
8175
|
}
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
const fg2 = fgColor ? fgColor.buffer : null;
|
|
7228
|
-
this.opentui.symbols.textBufferSetSelection(buffer, start, end, bg2, fg2);
|
|
7229
|
-
}
|
|
7230
|
-
textBufferResetSelection(buffer) {
|
|
7231
|
-
this.opentui.symbols.textBufferResetSelection(buffer);
|
|
8176
|
+
textBufferClear(buffer) {
|
|
8177
|
+
this.opentui.symbols.textBufferClear(buffer);
|
|
7232
8178
|
}
|
|
7233
8179
|
textBufferSetDefaultFg(buffer, fg2) {
|
|
7234
8180
|
const fgPtr = fg2 ? fg2.buffer : null;
|
|
@@ -7245,21 +8191,70 @@ class FFIRenderLib {
|
|
|
7245
8191
|
textBufferResetDefaults(buffer) {
|
|
7246
8192
|
this.opentui.symbols.textBufferResetDefaults(buffer);
|
|
7247
8193
|
}
|
|
7248
|
-
|
|
7249
|
-
const
|
|
7250
|
-
|
|
8194
|
+
textBufferRegisterMemBuffer(buffer, bytes, owned = false) {
|
|
8195
|
+
const result = this.opentui.symbols.textBufferRegisterMemBuffer(buffer, bytes, bytes.length, owned);
|
|
8196
|
+
if (result === 65535) {
|
|
8197
|
+
throw new Error("Failed to register memory buffer");
|
|
8198
|
+
}
|
|
8199
|
+
return result;
|
|
7251
8200
|
}
|
|
7252
|
-
|
|
7253
|
-
this.opentui.symbols.
|
|
8201
|
+
textBufferReplaceMemBuffer(buffer, memId, bytes, owned = false) {
|
|
8202
|
+
return this.opentui.symbols.textBufferReplaceMemBuffer(buffer, memId, bytes, bytes.length, owned);
|
|
8203
|
+
}
|
|
8204
|
+
textBufferClearMemRegistry(buffer) {
|
|
8205
|
+
this.opentui.symbols.textBufferClearMemRegistry(buffer);
|
|
8206
|
+
}
|
|
8207
|
+
textBufferSetTextFromMem(buffer, memId) {
|
|
8208
|
+
this.opentui.symbols.textBufferSetTextFromMem(buffer, memId);
|
|
8209
|
+
}
|
|
8210
|
+
textBufferLoadFile(buffer, path4) {
|
|
8211
|
+
const pathBytes = this.encoder.encode(path4);
|
|
8212
|
+
return this.opentui.symbols.textBufferLoadFile(buffer, pathBytes, pathBytes.length);
|
|
8213
|
+
}
|
|
8214
|
+
textBufferSetStyledText(buffer, chunks) {
|
|
8215
|
+
const nonEmptyChunks = chunks.filter((c) => c.text.length > 0);
|
|
8216
|
+
if (nonEmptyChunks.length === 0) {
|
|
8217
|
+
this.textBufferClear(buffer);
|
|
8218
|
+
return;
|
|
8219
|
+
}
|
|
8220
|
+
const chunksBuffer = StyledChunkStruct.packList(nonEmptyChunks);
|
|
8221
|
+
this.opentui.symbols.textBufferSetStyledText(buffer, ptr3(chunksBuffer), nonEmptyChunks.length);
|
|
7254
8222
|
}
|
|
7255
8223
|
textBufferGetLineCount(buffer) {
|
|
7256
8224
|
return this.opentui.symbols.textBufferGetLineCount(buffer);
|
|
7257
8225
|
}
|
|
7258
|
-
|
|
7259
|
-
|
|
8226
|
+
textBufferGetPlainText(buffer, outPtr, maxLen) {
|
|
8227
|
+
const result = this.opentui.symbols.textBufferGetPlainText(buffer, outPtr, maxLen);
|
|
8228
|
+
return typeof result === "bigint" ? Number(result) : result;
|
|
7260
8229
|
}
|
|
7261
|
-
|
|
7262
|
-
const
|
|
8230
|
+
getPlainTextBytes(buffer, maxLength) {
|
|
8231
|
+
const outBuffer = new Uint8Array(maxLength);
|
|
8232
|
+
const actualLen = this.textBufferGetPlainText(buffer, ptr3(outBuffer), maxLength);
|
|
8233
|
+
if (actualLen === 0) {
|
|
8234
|
+
return null;
|
|
8235
|
+
}
|
|
8236
|
+
return outBuffer.slice(0, actualLen);
|
|
8237
|
+
}
|
|
8238
|
+
createTextBufferView(textBuffer) {
|
|
8239
|
+
const viewPtr = this.opentui.symbols.createTextBufferView(textBuffer);
|
|
8240
|
+
if (!viewPtr) {
|
|
8241
|
+
throw new Error("Failed to create TextBufferView");
|
|
8242
|
+
}
|
|
8243
|
+
return viewPtr;
|
|
8244
|
+
}
|
|
8245
|
+
destroyTextBufferView(view) {
|
|
8246
|
+
this.opentui.symbols.destroyTextBufferView(view);
|
|
8247
|
+
}
|
|
8248
|
+
textBufferViewSetSelection(view, start, end, bgColor, fgColor) {
|
|
8249
|
+
const bg2 = bgColor ? bgColor.buffer : null;
|
|
8250
|
+
const fg2 = fgColor ? fgColor.buffer : null;
|
|
8251
|
+
this.opentui.symbols.textBufferViewSetSelection(view, start, end, bg2, fg2);
|
|
8252
|
+
}
|
|
8253
|
+
textBufferViewResetSelection(view) {
|
|
8254
|
+
this.opentui.symbols.textBufferViewResetSelection(view);
|
|
8255
|
+
}
|
|
8256
|
+
textBufferViewGetSelection(view) {
|
|
8257
|
+
const packedInfo = this.textBufferViewGetSelectionInfo(view);
|
|
7263
8258
|
if (packedInfo === 0xffff_ffff_ffff_ffffn) {
|
|
7264
8259
|
return null;
|
|
7265
8260
|
}
|
|
@@ -7267,92 +8262,401 @@ class FFIRenderLib {
|
|
|
7267
8262
|
const end = Number(packedInfo & 0xffff_ffffn);
|
|
7268
8263
|
return { start, end };
|
|
7269
8264
|
}
|
|
7270
|
-
|
|
7271
|
-
return this.opentui.symbols.
|
|
8265
|
+
textBufferViewGetSelectionInfo(view) {
|
|
8266
|
+
return this.opentui.symbols.textBufferViewGetSelectionInfo(view);
|
|
8267
|
+
}
|
|
8268
|
+
textBufferViewSetLocalSelection(view, anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
|
|
8269
|
+
const bg2 = bgColor ? bgColor.buffer : null;
|
|
8270
|
+
const fg2 = fgColor ? fgColor.buffer : null;
|
|
8271
|
+
return this.opentui.symbols.textBufferViewSetLocalSelection(view, anchorX, anchorY, focusX, focusY, bg2, fg2);
|
|
8272
|
+
}
|
|
8273
|
+
textBufferViewResetLocalSelection(view) {
|
|
8274
|
+
this.opentui.symbols.textBufferViewResetLocalSelection(view);
|
|
8275
|
+
}
|
|
8276
|
+
textBufferViewSetWrapWidth(view, width) {
|
|
8277
|
+
this.opentui.symbols.textBufferViewSetWrapWidth(view, width);
|
|
8278
|
+
}
|
|
8279
|
+
textBufferViewSetWrapMode(view, mode) {
|
|
8280
|
+
const modeValue = mode === "none" ? 0 : mode === "char" ? 1 : 2;
|
|
8281
|
+
this.opentui.symbols.textBufferViewSetWrapMode(view, modeValue);
|
|
8282
|
+
}
|
|
8283
|
+
textBufferViewSetViewportSize(view, width, height) {
|
|
8284
|
+
this.opentui.symbols.textBufferViewSetViewportSize(view, width, height);
|
|
8285
|
+
}
|
|
8286
|
+
textBufferViewGetLineInfo(view) {
|
|
8287
|
+
const lineCount = this.textBufferViewGetLineCount(view);
|
|
8288
|
+
if (lineCount === 0) {
|
|
8289
|
+
return { lineStarts: [], lineWidths: [], maxLineWidth: 0 };
|
|
8290
|
+
}
|
|
8291
|
+
const lineStarts = new Uint32Array(lineCount);
|
|
8292
|
+
const lineWidths = new Uint32Array(lineCount);
|
|
8293
|
+
const maxLineWidth = this.textBufferViewGetLineInfoDirect(view, ptr3(lineStarts), ptr3(lineWidths));
|
|
8294
|
+
return {
|
|
8295
|
+
maxLineWidth,
|
|
8296
|
+
lineStarts: Array.from(lineStarts),
|
|
8297
|
+
lineWidths: Array.from(lineWidths)
|
|
8298
|
+
};
|
|
8299
|
+
}
|
|
8300
|
+
textBufferViewGetLogicalLineInfo(view) {
|
|
8301
|
+
const lineCount = this.textBufferViewGetLineCount(view);
|
|
8302
|
+
if (lineCount === 0) {
|
|
8303
|
+
return { lineStarts: [], lineWidths: [], maxLineWidth: 0 };
|
|
8304
|
+
}
|
|
8305
|
+
const lineStarts = new Uint32Array(lineCount);
|
|
8306
|
+
const lineWidths = new Uint32Array(lineCount);
|
|
8307
|
+
const maxLineWidth = this.textBufferViewGetLogicalLineInfoDirect(view, ptr3(lineStarts), ptr3(lineWidths));
|
|
8308
|
+
return {
|
|
8309
|
+
maxLineWidth,
|
|
8310
|
+
lineStarts: Array.from(lineStarts),
|
|
8311
|
+
lineWidths: Array.from(lineWidths)
|
|
8312
|
+
};
|
|
8313
|
+
}
|
|
8314
|
+
textBufferViewGetLineCount(view) {
|
|
8315
|
+
return this.opentui.symbols.textBufferViewGetVirtualLineCount(view);
|
|
8316
|
+
}
|
|
8317
|
+
textBufferViewGetLineInfoDirect(view, lineStartsPtr, lineWidthsPtr) {
|
|
8318
|
+
return this.opentui.symbols.textBufferViewGetLineInfoDirect(view, lineStartsPtr, lineWidthsPtr);
|
|
8319
|
+
}
|
|
8320
|
+
textBufferViewGetLogicalLineInfoDirect(view, lineStartsPtr, lineWidthsPtr) {
|
|
8321
|
+
return this.opentui.symbols.textBufferViewGetLogicalLineInfoDirect(view, lineStartsPtr, lineWidthsPtr);
|
|
7272
8322
|
}
|
|
7273
|
-
|
|
7274
|
-
const result = this.opentui.symbols.
|
|
8323
|
+
textBufferViewGetSelectedText(view, outPtr, maxLen) {
|
|
8324
|
+
const result = this.opentui.symbols.textBufferViewGetSelectedText(view, outPtr, maxLen);
|
|
7275
8325
|
return typeof result === "bigint" ? Number(result) : result;
|
|
7276
8326
|
}
|
|
7277
|
-
|
|
7278
|
-
const result = this.opentui.symbols.
|
|
8327
|
+
textBufferViewGetPlainText(view, outPtr, maxLen) {
|
|
8328
|
+
const result = this.opentui.symbols.textBufferViewGetPlainText(view, outPtr, maxLen);
|
|
7279
8329
|
return typeof result === "bigint" ? Number(result) : result;
|
|
7280
8330
|
}
|
|
7281
|
-
|
|
8331
|
+
textBufferViewGetSelectedTextBytes(view, maxLength) {
|
|
7282
8332
|
const outBuffer = new Uint8Array(maxLength);
|
|
7283
|
-
const actualLen = this.
|
|
8333
|
+
const actualLen = this.textBufferViewGetSelectedText(view, ptr3(outBuffer), maxLength);
|
|
7284
8334
|
if (actualLen === 0) {
|
|
7285
8335
|
return null;
|
|
7286
8336
|
}
|
|
7287
8337
|
return outBuffer.slice(0, actualLen);
|
|
7288
8338
|
}
|
|
7289
|
-
|
|
8339
|
+
textBufferViewGetPlainTextBytes(view, maxLength) {
|
|
7290
8340
|
const outBuffer = new Uint8Array(maxLength);
|
|
7291
|
-
const actualLen = this.
|
|
8341
|
+
const actualLen = this.textBufferViewGetPlainText(view, ptr3(outBuffer), maxLength);
|
|
7292
8342
|
if (actualLen === 0) {
|
|
7293
8343
|
return null;
|
|
7294
8344
|
}
|
|
7295
8345
|
return outBuffer.slice(0, actualLen);
|
|
7296
8346
|
}
|
|
7297
|
-
|
|
7298
|
-
const
|
|
7299
|
-
|
|
7300
|
-
return this.opentui.symbols.textBufferSetLocalSelection(buffer, anchorX, anchorY, focusX, focusY, bg2, fg2);
|
|
8347
|
+
textBufferAddHighlightByCharRange(buffer, highlight) {
|
|
8348
|
+
const packedHighlight = HighlightStruct.pack(highlight);
|
|
8349
|
+
this.opentui.symbols.textBufferAddHighlightByCharRange(buffer, ptr3(packedHighlight));
|
|
7301
8350
|
}
|
|
7302
|
-
|
|
7303
|
-
|
|
8351
|
+
textBufferAddHighlight(buffer, lineIdx, highlight) {
|
|
8352
|
+
const packedHighlight = HighlightStruct.pack(highlight);
|
|
8353
|
+
this.opentui.symbols.textBufferAddHighlight(buffer, lineIdx, ptr3(packedHighlight));
|
|
7304
8354
|
}
|
|
7305
|
-
|
|
7306
|
-
|
|
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);
|
|
8355
|
+
textBufferRemoveHighlightsByRef(buffer, hlRef) {
|
|
8356
|
+
this.opentui.symbols.textBufferRemoveHighlightsByRef(buffer, hlRef);
|
|
7310
8357
|
}
|
|
7311
|
-
|
|
7312
|
-
|
|
7313
|
-
}
|
|
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);
|
|
8358
|
+
textBufferClearLineHighlights(buffer, lineIdx) {
|
|
8359
|
+
this.opentui.symbols.textBufferClearLineHighlights(buffer, lineIdx);
|
|
7319
8360
|
}
|
|
7320
|
-
|
|
7321
|
-
|
|
7322
|
-
return typeof result === "bigint" ? Number(result) : result;
|
|
8361
|
+
textBufferClearAllHighlights(buffer) {
|
|
8362
|
+
this.opentui.symbols.textBufferClearAllHighlights(buffer);
|
|
7323
8363
|
}
|
|
7324
|
-
|
|
7325
|
-
this.opentui.symbols.
|
|
8364
|
+
textBufferSetSyntaxStyle(buffer, style) {
|
|
8365
|
+
this.opentui.symbols.textBufferSetSyntaxStyle(buffer, style);
|
|
7326
8366
|
}
|
|
7327
|
-
|
|
7328
|
-
const
|
|
7329
|
-
this.opentui.symbols.
|
|
8367
|
+
textBufferGetLineHighlights(buffer, lineIdx) {
|
|
8368
|
+
const outCountBuf = new BigUint64Array(1);
|
|
8369
|
+
const nativePtr = this.opentui.symbols.textBufferGetLineHighlightsPtr(buffer, lineIdx, ptr3(outCountBuf));
|
|
8370
|
+
if (!nativePtr)
|
|
8371
|
+
return [];
|
|
8372
|
+
const count = Number(outCountBuf[0]);
|
|
8373
|
+
const byteLen = count * HighlightStruct.size;
|
|
8374
|
+
const raw = toArrayBuffer4(nativePtr, 0, byteLen);
|
|
8375
|
+
const results = HighlightStruct.unpackList(raw, count);
|
|
8376
|
+
this.opentui.symbols.textBufferFreeLineHighlights(nativePtr, count);
|
|
8377
|
+
return results;
|
|
7330
8378
|
}
|
|
7331
8379
|
getArenaAllocatedBytes() {
|
|
7332
8380
|
const result = this.opentui.symbols.getArenaAllocatedBytes();
|
|
7333
8381
|
return typeof result === "bigint" ? Number(result) : result;
|
|
7334
8382
|
}
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
|
|
8383
|
+
bufferDrawTextBufferView(buffer, view, x, y) {
|
|
8384
|
+
this.opentui.symbols.bufferDrawTextBufferView(buffer, view, x, y);
|
|
8385
|
+
}
|
|
8386
|
+
bufferDrawEditorView(buffer, view, x, y) {
|
|
8387
|
+
this.opentui.symbols.bufferDrawEditorView(buffer, view, x, y);
|
|
8388
|
+
}
|
|
8389
|
+
createEditorView(editBufferPtr, viewportWidth, viewportHeight) {
|
|
8390
|
+
const viewPtr = this.opentui.symbols.createEditorView(editBufferPtr, viewportWidth, viewportHeight);
|
|
8391
|
+
if (!viewPtr) {
|
|
8392
|
+
throw new Error("Failed to create EditorView");
|
|
7339
8393
|
}
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
|
|
8394
|
+
return viewPtr;
|
|
8395
|
+
}
|
|
8396
|
+
destroyEditorView(view) {
|
|
8397
|
+
this.opentui.symbols.destroyEditorView(view);
|
|
8398
|
+
}
|
|
8399
|
+
editorViewSetViewportSize(view, width, height) {
|
|
8400
|
+
this.opentui.symbols.editorViewSetViewportSize(view, width, height);
|
|
8401
|
+
}
|
|
8402
|
+
editorViewGetViewport(view) {
|
|
8403
|
+
const x = new Uint32Array(1);
|
|
8404
|
+
const y = new Uint32Array(1);
|
|
8405
|
+
const width = new Uint32Array(1);
|
|
8406
|
+
const height = new Uint32Array(1);
|
|
8407
|
+
this.opentui.symbols.editorViewGetViewport(view, ptr3(x), ptr3(y), ptr3(width), ptr3(height));
|
|
7343
8408
|
return {
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
8409
|
+
offsetX: x[0],
|
|
8410
|
+
offsetY: y[0],
|
|
8411
|
+
width: width[0],
|
|
8412
|
+
height: height[0]
|
|
7347
8413
|
};
|
|
7348
8414
|
}
|
|
7349
|
-
|
|
7350
|
-
|
|
7351
|
-
|
|
7352
|
-
|
|
7353
|
-
const
|
|
7354
|
-
|
|
7355
|
-
|
|
8415
|
+
editorViewSetScrollMargin(view, margin) {
|
|
8416
|
+
this.opentui.symbols.editorViewSetScrollMargin(view, margin);
|
|
8417
|
+
}
|
|
8418
|
+
editorViewSetWrapMode(view, mode) {
|
|
8419
|
+
const modeValue = mode === "none" ? 0 : mode === "char" ? 1 : 2;
|
|
8420
|
+
this.opentui.symbols.editorViewSetWrapMode(view, modeValue);
|
|
8421
|
+
}
|
|
8422
|
+
editorViewGetVirtualLineCount(view) {
|
|
8423
|
+
return this.opentui.symbols.editorViewGetVirtualLineCount(view);
|
|
8424
|
+
}
|
|
8425
|
+
editorViewGetTotalVirtualLineCount(view) {
|
|
8426
|
+
return this.opentui.symbols.editorViewGetTotalVirtualLineCount(view);
|
|
8427
|
+
}
|
|
8428
|
+
editorViewGetTextBufferView(view) {
|
|
8429
|
+
const result = this.opentui.symbols.editorViewGetTextBufferView(view);
|
|
8430
|
+
if (!result) {
|
|
8431
|
+
throw new Error("Failed to get TextBufferView from EditorView");
|
|
8432
|
+
}
|
|
8433
|
+
return result;
|
|
8434
|
+
}
|
|
8435
|
+
createEditBuffer(widthMethod) {
|
|
8436
|
+
const widthMethodCode = widthMethod === "wcwidth" ? 0 : 1;
|
|
8437
|
+
const bufferPtr = this.opentui.symbols.createEditBuffer(widthMethodCode);
|
|
8438
|
+
if (!bufferPtr) {
|
|
8439
|
+
throw new Error("Failed to create EditBuffer");
|
|
8440
|
+
}
|
|
8441
|
+
return bufferPtr;
|
|
8442
|
+
}
|
|
8443
|
+
destroyEditBuffer(buffer) {
|
|
8444
|
+
this.opentui.symbols.destroyEditBuffer(buffer);
|
|
8445
|
+
}
|
|
8446
|
+
editBufferSetText(buffer, textBytes, retainHistory = true) {
|
|
8447
|
+
this.opentui.symbols.editBufferSetText(buffer, textBytes, textBytes.length, retainHistory);
|
|
8448
|
+
}
|
|
8449
|
+
editBufferSetTextFromMem(buffer, memId, retainHistory = true) {
|
|
8450
|
+
this.opentui.symbols.editBufferSetTextFromMem(buffer, memId, retainHistory);
|
|
8451
|
+
}
|
|
8452
|
+
editBufferGetText(buffer, maxLength) {
|
|
8453
|
+
const outBuffer = new Uint8Array(maxLength);
|
|
8454
|
+
const actualLen = this.opentui.symbols.editBufferGetText(buffer, ptr3(outBuffer), maxLength);
|
|
8455
|
+
const len = typeof actualLen === "bigint" ? Number(actualLen) : actualLen;
|
|
8456
|
+
if (len === 0)
|
|
8457
|
+
return null;
|
|
8458
|
+
return outBuffer.slice(0, len);
|
|
8459
|
+
}
|
|
8460
|
+
editBufferInsertChar(buffer, char) {
|
|
8461
|
+
const charBytes = this.encoder.encode(char);
|
|
8462
|
+
this.opentui.symbols.editBufferInsertChar(buffer, charBytes, charBytes.length);
|
|
8463
|
+
}
|
|
8464
|
+
editBufferInsertText(buffer, text) {
|
|
8465
|
+
const textBytes = this.encoder.encode(text);
|
|
8466
|
+
this.opentui.symbols.editBufferInsertText(buffer, textBytes, textBytes.length);
|
|
8467
|
+
}
|
|
8468
|
+
editBufferDeleteChar(buffer) {
|
|
8469
|
+
this.opentui.symbols.editBufferDeleteChar(buffer);
|
|
8470
|
+
}
|
|
8471
|
+
editBufferDeleteCharBackward(buffer) {
|
|
8472
|
+
this.opentui.symbols.editBufferDeleteCharBackward(buffer);
|
|
8473
|
+
}
|
|
8474
|
+
editBufferDeleteRange(buffer, startLine, startCol, endLine, endCol) {
|
|
8475
|
+
this.opentui.symbols.editBufferDeleteRange(buffer, startLine, startCol, endLine, endCol);
|
|
8476
|
+
}
|
|
8477
|
+
editBufferNewLine(buffer) {
|
|
8478
|
+
this.opentui.symbols.editBufferNewLine(buffer);
|
|
8479
|
+
}
|
|
8480
|
+
editBufferDeleteLine(buffer) {
|
|
8481
|
+
this.opentui.symbols.editBufferDeleteLine(buffer);
|
|
8482
|
+
}
|
|
8483
|
+
editBufferMoveCursorLeft(buffer) {
|
|
8484
|
+
this.opentui.symbols.editBufferMoveCursorLeft(buffer);
|
|
8485
|
+
}
|
|
8486
|
+
editBufferMoveCursorRight(buffer) {
|
|
8487
|
+
this.opentui.symbols.editBufferMoveCursorRight(buffer);
|
|
8488
|
+
}
|
|
8489
|
+
editBufferMoveCursorUp(buffer) {
|
|
8490
|
+
this.opentui.symbols.editBufferMoveCursorUp(buffer);
|
|
8491
|
+
}
|
|
8492
|
+
editBufferMoveCursorDown(buffer) {
|
|
8493
|
+
this.opentui.symbols.editBufferMoveCursorDown(buffer);
|
|
8494
|
+
}
|
|
8495
|
+
editBufferGotoLine(buffer, line) {
|
|
8496
|
+
this.opentui.symbols.editBufferGotoLine(buffer, line);
|
|
8497
|
+
}
|
|
8498
|
+
editBufferSetCursor(buffer, line, byteOffset) {
|
|
8499
|
+
this.opentui.symbols.editBufferSetCursor(buffer, line, byteOffset);
|
|
8500
|
+
}
|
|
8501
|
+
editBufferSetCursorToLineCol(buffer, line, col) {
|
|
8502
|
+
this.opentui.symbols.editBufferSetCursorToLineCol(buffer, line, col);
|
|
8503
|
+
}
|
|
8504
|
+
editBufferSetCursorByOffset(buffer, offset) {
|
|
8505
|
+
this.opentui.symbols.editBufferSetCursorByOffset(buffer, offset);
|
|
8506
|
+
}
|
|
8507
|
+
editBufferGetCursorPosition(buffer) {
|
|
8508
|
+
const line = new Uint32Array(1);
|
|
8509
|
+
const visualColumn = new Uint32Array(1);
|
|
8510
|
+
const offset = new Uint32Array(1);
|
|
8511
|
+
this.opentui.symbols.editBufferGetCursorPosition(buffer, ptr3(line), ptr3(visualColumn), ptr3(offset));
|
|
8512
|
+
return {
|
|
8513
|
+
line: line[0],
|
|
8514
|
+
visualColumn: visualColumn[0],
|
|
8515
|
+
offset: offset[0]
|
|
8516
|
+
};
|
|
8517
|
+
}
|
|
8518
|
+
editBufferGetId(buffer) {
|
|
8519
|
+
return this.opentui.symbols.editBufferGetId(buffer);
|
|
8520
|
+
}
|
|
8521
|
+
editBufferGetTextBuffer(buffer) {
|
|
8522
|
+
const result = this.opentui.symbols.editBufferGetTextBuffer(buffer);
|
|
8523
|
+
if (!result) {
|
|
8524
|
+
throw new Error("Failed to get TextBuffer from EditBuffer");
|
|
8525
|
+
}
|
|
8526
|
+
return result;
|
|
8527
|
+
}
|
|
8528
|
+
editBufferDebugLogRope(buffer) {
|
|
8529
|
+
this.opentui.symbols.editBufferDebugLogRope(buffer);
|
|
8530
|
+
}
|
|
8531
|
+
editBufferUndo(buffer, maxLength) {
|
|
8532
|
+
const outBuffer = new Uint8Array(maxLength);
|
|
8533
|
+
const actualLen = this.opentui.symbols.editBufferUndo(buffer, ptr3(outBuffer), maxLength);
|
|
8534
|
+
const len = typeof actualLen === "bigint" ? Number(actualLen) : actualLen;
|
|
8535
|
+
if (len === 0)
|
|
8536
|
+
return null;
|
|
8537
|
+
return outBuffer.slice(0, len);
|
|
8538
|
+
}
|
|
8539
|
+
editBufferRedo(buffer, maxLength) {
|
|
8540
|
+
const outBuffer = new Uint8Array(maxLength);
|
|
8541
|
+
const actualLen = this.opentui.symbols.editBufferRedo(buffer, ptr3(outBuffer), maxLength);
|
|
8542
|
+
const len = typeof actualLen === "bigint" ? Number(actualLen) : actualLen;
|
|
8543
|
+
if (len === 0)
|
|
8544
|
+
return null;
|
|
8545
|
+
return outBuffer.slice(0, len);
|
|
8546
|
+
}
|
|
8547
|
+
editBufferCanUndo(buffer) {
|
|
8548
|
+
return this.opentui.symbols.editBufferCanUndo(buffer);
|
|
8549
|
+
}
|
|
8550
|
+
editBufferCanRedo(buffer) {
|
|
8551
|
+
return this.opentui.symbols.editBufferCanRedo(buffer);
|
|
8552
|
+
}
|
|
8553
|
+
editBufferClearHistory(buffer) {
|
|
8554
|
+
this.opentui.symbols.editBufferClearHistory(buffer);
|
|
8555
|
+
}
|
|
8556
|
+
editBufferSetPlaceholder(buffer, text) {
|
|
8557
|
+
if (text === null) {
|
|
8558
|
+
this.opentui.symbols.editBufferSetPlaceholder(buffer, null, 0);
|
|
8559
|
+
} else {
|
|
8560
|
+
const textBytes = this.encoder.encode(text);
|
|
8561
|
+
this.opentui.symbols.editBufferSetPlaceholder(buffer, textBytes, textBytes.length);
|
|
8562
|
+
}
|
|
8563
|
+
}
|
|
8564
|
+
editBufferSetPlaceholderColor(buffer, color) {
|
|
8565
|
+
this.opentui.symbols.editBufferSetPlaceholderColor(buffer, color.buffer);
|
|
8566
|
+
}
|
|
8567
|
+
editBufferGetNextWordBoundary(buffer) {
|
|
8568
|
+
const cursorBuffer = new ArrayBuffer(LogicalCursorStruct.size);
|
|
8569
|
+
this.opentui.symbols.editBufferGetNextWordBoundary(buffer, ptr3(cursorBuffer));
|
|
8570
|
+
return LogicalCursorStruct.unpack(cursorBuffer);
|
|
8571
|
+
}
|
|
8572
|
+
editBufferGetPrevWordBoundary(buffer) {
|
|
8573
|
+
const cursorBuffer = new ArrayBuffer(LogicalCursorStruct.size);
|
|
8574
|
+
this.opentui.symbols.editBufferGetPrevWordBoundary(buffer, ptr3(cursorBuffer));
|
|
8575
|
+
return LogicalCursorStruct.unpack(cursorBuffer);
|
|
8576
|
+
}
|
|
8577
|
+
editBufferGetEOL(buffer) {
|
|
8578
|
+
const cursorBuffer = new ArrayBuffer(LogicalCursorStruct.size);
|
|
8579
|
+
this.opentui.symbols.editBufferGetEOL(buffer, ptr3(cursorBuffer));
|
|
8580
|
+
return LogicalCursorStruct.unpack(cursorBuffer);
|
|
8581
|
+
}
|
|
8582
|
+
editorViewSetSelection(view, start, end, bgColor, fgColor) {
|
|
8583
|
+
const bg2 = bgColor ? bgColor.buffer : null;
|
|
8584
|
+
const fg2 = fgColor ? fgColor.buffer : null;
|
|
8585
|
+
this.opentui.symbols.editorViewSetSelection(view, start, end, bg2, fg2);
|
|
8586
|
+
}
|
|
8587
|
+
editorViewResetSelection(view) {
|
|
8588
|
+
this.opentui.symbols.editorViewResetSelection(view);
|
|
8589
|
+
}
|
|
8590
|
+
editorViewGetSelection(view) {
|
|
8591
|
+
const packedInfo = this.opentui.symbols.editorViewGetSelection(view);
|
|
8592
|
+
if (packedInfo === 0xffff_ffff_ffff_ffffn) {
|
|
8593
|
+
return null;
|
|
8594
|
+
}
|
|
8595
|
+
const start = Number(packedInfo >> 32n);
|
|
8596
|
+
const end = Number(packedInfo & 0xffff_ffffn);
|
|
8597
|
+
return { start, end };
|
|
8598
|
+
}
|
|
8599
|
+
editorViewSetLocalSelection(view, anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
|
|
8600
|
+
const bg2 = bgColor ? bgColor.buffer : null;
|
|
8601
|
+
const fg2 = fgColor ? fgColor.buffer : null;
|
|
8602
|
+
return this.opentui.symbols.editorViewSetLocalSelection(view, anchorX, anchorY, focusX, focusY, bg2, fg2);
|
|
8603
|
+
}
|
|
8604
|
+
editorViewResetLocalSelection(view) {
|
|
8605
|
+
this.opentui.symbols.editorViewResetLocalSelection(view);
|
|
8606
|
+
}
|
|
8607
|
+
editorViewGetSelectedTextBytes(view, maxLength) {
|
|
8608
|
+
const outBuffer = new Uint8Array(maxLength);
|
|
8609
|
+
const actualLen = this.opentui.symbols.editorViewGetSelectedTextBytes(view, ptr3(outBuffer), maxLength);
|
|
8610
|
+
const len = typeof actualLen === "bigint" ? Number(actualLen) : actualLen;
|
|
8611
|
+
if (len === 0)
|
|
8612
|
+
return null;
|
|
8613
|
+
return outBuffer.slice(0, len);
|
|
8614
|
+
}
|
|
8615
|
+
editorViewGetCursor(view) {
|
|
8616
|
+
const row = new Uint32Array(1);
|
|
8617
|
+
const col = new Uint32Array(1);
|
|
8618
|
+
this.opentui.symbols.editorViewGetCursor(view, ptr3(row), ptr3(col));
|
|
8619
|
+
return { row: row[0], col: col[0] };
|
|
8620
|
+
}
|
|
8621
|
+
editorViewGetText(view, maxLength) {
|
|
8622
|
+
const outBuffer = new Uint8Array(maxLength);
|
|
8623
|
+
const actualLen = this.opentui.symbols.editorViewGetText(view, ptr3(outBuffer), maxLength);
|
|
8624
|
+
const len = typeof actualLen === "bigint" ? Number(actualLen) : actualLen;
|
|
8625
|
+
if (len === 0)
|
|
8626
|
+
return null;
|
|
8627
|
+
return outBuffer.slice(0, len);
|
|
8628
|
+
}
|
|
8629
|
+
editorViewGetVisualCursor(view) {
|
|
8630
|
+
const cursorBuffer = new ArrayBuffer(VisualCursorStruct.size);
|
|
8631
|
+
this.opentui.symbols.editorViewGetVisualCursor(view, ptr3(cursorBuffer));
|
|
8632
|
+
return VisualCursorStruct.unpack(cursorBuffer);
|
|
8633
|
+
}
|
|
8634
|
+
editorViewMoveUpVisual(view) {
|
|
8635
|
+
this.opentui.symbols.editorViewMoveUpVisual(view);
|
|
8636
|
+
}
|
|
8637
|
+
editorViewMoveDownVisual(view) {
|
|
8638
|
+
this.opentui.symbols.editorViewMoveDownVisual(view);
|
|
8639
|
+
}
|
|
8640
|
+
editorViewDeleteSelectedText(view) {
|
|
8641
|
+
this.opentui.symbols.editorViewDeleteSelectedText(view);
|
|
8642
|
+
}
|
|
8643
|
+
editorViewSetCursorByOffset(view, offset) {
|
|
8644
|
+
this.opentui.symbols.editorViewSetCursorByOffset(view, offset);
|
|
8645
|
+
}
|
|
8646
|
+
editorViewGetNextWordBoundary(view) {
|
|
8647
|
+
const cursorBuffer = new ArrayBuffer(VisualCursorStruct.size);
|
|
8648
|
+
this.opentui.symbols.editorViewGetNextWordBoundary(view, ptr3(cursorBuffer));
|
|
8649
|
+
return VisualCursorStruct.unpack(cursorBuffer);
|
|
8650
|
+
}
|
|
8651
|
+
editorViewGetPrevWordBoundary(view) {
|
|
8652
|
+
const cursorBuffer = new ArrayBuffer(VisualCursorStruct.size);
|
|
8653
|
+
this.opentui.symbols.editorViewGetPrevWordBoundary(view, ptr3(cursorBuffer));
|
|
8654
|
+
return VisualCursorStruct.unpack(cursorBuffer);
|
|
8655
|
+
}
|
|
8656
|
+
editorViewGetEOL(view) {
|
|
8657
|
+
const cursorBuffer = new ArrayBuffer(VisualCursorStruct.size);
|
|
8658
|
+
this.opentui.symbols.editorViewGetEOL(view, ptr3(cursorBuffer));
|
|
8659
|
+
return VisualCursorStruct.unpack(cursorBuffer);
|
|
7356
8660
|
}
|
|
7357
8661
|
bufferPushScissorRect(buffer, x, y, width, height) {
|
|
7358
8662
|
this.opentui.symbols.bufferPushScissorRect(buffer, x, y, width, height);
|
|
@@ -7388,6 +8692,43 @@ class FFIRenderLib {
|
|
|
7388
8692
|
const responseBytes = this.encoder.encode(response);
|
|
7389
8693
|
this.opentui.symbols.processCapabilityResponse(renderer, responseBytes, responseBytes.length);
|
|
7390
8694
|
}
|
|
8695
|
+
createSyntaxStyle() {
|
|
8696
|
+
const stylePtr = this.opentui.symbols.createSyntaxStyle();
|
|
8697
|
+
if (!stylePtr) {
|
|
8698
|
+
throw new Error("Failed to create SyntaxStyle");
|
|
8699
|
+
}
|
|
8700
|
+
return stylePtr;
|
|
8701
|
+
}
|
|
8702
|
+
destroySyntaxStyle(style) {
|
|
8703
|
+
this.opentui.symbols.destroySyntaxStyle(style);
|
|
8704
|
+
}
|
|
8705
|
+
syntaxStyleRegister(style, name, fg2, bg2, attributes) {
|
|
8706
|
+
const nameBytes = this.encoder.encode(name);
|
|
8707
|
+
const fgPtr = fg2 ? fg2.buffer : null;
|
|
8708
|
+
const bgPtr = bg2 ? bg2.buffer : null;
|
|
8709
|
+
return this.opentui.symbols.syntaxStyleRegister(style, nameBytes, nameBytes.length, fgPtr, bgPtr, attributes);
|
|
8710
|
+
}
|
|
8711
|
+
syntaxStyleResolveByName(style, name) {
|
|
8712
|
+
const nameBytes = this.encoder.encode(name);
|
|
8713
|
+
const id = this.opentui.symbols.syntaxStyleResolveByName(style, nameBytes, nameBytes.length);
|
|
8714
|
+
return id === 0 ? null : id;
|
|
8715
|
+
}
|
|
8716
|
+
syntaxStyleGetStyleCount(style) {
|
|
8717
|
+
const result = this.opentui.symbols.syntaxStyleGetStyleCount(style);
|
|
8718
|
+
return typeof result === "bigint" ? Number(result) : result;
|
|
8719
|
+
}
|
|
8720
|
+
onNativeEvent(name, handler) {
|
|
8721
|
+
this._nativeEvents.on(name, handler);
|
|
8722
|
+
}
|
|
8723
|
+
onceNativeEvent(name, handler) {
|
|
8724
|
+
this._nativeEvents.once(name, handler);
|
|
8725
|
+
}
|
|
8726
|
+
offNativeEvent(name, handler) {
|
|
8727
|
+
this._nativeEvents.off(name, handler);
|
|
8728
|
+
}
|
|
8729
|
+
onAnyNativeEvent(handler) {
|
|
8730
|
+
this._anyEventHandlers.push(handler);
|
|
8731
|
+
}
|
|
7391
8732
|
}
|
|
7392
8733
|
var opentuiLibPath;
|
|
7393
8734
|
var opentuiLib;
|
|
@@ -7416,11 +8757,15 @@ class TextBuffer {
|
|
|
7416
8757
|
lib;
|
|
7417
8758
|
bufferPtr;
|
|
7418
8759
|
_length = 0;
|
|
8760
|
+
_byteSize = 0;
|
|
7419
8761
|
_lineInfo;
|
|
7420
8762
|
_destroyed = false;
|
|
7421
|
-
|
|
8763
|
+
_syntaxStyle;
|
|
8764
|
+
_textBytes;
|
|
8765
|
+
_memId;
|
|
8766
|
+
constructor(lib, ptr4) {
|
|
7422
8767
|
this.lib = lib;
|
|
7423
|
-
this.bufferPtr =
|
|
8768
|
+
this.bufferPtr = ptr4;
|
|
7424
8769
|
}
|
|
7425
8770
|
static create(widthMethod) {
|
|
7426
8771
|
const lib = resolveRenderLib();
|
|
@@ -7430,17 +8775,42 @@ class TextBuffer {
|
|
|
7430
8775
|
if (this._destroyed)
|
|
7431
8776
|
throw new Error("TextBuffer is destroyed");
|
|
7432
8777
|
}
|
|
7433
|
-
|
|
8778
|
+
setText(text) {
|
|
7434
8779
|
this.guard();
|
|
7435
|
-
this.lib.
|
|
7436
|
-
this.
|
|
8780
|
+
this._textBytes = this.lib.encoder.encode(text);
|
|
8781
|
+
if (this._memId === undefined) {
|
|
8782
|
+
this._memId = this.lib.textBufferRegisterMemBuffer(this.bufferPtr, this._textBytes, false);
|
|
8783
|
+
} else {
|
|
8784
|
+
this.lib.textBufferReplaceMemBuffer(this.bufferPtr, this._memId, this._textBytes, false);
|
|
8785
|
+
}
|
|
8786
|
+
this.lib.textBufferSetTextFromMem(this.bufferPtr, this._memId);
|
|
8787
|
+
this._length = this.lib.textBufferGetLength(this.bufferPtr);
|
|
8788
|
+
this._byteSize = this.lib.textBufferGetByteSize(this.bufferPtr);
|
|
7437
8789
|
this._lineInfo = undefined;
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
|
|
8790
|
+
}
|
|
8791
|
+
loadFile(path4) {
|
|
8792
|
+
this.guard();
|
|
8793
|
+
const success = this.lib.textBufferLoadFile(this.bufferPtr, path4);
|
|
8794
|
+
if (!success) {
|
|
8795
|
+
throw new Error(`Failed to load file: ${path4}`);
|
|
7441
8796
|
}
|
|
7442
|
-
this.lib.textBufferFinalizeLineInfo(this.bufferPtr);
|
|
7443
8797
|
this._length = this.lib.textBufferGetLength(this.bufferPtr);
|
|
8798
|
+
this._byteSize = this.lib.textBufferGetByteSize(this.bufferPtr);
|
|
8799
|
+
this._lineInfo = undefined;
|
|
8800
|
+
this._textBytes = undefined;
|
|
8801
|
+
}
|
|
8802
|
+
setStyledText(text) {
|
|
8803
|
+
this.guard();
|
|
8804
|
+
const chunks = text.chunks.map((chunk) => ({
|
|
8805
|
+
text: chunk.text,
|
|
8806
|
+
fg: chunk.fg || null,
|
|
8807
|
+
bg: chunk.bg || null,
|
|
8808
|
+
attributes: chunk.attributes ?? 0
|
|
8809
|
+
}));
|
|
8810
|
+
this.lib.textBufferSetStyledText(this.bufferPtr, chunks);
|
|
8811
|
+
this._length = this.lib.textBufferGetLength(this.bufferPtr);
|
|
8812
|
+
this._byteSize = this.lib.textBufferGetByteSize(this.bufferPtr);
|
|
8813
|
+
this._lineInfo = undefined;
|
|
7444
8814
|
}
|
|
7445
8815
|
setDefaultFg(fg2) {
|
|
7446
8816
|
this.guard();
|
|
@@ -7462,97 +8832,72 @@ class TextBuffer {
|
|
|
7462
8832
|
this.guard();
|
|
7463
8833
|
return this._length;
|
|
7464
8834
|
}
|
|
7465
|
-
get
|
|
8835
|
+
get byteSize() {
|
|
7466
8836
|
this.guard();
|
|
7467
|
-
return this.
|
|
8837
|
+
return this._byteSize;
|
|
7468
8838
|
}
|
|
7469
|
-
|
|
8839
|
+
get ptr() {
|
|
7470
8840
|
this.guard();
|
|
7471
|
-
|
|
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);
|
|
8841
|
+
return this.bufferPtr;
|
|
7477
8842
|
}
|
|
7478
8843
|
getPlainText() {
|
|
7479
8844
|
this.guard();
|
|
7480
|
-
if (this.
|
|
8845
|
+
if (this._byteSize === 0)
|
|
7481
8846
|
return "";
|
|
7482
|
-
const plainBytes = this.lib.getPlainTextBytes(this.bufferPtr, this.
|
|
8847
|
+
const plainBytes = this.lib.getPlainTextBytes(this.bufferPtr, this._byteSize);
|
|
7483
8848
|
if (!plainBytes)
|
|
7484
8849
|
return "";
|
|
7485
8850
|
return this.lib.decoder.decode(plainBytes);
|
|
7486
8851
|
}
|
|
7487
|
-
|
|
8852
|
+
addHighlightByCharRange(highlight) {
|
|
7488
8853
|
this.guard();
|
|
7489
|
-
|
|
7490
|
-
this._lineInfo = this.lib.textBufferGetLineInfo(this.bufferPtr);
|
|
7491
|
-
}
|
|
7492
|
-
return this._lineInfo;
|
|
7493
|
-
}
|
|
7494
|
-
setSelection(start, end, bgColor, fgColor) {
|
|
7495
|
-
this.guard();
|
|
7496
|
-
this.lib.textBufferSetSelection(this.bufferPtr, start, end, bgColor || null, fgColor || null);
|
|
7497
|
-
}
|
|
7498
|
-
resetSelection() {
|
|
7499
|
-
this.guard();
|
|
7500
|
-
this.lib.textBufferResetSelection(this.bufferPtr);
|
|
7501
|
-
}
|
|
7502
|
-
setLocalSelection(anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
|
|
7503
|
-
this.guard();
|
|
7504
|
-
return this.lib.textBufferSetLocalSelection(this.bufferPtr, anchorX, anchorY, focusX, focusY, bgColor || null, fgColor || null);
|
|
8854
|
+
this.lib.textBufferAddHighlightByCharRange(this.bufferPtr, highlight);
|
|
7505
8855
|
}
|
|
7506
|
-
|
|
8856
|
+
addHighlight(lineIdx, highlight) {
|
|
7507
8857
|
this.guard();
|
|
7508
|
-
this.lib.
|
|
8858
|
+
this.lib.textBufferAddHighlight(this.bufferPtr, lineIdx, highlight);
|
|
7509
8859
|
}
|
|
7510
|
-
|
|
8860
|
+
removeHighlightsByRef(hlRef) {
|
|
7511
8861
|
this.guard();
|
|
7512
|
-
|
|
8862
|
+
this.lib.textBufferRemoveHighlightsByRef(this.bufferPtr, hlRef);
|
|
7513
8863
|
}
|
|
7514
|
-
|
|
8864
|
+
clearLineHighlights(lineIdx) {
|
|
7515
8865
|
this.guard();
|
|
7516
|
-
|
|
8866
|
+
this.lib.textBufferClearLineHighlights(this.bufferPtr, lineIdx);
|
|
7517
8867
|
}
|
|
7518
|
-
|
|
8868
|
+
clearAllHighlights() {
|
|
7519
8869
|
this.guard();
|
|
7520
|
-
|
|
7521
|
-
this.insertEncodedChunkGroup(index, textBytes, fg2, bg2, attributes);
|
|
8870
|
+
this.lib.textBufferClearAllHighlights(this.bufferPtr);
|
|
7522
8871
|
}
|
|
7523
|
-
|
|
8872
|
+
getLineHighlights(lineIdx) {
|
|
7524
8873
|
this.guard();
|
|
7525
|
-
|
|
7526
|
-
this._lineInfo = undefined;
|
|
8874
|
+
return this.lib.textBufferGetLineHighlights(this.bufferPtr, lineIdx);
|
|
7527
8875
|
}
|
|
7528
|
-
|
|
8876
|
+
setSyntaxStyle(style) {
|
|
7529
8877
|
this.guard();
|
|
7530
|
-
this.
|
|
7531
|
-
this.
|
|
8878
|
+
this._syntaxStyle = style ?? undefined;
|
|
8879
|
+
this.lib.textBufferSetSyntaxStyle(this.bufferPtr, style?.ptr ?? null);
|
|
7532
8880
|
}
|
|
7533
|
-
|
|
8881
|
+
getSyntaxStyle() {
|
|
7534
8882
|
this.guard();
|
|
7535
|
-
|
|
7536
|
-
this.replaceEncodedChunkGroup(index, textBytes, fg2, bg2, attributes);
|
|
7537
|
-
}
|
|
7538
|
-
replaceEncodedChunkGroup(index, textBytes, fg2, bg2, attributes) {
|
|
7539
|
-
this.guard();
|
|
7540
|
-
this._length = this.lib.textBufferReplaceChunkGroup(this.bufferPtr, index, textBytes, fg2 || null, bg2 || null, attributes ?? null);
|
|
7541
|
-
this._lineInfo = undefined;
|
|
8883
|
+
return this._syntaxStyle ?? null;
|
|
7542
8884
|
}
|
|
7543
|
-
|
|
7544
|
-
this.guard();
|
|
7545
|
-
return this.lib.textBufferGetChunkGroupCount(this.bufferPtr);
|
|
7546
|
-
}
|
|
7547
|
-
setWrapWidth(width) {
|
|
8885
|
+
clear() {
|
|
7548
8886
|
this.guard();
|
|
7549
|
-
this.lib.
|
|
8887
|
+
this.lib.textBufferClear(this.bufferPtr);
|
|
8888
|
+
this._length = 0;
|
|
8889
|
+
this._byteSize = 0;
|
|
7550
8890
|
this._lineInfo = undefined;
|
|
8891
|
+
this._textBytes = undefined;
|
|
7551
8892
|
}
|
|
7552
|
-
|
|
8893
|
+
reset() {
|
|
7553
8894
|
this.guard();
|
|
7554
|
-
this.lib.
|
|
8895
|
+
this.lib.textBufferReset(this.bufferPtr);
|
|
8896
|
+
this._length = 0;
|
|
8897
|
+
this._byteSize = 0;
|
|
7555
8898
|
this._lineInfo = undefined;
|
|
8899
|
+
this._textBytes = undefined;
|
|
8900
|
+
this._memId = undefined;
|
|
7556
8901
|
}
|
|
7557
8902
|
destroy() {
|
|
7558
8903
|
if (this._destroyed)
|
|
@@ -7563,7 +8908,7 @@ class TextBuffer {
|
|
|
7563
8908
|
}
|
|
7564
8909
|
|
|
7565
8910
|
// src/Renderable.ts
|
|
7566
|
-
import { EventEmitter as
|
|
8911
|
+
import { EventEmitter as EventEmitter5 } from "events";
|
|
7567
8912
|
|
|
7568
8913
|
// src/lib/renderable.validations.ts
|
|
7569
8914
|
function validateOptions(id, options) {
|
|
@@ -7656,7 +9001,7 @@ function isRenderable(obj) {
|
|
|
7656
9001
|
return !!obj?.[BrandedRenderable];
|
|
7657
9002
|
}
|
|
7658
9003
|
|
|
7659
|
-
class BaseRenderable extends
|
|
9004
|
+
class BaseRenderable extends EventEmitter5 {
|
|
7660
9005
|
[BrandedRenderable] = true;
|
|
7661
9006
|
static renderableNumber = 1;
|
|
7662
9007
|
_id;
|
|
@@ -7728,6 +9073,7 @@ class Renderable extends BaseRenderable {
|
|
|
7728
9073
|
_positionType = "relative";
|
|
7729
9074
|
_overflow = "visible";
|
|
7730
9075
|
_position = {};
|
|
9076
|
+
_flexShrink = 1;
|
|
7731
9077
|
renderableMapById = new Map;
|
|
7732
9078
|
_childrenInLayoutOrder = [];
|
|
7733
9079
|
_childrenInZIndexOrder = [];
|
|
@@ -7974,6 +9320,10 @@ class Renderable extends BaseRenderable {
|
|
|
7974
9320
|
if (isDimensionType(value)) {
|
|
7975
9321
|
this._width = value;
|
|
7976
9322
|
this.yogaNode.setWidth(value);
|
|
9323
|
+
if (typeof value === "number" && this._flexShrink === 1) {
|
|
9324
|
+
this._flexShrink = 0;
|
|
9325
|
+
this.yogaNode.setFlexShrink(0);
|
|
9326
|
+
}
|
|
7977
9327
|
this.requestRender();
|
|
7978
9328
|
}
|
|
7979
9329
|
}
|
|
@@ -7984,6 +9334,10 @@ class Renderable extends BaseRenderable {
|
|
|
7984
9334
|
if (isDimensionType(value)) {
|
|
7985
9335
|
this._height = value;
|
|
7986
9336
|
this.yogaNode.setHeight(value);
|
|
9337
|
+
if (typeof value === "number" && this._flexShrink === 1) {
|
|
9338
|
+
this._flexShrink = 0;
|
|
9339
|
+
this.yogaNode.setFlexShrink(0);
|
|
9340
|
+
}
|
|
7987
9341
|
this.requestRender();
|
|
7988
9342
|
}
|
|
7989
9343
|
}
|
|
@@ -8038,9 +9392,13 @@ class Renderable extends BaseRenderable {
|
|
|
8038
9392
|
node.setFlexGrow(0);
|
|
8039
9393
|
}
|
|
8040
9394
|
if (options.flexShrink !== undefined) {
|
|
9395
|
+
this._flexShrink = options.flexShrink;
|
|
8041
9396
|
node.setFlexShrink(options.flexShrink);
|
|
8042
9397
|
} else {
|
|
8043
|
-
|
|
9398
|
+
const hasExplicitWidth = typeof options.width === "number";
|
|
9399
|
+
const hasExplicitHeight = typeof options.height === "number";
|
|
9400
|
+
this._flexShrink = hasExplicitWidth || hasExplicitHeight ? 0 : 1;
|
|
9401
|
+
node.setFlexShrink(this._flexShrink);
|
|
8044
9402
|
}
|
|
8045
9403
|
if (options.flexDirection !== undefined) {
|
|
8046
9404
|
node.setFlexDirection(parseFlexDirection(options.flexDirection));
|
|
@@ -8185,11 +9543,17 @@ class Renderable extends BaseRenderable {
|
|
|
8185
9543
|
this.requestRender();
|
|
8186
9544
|
}
|
|
8187
9545
|
set flexGrow(grow) {
|
|
8188
|
-
|
|
9546
|
+
if (grow == null) {
|
|
9547
|
+
this.yogaNode.setFlexGrow(0);
|
|
9548
|
+
} else {
|
|
9549
|
+
this.yogaNode.setFlexGrow(grow);
|
|
9550
|
+
}
|
|
8189
9551
|
this.requestRender();
|
|
8190
9552
|
}
|
|
8191
9553
|
set flexShrink(shrink) {
|
|
8192
|
-
|
|
9554
|
+
const value = shrink == null ? 1 : shrink;
|
|
9555
|
+
this._flexShrink = value;
|
|
9556
|
+
this.yogaNode.setFlexShrink(value);
|
|
8193
9557
|
this.requestRender();
|
|
8194
9558
|
}
|
|
8195
9559
|
set flexDirection(direction) {
|
|
@@ -8958,7 +10322,7 @@ function delegate(mapping, vnode) {
|
|
|
8958
10322
|
}
|
|
8959
10323
|
|
|
8960
10324
|
// src/console.ts
|
|
8961
|
-
import { EventEmitter as
|
|
10325
|
+
import { EventEmitter as EventEmitter7 } from "events";
|
|
8962
10326
|
import { Console } from "console";
|
|
8963
10327
|
import fs from "fs";
|
|
8964
10328
|
import path4 from "path";
|
|
@@ -8966,9 +10330,9 @@ import util2 from "util";
|
|
|
8966
10330
|
|
|
8967
10331
|
// src/lib/output.capture.ts
|
|
8968
10332
|
import { Writable } from "stream";
|
|
8969
|
-
import { EventEmitter as
|
|
10333
|
+
import { EventEmitter as EventEmitter6 } from "events";
|
|
8970
10334
|
|
|
8971
|
-
class Capture extends
|
|
10335
|
+
class Capture extends EventEmitter6 {
|
|
8972
10336
|
output = [];
|
|
8973
10337
|
constructor() {
|
|
8974
10338
|
super();
|
|
@@ -9044,11 +10408,12 @@ registerEnvVar({
|
|
|
9044
10408
|
default: false
|
|
9045
10409
|
});
|
|
9046
10410
|
|
|
9047
|
-
class TerminalConsoleCache extends
|
|
10411
|
+
class TerminalConsoleCache extends EventEmitter7 {
|
|
9048
10412
|
_cachedLogs = [];
|
|
9049
10413
|
MAX_CACHE_SIZE = 1000;
|
|
9050
10414
|
_collectCallerInfo = false;
|
|
9051
10415
|
_cachingEnabled = true;
|
|
10416
|
+
_originalConsole = null;
|
|
9052
10417
|
get cachedLogs() {
|
|
9053
10418
|
return this._cachedLogs;
|
|
9054
10419
|
}
|
|
@@ -9056,6 +10421,9 @@ class TerminalConsoleCache extends EventEmitter6 {
|
|
|
9056
10421
|
super();
|
|
9057
10422
|
}
|
|
9058
10423
|
activate() {
|
|
10424
|
+
if (!this._originalConsole) {
|
|
10425
|
+
this._originalConsole = global.console;
|
|
10426
|
+
}
|
|
9059
10427
|
this.setupConsoleCapture();
|
|
9060
10428
|
this.overrideConsoleMethods();
|
|
9061
10429
|
}
|
|
@@ -9105,8 +10473,9 @@ class TerminalConsoleCache extends EventEmitter6 {
|
|
|
9105
10473
|
this.restoreOriginalConsole();
|
|
9106
10474
|
}
|
|
9107
10475
|
restoreOriginalConsole() {
|
|
9108
|
-
|
|
9109
|
-
|
|
10476
|
+
if (this._originalConsole) {
|
|
10477
|
+
global.console = this._originalConsole;
|
|
10478
|
+
}
|
|
9110
10479
|
this.setupConsoleCapture();
|
|
9111
10480
|
}
|
|
9112
10481
|
addLogEntry(level, ...args) {
|
|
@@ -9165,7 +10534,7 @@ var DEFAULT_CONSOLE_OPTIONS = {
|
|
|
9165
10534
|
};
|
|
9166
10535
|
var INDENT_WIDTH = 2;
|
|
9167
10536
|
|
|
9168
|
-
class TerminalConsole extends
|
|
10537
|
+
class TerminalConsole extends EventEmitter7 {
|
|
9169
10538
|
isVisible = false;
|
|
9170
10539
|
isFocused = false;
|
|
9171
10540
|
renderer;
|
|
@@ -9625,7 +10994,7 @@ class TerminalConsole extends EventEmitter6 {
|
|
|
9625
10994
|
}
|
|
9626
10995
|
|
|
9627
10996
|
// src/renderer.ts
|
|
9628
|
-
import { EventEmitter as
|
|
10997
|
+
import { EventEmitter as EventEmitter8 } from "events";
|
|
9629
10998
|
|
|
9630
10999
|
// src/lib/objects-in-viewport.ts
|
|
9631
11000
|
function getObjectsInViewport(viewport, objects, direction = "column", padding = 10, minTriggerSize = 16) {
|
|
@@ -9661,24 +11030,39 @@ function getObjectsInViewport(viewport, objects, direction = "column", padding =
|
|
|
9661
11030
|
}
|
|
9662
11031
|
const visibleChildren = [];
|
|
9663
11032
|
if (candidate === -1) {
|
|
9664
|
-
|
|
11033
|
+
candidate = lo > 0 ? lo - 1 : 0;
|
|
9665
11034
|
}
|
|
11035
|
+
const maxLookBehind = 50;
|
|
9666
11036
|
let left = candidate;
|
|
11037
|
+
let gapCount = 0;
|
|
9667
11038
|
while (left - 1 >= 0) {
|
|
9668
11039
|
const prev = children[left - 1];
|
|
9669
|
-
|
|
9670
|
-
|
|
11040
|
+
const prevEnd = isRow ? prev.x + prev.width : prev.y + prev.height;
|
|
11041
|
+
if (prevEnd <= vpStart) {
|
|
11042
|
+
gapCount++;
|
|
11043
|
+
if (gapCount >= maxLookBehind) {
|
|
11044
|
+
break;
|
|
11045
|
+
}
|
|
11046
|
+
} else {
|
|
11047
|
+
gapCount = 0;
|
|
11048
|
+
}
|
|
9671
11049
|
left--;
|
|
9672
11050
|
}
|
|
9673
11051
|
let right = candidate + 1;
|
|
9674
11052
|
while (right < totalChildren) {
|
|
9675
11053
|
const next = children[right];
|
|
9676
|
-
if ((isRow ? next.x : next.y)
|
|
11054
|
+
if ((isRow ? next.x : next.y) >= vpEnd)
|
|
9677
11055
|
break;
|
|
9678
11056
|
right++;
|
|
9679
11057
|
}
|
|
9680
11058
|
for (let i = left;i < right; i++) {
|
|
9681
11059
|
const child = children[i];
|
|
11060
|
+
const start = isRow ? child.x : child.y;
|
|
11061
|
+
const end = isRow ? child.x + child.width : child.y + child.height;
|
|
11062
|
+
if (end <= vpStart)
|
|
11063
|
+
continue;
|
|
11064
|
+
if (start >= vpEnd)
|
|
11065
|
+
break;
|
|
9682
11066
|
if (isRow) {
|
|
9683
11067
|
const childBottom = child.y + child.height;
|
|
9684
11068
|
if (childBottom < viewportTop)
|
|
@@ -9836,7 +11220,7 @@ var RendererControlState;
|
|
|
9836
11220
|
RendererControlState2["EXPLICIT_STOPPED"] = "explicit_stopped";
|
|
9837
11221
|
})(RendererControlState ||= {});
|
|
9838
11222
|
|
|
9839
|
-
class CliRenderer extends
|
|
11223
|
+
class CliRenderer extends EventEmitter8 {
|
|
9840
11224
|
static animationFrameId = 0;
|
|
9841
11225
|
lib;
|
|
9842
11226
|
rendererPtr;
|
|
@@ -10086,7 +11470,7 @@ Captured output:
|
|
|
10086
11470
|
}
|
|
10087
11471
|
get widthMethod() {
|
|
10088
11472
|
const caps = this.capabilities;
|
|
10089
|
-
return caps?.unicode === "
|
|
11473
|
+
return caps?.unicode === "wcwidth" ? "wcwidth" : "unicode";
|
|
10090
11474
|
}
|
|
10091
11475
|
writeOut(chunk, encoding, callback) {
|
|
10092
11476
|
return this.realStdoutWrite.call(this.stdout, chunk, encoding, callback);
|
|
@@ -10852,10 +12236,12 @@ Captured output:
|
|
|
10852
12236
|
}
|
|
10853
12237
|
this.selectionContainers = [];
|
|
10854
12238
|
}
|
|
10855
|
-
startSelection(
|
|
12239
|
+
startSelection(renderable, x, y) {
|
|
12240
|
+
if (!renderable.selectable)
|
|
12241
|
+
return;
|
|
10856
12242
|
this.clearSelection();
|
|
10857
|
-
this.selectionContainers.push(
|
|
10858
|
-
this.currentSelection = new Selection(
|
|
12243
|
+
this.selectionContainers.push(renderable.parent || this.root);
|
|
12244
|
+
this.currentSelection = new Selection(renderable, { x, y }, { x, y });
|
|
10859
12245
|
this.notifySelectablesOfSelectionChange();
|
|
10860
12246
|
}
|
|
10861
12247
|
updateSelection(currentRenderable, x, y) {
|
|
@@ -10935,7 +12321,7 @@ Captured output:
|
|
|
10935
12321
|
}
|
|
10936
12322
|
}
|
|
10937
12323
|
|
|
10938
|
-
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,
|
|
12324
|
+
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, 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 };
|
|
10939
12325
|
|
|
10940
|
-
//# debugId=
|
|
10941
|
-
//# sourceMappingURL=index-
|
|
12326
|
+
//# debugId=19E28318FF03F69E64756E2164756E21
|
|
12327
|
+
//# sourceMappingURL=index-0qmm1k4p.js.map
|