@opentui/core 0.1.101 → 0.1.103
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/buffer.d.ts +3 -0
- package/{index-xsfpee0k.js → index-4pvh4sbk.js} +3221 -312
- package/index-4pvh4sbk.js.map +76 -0
- package/{index-9qfn9g6r.js → index-bmcatvmp.js} +3 -3
- package/{index-ekbq0zm9.js → index-gw3ynrc0.js} +357 -1671
- package/index-gw3ynrc0.js.map +35 -0
- package/index.js +33 -13
- package/index.js.map +1 -1
- package/lib/RGBA.d.ts +27 -3
- package/lib/render-geometry.d.ts +8 -0
- package/lib/stdin-parser.d.ts +2 -1
- package/lib/terminal-palette.d.ts +8 -0
- package/package.json +7 -7
- package/renderables/Markdown.d.ts +30 -0
- package/renderables/TextBufferRenderable.d.ts +1 -0
- package/renderables/TextTable.d.ts +7 -0
- package/renderables/markdown-parser.d.ts +1 -0
- package/renderer-theme-mode.d.ts +29 -0
- package/renderer.d.ts +77 -8
- package/runtime-plugin-support.js +3 -3
- package/runtime-plugin.js +3 -3
- package/testing.js +7 -4
- package/testing.js.map +3 -3
- package/text-buffer-view.d.ts +1 -0
- package/types.d.ts +1 -0
- package/zig-structs.d.ts +7 -1
- package/zig.d.ts +12 -0
- package/index-ekbq0zm9.js.map +0 -42
- package/index-xsfpee0k.js.map +0 -67
- /package/{index-9qfn9g6r.js.map → index-bmcatvmp.js.map} +0 -0
|
@@ -6,18 +6,22 @@ import {
|
|
|
6
6
|
BaseRenderable,
|
|
7
7
|
BorderCharArrays,
|
|
8
8
|
BorderChars,
|
|
9
|
+
BoxRenderable,
|
|
10
|
+
COLOR_TAG_DEFAULT,
|
|
11
|
+
COLOR_TAG_RGB,
|
|
9
12
|
CliRenderEvents,
|
|
10
13
|
CliRenderer,
|
|
14
|
+
CodeRenderable,
|
|
11
15
|
ConsolePosition,
|
|
16
|
+
DEFAULT_BACKGROUND_RGB,
|
|
17
|
+
DEFAULT_FOREGROUND_RGB,
|
|
12
18
|
DataPathsManager,
|
|
13
19
|
DebugOverlayCorner,
|
|
14
|
-
Edge,
|
|
15
20
|
EditBuffer,
|
|
16
21
|
EditBufferRenderable,
|
|
17
22
|
EditBufferRenderableEvents,
|
|
18
23
|
EditorView,
|
|
19
24
|
ExtmarksController,
|
|
20
|
-
Gutter,
|
|
21
25
|
InternalKeyHandler,
|
|
22
26
|
KeyEvent,
|
|
23
27
|
KeyHandler,
|
|
@@ -36,19 +40,26 @@ import {
|
|
|
36
40
|
RenderableEvents,
|
|
37
41
|
RendererControlState,
|
|
38
42
|
RootRenderable,
|
|
43
|
+
RootTextNodeRenderable,
|
|
39
44
|
Selection,
|
|
40
45
|
SpanInfoStruct,
|
|
41
46
|
StdinParser,
|
|
42
47
|
StyledText,
|
|
48
|
+
SyntaxStyle,
|
|
43
49
|
SystemClock,
|
|
44
50
|
TargetChannel,
|
|
45
51
|
TerminalConsole,
|
|
46
52
|
TerminalPalette,
|
|
47
53
|
TextAttributes,
|
|
48
54
|
TextBuffer,
|
|
55
|
+
TextBufferRenderable,
|
|
56
|
+
TextBufferView,
|
|
57
|
+
TextNodeRenderable,
|
|
58
|
+
TextRenderable,
|
|
49
59
|
TreeSitterClient,
|
|
50
60
|
__export,
|
|
51
61
|
addDefaultParsers,
|
|
62
|
+
ansi256IndexToRgb,
|
|
52
63
|
attributesWithLink,
|
|
53
64
|
basenameToFiletype,
|
|
54
65
|
bg,
|
|
@@ -75,15 +86,18 @@ import {
|
|
|
75
86
|
brightYellow,
|
|
76
87
|
buildKeyBindingsMap,
|
|
77
88
|
buildKittyKeyboardFlags,
|
|
89
|
+
buildTerminalPaletteSignature,
|
|
78
90
|
capture,
|
|
79
91
|
clearEnvCache,
|
|
80
92
|
convertGlobalToLocalSelection,
|
|
93
|
+
convertThemeToStyles,
|
|
81
94
|
coordinateToCharacterIndex,
|
|
82
95
|
createCliRenderer,
|
|
83
96
|
createExtmarksController,
|
|
84
97
|
createTerminalPalette,
|
|
85
98
|
createTextAttributes,
|
|
86
99
|
cyan,
|
|
100
|
+
decodeColorTag,
|
|
87
101
|
decodePasteBytes,
|
|
88
102
|
defaultKeyAliases,
|
|
89
103
|
delegate,
|
|
@@ -117,9 +131,9 @@ import {
|
|
|
117
131
|
isEditBufferRenderable,
|
|
118
132
|
isRenderable,
|
|
119
133
|
isStyledText,
|
|
134
|
+
isTextNodeRenderable,
|
|
120
135
|
isVNode,
|
|
121
136
|
isValidBorderStyle,
|
|
122
|
-
isValidPercentage,
|
|
123
137
|
italic,
|
|
124
138
|
link,
|
|
125
139
|
magenta,
|
|
@@ -129,6 +143,9 @@ import {
|
|
|
129
143
|
mergeKeyAliases,
|
|
130
144
|
mergeKeyBindings,
|
|
131
145
|
nonAlphanumericKeys,
|
|
146
|
+
normalizeColorValue,
|
|
147
|
+
normalizeIndexedColorIndex,
|
|
148
|
+
normalizeTerminalPalette,
|
|
132
149
|
parseAlign,
|
|
133
150
|
parseAlignItems,
|
|
134
151
|
parseBorderStyle,
|
|
@@ -167,7 +184,7 @@ import {
|
|
|
167
184
|
white,
|
|
168
185
|
wrapWithDelegates,
|
|
169
186
|
yellow
|
|
170
|
-
} from "./index-
|
|
187
|
+
} from "./index-4pvh4sbk.js";
|
|
171
188
|
|
|
172
189
|
// src/index.ts
|
|
173
190
|
var exports_src2 = {};
|
|
@@ -214,6 +231,9 @@ __export(exports_src2, {
|
|
|
214
231
|
parseBorderStyle: () => parseBorderStyle,
|
|
215
232
|
parseAlignItems: () => parseAlignItems,
|
|
216
233
|
parseAlign: () => parseAlign,
|
|
234
|
+
normalizeTerminalPalette: () => normalizeTerminalPalette,
|
|
235
|
+
normalizeIndexedColorIndex: () => normalizeIndexedColorIndex,
|
|
236
|
+
normalizeColorValue: () => normalizeColorValue,
|
|
217
237
|
nonAlphanumericKeys: () => nonAlphanumericKeys,
|
|
218
238
|
measureText: () => measureText,
|
|
219
239
|
maybeMakeRenderable: () => maybeMakeRenderable,
|
|
@@ -253,6 +273,7 @@ __export(exports_src2, {
|
|
|
253
273
|
detectLinks: () => detectLinks,
|
|
254
274
|
delegate: () => delegate,
|
|
255
275
|
decodePasteBytes: () => decodePasteBytes,
|
|
276
|
+
decodeColorTag: () => decodeColorTag,
|
|
256
277
|
cyan: () => cyan,
|
|
257
278
|
createTimeline: () => createTimeline,
|
|
258
279
|
createTextAttributes: () => createTextAttributes,
|
|
@@ -266,6 +287,7 @@ __export(exports_src2, {
|
|
|
266
287
|
convertGlobalToLocalSelection: () => convertGlobalToLocalSelection,
|
|
267
288
|
clearEnvCache: () => clearEnvCache,
|
|
268
289
|
capture: () => capture,
|
|
290
|
+
buildTerminalPaletteSignature: () => buildTerminalPaletteSignature,
|
|
269
291
|
buildKittyKeyboardFlags: () => buildKittyKeyboardFlags,
|
|
270
292
|
brightYellow: () => brightYellow,
|
|
271
293
|
brightWhite: () => brightWhite,
|
|
@@ -299,6 +321,7 @@ __export(exports_src2, {
|
|
|
299
321
|
applyChromaticAberration: () => applyChromaticAberration,
|
|
300
322
|
applyBrightness: () => applyBrightness,
|
|
301
323
|
applyAsciiArt: () => applyAsciiArt,
|
|
324
|
+
ansi256IndexToRgb: () => ansi256IndexToRgb,
|
|
302
325
|
addDefaultParsers: () => addDefaultParsers,
|
|
303
326
|
Yoga: () => exports_src,
|
|
304
327
|
VignetteEffect: () => VignetteEffect,
|
|
@@ -386,6 +409,8 @@ __export(exports_src2, {
|
|
|
386
409
|
DataPathsManager: () => DataPathsManager,
|
|
387
410
|
DEUTERANOPIA_SIM_MATRIX: () => DEUTERANOPIA_SIM_MATRIX,
|
|
388
411
|
DEUTERANOPIA_COMP_MATRIX: () => DEUTERANOPIA_COMP_MATRIX,
|
|
412
|
+
DEFAULT_FOREGROUND_RGB: () => DEFAULT_FOREGROUND_RGB,
|
|
413
|
+
DEFAULT_BACKGROUND_RGB: () => DEFAULT_BACKGROUND_RGB,
|
|
389
414
|
ConsolePosition: () => ConsolePosition,
|
|
390
415
|
CodeRenderable: () => CodeRenderable,
|
|
391
416
|
Code: () => Code,
|
|
@@ -393,6 +418,8 @@ __export(exports_src2, {
|
|
|
393
418
|
CliRenderer: () => CliRenderer,
|
|
394
419
|
CliRenderEvents: () => CliRenderEvents,
|
|
395
420
|
CRTRollingBarEffect: () => CRTRollingBarEffect,
|
|
421
|
+
COLOR_TAG_RGB: () => COLOR_TAG_RGB,
|
|
422
|
+
COLOR_TAG_DEFAULT: () => COLOR_TAG_DEFAULT,
|
|
396
423
|
BoxRenderable: () => BoxRenderable,
|
|
397
424
|
Box: () => Box,
|
|
398
425
|
BorderChars: () => BorderChars,
|
|
@@ -408,326 +435,6 @@ __export(exports_src2, {
|
|
|
408
435
|
ACHROMATOPSIA_MATRIX: () => ACHROMATOPSIA_MATRIX
|
|
409
436
|
});
|
|
410
437
|
|
|
411
|
-
// src/text-buffer-view.ts
|
|
412
|
-
class TextBufferView {
|
|
413
|
-
lib;
|
|
414
|
-
viewPtr;
|
|
415
|
-
textBuffer;
|
|
416
|
-
_destroyed = false;
|
|
417
|
-
constructor(lib, ptr, textBuffer) {
|
|
418
|
-
this.lib = lib;
|
|
419
|
-
this.viewPtr = ptr;
|
|
420
|
-
this.textBuffer = textBuffer;
|
|
421
|
-
}
|
|
422
|
-
static create(textBuffer) {
|
|
423
|
-
const lib = resolveRenderLib();
|
|
424
|
-
const viewPtr = lib.createTextBufferView(textBuffer.ptr);
|
|
425
|
-
return new TextBufferView(lib, viewPtr, textBuffer);
|
|
426
|
-
}
|
|
427
|
-
guard() {
|
|
428
|
-
if (this._destroyed)
|
|
429
|
-
throw new Error("TextBufferView is destroyed");
|
|
430
|
-
}
|
|
431
|
-
get ptr() {
|
|
432
|
-
this.guard();
|
|
433
|
-
return this.viewPtr;
|
|
434
|
-
}
|
|
435
|
-
setSelection(start, end, bgColor, fgColor) {
|
|
436
|
-
this.guard();
|
|
437
|
-
this.lib.textBufferViewSetSelection(this.viewPtr, start, end, bgColor || null, fgColor || null);
|
|
438
|
-
}
|
|
439
|
-
updateSelection(end, bgColor, fgColor) {
|
|
440
|
-
this.guard();
|
|
441
|
-
this.lib.textBufferViewUpdateSelection(this.viewPtr, end, bgColor || null, fgColor || null);
|
|
442
|
-
}
|
|
443
|
-
resetSelection() {
|
|
444
|
-
this.guard();
|
|
445
|
-
this.lib.textBufferViewResetSelection(this.viewPtr);
|
|
446
|
-
}
|
|
447
|
-
getSelection() {
|
|
448
|
-
this.guard();
|
|
449
|
-
return this.lib.textBufferViewGetSelection(this.viewPtr);
|
|
450
|
-
}
|
|
451
|
-
hasSelection() {
|
|
452
|
-
this.guard();
|
|
453
|
-
return this.getSelection() !== null;
|
|
454
|
-
}
|
|
455
|
-
setLocalSelection(anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
|
|
456
|
-
this.guard();
|
|
457
|
-
return this.lib.textBufferViewSetLocalSelection(this.viewPtr, anchorX, anchorY, focusX, focusY, bgColor || null, fgColor || null);
|
|
458
|
-
}
|
|
459
|
-
updateLocalSelection(anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
|
|
460
|
-
this.guard();
|
|
461
|
-
return this.lib.textBufferViewUpdateLocalSelection(this.viewPtr, anchorX, anchorY, focusX, focusY, bgColor || null, fgColor || null);
|
|
462
|
-
}
|
|
463
|
-
resetLocalSelection() {
|
|
464
|
-
this.guard();
|
|
465
|
-
this.lib.textBufferViewResetLocalSelection(this.viewPtr);
|
|
466
|
-
}
|
|
467
|
-
setWrapWidth(width) {
|
|
468
|
-
this.guard();
|
|
469
|
-
this.lib.textBufferViewSetWrapWidth(this.viewPtr, width ?? 0);
|
|
470
|
-
}
|
|
471
|
-
setWrapMode(mode) {
|
|
472
|
-
this.guard();
|
|
473
|
-
this.lib.textBufferViewSetWrapMode(this.viewPtr, mode);
|
|
474
|
-
}
|
|
475
|
-
setViewportSize(width, height) {
|
|
476
|
-
this.guard();
|
|
477
|
-
this.lib.textBufferViewSetViewportSize(this.viewPtr, width, height);
|
|
478
|
-
}
|
|
479
|
-
setViewport(x, y, width, height) {
|
|
480
|
-
this.guard();
|
|
481
|
-
this.lib.textBufferViewSetViewport(this.viewPtr, x, y, width, height);
|
|
482
|
-
}
|
|
483
|
-
get lineInfo() {
|
|
484
|
-
this.guard();
|
|
485
|
-
return this.lib.textBufferViewGetLineInfo(this.viewPtr);
|
|
486
|
-
}
|
|
487
|
-
get logicalLineInfo() {
|
|
488
|
-
this.guard();
|
|
489
|
-
return this.lib.textBufferViewGetLogicalLineInfo(this.viewPtr);
|
|
490
|
-
}
|
|
491
|
-
getSelectedText() {
|
|
492
|
-
this.guard();
|
|
493
|
-
const byteSize = this.textBuffer.byteSize;
|
|
494
|
-
if (byteSize === 0)
|
|
495
|
-
return "";
|
|
496
|
-
const selectedBytes = this.lib.textBufferViewGetSelectedTextBytes(this.viewPtr, byteSize);
|
|
497
|
-
if (!selectedBytes)
|
|
498
|
-
return "";
|
|
499
|
-
return this.lib.decoder.decode(selectedBytes);
|
|
500
|
-
}
|
|
501
|
-
getPlainText() {
|
|
502
|
-
this.guard();
|
|
503
|
-
const byteSize = this.textBuffer.byteSize;
|
|
504
|
-
if (byteSize === 0)
|
|
505
|
-
return "";
|
|
506
|
-
const plainBytes = this.lib.textBufferViewGetPlainTextBytes(this.viewPtr, byteSize);
|
|
507
|
-
if (!plainBytes)
|
|
508
|
-
return "";
|
|
509
|
-
return this.lib.decoder.decode(plainBytes);
|
|
510
|
-
}
|
|
511
|
-
setTabIndicator(indicator) {
|
|
512
|
-
this.guard();
|
|
513
|
-
const codePoint = typeof indicator === "string" ? indicator.codePointAt(0) ?? 0 : indicator;
|
|
514
|
-
this.lib.textBufferViewSetTabIndicator(this.viewPtr, codePoint);
|
|
515
|
-
}
|
|
516
|
-
setTabIndicatorColor(color) {
|
|
517
|
-
this.guard();
|
|
518
|
-
this.lib.textBufferViewSetTabIndicatorColor(this.viewPtr, color);
|
|
519
|
-
}
|
|
520
|
-
setTruncate(truncate) {
|
|
521
|
-
this.guard();
|
|
522
|
-
this.lib.textBufferViewSetTruncate(this.viewPtr, truncate);
|
|
523
|
-
}
|
|
524
|
-
measureForDimensions(width, height) {
|
|
525
|
-
this.guard();
|
|
526
|
-
return this.lib.textBufferViewMeasureForDimensions(this.viewPtr, width, height);
|
|
527
|
-
}
|
|
528
|
-
getVirtualLineCount() {
|
|
529
|
-
this.guard();
|
|
530
|
-
return this.lib.textBufferViewGetVirtualLineCount(this.viewPtr);
|
|
531
|
-
}
|
|
532
|
-
destroy() {
|
|
533
|
-
if (this._destroyed)
|
|
534
|
-
return;
|
|
535
|
-
this._destroyed = true;
|
|
536
|
-
this.lib.destroyTextBufferView(this.viewPtr);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
// src/syntax-style.ts
|
|
540
|
-
function convertThemeToStyles(theme) {
|
|
541
|
-
const flatStyles = {};
|
|
542
|
-
for (const tokenStyle of theme) {
|
|
543
|
-
const styleDefinition = {};
|
|
544
|
-
if (tokenStyle.style.foreground) {
|
|
545
|
-
styleDefinition.fg = parseColor(tokenStyle.style.foreground);
|
|
546
|
-
}
|
|
547
|
-
if (tokenStyle.style.background) {
|
|
548
|
-
styleDefinition.bg = parseColor(tokenStyle.style.background);
|
|
549
|
-
}
|
|
550
|
-
if (tokenStyle.style.bold !== undefined) {
|
|
551
|
-
styleDefinition.bold = tokenStyle.style.bold;
|
|
552
|
-
}
|
|
553
|
-
if (tokenStyle.style.italic !== undefined) {
|
|
554
|
-
styleDefinition.italic = tokenStyle.style.italic;
|
|
555
|
-
}
|
|
556
|
-
if (tokenStyle.style.underline !== undefined) {
|
|
557
|
-
styleDefinition.underline = tokenStyle.style.underline;
|
|
558
|
-
}
|
|
559
|
-
if (tokenStyle.style.dim !== undefined) {
|
|
560
|
-
styleDefinition.dim = tokenStyle.style.dim;
|
|
561
|
-
}
|
|
562
|
-
for (const scope of tokenStyle.scope) {
|
|
563
|
-
flatStyles[scope] = styleDefinition;
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
return flatStyles;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
class SyntaxStyle {
|
|
570
|
-
lib;
|
|
571
|
-
stylePtr;
|
|
572
|
-
_destroyed = false;
|
|
573
|
-
nameCache = new Map;
|
|
574
|
-
styleDefs = new Map;
|
|
575
|
-
mergedCache = new Map;
|
|
576
|
-
constructor(lib, ptr) {
|
|
577
|
-
this.lib = lib;
|
|
578
|
-
this.stylePtr = ptr;
|
|
579
|
-
}
|
|
580
|
-
static create() {
|
|
581
|
-
const lib = resolveRenderLib();
|
|
582
|
-
const ptr = lib.createSyntaxStyle();
|
|
583
|
-
return new SyntaxStyle(lib, ptr);
|
|
584
|
-
}
|
|
585
|
-
static fromTheme(theme) {
|
|
586
|
-
const style = SyntaxStyle.create();
|
|
587
|
-
const flatStyles = convertThemeToStyles(theme);
|
|
588
|
-
for (const [name, styleDef] of Object.entries(flatStyles)) {
|
|
589
|
-
style.registerStyle(name, styleDef);
|
|
590
|
-
}
|
|
591
|
-
return style;
|
|
592
|
-
}
|
|
593
|
-
static fromStyles(styles) {
|
|
594
|
-
const style = SyntaxStyle.create();
|
|
595
|
-
for (const [name, styleDef] of Object.entries(styles)) {
|
|
596
|
-
style.registerStyle(name, styleDef);
|
|
597
|
-
}
|
|
598
|
-
return style;
|
|
599
|
-
}
|
|
600
|
-
guard() {
|
|
601
|
-
if (this._destroyed)
|
|
602
|
-
throw new Error("NativeSyntaxStyle is destroyed");
|
|
603
|
-
}
|
|
604
|
-
registerStyle(name, style) {
|
|
605
|
-
this.guard();
|
|
606
|
-
const attributes = createTextAttributes({
|
|
607
|
-
bold: style.bold,
|
|
608
|
-
italic: style.italic,
|
|
609
|
-
underline: style.underline,
|
|
610
|
-
dim: style.dim
|
|
611
|
-
});
|
|
612
|
-
const id = this.lib.syntaxStyleRegister(this.stylePtr, name, style.fg || null, style.bg || null, attributes);
|
|
613
|
-
this.nameCache.set(name, id);
|
|
614
|
-
this.styleDefs.set(name, style);
|
|
615
|
-
return id;
|
|
616
|
-
}
|
|
617
|
-
resolveStyleId(name) {
|
|
618
|
-
this.guard();
|
|
619
|
-
const cached = this.nameCache.get(name);
|
|
620
|
-
if (cached !== undefined)
|
|
621
|
-
return cached;
|
|
622
|
-
const id = this.lib.syntaxStyleResolveByName(this.stylePtr, name);
|
|
623
|
-
if (id !== null) {
|
|
624
|
-
this.nameCache.set(name, id);
|
|
625
|
-
}
|
|
626
|
-
return id;
|
|
627
|
-
}
|
|
628
|
-
getStyleId(name) {
|
|
629
|
-
this.guard();
|
|
630
|
-
const id = this.resolveStyleId(name);
|
|
631
|
-
if (id !== null)
|
|
632
|
-
return id;
|
|
633
|
-
if (name.includes(".")) {
|
|
634
|
-
const baseName = name.split(".")[0];
|
|
635
|
-
return this.resolveStyleId(baseName);
|
|
636
|
-
}
|
|
637
|
-
return null;
|
|
638
|
-
}
|
|
639
|
-
get ptr() {
|
|
640
|
-
this.guard();
|
|
641
|
-
return this.stylePtr;
|
|
642
|
-
}
|
|
643
|
-
getStyleCount() {
|
|
644
|
-
this.guard();
|
|
645
|
-
return this.lib.syntaxStyleGetStyleCount(this.stylePtr);
|
|
646
|
-
}
|
|
647
|
-
clearNameCache() {
|
|
648
|
-
this.nameCache.clear();
|
|
649
|
-
}
|
|
650
|
-
getStyle(name) {
|
|
651
|
-
this.guard();
|
|
652
|
-
if (Object.prototype.hasOwnProperty.call(this.styleDefs, name)) {
|
|
653
|
-
return;
|
|
654
|
-
}
|
|
655
|
-
const style = this.styleDefs.get(name);
|
|
656
|
-
if (style)
|
|
657
|
-
return style;
|
|
658
|
-
if (name.includes(".")) {
|
|
659
|
-
const baseName = name.split(".")[0];
|
|
660
|
-
if (Object.prototype.hasOwnProperty.call(this.styleDefs, baseName)) {
|
|
661
|
-
return;
|
|
662
|
-
}
|
|
663
|
-
return this.styleDefs.get(baseName);
|
|
664
|
-
}
|
|
665
|
-
return;
|
|
666
|
-
}
|
|
667
|
-
mergeStyles(...styleNames) {
|
|
668
|
-
this.guard();
|
|
669
|
-
const cacheKey = styleNames.join(":");
|
|
670
|
-
const cached = this.mergedCache.get(cacheKey);
|
|
671
|
-
if (cached)
|
|
672
|
-
return cached;
|
|
673
|
-
const styleDefinition = {};
|
|
674
|
-
for (const name of styleNames) {
|
|
675
|
-
const style = this.getStyle(name);
|
|
676
|
-
if (!style)
|
|
677
|
-
continue;
|
|
678
|
-
if (style.fg)
|
|
679
|
-
styleDefinition.fg = style.fg;
|
|
680
|
-
if (style.bg)
|
|
681
|
-
styleDefinition.bg = style.bg;
|
|
682
|
-
if (style.bold !== undefined)
|
|
683
|
-
styleDefinition.bold = style.bold;
|
|
684
|
-
if (style.italic !== undefined)
|
|
685
|
-
styleDefinition.italic = style.italic;
|
|
686
|
-
if (style.underline !== undefined)
|
|
687
|
-
styleDefinition.underline = style.underline;
|
|
688
|
-
if (style.dim !== undefined)
|
|
689
|
-
styleDefinition.dim = style.dim;
|
|
690
|
-
}
|
|
691
|
-
const attributes = createTextAttributes({
|
|
692
|
-
bold: styleDefinition.bold,
|
|
693
|
-
italic: styleDefinition.italic,
|
|
694
|
-
underline: styleDefinition.underline,
|
|
695
|
-
dim: styleDefinition.dim
|
|
696
|
-
});
|
|
697
|
-
const merged = {
|
|
698
|
-
fg: styleDefinition.fg,
|
|
699
|
-
bg: styleDefinition.bg,
|
|
700
|
-
attributes
|
|
701
|
-
};
|
|
702
|
-
this.mergedCache.set(cacheKey, merged);
|
|
703
|
-
return merged;
|
|
704
|
-
}
|
|
705
|
-
clearCache() {
|
|
706
|
-
this.guard();
|
|
707
|
-
this.mergedCache.clear();
|
|
708
|
-
}
|
|
709
|
-
getCacheSize() {
|
|
710
|
-
this.guard();
|
|
711
|
-
return this.mergedCache.size;
|
|
712
|
-
}
|
|
713
|
-
getAllStyles() {
|
|
714
|
-
this.guard();
|
|
715
|
-
return new Map(this.styleDefs);
|
|
716
|
-
}
|
|
717
|
-
getRegisteredNames() {
|
|
718
|
-
this.guard();
|
|
719
|
-
return Array.from(this.styleDefs.keys());
|
|
720
|
-
}
|
|
721
|
-
destroy() {
|
|
722
|
-
if (this._destroyed)
|
|
723
|
-
return;
|
|
724
|
-
this._destroyed = true;
|
|
725
|
-
this.nameCache.clear();
|
|
726
|
-
this.styleDefs.clear();
|
|
727
|
-
this.mergedCache.clear();
|
|
728
|
-
this.lib.destroySyntaxStyle(this.stylePtr);
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
438
|
// src/post/effects.ts
|
|
732
439
|
class DistortionEffect {
|
|
733
440
|
glitchChancePerSecond = 0.5;
|
|
@@ -3385,1264 +3092,124 @@ class ASCIIFontRenderable extends FrameBufferRenderable {
|
|
|
3385
3092
|
this._backgroundColor = options.backgroundColor || defaultOptions.backgroundColor;
|
|
3386
3093
|
this._selectionBg = options.selectionBg ? parseColor(options.selectionBg) : undefined;
|
|
3387
3094
|
this._selectionFg = options.selectionFg ? parseColor(options.selectionFg) : undefined;
|
|
3388
|
-
this.selectable = options.selectable ?? true;
|
|
3389
|
-
this.selectionHelper = new ASCIIFontSelectionHelper(() => this._text, () => this._font);
|
|
3390
|
-
this.renderFontToBuffer();
|
|
3391
|
-
}
|
|
3392
|
-
get text() {
|
|
3393
|
-
return this._text;
|
|
3394
|
-
}
|
|
3395
|
-
set text(value) {
|
|
3396
|
-
this._text = value;
|
|
3397
|
-
this.updateDimensions();
|
|
3398
|
-
if (this.lastLocalSelection) {
|
|
3399
|
-
this.selectionHelper.onLocalSelectionChanged(this.lastLocalSelection, this.width, this.height);
|
|
3400
|
-
}
|
|
3401
|
-
this.renderFontToBuffer();
|
|
3402
|
-
this.requestRender();
|
|
3403
|
-
}
|
|
3404
|
-
get font() {
|
|
3405
|
-
return this._font;
|
|
3406
|
-
}
|
|
3407
|
-
set font(value) {
|
|
3408
|
-
this._font = value;
|
|
3409
|
-
this.updateDimensions();
|
|
3410
|
-
if (this.lastLocalSelection) {
|
|
3411
|
-
this.selectionHelper.onLocalSelectionChanged(this.lastLocalSelection, this.width, this.height);
|
|
3412
|
-
}
|
|
3413
|
-
this.renderFontToBuffer();
|
|
3414
|
-
this.requestRender();
|
|
3415
|
-
}
|
|
3416
|
-
get color() {
|
|
3417
|
-
return this._color;
|
|
3418
|
-
}
|
|
3419
|
-
set color(value) {
|
|
3420
|
-
this._color = value;
|
|
3421
|
-
this.renderFontToBuffer();
|
|
3422
|
-
this.requestRender();
|
|
3423
|
-
}
|
|
3424
|
-
get backgroundColor() {
|
|
3425
|
-
return this._backgroundColor;
|
|
3426
|
-
}
|
|
3427
|
-
set backgroundColor(value) {
|
|
3428
|
-
this._backgroundColor = value;
|
|
3429
|
-
this.renderFontToBuffer();
|
|
3430
|
-
this.requestRender();
|
|
3431
|
-
}
|
|
3432
|
-
updateDimensions() {
|
|
3433
|
-
const measurements = measureText({ text: this._text, font: this._font });
|
|
3434
|
-
this.width = measurements.width;
|
|
3435
|
-
this.height = measurements.height;
|
|
3436
|
-
}
|
|
3437
|
-
shouldStartSelection(x, y) {
|
|
3438
|
-
const localX = x - this.x;
|
|
3439
|
-
const localY = y - this.y;
|
|
3440
|
-
return this.selectionHelper.shouldStartSelection(localX, localY, this.width, this.height);
|
|
3441
|
-
}
|
|
3442
|
-
onSelectionChanged(selection) {
|
|
3443
|
-
const localSelection = convertGlobalToLocalSelection(selection, this.x, this.y);
|
|
3444
|
-
this.lastLocalSelection = localSelection;
|
|
3445
|
-
const changed = this.selectionHelper.onLocalSelectionChanged(localSelection, this.width, this.height);
|
|
3446
|
-
if (changed) {
|
|
3447
|
-
this.renderFontToBuffer();
|
|
3448
|
-
this.requestRender();
|
|
3449
|
-
}
|
|
3450
|
-
return changed;
|
|
3451
|
-
}
|
|
3452
|
-
getSelectedText() {
|
|
3453
|
-
const selection = this.selectionHelper.getSelection();
|
|
3454
|
-
if (!selection)
|
|
3455
|
-
return "";
|
|
3456
|
-
return this._text.slice(selection.start, selection.end);
|
|
3457
|
-
}
|
|
3458
|
-
hasSelection() {
|
|
3459
|
-
return this.selectionHelper.hasSelection();
|
|
3460
|
-
}
|
|
3461
|
-
onResize(width, height) {
|
|
3462
|
-
super.onResize(width, height);
|
|
3463
|
-
this.renderFontToBuffer();
|
|
3464
|
-
}
|
|
3465
|
-
renderFontToBuffer() {
|
|
3466
|
-
if (this.isDestroyed)
|
|
3467
|
-
return;
|
|
3468
|
-
this.frameBuffer.clear(parseColor(this._backgroundColor));
|
|
3469
|
-
renderFontToFrameBuffer(this.frameBuffer, {
|
|
3470
|
-
text: this._text,
|
|
3471
|
-
x: 0,
|
|
3472
|
-
y: 0,
|
|
3473
|
-
color: this.color,
|
|
3474
|
-
backgroundColor: this._backgroundColor,
|
|
3475
|
-
font: this._font
|
|
3476
|
-
});
|
|
3477
|
-
const selection = this.selectionHelper.getSelection();
|
|
3478
|
-
if (selection && (this._selectionBg || this._selectionFg)) {
|
|
3479
|
-
this.renderSelectionHighlight(selection);
|
|
3480
|
-
}
|
|
3481
|
-
}
|
|
3482
|
-
renderSelectionHighlight(selection) {
|
|
3483
|
-
if (!this._selectionBg && !this._selectionFg)
|
|
3484
|
-
return;
|
|
3485
|
-
const selectedText = this._text.slice(selection.start, selection.end);
|
|
3486
|
-
if (!selectedText)
|
|
3487
|
-
return;
|
|
3488
|
-
const positions = getCharacterPositions(this._text, this._font);
|
|
3489
|
-
const startX = positions[selection.start] || 0;
|
|
3490
|
-
const endX = selection.end < positions.length ? positions[selection.end] : measureText({ text: this._text, font: this._font }).width;
|
|
3491
|
-
if (this._selectionBg) {
|
|
3492
|
-
this.frameBuffer.fillRect(startX, 0, endX - startX, this.height, parseColor(this._selectionBg));
|
|
3493
|
-
}
|
|
3494
|
-
if (this._selectionFg || this._selectionBg) {
|
|
3495
|
-
renderFontToFrameBuffer(this.frameBuffer, {
|
|
3496
|
-
text: selectedText,
|
|
3497
|
-
x: startX,
|
|
3498
|
-
y: 0,
|
|
3499
|
-
color: this._selectionFg ? this._selectionFg : this._color,
|
|
3500
|
-
backgroundColor: this._selectionBg ? this._selectionBg : this._backgroundColor,
|
|
3501
|
-
font: this._font
|
|
3502
|
-
});
|
|
3503
|
-
}
|
|
3504
|
-
}
|
|
3505
|
-
}
|
|
3506
|
-
// src/renderables/Box.ts
|
|
3507
|
-
function isGapType(value) {
|
|
3508
|
-
if (value === undefined) {
|
|
3509
|
-
return true;
|
|
3510
|
-
}
|
|
3511
|
-
if (typeof value === "number" && !Number.isNaN(value)) {
|
|
3512
|
-
return true;
|
|
3513
|
-
}
|
|
3514
|
-
return isValidPercentage(value);
|
|
3515
|
-
}
|
|
3516
|
-
|
|
3517
|
-
class BoxRenderable extends Renderable {
|
|
3518
|
-
_backgroundColor;
|
|
3519
|
-
_border;
|
|
3520
|
-
_borderStyle;
|
|
3521
|
-
_borderColor;
|
|
3522
|
-
_focusedBorderColor;
|
|
3523
|
-
_customBorderCharsObj;
|
|
3524
|
-
_customBorderChars;
|
|
3525
|
-
borderSides;
|
|
3526
|
-
shouldFill;
|
|
3527
|
-
_title;
|
|
3528
|
-
_titleAlignment;
|
|
3529
|
-
_bottomTitle;
|
|
3530
|
-
_bottomTitleAlignment;
|
|
3531
|
-
_defaultOptions = {
|
|
3532
|
-
backgroundColor: "transparent",
|
|
3533
|
-
borderStyle: "single",
|
|
3534
|
-
border: false,
|
|
3535
|
-
borderColor: "#FFFFFF",
|
|
3536
|
-
shouldFill: true,
|
|
3537
|
-
titleAlignment: "left",
|
|
3538
|
-
bottomTitleAlignment: "left",
|
|
3539
|
-
focusedBorderColor: "#00AAFF"
|
|
3540
|
-
};
|
|
3541
|
-
constructor(ctx, options) {
|
|
3542
|
-
super(ctx, options);
|
|
3543
|
-
if (options.focusable === true) {
|
|
3544
|
-
this._focusable = true;
|
|
3545
|
-
}
|
|
3546
|
-
this._backgroundColor = parseColor(options.backgroundColor || this._defaultOptions.backgroundColor);
|
|
3547
|
-
this._border = options.border ?? this._defaultOptions.border;
|
|
3548
|
-
if (!options.border && (options.borderStyle || options.borderColor || options.focusedBorderColor || options.customBorderChars)) {
|
|
3549
|
-
this._border = true;
|
|
3550
|
-
}
|
|
3551
|
-
this._borderStyle = parseBorderStyle(options.borderStyle, this._defaultOptions.borderStyle);
|
|
3552
|
-
this._borderColor = parseColor(options.borderColor || this._defaultOptions.borderColor);
|
|
3553
|
-
this._focusedBorderColor = parseColor(options.focusedBorderColor || this._defaultOptions.focusedBorderColor);
|
|
3554
|
-
this._customBorderCharsObj = options.customBorderChars;
|
|
3555
|
-
this._customBorderChars = this._customBorderCharsObj ? borderCharsToArray(this._customBorderCharsObj) : undefined;
|
|
3556
|
-
this.borderSides = getBorderSides(this._border);
|
|
3557
|
-
this.shouldFill = options.shouldFill ?? this._defaultOptions.shouldFill;
|
|
3558
|
-
this._title = options.title;
|
|
3559
|
-
this._titleAlignment = options.titleAlignment || this._defaultOptions.titleAlignment;
|
|
3560
|
-
this._bottomTitle = options.bottomTitle;
|
|
3561
|
-
this._bottomTitleAlignment = options.bottomTitleAlignment || this._defaultOptions.bottomTitleAlignment;
|
|
3562
|
-
this.applyYogaBorders();
|
|
3563
|
-
const hasInitialGapProps = options.gap !== undefined || options.rowGap !== undefined || options.columnGap !== undefined;
|
|
3564
|
-
if (hasInitialGapProps) {
|
|
3565
|
-
this.applyYogaGap(options);
|
|
3566
|
-
}
|
|
3567
|
-
}
|
|
3568
|
-
initializeBorder() {
|
|
3569
|
-
if (this._border === false) {
|
|
3570
|
-
this._border = true;
|
|
3571
|
-
this.borderSides = getBorderSides(this._border);
|
|
3572
|
-
this.applyYogaBorders();
|
|
3573
|
-
}
|
|
3574
|
-
}
|
|
3575
|
-
get customBorderChars() {
|
|
3576
|
-
return this._customBorderCharsObj;
|
|
3577
|
-
}
|
|
3578
|
-
set customBorderChars(value) {
|
|
3579
|
-
this._customBorderCharsObj = value;
|
|
3580
|
-
this._customBorderChars = value ? borderCharsToArray(value) : undefined;
|
|
3581
|
-
this.requestRender();
|
|
3582
|
-
}
|
|
3583
|
-
get backgroundColor() {
|
|
3584
|
-
return this._backgroundColor;
|
|
3585
|
-
}
|
|
3586
|
-
set backgroundColor(value) {
|
|
3587
|
-
const newColor = parseColor(value ?? this._defaultOptions.backgroundColor);
|
|
3588
|
-
if (this._backgroundColor !== newColor) {
|
|
3589
|
-
this._backgroundColor = newColor;
|
|
3590
|
-
this.requestRender();
|
|
3591
|
-
}
|
|
3592
|
-
}
|
|
3593
|
-
get border() {
|
|
3594
|
-
return this._border;
|
|
3595
|
-
}
|
|
3596
|
-
set border(value) {
|
|
3597
|
-
if (this._border !== value) {
|
|
3598
|
-
this._border = value;
|
|
3599
|
-
this.borderSides = getBorderSides(value);
|
|
3600
|
-
this.applyYogaBorders();
|
|
3601
|
-
this.requestRender();
|
|
3602
|
-
}
|
|
3603
|
-
}
|
|
3604
|
-
get borderStyle() {
|
|
3605
|
-
return this._borderStyle;
|
|
3606
|
-
}
|
|
3607
|
-
set borderStyle(value) {
|
|
3608
|
-
const _value = parseBorderStyle(value, this._defaultOptions.borderStyle);
|
|
3609
|
-
if (this._borderStyle !== _value || !this._border) {
|
|
3610
|
-
this._borderStyle = _value;
|
|
3611
|
-
this._customBorderChars = undefined;
|
|
3612
|
-
this.initializeBorder();
|
|
3613
|
-
this.requestRender();
|
|
3614
|
-
}
|
|
3615
|
-
}
|
|
3616
|
-
get borderColor() {
|
|
3617
|
-
return this._borderColor;
|
|
3618
|
-
}
|
|
3619
|
-
set borderColor(value) {
|
|
3620
|
-
const newColor = parseColor(value ?? this._defaultOptions.borderColor);
|
|
3621
|
-
if (this._borderColor !== newColor) {
|
|
3622
|
-
this._borderColor = newColor;
|
|
3623
|
-
this.initializeBorder();
|
|
3624
|
-
this.requestRender();
|
|
3625
|
-
}
|
|
3626
|
-
}
|
|
3627
|
-
get focusedBorderColor() {
|
|
3628
|
-
return this._focusedBorderColor;
|
|
3629
|
-
}
|
|
3630
|
-
set focusedBorderColor(value) {
|
|
3631
|
-
const newColor = parseColor(value ?? this._defaultOptions.focusedBorderColor);
|
|
3632
|
-
if (this._focusedBorderColor !== newColor) {
|
|
3633
|
-
this._focusedBorderColor = newColor;
|
|
3634
|
-
this.initializeBorder();
|
|
3635
|
-
if (this._focused) {
|
|
3636
|
-
this.requestRender();
|
|
3637
|
-
}
|
|
3638
|
-
}
|
|
3639
|
-
}
|
|
3640
|
-
get title() {
|
|
3641
|
-
return this._title;
|
|
3642
|
-
}
|
|
3643
|
-
set title(value) {
|
|
3644
|
-
if (this._title !== value) {
|
|
3645
|
-
this._title = value;
|
|
3646
|
-
this.requestRender();
|
|
3647
|
-
}
|
|
3648
|
-
}
|
|
3649
|
-
get titleAlignment() {
|
|
3650
|
-
return this._titleAlignment;
|
|
3651
|
-
}
|
|
3652
|
-
set titleAlignment(value) {
|
|
3653
|
-
if (this._titleAlignment !== value) {
|
|
3654
|
-
this._titleAlignment = value;
|
|
3655
|
-
this.requestRender();
|
|
3656
|
-
}
|
|
3657
|
-
}
|
|
3658
|
-
get bottomTitle() {
|
|
3659
|
-
return this._bottomTitle;
|
|
3660
|
-
}
|
|
3661
|
-
set bottomTitle(value) {
|
|
3662
|
-
if (this._bottomTitle !== value) {
|
|
3663
|
-
this._bottomTitle = value;
|
|
3664
|
-
this.requestRender();
|
|
3665
|
-
}
|
|
3666
|
-
}
|
|
3667
|
-
get bottomTitleAlignment() {
|
|
3668
|
-
return this._bottomTitleAlignment;
|
|
3669
|
-
}
|
|
3670
|
-
set bottomTitleAlignment(value) {
|
|
3671
|
-
if (this._bottomTitleAlignment !== value) {
|
|
3672
|
-
this._bottomTitleAlignment = value;
|
|
3673
|
-
this.requestRender();
|
|
3674
|
-
}
|
|
3675
|
-
}
|
|
3676
|
-
renderSelf(buffer) {
|
|
3677
|
-
const hasBorder = this.borderSides.top || this.borderSides.right || this.borderSides.bottom || this.borderSides.left;
|
|
3678
|
-
const hasVisibleFill = this.shouldFill && this._backgroundColor.a > 0;
|
|
3679
|
-
if (!hasBorder && !hasVisibleFill) {
|
|
3680
|
-
return;
|
|
3681
|
-
}
|
|
3682
|
-
const hasFocusWithin = this._focusable && (this._focused || this._hasFocusedDescendant);
|
|
3683
|
-
const currentBorderColor = hasFocusWithin ? this._focusedBorderColor : this._borderColor;
|
|
3684
|
-
const screenX = this._screenX;
|
|
3685
|
-
const screenY = this._screenY;
|
|
3686
|
-
buffer.drawBox({
|
|
3687
|
-
x: screenX,
|
|
3688
|
-
y: screenY,
|
|
3689
|
-
width: this.width,
|
|
3690
|
-
height: this.height,
|
|
3691
|
-
borderStyle: this._borderStyle,
|
|
3692
|
-
customBorderChars: this._customBorderChars,
|
|
3693
|
-
border: this._border,
|
|
3694
|
-
borderColor: currentBorderColor,
|
|
3695
|
-
backgroundColor: this._backgroundColor,
|
|
3696
|
-
shouldFill: this.shouldFill,
|
|
3697
|
-
title: this._title,
|
|
3698
|
-
titleAlignment: this._titleAlignment,
|
|
3699
|
-
bottomTitle: this._bottomTitle,
|
|
3700
|
-
bottomTitleAlignment: this._bottomTitleAlignment
|
|
3701
|
-
});
|
|
3702
|
-
}
|
|
3703
|
-
getScissorRect() {
|
|
3704
|
-
const baseRect = super.getScissorRect();
|
|
3705
|
-
if (!this.borderSides.top && !this.borderSides.right && !this.borderSides.bottom && !this.borderSides.left) {
|
|
3706
|
-
return baseRect;
|
|
3707
|
-
}
|
|
3708
|
-
const leftInset = this.borderSides.left ? 1 : 0;
|
|
3709
|
-
const rightInset = this.borderSides.right ? 1 : 0;
|
|
3710
|
-
const topInset = this.borderSides.top ? 1 : 0;
|
|
3711
|
-
const bottomInset = this.borderSides.bottom ? 1 : 0;
|
|
3712
|
-
return {
|
|
3713
|
-
x: baseRect.x + leftInset,
|
|
3714
|
-
y: baseRect.y + topInset,
|
|
3715
|
-
width: Math.max(0, baseRect.width - leftInset - rightInset),
|
|
3716
|
-
height: Math.max(0, baseRect.height - topInset - bottomInset)
|
|
3717
|
-
};
|
|
3718
|
-
}
|
|
3719
|
-
applyYogaBorders() {
|
|
3720
|
-
const node = this.yogaNode;
|
|
3721
|
-
node.setBorder(Edge.Left, this.borderSides.left ? 1 : 0);
|
|
3722
|
-
node.setBorder(Edge.Right, this.borderSides.right ? 1 : 0);
|
|
3723
|
-
node.setBorder(Edge.Top, this.borderSides.top ? 1 : 0);
|
|
3724
|
-
node.setBorder(Edge.Bottom, this.borderSides.bottom ? 1 : 0);
|
|
3725
|
-
this.requestRender();
|
|
3726
|
-
}
|
|
3727
|
-
applyYogaGap(options) {
|
|
3728
|
-
const node = this.yogaNode;
|
|
3729
|
-
if (isGapType(options.gap)) {
|
|
3730
|
-
node.setGap(Gutter.All, options.gap);
|
|
3731
|
-
}
|
|
3732
|
-
if (isGapType(options.rowGap)) {
|
|
3733
|
-
node.setGap(Gutter.Row, options.rowGap);
|
|
3734
|
-
}
|
|
3735
|
-
if (isGapType(options.columnGap)) {
|
|
3736
|
-
node.setGap(Gutter.Column, options.columnGap);
|
|
3737
|
-
}
|
|
3738
|
-
}
|
|
3739
|
-
set gap(gap) {
|
|
3740
|
-
if (isGapType(gap)) {
|
|
3741
|
-
this.yogaNode.setGap(Gutter.All, gap);
|
|
3742
|
-
this.requestRender();
|
|
3743
|
-
}
|
|
3744
|
-
}
|
|
3745
|
-
set rowGap(rowGap) {
|
|
3746
|
-
if (isGapType(rowGap)) {
|
|
3747
|
-
this.yogaNode.setGap(Gutter.Row, rowGap);
|
|
3748
|
-
this.requestRender();
|
|
3749
|
-
}
|
|
3750
|
-
}
|
|
3751
|
-
set columnGap(columnGap) {
|
|
3752
|
-
if (isGapType(columnGap)) {
|
|
3753
|
-
this.yogaNode.setGap(Gutter.Column, columnGap);
|
|
3754
|
-
this.requestRender();
|
|
3755
|
-
}
|
|
3756
|
-
}
|
|
3757
|
-
}
|
|
3758
|
-
// src/renderables/TextBufferRenderable.ts
|
|
3759
|
-
class TextBufferRenderable extends Renderable {
|
|
3760
|
-
selectable = true;
|
|
3761
|
-
_defaultFg;
|
|
3762
|
-
_defaultBg;
|
|
3763
|
-
_defaultAttributes;
|
|
3764
|
-
_selectionBg;
|
|
3765
|
-
_selectionFg;
|
|
3766
|
-
_wrapMode = "word";
|
|
3767
|
-
lastLocalSelection = null;
|
|
3768
|
-
_tabIndicator;
|
|
3769
|
-
_tabIndicatorColor;
|
|
3770
|
-
_scrollX = 0;
|
|
3771
|
-
_scrollY = 0;
|
|
3772
|
-
_truncate = false;
|
|
3773
|
-
textBuffer;
|
|
3774
|
-
textBufferView;
|
|
3775
|
-
_textBufferSyntaxStyle;
|
|
3776
|
-
_defaultOptions = {
|
|
3777
|
-
fg: RGBA.fromValues(1, 1, 1, 1),
|
|
3778
|
-
bg: RGBA.fromValues(0, 0, 0, 0),
|
|
3779
|
-
selectionBg: undefined,
|
|
3780
|
-
selectionFg: undefined,
|
|
3781
|
-
selectable: true,
|
|
3782
|
-
attributes: 0,
|
|
3783
|
-
wrapMode: "word",
|
|
3784
|
-
tabIndicator: undefined,
|
|
3785
|
-
tabIndicatorColor: undefined,
|
|
3786
|
-
truncate: false
|
|
3787
|
-
};
|
|
3788
|
-
constructor(ctx, options) {
|
|
3789
|
-
super(ctx, options);
|
|
3790
|
-
this._defaultFg = parseColor(options.fg ?? this._defaultOptions.fg);
|
|
3791
|
-
this._defaultBg = parseColor(options.bg ?? this._defaultOptions.bg);
|
|
3792
|
-
this._defaultAttributes = options.attributes ?? this._defaultOptions.attributes;
|
|
3793
|
-
this._selectionBg = options.selectionBg ? parseColor(options.selectionBg) : this._defaultOptions.selectionBg;
|
|
3794
|
-
this._selectionFg = options.selectionFg ? parseColor(options.selectionFg) : this._defaultOptions.selectionFg;
|
|
3795
|
-
this.selectable = options.selectable ?? this._defaultOptions.selectable;
|
|
3796
|
-
this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
|
|
3797
|
-
this._tabIndicator = options.tabIndicator ?? this._defaultOptions.tabIndicator;
|
|
3798
|
-
this._tabIndicatorColor = options.tabIndicatorColor ? parseColor(options.tabIndicatorColor) : this._defaultOptions.tabIndicatorColor;
|
|
3799
|
-
this._truncate = options.truncate ?? this._defaultOptions.truncate;
|
|
3800
|
-
this.textBuffer = TextBuffer.create(this._ctx.widthMethod);
|
|
3801
|
-
this.textBufferView = TextBufferView.create(this.textBuffer);
|
|
3802
|
-
this._textBufferSyntaxStyle = SyntaxStyle.create();
|
|
3803
|
-
this.textBuffer.setSyntaxStyle(this._textBufferSyntaxStyle);
|
|
3804
|
-
this.textBufferView.setWrapMode(this._wrapMode);
|
|
3805
|
-
this.setupMeasureFunc();
|
|
3806
|
-
this.textBuffer.setDefaultFg(this._defaultFg);
|
|
3807
|
-
this.textBuffer.setDefaultBg(this._defaultBg);
|
|
3808
|
-
this.textBuffer.setDefaultAttributes(this._defaultAttributes);
|
|
3809
|
-
if (this._tabIndicator !== undefined) {
|
|
3810
|
-
this.textBufferView.setTabIndicator(this._tabIndicator);
|
|
3811
|
-
}
|
|
3812
|
-
if (this._tabIndicatorColor !== undefined) {
|
|
3813
|
-
this.textBufferView.setTabIndicatorColor(this._tabIndicatorColor);
|
|
3814
|
-
}
|
|
3815
|
-
if (this._wrapMode !== "none" && this.width > 0) {
|
|
3816
|
-
this.textBufferView.setWrapWidth(this.width);
|
|
3817
|
-
}
|
|
3818
|
-
if (this.width > 0 && this.height > 0) {
|
|
3819
|
-
this.textBufferView.setViewport(this._scrollX, this._scrollY, this.width, this.height);
|
|
3820
|
-
}
|
|
3821
|
-
this.textBufferView.setTruncate(this._truncate);
|
|
3822
|
-
this.updateTextInfo();
|
|
3823
|
-
}
|
|
3824
|
-
onMouseEvent(event) {
|
|
3825
|
-
if (event.type === "scroll") {
|
|
3826
|
-
this.handleScroll(event);
|
|
3827
|
-
}
|
|
3828
|
-
}
|
|
3829
|
-
handleScroll(event) {
|
|
3830
|
-
if (!event.scroll)
|
|
3831
|
-
return;
|
|
3832
|
-
const { direction, delta } = event.scroll;
|
|
3833
|
-
if (direction === "up") {
|
|
3834
|
-
this.scrollY -= delta;
|
|
3835
|
-
} else if (direction === "down") {
|
|
3836
|
-
this.scrollY += delta;
|
|
3837
|
-
}
|
|
3838
|
-
if (this._wrapMode === "none") {
|
|
3839
|
-
if (direction === "left") {
|
|
3840
|
-
this.scrollX -= delta;
|
|
3841
|
-
} else if (direction === "right") {
|
|
3842
|
-
this.scrollX += delta;
|
|
3843
|
-
}
|
|
3844
|
-
}
|
|
3845
|
-
}
|
|
3846
|
-
get lineInfo() {
|
|
3847
|
-
return this.textBufferView.logicalLineInfo;
|
|
3848
|
-
}
|
|
3849
|
-
get lineCount() {
|
|
3850
|
-
return this.textBuffer.getLineCount();
|
|
3851
|
-
}
|
|
3852
|
-
get virtualLineCount() {
|
|
3853
|
-
return this.textBufferView.getVirtualLineCount();
|
|
3854
|
-
}
|
|
3855
|
-
get scrollY() {
|
|
3856
|
-
return this._scrollY;
|
|
3857
|
-
}
|
|
3858
|
-
set scrollY(value) {
|
|
3859
|
-
const maxScrollY = Math.max(0, this.scrollHeight - this.height);
|
|
3860
|
-
const clamped = Math.max(0, Math.min(value, maxScrollY));
|
|
3861
|
-
if (this._scrollY !== clamped) {
|
|
3862
|
-
this._scrollY = clamped;
|
|
3863
|
-
this.updateViewportOffset();
|
|
3864
|
-
this.requestRender();
|
|
3865
|
-
}
|
|
3866
|
-
}
|
|
3867
|
-
get scrollX() {
|
|
3868
|
-
return this._scrollX;
|
|
3869
|
-
}
|
|
3870
|
-
set scrollX(value) {
|
|
3871
|
-
const maxScrollX = Math.max(0, this.scrollWidth - this.width);
|
|
3872
|
-
const clamped = Math.max(0, Math.min(value, maxScrollX));
|
|
3873
|
-
if (this._scrollX !== clamped) {
|
|
3874
|
-
this._scrollX = clamped;
|
|
3875
|
-
this.updateViewportOffset();
|
|
3876
|
-
this.requestRender();
|
|
3877
|
-
}
|
|
3878
|
-
}
|
|
3879
|
-
get scrollWidth() {
|
|
3880
|
-
return this.lineInfo.lineWidthColsMax;
|
|
3881
|
-
}
|
|
3882
|
-
get scrollHeight() {
|
|
3883
|
-
return this.lineInfo.lineStartCols.length;
|
|
3884
|
-
}
|
|
3885
|
-
get maxScrollY() {
|
|
3886
|
-
return Math.max(0, this.scrollHeight - this.height);
|
|
3887
|
-
}
|
|
3888
|
-
get maxScrollX() {
|
|
3889
|
-
return Math.max(0, this.scrollWidth - this.width);
|
|
3890
|
-
}
|
|
3891
|
-
updateViewportOffset() {
|
|
3892
|
-
if (this.width > 0 && this.height > 0) {
|
|
3893
|
-
this.textBufferView.setViewport(this._scrollX, this._scrollY, this.width, this.height);
|
|
3894
|
-
}
|
|
3895
|
-
}
|
|
3896
|
-
get plainText() {
|
|
3897
|
-
return this.textBuffer.getPlainText();
|
|
3898
|
-
}
|
|
3899
|
-
get textLength() {
|
|
3900
|
-
return this.textBuffer.length;
|
|
3901
|
-
}
|
|
3902
|
-
get fg() {
|
|
3903
|
-
return this._defaultFg;
|
|
3904
|
-
}
|
|
3905
|
-
set fg(value) {
|
|
3906
|
-
const newColor = parseColor(value ?? this._defaultOptions.fg);
|
|
3907
|
-
if (this._defaultFg !== newColor) {
|
|
3908
|
-
this._defaultFg = newColor;
|
|
3909
|
-
this.textBuffer.setDefaultFg(this._defaultFg);
|
|
3910
|
-
this.onFgChanged(newColor);
|
|
3911
|
-
this.requestRender();
|
|
3912
|
-
}
|
|
3913
|
-
}
|
|
3914
|
-
get selectionBg() {
|
|
3915
|
-
return this._selectionBg;
|
|
3916
|
-
}
|
|
3917
|
-
set selectionBg(value) {
|
|
3918
|
-
const newColor = value ? parseColor(value) : this._defaultOptions.selectionBg;
|
|
3919
|
-
if (this._selectionBg !== newColor) {
|
|
3920
|
-
this._selectionBg = newColor;
|
|
3921
|
-
if (this.lastLocalSelection) {
|
|
3922
|
-
this.updateLocalSelection(this.lastLocalSelection);
|
|
3923
|
-
}
|
|
3924
|
-
this.requestRender();
|
|
3925
|
-
}
|
|
3926
|
-
}
|
|
3927
|
-
get selectionFg() {
|
|
3928
|
-
return this._selectionFg;
|
|
3929
|
-
}
|
|
3930
|
-
set selectionFg(value) {
|
|
3931
|
-
const newColor = value ? parseColor(value) : this._defaultOptions.selectionFg;
|
|
3932
|
-
if (this._selectionFg !== newColor) {
|
|
3933
|
-
this._selectionFg = newColor;
|
|
3934
|
-
if (this.lastLocalSelection) {
|
|
3935
|
-
this.updateLocalSelection(this.lastLocalSelection);
|
|
3936
|
-
}
|
|
3937
|
-
this.requestRender();
|
|
3938
|
-
}
|
|
3939
|
-
}
|
|
3940
|
-
get bg() {
|
|
3941
|
-
return this._defaultBg;
|
|
3942
|
-
}
|
|
3943
|
-
set bg(value) {
|
|
3944
|
-
const newColor = parseColor(value ?? this._defaultOptions.bg);
|
|
3945
|
-
if (this._defaultBg !== newColor) {
|
|
3946
|
-
this._defaultBg = newColor;
|
|
3947
|
-
this.textBuffer.setDefaultBg(this._defaultBg);
|
|
3948
|
-
this.onBgChanged(newColor);
|
|
3949
|
-
this.requestRender();
|
|
3950
|
-
}
|
|
3951
|
-
}
|
|
3952
|
-
get attributes() {
|
|
3953
|
-
return this._defaultAttributes;
|
|
3954
|
-
}
|
|
3955
|
-
set attributes(value) {
|
|
3956
|
-
if (this._defaultAttributes !== value) {
|
|
3957
|
-
this._defaultAttributes = value;
|
|
3958
|
-
this.textBuffer.setDefaultAttributes(this._defaultAttributes);
|
|
3959
|
-
this.onAttributesChanged(value);
|
|
3960
|
-
this.requestRender();
|
|
3961
|
-
}
|
|
3962
|
-
}
|
|
3963
|
-
get wrapMode() {
|
|
3964
|
-
return this._wrapMode;
|
|
3965
|
-
}
|
|
3966
|
-
set wrapMode(value) {
|
|
3967
|
-
if (this._wrapMode !== value) {
|
|
3968
|
-
this._wrapMode = value;
|
|
3969
|
-
this.textBufferView.setWrapMode(this._wrapMode);
|
|
3970
|
-
if (value !== "none" && this.width > 0) {
|
|
3971
|
-
this.textBufferView.setWrapWidth(this.width);
|
|
3972
|
-
}
|
|
3973
|
-
this.yogaNode.markDirty();
|
|
3974
|
-
this.requestRender();
|
|
3975
|
-
}
|
|
3976
|
-
}
|
|
3977
|
-
get tabIndicator() {
|
|
3978
|
-
return this._tabIndicator;
|
|
3979
|
-
}
|
|
3980
|
-
set tabIndicator(value) {
|
|
3981
|
-
if (this._tabIndicator !== value) {
|
|
3982
|
-
this._tabIndicator = value;
|
|
3983
|
-
if (value !== undefined) {
|
|
3984
|
-
this.textBufferView.setTabIndicator(value);
|
|
3985
|
-
}
|
|
3986
|
-
this.requestRender();
|
|
3987
|
-
}
|
|
3988
|
-
}
|
|
3989
|
-
get tabIndicatorColor() {
|
|
3990
|
-
return this._tabIndicatorColor;
|
|
3991
|
-
}
|
|
3992
|
-
set tabIndicatorColor(value) {
|
|
3993
|
-
const newColor = value ? parseColor(value) : undefined;
|
|
3994
|
-
if (this._tabIndicatorColor !== newColor) {
|
|
3995
|
-
this._tabIndicatorColor = newColor;
|
|
3996
|
-
if (newColor !== undefined) {
|
|
3997
|
-
this.textBufferView.setTabIndicatorColor(newColor);
|
|
3998
|
-
}
|
|
3999
|
-
this.requestRender();
|
|
4000
|
-
}
|
|
4001
|
-
}
|
|
4002
|
-
get truncate() {
|
|
4003
|
-
return this._truncate;
|
|
4004
|
-
}
|
|
4005
|
-
set truncate(value) {
|
|
4006
|
-
if (this._truncate !== value) {
|
|
4007
|
-
this._truncate = value;
|
|
4008
|
-
this.textBufferView.setTruncate(value);
|
|
4009
|
-
this.requestRender();
|
|
4010
|
-
}
|
|
4011
|
-
}
|
|
4012
|
-
onResize(width, height) {
|
|
4013
|
-
this.textBufferView.setViewport(this._scrollX, this._scrollY, width, height);
|
|
4014
|
-
this.yogaNode.markDirty();
|
|
4015
|
-
this.requestRender();
|
|
4016
|
-
this.emit("line-info-change");
|
|
4017
|
-
}
|
|
4018
|
-
refreshLocalSelection() {
|
|
4019
|
-
if (this.lastLocalSelection) {
|
|
4020
|
-
return this.updateLocalSelection(this.lastLocalSelection);
|
|
4021
|
-
}
|
|
4022
|
-
return false;
|
|
4023
|
-
}
|
|
4024
|
-
updateLocalSelection(localSelection) {
|
|
4025
|
-
if (!localSelection?.isActive) {
|
|
4026
|
-
this.textBufferView.resetLocalSelection();
|
|
4027
|
-
return true;
|
|
4028
|
-
}
|
|
4029
|
-
return this.textBufferView.setLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg);
|
|
4030
|
-
}
|
|
4031
|
-
updateTextInfo() {
|
|
4032
|
-
if (this.lastLocalSelection) {
|
|
4033
|
-
this.updateLocalSelection(this.lastLocalSelection);
|
|
4034
|
-
}
|
|
4035
|
-
this.yogaNode.markDirty();
|
|
4036
|
-
this.requestRender();
|
|
4037
|
-
this.emit("line-info-change");
|
|
4038
|
-
}
|
|
4039
|
-
setupMeasureFunc() {
|
|
4040
|
-
const measureFunc = (width, widthMode, height, heightMode) => {
|
|
4041
|
-
let effectiveWidth;
|
|
4042
|
-
if (widthMode === MeasureMode.Undefined || isNaN(width)) {
|
|
4043
|
-
effectiveWidth = 0;
|
|
4044
|
-
} else {
|
|
4045
|
-
effectiveWidth = width;
|
|
4046
|
-
}
|
|
4047
|
-
const effectiveHeight = isNaN(height) ? 1 : height;
|
|
4048
|
-
const measureResult = this.textBufferView.measureForDimensions(Math.floor(effectiveWidth), Math.floor(effectiveHeight));
|
|
4049
|
-
const measuredWidth = measureResult ? Math.max(1, measureResult.widthColsMax) : 1;
|
|
4050
|
-
const measuredHeight = measureResult ? Math.max(1, measureResult.lineCount) : 1;
|
|
4051
|
-
if (widthMode === MeasureMode.AtMost && this._positionType !== "absolute") {
|
|
4052
|
-
return {
|
|
4053
|
-
width: Math.min(effectiveWidth, measuredWidth),
|
|
4054
|
-
height: Math.min(effectiveHeight, measuredHeight)
|
|
4055
|
-
};
|
|
4056
|
-
}
|
|
4057
|
-
return {
|
|
4058
|
-
width: measuredWidth,
|
|
4059
|
-
height: measuredHeight
|
|
4060
|
-
};
|
|
4061
|
-
};
|
|
4062
|
-
this.yogaNode.setMeasureFunc(measureFunc);
|
|
4063
|
-
}
|
|
4064
|
-
shouldStartSelection(x, y) {
|
|
4065
|
-
if (!this.selectable)
|
|
4066
|
-
return false;
|
|
4067
|
-
const localX = x - this.x;
|
|
4068
|
-
const localY = y - this.y;
|
|
4069
|
-
return localX >= 0 && localX < this.width && localY >= 0 && localY < this.height;
|
|
4070
|
-
}
|
|
4071
|
-
onSelectionChanged(selection) {
|
|
4072
|
-
const localSelection = convertGlobalToLocalSelection(selection, this.x, this.y);
|
|
4073
|
-
this.lastLocalSelection = localSelection;
|
|
4074
|
-
let changed;
|
|
4075
|
-
if (!localSelection?.isActive) {
|
|
4076
|
-
this.textBufferView.resetLocalSelection();
|
|
4077
|
-
changed = true;
|
|
4078
|
-
} else if (selection?.isStart) {
|
|
4079
|
-
changed = this.textBufferView.setLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg);
|
|
4080
|
-
} else {
|
|
4081
|
-
changed = this.textBufferView.updateLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg);
|
|
4082
|
-
}
|
|
4083
|
-
if (changed) {
|
|
4084
|
-
this.requestRender();
|
|
4085
|
-
}
|
|
4086
|
-
return this.hasSelection();
|
|
4087
|
-
}
|
|
4088
|
-
getSelectedText() {
|
|
4089
|
-
return this.textBufferView.getSelectedText();
|
|
4090
|
-
}
|
|
4091
|
-
hasSelection() {
|
|
4092
|
-
return this.textBufferView.hasSelection();
|
|
4093
|
-
}
|
|
4094
|
-
getSelection() {
|
|
4095
|
-
return this.textBufferView.getSelection();
|
|
4096
|
-
}
|
|
4097
|
-
render(buffer, deltaTime) {
|
|
4098
|
-
if (!this.visible)
|
|
4099
|
-
return;
|
|
4100
|
-
const screenX = this._screenX;
|
|
4101
|
-
const screenY = this._screenY;
|
|
4102
|
-
this.markClean();
|
|
4103
|
-
this._ctx.addToHitGrid(screenX, screenY, this.width, this.height, this.num);
|
|
4104
|
-
this.renderSelf(buffer);
|
|
4105
|
-
if (this.buffered && this.frameBuffer) {
|
|
4106
|
-
buffer.drawFrameBuffer(screenX, screenY, this.frameBuffer);
|
|
4107
|
-
}
|
|
4108
|
-
}
|
|
4109
|
-
renderSelf(buffer) {
|
|
4110
|
-
if (this.textBuffer.ptr) {
|
|
4111
|
-
buffer.drawTextBuffer(this.textBufferView, this._screenX, this._screenY);
|
|
4112
|
-
}
|
|
4113
|
-
}
|
|
4114
|
-
destroy() {
|
|
4115
|
-
if (this.isDestroyed)
|
|
4116
|
-
return;
|
|
4117
|
-
this.textBuffer.setSyntaxStyle(null);
|
|
4118
|
-
this._textBufferSyntaxStyle.destroy();
|
|
4119
|
-
this.textBufferView.destroy();
|
|
4120
|
-
this.textBuffer.destroy();
|
|
4121
|
-
super.destroy();
|
|
4122
|
-
}
|
|
4123
|
-
onFgChanged(newColor) {}
|
|
4124
|
-
onBgChanged(newColor) {}
|
|
4125
|
-
onAttributesChanged(newAttributes) {}
|
|
4126
|
-
}
|
|
4127
|
-
|
|
4128
|
-
// src/renderables/Code.ts
|
|
4129
|
-
class CodeRenderable extends TextBufferRenderable {
|
|
4130
|
-
_content;
|
|
4131
|
-
_filetype;
|
|
4132
|
-
_syntaxStyle;
|
|
4133
|
-
_isHighlighting = false;
|
|
4134
|
-
_treeSitterClient;
|
|
4135
|
-
_highlightsDirty = false;
|
|
4136
|
-
_highlightSnapshotId = 0;
|
|
4137
|
-
_conceal;
|
|
4138
|
-
_drawUnstyledText;
|
|
4139
|
-
_shouldRenderTextBuffer = true;
|
|
4140
|
-
_streaming;
|
|
4141
|
-
_hadInitialContent = false;
|
|
4142
|
-
_lastHighlights = [];
|
|
4143
|
-
_onHighlight;
|
|
4144
|
-
_onChunks;
|
|
4145
|
-
_highlightingPromise = Promise.resolve();
|
|
4146
|
-
_contentDefaultOptions = {
|
|
4147
|
-
content: "",
|
|
4148
|
-
conceal: true,
|
|
4149
|
-
drawUnstyledText: true,
|
|
4150
|
-
streaming: false
|
|
4151
|
-
};
|
|
4152
|
-
constructor(ctx, options) {
|
|
4153
|
-
super(ctx, options);
|
|
4154
|
-
this._content = options.content ?? this._contentDefaultOptions.content;
|
|
4155
|
-
this._filetype = options.filetype;
|
|
4156
|
-
this._syntaxStyle = options.syntaxStyle;
|
|
4157
|
-
this._treeSitterClient = options.treeSitterClient ?? getTreeSitterClient();
|
|
4158
|
-
this._conceal = options.conceal ?? this._contentDefaultOptions.conceal;
|
|
4159
|
-
this._drawUnstyledText = options.drawUnstyledText ?? this._contentDefaultOptions.drawUnstyledText;
|
|
4160
|
-
this._streaming = options.streaming ?? this._contentDefaultOptions.streaming;
|
|
4161
|
-
this._onHighlight = options.onHighlight;
|
|
4162
|
-
this._onChunks = options.onChunks;
|
|
4163
|
-
if (this._content.length > 0) {
|
|
4164
|
-
this.textBuffer.setText(this._content);
|
|
4165
|
-
this.updateTextInfo();
|
|
4166
|
-
this._shouldRenderTextBuffer = this._drawUnstyledText || !this._filetype;
|
|
4167
|
-
}
|
|
4168
|
-
this._highlightsDirty = this._content.length > 0;
|
|
4169
|
-
}
|
|
4170
|
-
get content() {
|
|
4171
|
-
return this._content;
|
|
4172
|
-
}
|
|
4173
|
-
set content(value) {
|
|
4174
|
-
if (this._content !== value) {
|
|
4175
|
-
this._content = value;
|
|
4176
|
-
this._highlightsDirty = true;
|
|
4177
|
-
this._highlightSnapshotId++;
|
|
4178
|
-
if (this._streaming && !this._drawUnstyledText && this._filetype) {
|
|
4179
|
-
return;
|
|
4180
|
-
}
|
|
4181
|
-
this.textBuffer.setText(value);
|
|
4182
|
-
this.updateTextInfo();
|
|
4183
|
-
}
|
|
4184
|
-
}
|
|
4185
|
-
get filetype() {
|
|
4186
|
-
return this._filetype;
|
|
4187
|
-
}
|
|
4188
|
-
set filetype(value) {
|
|
4189
|
-
if (this._filetype !== value) {
|
|
4190
|
-
this._filetype = value;
|
|
4191
|
-
this._highlightsDirty = true;
|
|
4192
|
-
}
|
|
4193
|
-
}
|
|
4194
|
-
get syntaxStyle() {
|
|
4195
|
-
return this._syntaxStyle;
|
|
4196
|
-
}
|
|
4197
|
-
set syntaxStyle(value) {
|
|
4198
|
-
if (this._syntaxStyle !== value) {
|
|
4199
|
-
this._syntaxStyle = value;
|
|
4200
|
-
this._highlightsDirty = true;
|
|
4201
|
-
}
|
|
4202
|
-
}
|
|
4203
|
-
get conceal() {
|
|
4204
|
-
return this._conceal;
|
|
4205
|
-
}
|
|
4206
|
-
set conceal(value) {
|
|
4207
|
-
if (this._conceal !== value) {
|
|
4208
|
-
this._conceal = value;
|
|
4209
|
-
this._highlightsDirty = true;
|
|
4210
|
-
}
|
|
4211
|
-
}
|
|
4212
|
-
get drawUnstyledText() {
|
|
4213
|
-
return this._drawUnstyledText;
|
|
4214
|
-
}
|
|
4215
|
-
set drawUnstyledText(value) {
|
|
4216
|
-
if (this._drawUnstyledText !== value) {
|
|
4217
|
-
this._drawUnstyledText = value;
|
|
4218
|
-
this._highlightsDirty = true;
|
|
4219
|
-
}
|
|
4220
|
-
}
|
|
4221
|
-
get streaming() {
|
|
4222
|
-
return this._streaming;
|
|
4223
|
-
}
|
|
4224
|
-
set streaming(value) {
|
|
4225
|
-
if (this._streaming !== value) {
|
|
4226
|
-
this._streaming = value;
|
|
4227
|
-
this._hadInitialContent = false;
|
|
4228
|
-
this._lastHighlights = [];
|
|
4229
|
-
this._highlightsDirty = true;
|
|
4230
|
-
}
|
|
4231
|
-
}
|
|
4232
|
-
get treeSitterClient() {
|
|
4233
|
-
return this._treeSitterClient;
|
|
4234
|
-
}
|
|
4235
|
-
set treeSitterClient(value) {
|
|
4236
|
-
if (this._treeSitterClient !== value) {
|
|
4237
|
-
this._treeSitterClient = value;
|
|
4238
|
-
this._highlightsDirty = true;
|
|
4239
|
-
}
|
|
4240
|
-
}
|
|
4241
|
-
get onHighlight() {
|
|
4242
|
-
return this._onHighlight;
|
|
4243
|
-
}
|
|
4244
|
-
set onHighlight(value) {
|
|
4245
|
-
if (this._onHighlight !== value) {
|
|
4246
|
-
this._onHighlight = value;
|
|
4247
|
-
this._highlightsDirty = true;
|
|
4248
|
-
}
|
|
4249
|
-
}
|
|
4250
|
-
get onChunks() {
|
|
4251
|
-
return this._onChunks;
|
|
4252
|
-
}
|
|
4253
|
-
set onChunks(value) {
|
|
4254
|
-
if (this._onChunks !== value) {
|
|
4255
|
-
this._onChunks = value;
|
|
4256
|
-
this._highlightsDirty = true;
|
|
4257
|
-
}
|
|
4258
|
-
}
|
|
4259
|
-
get isHighlighting() {
|
|
4260
|
-
return this._isHighlighting;
|
|
4261
|
-
}
|
|
4262
|
-
get highlightingDone() {
|
|
4263
|
-
return this._highlightingPromise;
|
|
4264
|
-
}
|
|
4265
|
-
async transformChunks(chunks, context) {
|
|
4266
|
-
if (!this._onChunks)
|
|
4267
|
-
return chunks;
|
|
4268
|
-
const modified = await this._onChunks(chunks, context);
|
|
4269
|
-
return modified ?? chunks;
|
|
4270
|
-
}
|
|
4271
|
-
ensureVisibleTextBeforeHighlight() {
|
|
4272
|
-
if (this.isDestroyed)
|
|
4273
|
-
return;
|
|
4274
|
-
const content = this._content;
|
|
4275
|
-
if (!this._filetype) {
|
|
4276
|
-
this._shouldRenderTextBuffer = true;
|
|
4277
|
-
return;
|
|
4278
|
-
}
|
|
4279
|
-
const isInitialContent = this._streaming && !this._hadInitialContent;
|
|
4280
|
-
const shouldDrawUnstyledNow = this._streaming ? isInitialContent && this._drawUnstyledText : this._drawUnstyledText;
|
|
4281
|
-
if (this._streaming && !isInitialContent) {
|
|
4282
|
-
this._shouldRenderTextBuffer = true;
|
|
4283
|
-
} else if (shouldDrawUnstyledNow) {
|
|
4284
|
-
this.textBuffer.setText(content);
|
|
4285
|
-
this._shouldRenderTextBuffer = true;
|
|
4286
|
-
} else {
|
|
4287
|
-
this._shouldRenderTextBuffer = false;
|
|
4288
|
-
}
|
|
4289
|
-
}
|
|
4290
|
-
async startHighlight() {
|
|
4291
|
-
const content = this._content;
|
|
4292
|
-
const filetype = this._filetype;
|
|
4293
|
-
const snapshotId = ++this._highlightSnapshotId;
|
|
4294
|
-
if (!filetype)
|
|
4295
|
-
return;
|
|
4296
|
-
const isInitialContent = this._streaming && !this._hadInitialContent;
|
|
4297
|
-
if (isInitialContent) {
|
|
4298
|
-
this._hadInitialContent = true;
|
|
4299
|
-
}
|
|
4300
|
-
this._isHighlighting = true;
|
|
4301
|
-
try {
|
|
4302
|
-
const result = await this._treeSitterClient.highlightOnce(content, filetype);
|
|
4303
|
-
if (snapshotId !== this._highlightSnapshotId) {
|
|
4304
|
-
return;
|
|
4305
|
-
}
|
|
4306
|
-
if (this.isDestroyed)
|
|
4307
|
-
return;
|
|
4308
|
-
let highlights = result.highlights ?? [];
|
|
4309
|
-
if (this._onHighlight && highlights.length >= 0) {
|
|
4310
|
-
const context = {
|
|
4311
|
-
content,
|
|
4312
|
-
filetype,
|
|
4313
|
-
syntaxStyle: this._syntaxStyle
|
|
4314
|
-
};
|
|
4315
|
-
const modified = await this._onHighlight(highlights, context);
|
|
4316
|
-
if (modified !== undefined) {
|
|
4317
|
-
highlights = modified;
|
|
4318
|
-
}
|
|
4319
|
-
}
|
|
4320
|
-
if (snapshotId !== this._highlightSnapshotId) {
|
|
4321
|
-
return;
|
|
4322
|
-
}
|
|
4323
|
-
if (this.isDestroyed)
|
|
4324
|
-
return;
|
|
4325
|
-
if (highlights.length > 0) {
|
|
4326
|
-
if (this._streaming) {
|
|
4327
|
-
this._lastHighlights = highlights;
|
|
4328
|
-
}
|
|
4329
|
-
}
|
|
4330
|
-
if (highlights.length > 0 || this._onChunks) {
|
|
4331
|
-
const context = {
|
|
4332
|
-
content,
|
|
4333
|
-
filetype,
|
|
4334
|
-
syntaxStyle: this._syntaxStyle,
|
|
4335
|
-
highlights
|
|
4336
|
-
};
|
|
4337
|
-
let chunks = treeSitterToTextChunks(content, highlights, this._syntaxStyle, {
|
|
4338
|
-
enabled: this._conceal
|
|
4339
|
-
});
|
|
4340
|
-
chunks = await this.transformChunks(chunks, context);
|
|
4341
|
-
if (snapshotId !== this._highlightSnapshotId) {
|
|
4342
|
-
return;
|
|
4343
|
-
}
|
|
4344
|
-
if (this.isDestroyed)
|
|
4345
|
-
return;
|
|
4346
|
-
const styledText = new StyledText(chunks);
|
|
4347
|
-
this.textBuffer.setStyledText(styledText);
|
|
4348
|
-
} else {
|
|
4349
|
-
this.textBuffer.setText(content);
|
|
4350
|
-
}
|
|
4351
|
-
this._shouldRenderTextBuffer = true;
|
|
4352
|
-
this._isHighlighting = false;
|
|
4353
|
-
this._highlightsDirty = false;
|
|
4354
|
-
this.updateTextInfo();
|
|
4355
|
-
this.requestRender();
|
|
4356
|
-
} catch (error) {
|
|
4357
|
-
if (snapshotId !== this._highlightSnapshotId) {
|
|
4358
|
-
return;
|
|
4359
|
-
}
|
|
4360
|
-
console.warn("Code highlighting failed, falling back to plain text:", error);
|
|
4361
|
-
if (this.isDestroyed)
|
|
4362
|
-
return;
|
|
4363
|
-
this.textBuffer.setText(content);
|
|
4364
|
-
this._shouldRenderTextBuffer = true;
|
|
4365
|
-
this._isHighlighting = false;
|
|
4366
|
-
this._highlightsDirty = false;
|
|
4367
|
-
this.updateTextInfo();
|
|
4368
|
-
this.requestRender();
|
|
4369
|
-
}
|
|
4370
|
-
}
|
|
4371
|
-
getLineHighlights(lineIdx) {
|
|
4372
|
-
return this.textBuffer.getLineHighlights(lineIdx);
|
|
4373
|
-
}
|
|
4374
|
-
renderSelf(buffer) {
|
|
4375
|
-
if (this._highlightsDirty) {
|
|
4376
|
-
if (this.isDestroyed)
|
|
4377
|
-
return;
|
|
4378
|
-
if (this._content.length === 0) {
|
|
4379
|
-
this._shouldRenderTextBuffer = false;
|
|
4380
|
-
this._highlightsDirty = false;
|
|
4381
|
-
} else if (!this._filetype) {
|
|
4382
|
-
this._shouldRenderTextBuffer = true;
|
|
4383
|
-
this._highlightsDirty = false;
|
|
4384
|
-
} else {
|
|
4385
|
-
this.ensureVisibleTextBeforeHighlight();
|
|
4386
|
-
this._highlightsDirty = false;
|
|
4387
|
-
this._highlightingPromise = this.startHighlight();
|
|
4388
|
-
}
|
|
4389
|
-
}
|
|
4390
|
-
if (!this._shouldRenderTextBuffer)
|
|
4391
|
-
return;
|
|
4392
|
-
super.renderSelf(buffer);
|
|
4393
|
-
}
|
|
4394
|
-
}
|
|
4395
|
-
// src/renderables/TextNode.ts
|
|
4396
|
-
var BrandedTextNodeRenderable = Symbol.for("@opentui/core/TextNodeRenderable");
|
|
4397
|
-
function isTextNodeRenderable(obj) {
|
|
4398
|
-
return !!obj?.[BrandedTextNodeRenderable];
|
|
4399
|
-
}
|
|
4400
|
-
function styledTextToTextNodes(styledText) {
|
|
4401
|
-
return styledText.chunks.map((chunk) => {
|
|
4402
|
-
const node = new TextNodeRenderable({
|
|
4403
|
-
fg: chunk.fg,
|
|
4404
|
-
bg: chunk.bg,
|
|
4405
|
-
attributes: chunk.attributes,
|
|
4406
|
-
link: chunk.link
|
|
4407
|
-
});
|
|
4408
|
-
node.add(chunk.text);
|
|
4409
|
-
return node;
|
|
4410
|
-
});
|
|
4411
|
-
}
|
|
4412
|
-
|
|
4413
|
-
class TextNodeRenderable extends BaseRenderable {
|
|
4414
|
-
[BrandedTextNodeRenderable] = true;
|
|
4415
|
-
_fg;
|
|
4416
|
-
_bg;
|
|
4417
|
-
_attributes;
|
|
4418
|
-
_link;
|
|
4419
|
-
_children = [];
|
|
4420
|
-
parent = null;
|
|
4421
|
-
constructor(options) {
|
|
4422
|
-
super(options);
|
|
4423
|
-
this._fg = options.fg ? parseColor(options.fg) : undefined;
|
|
4424
|
-
this._bg = options.bg ? parseColor(options.bg) : undefined;
|
|
4425
|
-
this._attributes = options.attributes ?? 0;
|
|
4426
|
-
this._link = options.link;
|
|
4427
|
-
}
|
|
4428
|
-
get children() {
|
|
4429
|
-
return this._children;
|
|
4430
|
-
}
|
|
4431
|
-
set children(children) {
|
|
4432
|
-
this._children = children;
|
|
4433
|
-
this.requestRender();
|
|
4434
|
-
}
|
|
4435
|
-
requestRender() {
|
|
4436
|
-
this.markDirty();
|
|
4437
|
-
this.parent?.requestRender();
|
|
4438
|
-
}
|
|
4439
|
-
add(obj, index) {
|
|
4440
|
-
if (typeof obj === "string") {
|
|
4441
|
-
if (index !== undefined) {
|
|
4442
|
-
this._children.splice(index, 0, obj);
|
|
4443
|
-
this.requestRender();
|
|
4444
|
-
return index;
|
|
4445
|
-
}
|
|
4446
|
-
const insertIndex = this._children.length;
|
|
4447
|
-
this._children.push(obj);
|
|
4448
|
-
this.requestRender();
|
|
4449
|
-
return insertIndex;
|
|
4450
|
-
}
|
|
4451
|
-
if (isTextNodeRenderable(obj)) {
|
|
4452
|
-
if (index !== undefined) {
|
|
4453
|
-
this._children.splice(index, 0, obj);
|
|
4454
|
-
obj.parent = this;
|
|
4455
|
-
this.requestRender();
|
|
4456
|
-
return index;
|
|
4457
|
-
}
|
|
4458
|
-
const insertIndex = this._children.length;
|
|
4459
|
-
this._children.push(obj);
|
|
4460
|
-
obj.parent = this;
|
|
4461
|
-
this.requestRender();
|
|
4462
|
-
return insertIndex;
|
|
4463
|
-
}
|
|
4464
|
-
if (isStyledText(obj)) {
|
|
4465
|
-
const textNodes = styledTextToTextNodes(obj);
|
|
4466
|
-
if (index !== undefined) {
|
|
4467
|
-
this._children.splice(index, 0, ...textNodes);
|
|
4468
|
-
textNodes.forEach((node) => node.parent = this);
|
|
4469
|
-
this.requestRender();
|
|
4470
|
-
return index;
|
|
4471
|
-
}
|
|
4472
|
-
const insertIndex = this._children.length;
|
|
4473
|
-
this._children.push(...textNodes);
|
|
4474
|
-
textNodes.forEach((node) => node.parent = this);
|
|
4475
|
-
this.requestRender();
|
|
4476
|
-
return insertIndex;
|
|
4477
|
-
}
|
|
4478
|
-
throw new Error("TextNodeRenderable only accepts strings, TextNodeRenderable instances, or StyledText instances");
|
|
3095
|
+
this.selectable = options.selectable ?? true;
|
|
3096
|
+
this.selectionHelper = new ASCIIFontSelectionHelper(() => this._text, () => this._font);
|
|
3097
|
+
this.renderFontToBuffer();
|
|
4479
3098
|
}
|
|
4480
|
-
|
|
4481
|
-
this.
|
|
4482
|
-
if (typeof obj !== "string") {
|
|
4483
|
-
obj.parent = this;
|
|
4484
|
-
}
|
|
4485
|
-
this.requestRender();
|
|
3099
|
+
get text() {
|
|
3100
|
+
return this._text;
|
|
4486
3101
|
}
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
if (anchorIndex === -1) {
|
|
4493
|
-
throw new Error("Anchor node not found in children");
|
|
4494
|
-
}
|
|
4495
|
-
if (typeof child === "string") {
|
|
4496
|
-
this._children.splice(anchorIndex, 0, child);
|
|
4497
|
-
} else if (isTextNodeRenderable(child)) {
|
|
4498
|
-
this._children.splice(anchorIndex, 0, child);
|
|
4499
|
-
child.parent = this;
|
|
4500
|
-
} else if (child instanceof StyledText) {
|
|
4501
|
-
const textNodes = styledTextToTextNodes(child);
|
|
4502
|
-
this._children.splice(anchorIndex, 0, ...textNodes);
|
|
4503
|
-
textNodes.forEach((node) => node.parent = this);
|
|
4504
|
-
} else {
|
|
4505
|
-
throw new Error("Child must be a string, TextNodeRenderable, or StyledText instance");
|
|
3102
|
+
set text(value) {
|
|
3103
|
+
this._text = value;
|
|
3104
|
+
this.updateDimensions();
|
|
3105
|
+
if (this.lastLocalSelection) {
|
|
3106
|
+
this.selectionHelper.onLocalSelectionChanged(this.lastLocalSelection, this.width, this.height);
|
|
4506
3107
|
}
|
|
3108
|
+
this.renderFontToBuffer();
|
|
4507
3109
|
this.requestRender();
|
|
4508
|
-
return this;
|
|
4509
3110
|
}
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
if (childIndex === -1) {
|
|
4513
|
-
throw new Error("Child not found in children");
|
|
4514
|
-
}
|
|
4515
|
-
const child = this._children[childIndex];
|
|
4516
|
-
this._children.splice(childIndex, 1);
|
|
4517
|
-
child.parent = null;
|
|
4518
|
-
this.requestRender();
|
|
4519
|
-
return this;
|
|
3111
|
+
get font() {
|
|
3112
|
+
return this._font;
|
|
4520
3113
|
}
|
|
4521
|
-
|
|
4522
|
-
this.
|
|
3114
|
+
set font(value) {
|
|
3115
|
+
this._font = value;
|
|
3116
|
+
this.updateDimensions();
|
|
3117
|
+
if (this.lastLocalSelection) {
|
|
3118
|
+
this.selectionHelper.onLocalSelectionChanged(this.lastLocalSelection, this.width, this.height);
|
|
3119
|
+
}
|
|
3120
|
+
this.renderFontToBuffer();
|
|
4523
3121
|
this.requestRender();
|
|
4524
3122
|
}
|
|
4525
|
-
|
|
4526
|
-
return
|
|
4527
|
-
fg: this._fg ?? parentStyle.fg,
|
|
4528
|
-
bg: this._bg ?? parentStyle.bg,
|
|
4529
|
-
attributes: this._attributes | parentStyle.attributes,
|
|
4530
|
-
link: this._link ?? parentStyle.link
|
|
4531
|
-
};
|
|
3123
|
+
get color() {
|
|
3124
|
+
return this._color;
|
|
4532
3125
|
}
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
}) {
|
|
4538
|
-
const currentStyle = this.mergeStyles(parentStyle);
|
|
4539
|
-
const chunks = [];
|
|
4540
|
-
for (const child of this._children) {
|
|
4541
|
-
if (typeof child === "string") {
|
|
4542
|
-
chunks.push({
|
|
4543
|
-
__isChunk: true,
|
|
4544
|
-
text: child,
|
|
4545
|
-
fg: currentStyle.fg,
|
|
4546
|
-
bg: currentStyle.bg,
|
|
4547
|
-
attributes: currentStyle.attributes,
|
|
4548
|
-
link: currentStyle.link
|
|
4549
|
-
});
|
|
4550
|
-
} else {
|
|
4551
|
-
const childChunks = child.gatherWithInheritedStyle(currentStyle);
|
|
4552
|
-
chunks.push(...childChunks);
|
|
4553
|
-
}
|
|
4554
|
-
}
|
|
4555
|
-
this.markClean();
|
|
4556
|
-
return chunks;
|
|
3126
|
+
set color(value) {
|
|
3127
|
+
this._color = value;
|
|
3128
|
+
this.renderFontToBuffer();
|
|
3129
|
+
this.requestRender();
|
|
4557
3130
|
}
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
node.add(text);
|
|
4561
|
-
return node;
|
|
3131
|
+
get backgroundColor() {
|
|
3132
|
+
return this._backgroundColor;
|
|
4562
3133
|
}
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
}
|
|
4568
|
-
return node;
|
|
3134
|
+
set backgroundColor(value) {
|
|
3135
|
+
this._backgroundColor = value;
|
|
3136
|
+
this.renderFontToBuffer();
|
|
3137
|
+
this.requestRender();
|
|
4569
3138
|
}
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
}) {
|
|
4575
|
-
return this.gatherWithInheritedStyle(parentStyle);
|
|
3139
|
+
updateDimensions() {
|
|
3140
|
+
const measurements = measureText({ text: this._text, font: this._font });
|
|
3141
|
+
this.width = measurements.width;
|
|
3142
|
+
this.height = measurements.height;
|
|
4576
3143
|
}
|
|
4577
|
-
|
|
4578
|
-
|
|
3144
|
+
shouldStartSelection(x, y) {
|
|
3145
|
+
const localX = x - this.x;
|
|
3146
|
+
const localY = y - this.y;
|
|
3147
|
+
return this.selectionHelper.shouldStartSelection(localX, localY, this.width, this.height);
|
|
4579
3148
|
}
|
|
4580
|
-
|
|
4581
|
-
|
|
3149
|
+
onSelectionChanged(selection) {
|
|
3150
|
+
const localSelection = convertGlobalToLocalSelection(selection, this.x, this.y);
|
|
3151
|
+
this.lastLocalSelection = localSelection;
|
|
3152
|
+
const changed = this.selectionHelper.onLocalSelectionChanged(localSelection, this.width, this.height);
|
|
3153
|
+
if (changed) {
|
|
3154
|
+
this.renderFontToBuffer();
|
|
3155
|
+
this.requestRender();
|
|
3156
|
+
}
|
|
3157
|
+
return changed;
|
|
4582
3158
|
}
|
|
4583
|
-
|
|
4584
|
-
|
|
3159
|
+
getSelectedText() {
|
|
3160
|
+
const selection = this.selectionHelper.getSelection();
|
|
3161
|
+
if (!selection)
|
|
3162
|
+
return "";
|
|
3163
|
+
return this._text.slice(selection.start, selection.end);
|
|
4585
3164
|
}
|
|
4586
|
-
|
|
4587
|
-
return this.
|
|
3165
|
+
hasSelection() {
|
|
3166
|
+
return this.selectionHelper.hasSelection();
|
|
4588
3167
|
}
|
|
4589
|
-
|
|
4590
|
-
|
|
3168
|
+
onResize(width, height) {
|
|
3169
|
+
super.onResize(width, height);
|
|
3170
|
+
this.renderFontToBuffer();
|
|
4591
3171
|
}
|
|
4592
|
-
|
|
4593
|
-
if (
|
|
4594
|
-
this._fg = undefined;
|
|
4595
|
-
this.requestRender();
|
|
3172
|
+
renderFontToBuffer() {
|
|
3173
|
+
if (this.isDestroyed)
|
|
4596
3174
|
return;
|
|
3175
|
+
this.frameBuffer.clear(parseColor(this._backgroundColor));
|
|
3176
|
+
renderFontToFrameBuffer(this.frameBuffer, {
|
|
3177
|
+
text: this._text,
|
|
3178
|
+
x: 0,
|
|
3179
|
+
y: 0,
|
|
3180
|
+
color: this.color,
|
|
3181
|
+
backgroundColor: this._backgroundColor,
|
|
3182
|
+
font: this._font
|
|
3183
|
+
});
|
|
3184
|
+
const selection = this.selectionHelper.getSelection();
|
|
3185
|
+
if (selection && (this._selectionBg || this._selectionFg)) {
|
|
3186
|
+
this.renderSelectionHighlight(selection);
|
|
4597
3187
|
}
|
|
4598
|
-
this._fg = parseColor(fg2);
|
|
4599
|
-
this.requestRender();
|
|
4600
3188
|
}
|
|
4601
|
-
|
|
4602
|
-
if (!
|
|
4603
|
-
this._bg = undefined;
|
|
4604
|
-
this.requestRender();
|
|
3189
|
+
renderSelectionHighlight(selection) {
|
|
3190
|
+
if (!this._selectionBg && !this._selectionFg)
|
|
4605
3191
|
return;
|
|
3192
|
+
const selectedText = this._text.slice(selection.start, selection.end);
|
|
3193
|
+
if (!selectedText)
|
|
3194
|
+
return;
|
|
3195
|
+
const positions = getCharacterPositions(this._text, this._font);
|
|
3196
|
+
const startX = positions[selection.start] || 0;
|
|
3197
|
+
const endX = selection.end < positions.length ? positions[selection.end] : measureText({ text: this._text, font: this._font }).width;
|
|
3198
|
+
if (this._selectionBg) {
|
|
3199
|
+
this.frameBuffer.fillRect(startX, 0, endX - startX, this.height, parseColor(this._selectionBg));
|
|
3200
|
+
}
|
|
3201
|
+
if (this._selectionFg || this._selectionBg) {
|
|
3202
|
+
renderFontToFrameBuffer(this.frameBuffer, {
|
|
3203
|
+
text: selectedText,
|
|
3204
|
+
x: startX,
|
|
3205
|
+
y: 0,
|
|
3206
|
+
color: this._selectionFg ? this._selectionFg : this._color,
|
|
3207
|
+
backgroundColor: this._selectionBg ? this._selectionBg : this._backgroundColor,
|
|
3208
|
+
font: this._font
|
|
3209
|
+
});
|
|
4606
3210
|
}
|
|
4607
|
-
this._bg = parseColor(bg2);
|
|
4608
|
-
this.requestRender();
|
|
4609
|
-
}
|
|
4610
|
-
get bg() {
|
|
4611
|
-
return this._bg;
|
|
4612
|
-
}
|
|
4613
|
-
set attributes(attributes) {
|
|
4614
|
-
this._attributes = attributes;
|
|
4615
|
-
this.requestRender();
|
|
4616
|
-
}
|
|
4617
|
-
get attributes() {
|
|
4618
|
-
return this._attributes;
|
|
4619
|
-
}
|
|
4620
|
-
set link(link2) {
|
|
4621
|
-
this._link = link2;
|
|
4622
|
-
this.requestRender();
|
|
4623
|
-
}
|
|
4624
|
-
get link() {
|
|
4625
|
-
return this._link;
|
|
4626
|
-
}
|
|
4627
|
-
findDescendantById(id) {
|
|
4628
|
-
return;
|
|
4629
|
-
}
|
|
4630
|
-
}
|
|
4631
|
-
|
|
4632
|
-
class RootTextNodeRenderable extends TextNodeRenderable {
|
|
4633
|
-
ctx;
|
|
4634
|
-
textParent;
|
|
4635
|
-
constructor(ctx, options, textParent) {
|
|
4636
|
-
super(options);
|
|
4637
|
-
this.ctx = ctx;
|
|
4638
|
-
this.textParent = textParent;
|
|
4639
|
-
}
|
|
4640
|
-
requestRender() {
|
|
4641
|
-
this.markDirty();
|
|
4642
|
-
this.ctx.requestRender();
|
|
4643
3211
|
}
|
|
4644
3212
|
}
|
|
4645
|
-
|
|
4646
3213
|
// src/renderables/composition/constructs.ts
|
|
4647
3214
|
function Generic(props, ...children) {
|
|
4648
3215
|
return h(VRenderable, props || {}, ...children);
|
|
@@ -5346,103 +3913,6 @@ function parsePatch(uniDiff) {
|
|
|
5346
3913
|
}
|
|
5347
3914
|
return list;
|
|
5348
3915
|
}
|
|
5349
|
-
// src/renderables/Text.ts
|
|
5350
|
-
class TextRenderable extends TextBufferRenderable {
|
|
5351
|
-
_text;
|
|
5352
|
-
_hasManualStyledText = false;
|
|
5353
|
-
rootTextNode;
|
|
5354
|
-
_contentDefaultOptions = {
|
|
5355
|
-
content: ""
|
|
5356
|
-
};
|
|
5357
|
-
constructor(ctx, options) {
|
|
5358
|
-
super(ctx, options);
|
|
5359
|
-
const content = options.content ?? this._contentDefaultOptions.content;
|
|
5360
|
-
const styledText = typeof content === "string" ? stringToStyledText(content) : content;
|
|
5361
|
-
this._text = styledText;
|
|
5362
|
-
this._hasManualStyledText = options.content !== undefined && content !== "";
|
|
5363
|
-
this.rootTextNode = new RootTextNodeRenderable(ctx, {
|
|
5364
|
-
id: `${this.id}-root`,
|
|
5365
|
-
fg: this._defaultFg,
|
|
5366
|
-
bg: this._defaultBg,
|
|
5367
|
-
attributes: this._defaultAttributes
|
|
5368
|
-
}, this);
|
|
5369
|
-
this.updateTextBuffer(styledText);
|
|
5370
|
-
}
|
|
5371
|
-
updateTextBuffer(styledText) {
|
|
5372
|
-
this.textBuffer.setStyledText(styledText);
|
|
5373
|
-
this.clearChunks(styledText);
|
|
5374
|
-
}
|
|
5375
|
-
clearChunks(styledText) {}
|
|
5376
|
-
get content() {
|
|
5377
|
-
return this._text;
|
|
5378
|
-
}
|
|
5379
|
-
get chunks() {
|
|
5380
|
-
return this._text.chunks;
|
|
5381
|
-
}
|
|
5382
|
-
get textNode() {
|
|
5383
|
-
return this.rootTextNode;
|
|
5384
|
-
}
|
|
5385
|
-
set content(value) {
|
|
5386
|
-
this._hasManualStyledText = true;
|
|
5387
|
-
const styledText = typeof value === "string" ? stringToStyledText(value) : value;
|
|
5388
|
-
if (this._text !== styledText) {
|
|
5389
|
-
this._text = styledText;
|
|
5390
|
-
this.updateTextBuffer(styledText);
|
|
5391
|
-
this.updateTextInfo();
|
|
5392
|
-
}
|
|
5393
|
-
}
|
|
5394
|
-
updateTextFromNodes() {
|
|
5395
|
-
if (this.rootTextNode.isDirty && !this._hasManualStyledText) {
|
|
5396
|
-
const chunks = this.rootTextNode.gatherWithInheritedStyle({
|
|
5397
|
-
fg: this._defaultFg,
|
|
5398
|
-
bg: this._defaultBg,
|
|
5399
|
-
attributes: this._defaultAttributes,
|
|
5400
|
-
link: undefined
|
|
5401
|
-
});
|
|
5402
|
-
this.textBuffer.setStyledText(new StyledText(chunks));
|
|
5403
|
-
this.refreshLocalSelection();
|
|
5404
|
-
this.yogaNode.markDirty();
|
|
5405
|
-
}
|
|
5406
|
-
}
|
|
5407
|
-
add(obj, index) {
|
|
5408
|
-
return this.rootTextNode.add(obj, index);
|
|
5409
|
-
}
|
|
5410
|
-
remove(id) {
|
|
5411
|
-
this.rootTextNode.remove(id);
|
|
5412
|
-
}
|
|
5413
|
-
insertBefore(obj, anchor) {
|
|
5414
|
-
this.rootTextNode.insertBefore(obj, anchor);
|
|
5415
|
-
return this.rootTextNode.children.indexOf(obj);
|
|
5416
|
-
}
|
|
5417
|
-
getTextChildren() {
|
|
5418
|
-
return this.rootTextNode.getChildren();
|
|
5419
|
-
}
|
|
5420
|
-
clear() {
|
|
5421
|
-
this.rootTextNode.clear();
|
|
5422
|
-
const emptyStyledText = stringToStyledText("");
|
|
5423
|
-
this._text = emptyStyledText;
|
|
5424
|
-
this.updateTextBuffer(emptyStyledText);
|
|
5425
|
-
this.updateTextInfo();
|
|
5426
|
-
this.requestRender();
|
|
5427
|
-
}
|
|
5428
|
-
onLifecyclePass = () => {
|
|
5429
|
-
this.updateTextFromNodes();
|
|
5430
|
-
};
|
|
5431
|
-
onFgChanged(newColor) {
|
|
5432
|
-
this.rootTextNode.fg = newColor;
|
|
5433
|
-
}
|
|
5434
|
-
onBgChanged(newColor) {
|
|
5435
|
-
this.rootTextNode.bg = newColor;
|
|
5436
|
-
}
|
|
5437
|
-
onAttributesChanged(newAttributes) {
|
|
5438
|
-
this.rootTextNode.attributes = newAttributes;
|
|
5439
|
-
}
|
|
5440
|
-
destroy() {
|
|
5441
|
-
this.rootTextNode.children.length = 0;
|
|
5442
|
-
super.destroy();
|
|
5443
|
-
}
|
|
5444
|
-
}
|
|
5445
|
-
|
|
5446
3916
|
// src/renderables/Diff.ts
|
|
5447
3917
|
class DiffRenderable extends Renderable {
|
|
5448
3918
|
_diff;
|
|
@@ -6895,6 +5365,7 @@ class TextTableRenderable extends Renderable {
|
|
|
6895
5365
|
_columnWidthMode;
|
|
6896
5366
|
_columnFitter;
|
|
6897
5367
|
_cellPadding;
|
|
5368
|
+
_columnGap;
|
|
6898
5369
|
_showBorders;
|
|
6899
5370
|
_border;
|
|
6900
5371
|
_outerBorder;
|
|
@@ -6925,6 +5396,7 @@ class TextTableRenderable extends Renderable {
|
|
|
6925
5396
|
columnWidthMode: "full",
|
|
6926
5397
|
columnFitter: "proportional",
|
|
6927
5398
|
cellPadding: 0,
|
|
5399
|
+
columnGap: 0,
|
|
6928
5400
|
showBorders: true,
|
|
6929
5401
|
border: true,
|
|
6930
5402
|
outerBorder: true,
|
|
@@ -6946,6 +5418,7 @@ class TextTableRenderable extends Renderable {
|
|
|
6946
5418
|
this._columnWidthMode = options.columnWidthMode ?? this._defaultOptions.columnWidthMode;
|
|
6947
5419
|
this._columnFitter = this.resolveColumnFitter(options.columnFitter);
|
|
6948
5420
|
this._cellPadding = this.resolveCellPadding(options.cellPadding);
|
|
5421
|
+
this._columnGap = this.resolveColumnGap(options.columnGap);
|
|
6949
5422
|
this._showBorders = options.showBorders ?? this._defaultOptions.showBorders;
|
|
6950
5423
|
this._border = options.border ?? this._defaultOptions.border;
|
|
6951
5424
|
this._hasExplicitOuterBorder = options.outerBorder !== undefined;
|
|
@@ -7013,6 +5486,16 @@ class TextTableRenderable extends Renderable {
|
|
|
7013
5486
|
this._cellPadding = next;
|
|
7014
5487
|
this.invalidateLayoutAndRaster();
|
|
7015
5488
|
}
|
|
5489
|
+
get columnGap() {
|
|
5490
|
+
return this._columnGap;
|
|
5491
|
+
}
|
|
5492
|
+
set columnGap(value) {
|
|
5493
|
+
const next = this.resolveColumnGap(value);
|
|
5494
|
+
if (this._columnGap === next)
|
|
5495
|
+
return;
|
|
5496
|
+
this._columnGap = next;
|
|
5497
|
+
this.invalidateLayoutAndRaster();
|
|
5498
|
+
}
|
|
7016
5499
|
get showBorders() {
|
|
7017
5500
|
return this._showBorders;
|
|
7018
5501
|
}
|
|
@@ -7326,7 +5809,7 @@ class TextTableRenderable extends Renderable {
|
|
|
7326
5809
|
const borderLayout = this.resolveBorderLayout();
|
|
7327
5810
|
const columnWidths = this.computeColumnWidths(maxTableWidth, borderLayout);
|
|
7328
5811
|
const rowHeights = this.computeRowHeights(columnWidths);
|
|
7329
|
-
const columnOffsets = this.computeOffsets(columnWidths, borderLayout.left, borderLayout.right, borderLayout.innerVertical);
|
|
5812
|
+
const columnOffsets = this.computeOffsets(columnWidths, borderLayout.left, borderLayout.right, borderLayout.innerVertical, this.getInterColumnGap(borderLayout));
|
|
7330
5813
|
const rowOffsets = this.computeOffsets(rowHeights, borderLayout.top, borderLayout.bottom, borderLayout.innerHorizontal);
|
|
7331
5814
|
return {
|
|
7332
5815
|
columnWidths,
|
|
@@ -7358,7 +5841,7 @@ class TextTableRenderable extends Renderable {
|
|
|
7358
5841
|
if (maxTableWidth === undefined || !Number.isFinite(maxTableWidth) || maxTableWidth <= 0) {
|
|
7359
5842
|
return intrinsicWidths;
|
|
7360
5843
|
}
|
|
7361
|
-
const maxContentWidth = Math.max(1, Math.floor(maxTableWidth) - this.getVerticalBorderCount(borderLayout));
|
|
5844
|
+
const maxContentWidth = Math.max(1, Math.floor(maxTableWidth) - this.getVerticalBorderCount(borderLayout) - this.getTotalInterColumnGap(borderLayout));
|
|
7362
5845
|
const currentWidth = intrinsicWidths.reduce((sum, width) => sum + width, 0);
|
|
7363
5846
|
if (currentWidth === maxContentWidth) {
|
|
7364
5847
|
return intrinsicWidths;
|
|
@@ -7541,17 +6024,26 @@ class TextTableRenderable extends Renderable {
|
|
|
7541
6024
|
}
|
|
7542
6025
|
return rowHeights;
|
|
7543
6026
|
}
|
|
7544
|
-
computeOffsets(parts, startBoundary, endBoundary, includeInnerBoundaries) {
|
|
6027
|
+
computeOffsets(parts, startBoundary, endBoundary, includeInnerBoundaries, innerGap = 0) {
|
|
7545
6028
|
const offsets = [startBoundary ? 0 : -1];
|
|
7546
6029
|
let cursor = offsets[0] ?? 0;
|
|
7547
6030
|
for (let idx = 0;idx < parts.length; idx++) {
|
|
7548
6031
|
const size = parts[idx] ?? 1;
|
|
7549
|
-
const
|
|
7550
|
-
cursor += size +
|
|
6032
|
+
const separatorAfter = idx < parts.length - 1 ? includeInnerBoundaries ? 1 : innerGap : endBoundary ? 1 : 0;
|
|
6033
|
+
cursor += size + separatorAfter;
|
|
7551
6034
|
offsets.push(cursor);
|
|
7552
6035
|
}
|
|
7553
6036
|
return offsets;
|
|
7554
6037
|
}
|
|
6038
|
+
getInterColumnGap(borderLayout) {
|
|
6039
|
+
if (borderLayout.innerVertical) {
|
|
6040
|
+
return 0;
|
|
6041
|
+
}
|
|
6042
|
+
return this._columnGap;
|
|
6043
|
+
}
|
|
6044
|
+
getTotalInterColumnGap(borderLayout) {
|
|
6045
|
+
return Math.max(0, this._columnCount - 1) * this.getInterColumnGap(borderLayout);
|
|
6046
|
+
}
|
|
7555
6047
|
applyLayoutToViews(layout) {
|
|
7556
6048
|
const horizontalPadding = this.getHorizontalCellPadding();
|
|
7557
6049
|
const verticalPadding = this.getVerticalCellPadding();
|
|
@@ -7870,6 +6362,12 @@ class TextTableRenderable extends Renderable {
|
|
|
7870
6362
|
}
|
|
7871
6363
|
return Math.max(0, Math.floor(value));
|
|
7872
6364
|
}
|
|
6365
|
+
resolveColumnGap(value) {
|
|
6366
|
+
if (value === undefined || !Number.isFinite(value)) {
|
|
6367
|
+
return this._defaultOptions.columnGap;
|
|
6368
|
+
}
|
|
6369
|
+
return Math.max(0, Math.floor(value));
|
|
6370
|
+
}
|
|
7873
6371
|
invalidateLayoutAndRaster(markYogaDirty = true) {
|
|
7874
6372
|
this._layoutDirty = true;
|
|
7875
6373
|
this._rasterDirty = true;
|
|
@@ -9156,9 +7654,13 @@ function parseMarkdownIncremental(newContent, prevState, trailingUnstable = 2) {
|
|
|
9156
7654
|
if (!prevState || prevState.tokens.length === 0) {
|
|
9157
7655
|
try {
|
|
9158
7656
|
const tokens = x.lex(newContent, { gfm: true });
|
|
9159
|
-
return {
|
|
7657
|
+
return {
|
|
7658
|
+
content: newContent,
|
|
7659
|
+
tokens,
|
|
7660
|
+
stableTokenCount: Math.max(0, tokens.length - trailingUnstable)
|
|
7661
|
+
};
|
|
9160
7662
|
} catch {
|
|
9161
|
-
return { content: newContent, tokens: [] };
|
|
7663
|
+
return { content: newContent, tokens: [], stableTokenCount: 0 };
|
|
9162
7664
|
}
|
|
9163
7665
|
}
|
|
9164
7666
|
let offset = 0;
|
|
@@ -9180,23 +7682,32 @@ function parseMarkdownIncremental(newContent, prevState, trailingUnstable = 2) {
|
|
|
9180
7682
|
const stableTokens = prevState.tokens.slice(0, reuseCount);
|
|
9181
7683
|
const remainingContent = newContent.slice(offset);
|
|
9182
7684
|
if (!remainingContent) {
|
|
9183
|
-
return {
|
|
7685
|
+
return {
|
|
7686
|
+
content: newContent,
|
|
7687
|
+
tokens: stableTokens,
|
|
7688
|
+
stableTokenCount: stableTokens.length
|
|
7689
|
+
};
|
|
9184
7690
|
}
|
|
9185
7691
|
try {
|
|
9186
7692
|
const newTokens = x.lex(remainingContent, { gfm: true });
|
|
9187
|
-
return {
|
|
7693
|
+
return {
|
|
7694
|
+
content: newContent,
|
|
7695
|
+
tokens: [...stableTokens, ...newTokens],
|
|
7696
|
+
stableTokenCount: trailingUnstable === 0 ? stableTokens.length + newTokens.length : stableTokens.length
|
|
7697
|
+
};
|
|
9188
7698
|
} catch {
|
|
9189
7699
|
try {
|
|
9190
7700
|
const fullTokens = x.lex(newContent, { gfm: true });
|
|
9191
|
-
return { content: newContent, tokens: fullTokens };
|
|
7701
|
+
return { content: newContent, tokens: fullTokens, stableTokenCount: 0 };
|
|
9192
7702
|
} catch {
|
|
9193
|
-
return { content: newContent, tokens: [] };
|
|
7703
|
+
return { content: newContent, tokens: [], stableTokenCount: 0 };
|
|
9194
7704
|
}
|
|
9195
7705
|
}
|
|
9196
7706
|
}
|
|
9197
7707
|
|
|
9198
7708
|
// src/renderables/Markdown.ts
|
|
9199
7709
|
var TRAILING_MARKDOWN_BLOCK_BREAKS_RE = /(?:\r?\n){2,}$/;
|
|
7710
|
+
var TRAILING_MARKDOWN_BLOCK_NEWLINES_RE = /(?:\r?\n)+$/;
|
|
9200
7711
|
function colorsEqual(left, right) {
|
|
9201
7712
|
if (!left || !right)
|
|
9202
7713
|
return left === right;
|
|
@@ -9213,9 +7724,11 @@ class MarkdownRenderable extends Renderable {
|
|
|
9213
7724
|
_treeSitterClient;
|
|
9214
7725
|
_tableOptions;
|
|
9215
7726
|
_renderNode;
|
|
7727
|
+
_internalBlockMode;
|
|
9216
7728
|
_parseState = null;
|
|
9217
7729
|
_streaming = false;
|
|
9218
7730
|
_blockStates = [];
|
|
7731
|
+
_stableBlockCount = 0;
|
|
9219
7732
|
_styleDirty = false;
|
|
9220
7733
|
_linkifyMarkdownChunks = (chunks, context) => detectLinks(chunks, {
|
|
9221
7734
|
content: context.content,
|
|
@@ -9225,7 +7738,8 @@ class MarkdownRenderable extends Renderable {
|
|
|
9225
7738
|
content: "",
|
|
9226
7739
|
conceal: true,
|
|
9227
7740
|
concealCode: false,
|
|
9228
|
-
streaming: false
|
|
7741
|
+
streaming: false,
|
|
7742
|
+
internalBlockMode: "coalesced"
|
|
9229
7743
|
};
|
|
9230
7744
|
constructor(ctx, options) {
|
|
9231
7745
|
super(ctx, {
|
|
@@ -9243,6 +7757,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
9243
7757
|
this._tableOptions = options.tableOptions;
|
|
9244
7758
|
this._renderNode = options.renderNode;
|
|
9245
7759
|
this._streaming = options.streaming ?? this._contentDefaultOptions.streaming;
|
|
7760
|
+
this._internalBlockMode = options.internalBlockMode ?? this._contentDefaultOptions.internalBlockMode;
|
|
9246
7761
|
this.updateBlocks();
|
|
9247
7762
|
}
|
|
9248
7763
|
get content() {
|
|
@@ -9474,6 +7989,10 @@ class MarkdownRenderable extends Renderable {
|
|
|
9474
7989
|
break;
|
|
9475
7990
|
}
|
|
9476
7991
|
}
|
|
7992
|
+
applyMargins(renderable, marginTop, marginBottom) {
|
|
7993
|
+
renderable.marginTop = marginTop;
|
|
7994
|
+
renderable.marginBottom = marginBottom;
|
|
7995
|
+
}
|
|
9477
7996
|
createMarkdownCodeRenderable(content, id, marginBottom = 0) {
|
|
9478
7997
|
return new CodeRenderable(this.ctx, {
|
|
9479
7998
|
id,
|
|
@@ -9549,6 +8068,9 @@ class MarkdownRenderable extends Renderable {
|
|
|
9549
8068
|
return raw.replace(TRAILING_MARKDOWN_BLOCK_BREAKS_RE, `
|
|
9550
8069
|
`);
|
|
9551
8070
|
}
|
|
8071
|
+
normalizeScrollbackMarkdownBlockRaw(raw) {
|
|
8072
|
+
return raw.replace(TRAILING_MARKDOWN_BLOCK_NEWLINES_RE, "");
|
|
8073
|
+
}
|
|
9552
8074
|
buildRenderableTokens(tokens) {
|
|
9553
8075
|
if (this._renderNode) {
|
|
9554
8076
|
return tokens.filter((token) => token.type !== "space");
|
|
@@ -9590,6 +8112,26 @@ class MarkdownRenderable extends Renderable {
|
|
|
9590
8112
|
flushMarkdownRaw();
|
|
9591
8113
|
return renderTokens;
|
|
9592
8114
|
}
|
|
8115
|
+
buildTopLevelRenderBlocks(tokens) {
|
|
8116
|
+
const blocks = [];
|
|
8117
|
+
let gapBefore = "";
|
|
8118
|
+
for (let i = 0;i < tokens.length; i += 1) {
|
|
8119
|
+
const token = tokens[i];
|
|
8120
|
+
if (token.type === "space") {
|
|
8121
|
+
gapBefore += token.raw;
|
|
8122
|
+
continue;
|
|
8123
|
+
}
|
|
8124
|
+
const prev = blocks[blocks.length - 1];
|
|
8125
|
+
const marginTop = prev && (this.shouldRenderSeparately(prev.token) || TRAILING_MARKDOWN_BLOCK_BREAKS_RE.test(prev.token.raw + gapBefore)) ? 1 : 0;
|
|
8126
|
+
blocks.push({
|
|
8127
|
+
token,
|
|
8128
|
+
sourceTokenEnd: i + 1,
|
|
8129
|
+
marginTop
|
|
8130
|
+
});
|
|
8131
|
+
gapBefore = "";
|
|
8132
|
+
}
|
|
8133
|
+
return blocks;
|
|
8134
|
+
}
|
|
9593
8135
|
getTableRowsToRender(table) {
|
|
9594
8136
|
return table.rows;
|
|
9595
8137
|
}
|
|
@@ -9711,13 +8253,29 @@ class MarkdownRenderable extends Renderable {
|
|
|
9711
8253
|
changed
|
|
9712
8254
|
};
|
|
9713
8255
|
}
|
|
8256
|
+
resolveTableStyle(options = this._tableOptions) {
|
|
8257
|
+
if (options?.style === "columns") {
|
|
8258
|
+
return "columns";
|
|
8259
|
+
}
|
|
8260
|
+
if (options?.style === "grid") {
|
|
8261
|
+
return "grid";
|
|
8262
|
+
}
|
|
8263
|
+
return this._internalBlockMode === "top-level" ? "columns" : "grid";
|
|
8264
|
+
}
|
|
8265
|
+
usesBorderlessColumnSpacing(options = this._tableOptions) {
|
|
8266
|
+
const style = this.resolveTableStyle(options);
|
|
8267
|
+
const borders = options?.borders ?? style === "grid";
|
|
8268
|
+
return style === "columns" && !borders;
|
|
8269
|
+
}
|
|
9714
8270
|
resolveTableRenderableOptions() {
|
|
9715
|
-
const
|
|
8271
|
+
const style = this.resolveTableStyle();
|
|
8272
|
+
const borders = this._tableOptions?.borders ?? style === "grid";
|
|
9716
8273
|
return {
|
|
9717
|
-
columnWidthMode: this._tableOptions?.widthMode ?? "full",
|
|
8274
|
+
columnWidthMode: this._tableOptions?.widthMode ?? (style === "columns" ? "content" : "full"),
|
|
9718
8275
|
columnFitter: this._tableOptions?.columnFitter ?? "proportional",
|
|
9719
8276
|
wrapMode: this._tableOptions?.wrapMode ?? "word",
|
|
9720
8277
|
cellPadding: this._tableOptions?.cellPadding ?? 0,
|
|
8278
|
+
columnGap: this.usesBorderlessColumnSpacing() ? 2 : 0,
|
|
9721
8279
|
border: borders,
|
|
9722
8280
|
outerBorder: this._tableOptions?.outerBorder ?? borders,
|
|
9723
8281
|
showBorders: borders,
|
|
@@ -9731,6 +8289,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
9731
8289
|
tableRenderable.columnFitter = options.columnFitter;
|
|
9732
8290
|
tableRenderable.wrapMode = options.wrapMode;
|
|
9733
8291
|
tableRenderable.cellPadding = options.cellPadding;
|
|
8292
|
+
tableRenderable.columnGap = options.columnGap;
|
|
9734
8293
|
tableRenderable.border = options.border;
|
|
9735
8294
|
tableRenderable.outerBorder = options.outerBorder;
|
|
9736
8295
|
tableRenderable.showBorders = options.showBorders;
|
|
@@ -9762,6 +8321,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
9762
8321
|
columnFitter: options.columnFitter,
|
|
9763
8322
|
wrapMode: options.wrapMode,
|
|
9764
8323
|
cellPadding: options.cellPadding,
|
|
8324
|
+
columnGap: options.columnGap,
|
|
9765
8325
|
border: options.border,
|
|
9766
8326
|
outerBorder: options.outerBorder,
|
|
9767
8327
|
showBorders: options.showBorders,
|
|
@@ -9782,6 +8342,75 @@ class MarkdownRenderable extends Renderable {
|
|
|
9782
8342
|
tableContentCache: cache
|
|
9783
8343
|
};
|
|
9784
8344
|
}
|
|
8345
|
+
getStableBlockCount(blocks, stableTokenCount) {
|
|
8346
|
+
if (this._internalBlockMode !== "top-level") {
|
|
8347
|
+
return 0;
|
|
8348
|
+
}
|
|
8349
|
+
let stableBlockCount = 0;
|
|
8350
|
+
for (const block of blocks) {
|
|
8351
|
+
if (block.sourceTokenEnd <= stableTokenCount) {
|
|
8352
|
+
stableBlockCount += 1;
|
|
8353
|
+
continue;
|
|
8354
|
+
}
|
|
8355
|
+
break;
|
|
8356
|
+
}
|
|
8357
|
+
return stableBlockCount;
|
|
8358
|
+
}
|
|
8359
|
+
syncTopLevelBlockState(state, block, tableContentCache = state.tableContentCache) {
|
|
8360
|
+
state.token = block.token;
|
|
8361
|
+
state.tokenRaw = block.token.raw;
|
|
8362
|
+
state.marginTop = block.marginTop;
|
|
8363
|
+
state.tableContentCache = tableContentCache;
|
|
8364
|
+
}
|
|
8365
|
+
getTopLevelBlockRaw(token) {
|
|
8366
|
+
if (!token.raw) {
|
|
8367
|
+
return;
|
|
8368
|
+
}
|
|
8369
|
+
return this.shouldRenderSeparately(token) ? token.raw : this.normalizeScrollbackMarkdownBlockRaw(token.raw);
|
|
8370
|
+
}
|
|
8371
|
+
createTopLevelDefaultRenderable(block, index) {
|
|
8372
|
+
const { token, marginTop } = block;
|
|
8373
|
+
const id = `${this.id}-block-${index}`;
|
|
8374
|
+
if (token.type === "code") {
|
|
8375
|
+
const renderable2 = this.createCodeRenderable(token, id);
|
|
8376
|
+
renderable2.marginTop = marginTop;
|
|
8377
|
+
return { renderable: renderable2 };
|
|
8378
|
+
}
|
|
8379
|
+
if (token.type === "table") {
|
|
8380
|
+
const next = this.createTableBlock(token, id);
|
|
8381
|
+
next.renderable.marginTop = marginTop;
|
|
8382
|
+
return next;
|
|
8383
|
+
}
|
|
8384
|
+
const markdownRaw = this.getTopLevelBlockRaw(token);
|
|
8385
|
+
if (!markdownRaw) {
|
|
8386
|
+
return { renderable: undefined };
|
|
8387
|
+
}
|
|
8388
|
+
const renderable = this.createMarkdownCodeRenderable(markdownRaw, id);
|
|
8389
|
+
renderable.marginTop = marginTop;
|
|
8390
|
+
return { renderable };
|
|
8391
|
+
}
|
|
8392
|
+
createTopLevelRenderable(block, index) {
|
|
8393
|
+
if (!this._renderNode) {
|
|
8394
|
+
return this.createTopLevelDefaultRenderable(block, index);
|
|
8395
|
+
}
|
|
8396
|
+
let next;
|
|
8397
|
+
const context = {
|
|
8398
|
+
syntaxStyle: this._syntaxStyle,
|
|
8399
|
+
conceal: this._conceal,
|
|
8400
|
+
concealCode: this._concealCode,
|
|
8401
|
+
treeSitterClient: this._treeSitterClient,
|
|
8402
|
+
defaultRender: () => {
|
|
8403
|
+
next = this.createTopLevelDefaultRenderable(block, index);
|
|
8404
|
+
return next.renderable ?? null;
|
|
8405
|
+
}
|
|
8406
|
+
};
|
|
8407
|
+
const custom = this._renderNode(block.token, context);
|
|
8408
|
+
if (custom) {
|
|
8409
|
+
this.applyMargins(custom, block.marginTop, 0);
|
|
8410
|
+
return { renderable: custom };
|
|
8411
|
+
}
|
|
8412
|
+
return next ?? this.createTopLevelDefaultRenderable(block, index);
|
|
8413
|
+
}
|
|
9785
8414
|
createDefaultRenderable(token, index, hasNextToken = false) {
|
|
9786
8415
|
const id = `${this.id}-block-${index}`;
|
|
9787
8416
|
const marginBottom = this.getInterBlockMargin(token, hasNextToken);
|
|
@@ -9846,12 +8475,57 @@ class MarkdownRenderable extends Renderable {
|
|
|
9846
8475
|
this.add(markdownRenderable);
|
|
9847
8476
|
state.renderable = markdownRenderable;
|
|
9848
8477
|
}
|
|
8478
|
+
updateTopLevelBlocks(tokens, forceTableRefresh) {
|
|
8479
|
+
const blocks = this.buildTopLevelRenderBlocks(tokens);
|
|
8480
|
+
this._stableBlockCount = this.getStableBlockCount(blocks, this._parseState?.stableTokenCount ?? 0);
|
|
8481
|
+
let blockIndex = 0;
|
|
8482
|
+
for (let i = 0;i < blocks.length; i += 1) {
|
|
8483
|
+
const block = blocks[i];
|
|
8484
|
+
const existing = this._blockStates[blockIndex];
|
|
8485
|
+
if (existing && existing.token === block.token && !forceTableRefresh) {
|
|
8486
|
+
if (existing.marginTop !== block.marginTop) {
|
|
8487
|
+
this.applyMargins(existing.renderable, block.marginTop, 0);
|
|
8488
|
+
}
|
|
8489
|
+
this.syncTopLevelBlockState(existing, block);
|
|
8490
|
+
blockIndex++;
|
|
8491
|
+
continue;
|
|
8492
|
+
}
|
|
8493
|
+
if (existing && existing.tokenRaw === block.token.raw && existing.token.type === block.token.type && !forceTableRefresh) {
|
|
8494
|
+
if (existing.marginTop !== block.marginTop) {
|
|
8495
|
+
this.applyMargins(existing.renderable, block.marginTop, 0);
|
|
8496
|
+
}
|
|
8497
|
+
this.syncTopLevelBlockState(existing, block);
|
|
8498
|
+
blockIndex++;
|
|
8499
|
+
continue;
|
|
8500
|
+
}
|
|
8501
|
+
if (existing) {
|
|
8502
|
+
existing.renderable.destroyRecursively();
|
|
8503
|
+
}
|
|
8504
|
+
const next = this.createTopLevelRenderable(block, blockIndex);
|
|
8505
|
+
if (next.renderable) {
|
|
8506
|
+
this.add(next.renderable);
|
|
8507
|
+
this._blockStates[blockIndex] = {
|
|
8508
|
+
token: block.token,
|
|
8509
|
+
tokenRaw: block.token.raw,
|
|
8510
|
+
marginTop: block.marginTop,
|
|
8511
|
+
renderable: next.renderable,
|
|
8512
|
+
tableContentCache: next.tableContentCache
|
|
8513
|
+
};
|
|
8514
|
+
}
|
|
8515
|
+
blockIndex++;
|
|
8516
|
+
}
|
|
8517
|
+
while (this._blockStates.length > blockIndex) {
|
|
8518
|
+
const removed = this._blockStates.pop();
|
|
8519
|
+
removed.renderable.destroyRecursively();
|
|
8520
|
+
}
|
|
8521
|
+
}
|
|
9849
8522
|
updateBlocks(forceTableRefresh = false) {
|
|
9850
8523
|
if (this.isDestroyed)
|
|
9851
8524
|
return;
|
|
9852
8525
|
if (!this._content) {
|
|
9853
8526
|
this.clearBlockStates();
|
|
9854
8527
|
this._parseState = null;
|
|
8528
|
+
this._stableBlockCount = 0;
|
|
9855
8529
|
return;
|
|
9856
8530
|
}
|
|
9857
8531
|
const trailingUnstable = this._streaming ? 2 : 0;
|
|
@@ -9859,17 +8533,24 @@ class MarkdownRenderable extends Renderable {
|
|
|
9859
8533
|
const tokens = this._parseState.tokens;
|
|
9860
8534
|
if (tokens.length === 0 && this._content.length > 0) {
|
|
9861
8535
|
this.clearBlockStates();
|
|
8536
|
+
this._stableBlockCount = 0;
|
|
9862
8537
|
const fallback = this.createMarkdownCodeRenderable(this._content, `${this.id}-fallback`);
|
|
9863
8538
|
this.add(fallback);
|
|
9864
8539
|
this._blockStates = [
|
|
9865
8540
|
{
|
|
9866
8541
|
token: { type: "text", raw: this._content, text: this._content },
|
|
9867
8542
|
tokenRaw: this._content,
|
|
8543
|
+
marginTop: 0,
|
|
9868
8544
|
renderable: fallback
|
|
9869
8545
|
}
|
|
9870
8546
|
];
|
|
9871
8547
|
return;
|
|
9872
8548
|
}
|
|
8549
|
+
if (this._internalBlockMode === "top-level") {
|
|
8550
|
+
this.updateTopLevelBlocks(tokens, forceTableRefresh);
|
|
8551
|
+
return;
|
|
8552
|
+
}
|
|
8553
|
+
this._stableBlockCount = 0;
|
|
9873
8554
|
const blockTokens = this.buildRenderableTokens(tokens);
|
|
9874
8555
|
const lastBlockIndex = blockTokens.length - 1;
|
|
9875
8556
|
let blockIndex = 0;
|
|
@@ -9954,8 +8635,13 @@ class MarkdownRenderable extends Renderable {
|
|
|
9954
8635
|
state.renderable.destroyRecursively();
|
|
9955
8636
|
}
|
|
9956
8637
|
this._blockStates = [];
|
|
8638
|
+
this._stableBlockCount = 0;
|
|
9957
8639
|
}
|
|
9958
8640
|
rerenderBlocks() {
|
|
8641
|
+
if (this._internalBlockMode === "top-level") {
|
|
8642
|
+
this.updateBlocks(true);
|
|
8643
|
+
return;
|
|
8644
|
+
}
|
|
9959
8645
|
for (let i = 0;i < this._blockStates.length; i++) {
|
|
9960
8646
|
const state = this._blockStates[i];
|
|
9961
8647
|
const hasNextToken = i < this._blockStates.length - 1;
|
|
@@ -12061,7 +10747,7 @@ class TimeToFirstDrawRenderable extends Renderable {
|
|
|
12061
10747
|
return Math.max(0, Math.floor(value));
|
|
12062
10748
|
}
|
|
12063
10749
|
}
|
|
12064
|
-
export {
|
|
10750
|
+
export { DistortionEffect, VignetteEffect, CloudsEffect, FlamesEffect, CRTRollingBarEffect, RainbowTextEffect, applyScanlines, applyInvert, applyNoise, applyChromaticAberration, applyAsciiArt, applyBrightness, applyGain, applySaturation, BloomEffect, SEPIA_MATRIX, PROTANOPIA_SIM_MATRIX, DEUTERANOPIA_SIM_MATRIX, TRITANOPIA_SIM_MATRIX, ACHROMATOPSIA_MATRIX, PROTANOPIA_COMP_MATRIX, DEUTERANOPIA_COMP_MATRIX, TRITANOPIA_COMP_MATRIX, TECHNICOLOR_MATRIX, SOLARIZATION_MATRIX, SYNTHWAVE_MATRIX, GREENSCALE_MATRIX, GRAYSCALE_MATRIX, INVERT_MATRIX, Timeline, engine, createTimeline, SlotRegistry, createSlotRegistry, createCoreSlotRegistry, registerCorePlugin, resolveCoreSlot, SlotRenderable, NativeSpanFeed, FrameBufferRenderable, ASCIIFontRenderable, Generic, Box, Text, ASCIIFont, Input, Select, TabSelect, FrameBuffer, Code, ScrollBox, vstyles, VRenderable, LineNumberRenderable, DiffRenderable, TextareaRenderable, InputRenderableEvents, InputRenderable, TextTableRenderable, MarkdownRenderable, SliderRenderable, ScrollBarRenderable, ArrowRenderable, ScrollBoxRenderable, SelectRenderableEvents, SelectRenderable, TabSelectRenderableEvents, TabSelectRenderable, TimeToFirstDrawRenderable, exports_src2 as exports_src };
|
|
12065
10751
|
|
|
12066
|
-
//# debugId=
|
|
12067
|
-
//# sourceMappingURL=index-
|
|
10752
|
+
//# debugId=05EEDCB6E0D9D7B564756E2164756E21
|
|
10753
|
+
//# sourceMappingURL=index-gw3ynrc0.js.map
|