@opentui/core 0.0.0-20250930-6541ec7f → 0.0.0-20250930-d50102aa
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 +5 -3
- package/3d.js.map +2 -2
- package/README.md +5 -1
- package/highlights-eq9cgrbb.scm +604 -0
- package/highlights-ghv9g403.scm +205 -0
- package/{index-kvwmgj67.js → index-0p8687g8.js} +1092 -105
- package/{index-kvwmgj67.js.map → index-0p8687g8.js.map} +19 -8
- package/index-cc14z67g.js +3846 -0
- package/index-cc14z67g.js.map +12 -0
- package/index.js +394 -240
- package/index.js.map +6 -4
- package/lib/data-paths.d.ts +26 -0
- package/lib/debounce.d.ts +42 -0
- package/lib/env.d.ts +2 -1
- package/lib/hast-styled-text.d.ts +3 -23
- package/lib/index.d.ts +4 -0
- package/lib/queue.d.ts +15 -0
- package/lib/singleton.d.ts +2 -0
- package/lib/styled-text.d.ts +0 -15
- package/lib/syntax-style.d.ts +36 -0
- package/lib/tree-sitter/assets/update.d.ts +11 -0
- package/lib/tree-sitter/client.d.ts +42 -0
- package/lib/tree-sitter/default-parsers.d.ts +2 -0
- package/lib/tree-sitter/download-utils.d.ts +21 -0
- package/lib/tree-sitter/index.d.ts +10 -0
- package/lib/tree-sitter/parser.worker.d.ts +1 -0
- package/lib/tree-sitter/resolve-ft.d.ts +2 -0
- package/lib/tree-sitter/types.d.ts +64 -0
- package/lib/tree-sitter-styled-text.d.ts +7 -0
- package/lib/validate-dir-name.d.ts +1 -0
- package/package.json +12 -7
- package/parser.worker.d.ts +1 -0
- package/parser.worker.js +5 -0
- package/parser.worker.js.map +9 -0
- package/renderables/Code.d.ts +31 -0
- package/renderables/Text.d.ts +10 -67
- package/renderables/TextBufferRenderable.d.ts +81 -0
- package/renderables/index.d.ts +2 -0
- package/testing.js +3 -2
- package/testing.js.map +2 -2
- package/tree-sitter-javascript-nd0q4pe9.wasm +0 -0
- package/tree-sitter-typescript-zxjzwt75.wasm +0 -0
package/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
CliRenderEvents,
|
|
8
8
|
CliRenderer,
|
|
9
9
|
ConsolePosition,
|
|
10
|
+
DataPathsManager,
|
|
10
11
|
DebugOverlayCorner,
|
|
11
12
|
Edge,
|
|
12
13
|
Gutter,
|
|
@@ -30,6 +31,8 @@ import {
|
|
|
30
31
|
TerminalConsole,
|
|
31
32
|
TextAttributes,
|
|
32
33
|
TextBuffer,
|
|
34
|
+
TreeSitterClient,
|
|
35
|
+
addDefaultParsers,
|
|
33
36
|
bg,
|
|
34
37
|
bgBlack,
|
|
35
38
|
bgBlue,
|
|
@@ -53,7 +56,9 @@ import {
|
|
|
53
56
|
brightWhite,
|
|
54
57
|
brightYellow,
|
|
55
58
|
capture,
|
|
59
|
+
clearEnvCache,
|
|
56
60
|
convertGlobalToLocalSelection,
|
|
61
|
+
convertThemeToStyles,
|
|
57
62
|
coordinateToCharacterIndex,
|
|
58
63
|
createCliRenderer,
|
|
59
64
|
createTextAttributes,
|
|
@@ -63,6 +68,7 @@ import {
|
|
|
63
68
|
env,
|
|
64
69
|
envRegistry,
|
|
65
70
|
exports_src,
|
|
71
|
+
extToFiletype,
|
|
66
72
|
fg,
|
|
67
73
|
fonts,
|
|
68
74
|
generateEnvColored,
|
|
@@ -70,7 +76,9 @@ import {
|
|
|
70
76
|
getBorderFromSides,
|
|
71
77
|
getBorderSides,
|
|
72
78
|
getCharacterPositions,
|
|
79
|
+
getDataPaths,
|
|
73
80
|
getObjectsInViewport,
|
|
81
|
+
getTreeSitterClient,
|
|
74
82
|
green,
|
|
75
83
|
h,
|
|
76
84
|
hastToStyledText,
|
|
@@ -83,6 +91,7 @@ import {
|
|
|
83
91
|
isValidPercentage,
|
|
84
92
|
italic,
|
|
85
93
|
magenta,
|
|
94
|
+
main,
|
|
86
95
|
maybeMakeRenderable,
|
|
87
96
|
measureText,
|
|
88
97
|
nonAlphanumericKeys,
|
|
@@ -103,6 +112,7 @@ import {
|
|
|
103
112
|
parsePositionType,
|
|
104
113
|
parseUnit,
|
|
105
114
|
parseWrap,
|
|
115
|
+
pathToFiletype,
|
|
106
116
|
red,
|
|
107
117
|
registerEnvVar,
|
|
108
118
|
renderFontToFrameBuffer,
|
|
@@ -113,12 +123,15 @@ import {
|
|
|
113
123
|
strikethrough,
|
|
114
124
|
stringToStyledText,
|
|
115
125
|
t,
|
|
126
|
+
treeSitterToStyledText,
|
|
127
|
+
treeSitterToTextChunks,
|
|
116
128
|
underline,
|
|
117
129
|
visualizeRenderableTree,
|
|
118
130
|
white,
|
|
119
131
|
wrapWithDelegates,
|
|
120
132
|
yellow
|
|
121
|
-
} from "./index-
|
|
133
|
+
} from "./index-0p8687g8.js";
|
|
134
|
+
import"./index-cc14z67g.js";
|
|
122
135
|
// src/post/filters.ts
|
|
123
136
|
function applyScanlines(buffer, strength = 0.8, step = 2) {
|
|
124
137
|
const width = buffer.width;
|
|
@@ -1414,6 +1427,353 @@ class BoxRenderable extends Renderable {
|
|
|
1414
1427
|
}
|
|
1415
1428
|
}
|
|
1416
1429
|
}
|
|
1430
|
+
// src/renderables/TextBufferRenderable.ts
|
|
1431
|
+
class TextBufferRenderable extends Renderable {
|
|
1432
|
+
selectable = true;
|
|
1433
|
+
_defaultFg;
|
|
1434
|
+
_defaultBg;
|
|
1435
|
+
_defaultAttributes;
|
|
1436
|
+
_selectionBg;
|
|
1437
|
+
_selectionFg;
|
|
1438
|
+
_wrap = false;
|
|
1439
|
+
_wrapMode = "word";
|
|
1440
|
+
lastLocalSelection = null;
|
|
1441
|
+
textBuffer;
|
|
1442
|
+
_lineInfo = { lineStarts: [], lineWidths: [], maxLineWidth: 0 };
|
|
1443
|
+
_defaultOptions = {
|
|
1444
|
+
fg: RGBA.fromValues(1, 1, 1, 1),
|
|
1445
|
+
bg: RGBA.fromValues(0, 0, 0, 0),
|
|
1446
|
+
selectionBg: undefined,
|
|
1447
|
+
selectionFg: undefined,
|
|
1448
|
+
selectable: true,
|
|
1449
|
+
attributes: 0,
|
|
1450
|
+
wrap: true,
|
|
1451
|
+
wrapMode: "word"
|
|
1452
|
+
};
|
|
1453
|
+
constructor(ctx, options) {
|
|
1454
|
+
super(ctx, options);
|
|
1455
|
+
this._defaultFg = parseColor(options.fg ?? this._defaultOptions.fg);
|
|
1456
|
+
this._defaultBg = parseColor(options.bg ?? this._defaultOptions.bg);
|
|
1457
|
+
this._defaultAttributes = options.attributes ?? this._defaultOptions.attributes;
|
|
1458
|
+
this._selectionBg = options.selectionBg ? parseColor(options.selectionBg) : this._defaultOptions.selectionBg;
|
|
1459
|
+
this._selectionFg = options.selectionFg ? parseColor(options.selectionFg) : this._defaultOptions.selectionFg;
|
|
1460
|
+
this.selectable = options.selectable ?? this._defaultOptions.selectable;
|
|
1461
|
+
this._wrap = options.wrap ?? this._defaultOptions.wrap;
|
|
1462
|
+
this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
|
|
1463
|
+
this.textBuffer = TextBuffer.create(this._ctx.widthMethod);
|
|
1464
|
+
this.textBuffer.setWrapMode(this._wrapMode);
|
|
1465
|
+
this.setupMeasureFunc();
|
|
1466
|
+
this.textBuffer.setDefaultFg(this._defaultFg);
|
|
1467
|
+
this.textBuffer.setDefaultBg(this._defaultBg);
|
|
1468
|
+
this.textBuffer.setDefaultAttributes(this._defaultAttributes);
|
|
1469
|
+
if (this._wrap && this.width > 0) {
|
|
1470
|
+
this.updateWrapWidth(this.width);
|
|
1471
|
+
}
|
|
1472
|
+
this.updateTextInfo();
|
|
1473
|
+
}
|
|
1474
|
+
get plainText() {
|
|
1475
|
+
return this.textBuffer.getPlainText();
|
|
1476
|
+
}
|
|
1477
|
+
get textLength() {
|
|
1478
|
+
return this.textBuffer.length;
|
|
1479
|
+
}
|
|
1480
|
+
get fg() {
|
|
1481
|
+
return this._defaultFg;
|
|
1482
|
+
}
|
|
1483
|
+
set fg(value) {
|
|
1484
|
+
const newColor = parseColor(value ?? this._defaultOptions.fg);
|
|
1485
|
+
if (this._defaultFg !== newColor) {
|
|
1486
|
+
this._defaultFg = newColor;
|
|
1487
|
+
this.textBuffer.setDefaultFg(this._defaultFg);
|
|
1488
|
+
this.onFgChanged(newColor);
|
|
1489
|
+
this.requestRender();
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
get selectionBg() {
|
|
1493
|
+
return this._selectionBg;
|
|
1494
|
+
}
|
|
1495
|
+
set selectionBg(value) {
|
|
1496
|
+
const newColor = value ? parseColor(value) : this._defaultOptions.selectionBg;
|
|
1497
|
+
if (this._selectionBg !== newColor) {
|
|
1498
|
+
this._selectionBg = newColor;
|
|
1499
|
+
if (this.lastLocalSelection) {
|
|
1500
|
+
this.updateLocalSelection(this.lastLocalSelection);
|
|
1501
|
+
}
|
|
1502
|
+
this.requestRender();
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
get selectionFg() {
|
|
1506
|
+
return this._selectionFg;
|
|
1507
|
+
}
|
|
1508
|
+
set selectionFg(value) {
|
|
1509
|
+
const newColor = value ? parseColor(value) : this._defaultOptions.selectionFg;
|
|
1510
|
+
if (this._selectionFg !== newColor) {
|
|
1511
|
+
this._selectionFg = newColor;
|
|
1512
|
+
if (this.lastLocalSelection) {
|
|
1513
|
+
this.updateLocalSelection(this.lastLocalSelection);
|
|
1514
|
+
}
|
|
1515
|
+
this.requestRender();
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
get bg() {
|
|
1519
|
+
return this._defaultBg;
|
|
1520
|
+
}
|
|
1521
|
+
set bg(value) {
|
|
1522
|
+
const newColor = parseColor(value ?? this._defaultOptions.bg);
|
|
1523
|
+
if (this._defaultBg !== newColor) {
|
|
1524
|
+
this._defaultBg = newColor;
|
|
1525
|
+
this.textBuffer.setDefaultBg(this._defaultBg);
|
|
1526
|
+
this.onBgChanged(newColor);
|
|
1527
|
+
this.requestRender();
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
get attributes() {
|
|
1531
|
+
return this._defaultAttributes;
|
|
1532
|
+
}
|
|
1533
|
+
set attributes(value) {
|
|
1534
|
+
if (this._defaultAttributes !== value) {
|
|
1535
|
+
this._defaultAttributes = value;
|
|
1536
|
+
this.textBuffer.setDefaultAttributes(this._defaultAttributes);
|
|
1537
|
+
this.onAttributesChanged(value);
|
|
1538
|
+
this.requestRender();
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
get wrap() {
|
|
1542
|
+
return this._wrap;
|
|
1543
|
+
}
|
|
1544
|
+
set wrap(value) {
|
|
1545
|
+
if (this._wrap !== value) {
|
|
1546
|
+
this._wrap = value;
|
|
1547
|
+
this.textBuffer.setWrapWidth(this._wrap ? this.width : null);
|
|
1548
|
+
this.requestRender();
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
get wrapMode() {
|
|
1552
|
+
return this._wrapMode;
|
|
1553
|
+
}
|
|
1554
|
+
set wrapMode(value) {
|
|
1555
|
+
if (this._wrapMode !== value) {
|
|
1556
|
+
this._wrapMode = value;
|
|
1557
|
+
this.textBuffer.setWrapMode(this._wrapMode);
|
|
1558
|
+
this.requestRender();
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
onResize(width, height) {
|
|
1562
|
+
if (this.lastLocalSelection) {
|
|
1563
|
+
const changed = this.updateLocalSelection(this.lastLocalSelection);
|
|
1564
|
+
if (changed) {
|
|
1565
|
+
this.requestRender();
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
refreshLocalSelection() {
|
|
1570
|
+
if (this.lastLocalSelection) {
|
|
1571
|
+
return this.updateLocalSelection(this.lastLocalSelection);
|
|
1572
|
+
}
|
|
1573
|
+
return false;
|
|
1574
|
+
}
|
|
1575
|
+
updateLocalSelection(localSelection) {
|
|
1576
|
+
if (!localSelection?.isActive) {
|
|
1577
|
+
this.textBuffer.resetLocalSelection();
|
|
1578
|
+
return true;
|
|
1579
|
+
}
|
|
1580
|
+
return this.textBuffer.setLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg);
|
|
1581
|
+
}
|
|
1582
|
+
updateTextInfo() {
|
|
1583
|
+
if (this.lastLocalSelection) {
|
|
1584
|
+
const changed = this.updateLocalSelection(this.lastLocalSelection);
|
|
1585
|
+
if (changed) {
|
|
1586
|
+
this.requestRender();
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
this.yogaNode.markDirty();
|
|
1590
|
+
this.requestRender();
|
|
1591
|
+
}
|
|
1592
|
+
updateLineInfo() {
|
|
1593
|
+
const lineInfo = this.textBuffer.lineInfo;
|
|
1594
|
+
this._lineInfo.lineStarts = lineInfo.lineStarts;
|
|
1595
|
+
this._lineInfo.lineWidths = lineInfo.lineWidths;
|
|
1596
|
+
this._lineInfo.maxLineWidth = lineInfo.maxLineWidth;
|
|
1597
|
+
}
|
|
1598
|
+
updateWrapWidth(width) {
|
|
1599
|
+
this.textBuffer.setWrapWidth(width);
|
|
1600
|
+
this.updateLineInfo();
|
|
1601
|
+
}
|
|
1602
|
+
setupMeasureFunc() {
|
|
1603
|
+
const measureFunc = (width, widthMode, height, heightMode) => {
|
|
1604
|
+
if (this._wrap && this.width !== width) {
|
|
1605
|
+
this.updateWrapWidth(width);
|
|
1606
|
+
} else {
|
|
1607
|
+
this.updateLineInfo();
|
|
1608
|
+
}
|
|
1609
|
+
const measuredWidth = this._lineInfo.maxLineWidth;
|
|
1610
|
+
const measuredHeight = this._lineInfo.lineStarts.length;
|
|
1611
|
+
return {
|
|
1612
|
+
width: Math.max(1, measuredWidth),
|
|
1613
|
+
height: Math.max(1, measuredHeight)
|
|
1614
|
+
};
|
|
1615
|
+
};
|
|
1616
|
+
this.yogaNode.setMeasureFunc(measureFunc);
|
|
1617
|
+
}
|
|
1618
|
+
insertChunk(chunk, index) {
|
|
1619
|
+
this.textBuffer.insertChunkGroup(index ?? this.textBuffer.chunkGroupCount, chunk.text, chunk.fg, chunk.bg, chunk.attributes);
|
|
1620
|
+
this.updateTextInfo();
|
|
1621
|
+
}
|
|
1622
|
+
removeChunk(index) {
|
|
1623
|
+
this.textBuffer.removeChunkGroup(index);
|
|
1624
|
+
this.updateTextInfo();
|
|
1625
|
+
}
|
|
1626
|
+
replaceChunk(index, chunk) {
|
|
1627
|
+
this.textBuffer.replaceChunkGroup(index, chunk.text, chunk.fg, chunk.bg, chunk.attributes);
|
|
1628
|
+
this.updateTextInfo();
|
|
1629
|
+
}
|
|
1630
|
+
shouldStartSelection(x, y) {
|
|
1631
|
+
if (!this.selectable)
|
|
1632
|
+
return false;
|
|
1633
|
+
const localX = x - this.x;
|
|
1634
|
+
const localY = y - this.y;
|
|
1635
|
+
return localX >= 0 && localX < this.width && localY >= 0 && localY < this.height;
|
|
1636
|
+
}
|
|
1637
|
+
onSelectionChanged(selection) {
|
|
1638
|
+
const localSelection = convertGlobalToLocalSelection(selection, this.x, this.y);
|
|
1639
|
+
this.lastLocalSelection = localSelection;
|
|
1640
|
+
const changed = this.updateLocalSelection(localSelection);
|
|
1641
|
+
if (changed) {
|
|
1642
|
+
this.requestRender();
|
|
1643
|
+
}
|
|
1644
|
+
return this.hasSelection();
|
|
1645
|
+
}
|
|
1646
|
+
getSelectedText() {
|
|
1647
|
+
return this.textBuffer.getSelectedText();
|
|
1648
|
+
}
|
|
1649
|
+
hasSelection() {
|
|
1650
|
+
return this.textBuffer.hasSelection();
|
|
1651
|
+
}
|
|
1652
|
+
getSelection() {
|
|
1653
|
+
return this.textBuffer.getSelection();
|
|
1654
|
+
}
|
|
1655
|
+
render(buffer, deltaTime) {
|
|
1656
|
+
if (!this.visible)
|
|
1657
|
+
return;
|
|
1658
|
+
this.markClean();
|
|
1659
|
+
this._ctx.addToHitGrid(this.x, this.y, this.width, this.height, this.num);
|
|
1660
|
+
this.renderSelf(buffer);
|
|
1661
|
+
}
|
|
1662
|
+
renderSelf(buffer) {
|
|
1663
|
+
if (this.textBuffer.ptr) {
|
|
1664
|
+
const clipRect = {
|
|
1665
|
+
x: this.x,
|
|
1666
|
+
y: this.y,
|
|
1667
|
+
width: this.width,
|
|
1668
|
+
height: this.height
|
|
1669
|
+
};
|
|
1670
|
+
buffer.drawTextBuffer(this.textBuffer, this.x, this.y, clipRect);
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
destroy() {
|
|
1674
|
+
this.textBuffer.destroy();
|
|
1675
|
+
super.destroy();
|
|
1676
|
+
}
|
|
1677
|
+
onFgChanged(newColor) {}
|
|
1678
|
+
onBgChanged(newColor) {}
|
|
1679
|
+
onAttributesChanged(newAttributes) {}
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
// src/renderables/Code.ts
|
|
1683
|
+
class CodeRenderable extends TextBufferRenderable {
|
|
1684
|
+
_content;
|
|
1685
|
+
_filetype;
|
|
1686
|
+
_syntaxStyle;
|
|
1687
|
+
_isHighlighting = false;
|
|
1688
|
+
_treeSitterClient;
|
|
1689
|
+
_pendingRehighlight = false;
|
|
1690
|
+
_contentDefaultOptions = {
|
|
1691
|
+
content: ""
|
|
1692
|
+
};
|
|
1693
|
+
constructor(ctx, options) {
|
|
1694
|
+
super(ctx, options);
|
|
1695
|
+
this._content = options.content ?? this._contentDefaultOptions.content;
|
|
1696
|
+
this._filetype = options.filetype;
|
|
1697
|
+
this._syntaxStyle = options.syntaxStyle;
|
|
1698
|
+
this._treeSitterClient = options.treeSitterClient ?? getTreeSitterClient();
|
|
1699
|
+
this.updateContent(this._content);
|
|
1700
|
+
}
|
|
1701
|
+
get content() {
|
|
1702
|
+
return this._content;
|
|
1703
|
+
}
|
|
1704
|
+
set content(value) {
|
|
1705
|
+
if (this._content !== value) {
|
|
1706
|
+
this._content = value;
|
|
1707
|
+
this.updateContent(value);
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
get filetype() {
|
|
1711
|
+
return this._filetype;
|
|
1712
|
+
}
|
|
1713
|
+
set filetype(value) {
|
|
1714
|
+
if (this._filetype !== value) {
|
|
1715
|
+
this._filetype = value;
|
|
1716
|
+
this.updateContent(this._content);
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
get syntaxStyle() {
|
|
1720
|
+
return this._syntaxStyle;
|
|
1721
|
+
}
|
|
1722
|
+
set syntaxStyle(value) {
|
|
1723
|
+
if (this._syntaxStyle !== value) {
|
|
1724
|
+
this._syntaxStyle = value;
|
|
1725
|
+
this.updateContent(this._content);
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
async updateContent(content) {
|
|
1729
|
+
if (content.length === 0)
|
|
1730
|
+
return;
|
|
1731
|
+
if (this._isHighlighting) {
|
|
1732
|
+
this._pendingRehighlight = true;
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1735
|
+
if (!this._filetype) {
|
|
1736
|
+
this.fallback(content);
|
|
1737
|
+
return;
|
|
1738
|
+
}
|
|
1739
|
+
this._isHighlighting = true;
|
|
1740
|
+
try {
|
|
1741
|
+
const styledText = await treeSitterToStyledText(content, this._filetype, this._syntaxStyle, this._treeSitterClient);
|
|
1742
|
+
if (this.isDestroyed)
|
|
1743
|
+
return;
|
|
1744
|
+
this.textBuffer.setStyledText(styledText);
|
|
1745
|
+
this.updateTextInfo();
|
|
1746
|
+
} catch (error) {
|
|
1747
|
+
console.warn("Code highlighting failed, falling back to plain text:", error);
|
|
1748
|
+
this.fallback(content);
|
|
1749
|
+
} finally {
|
|
1750
|
+
this._isHighlighting = false;
|
|
1751
|
+
if (this._pendingRehighlight) {
|
|
1752
|
+
this._pendingRehighlight = false;
|
|
1753
|
+
process.nextTick(() => this.updateContent(this._content));
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
fallback(content) {
|
|
1758
|
+
const fallbackStyledText = this.createFallbackStyledText(content);
|
|
1759
|
+
if (this.isDestroyed)
|
|
1760
|
+
return;
|
|
1761
|
+
this.textBuffer.setStyledText(fallbackStyledText);
|
|
1762
|
+
this.updateTextInfo();
|
|
1763
|
+
}
|
|
1764
|
+
createFallbackStyledText(content) {
|
|
1765
|
+
const chunks = [
|
|
1766
|
+
{
|
|
1767
|
+
__isChunk: true,
|
|
1768
|
+
text: content,
|
|
1769
|
+
fg: this._defaultFg,
|
|
1770
|
+
bg: this._defaultBg,
|
|
1771
|
+
attributes: this._defaultAttributes
|
|
1772
|
+
}
|
|
1773
|
+
];
|
|
1774
|
+
return new StyledText(chunks);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1417
1777
|
// src/renderables/FrameBuffer.ts
|
|
1418
1778
|
class FrameBufferRenderable extends Renderable {
|
|
1419
1779
|
frameBuffer;
|
|
@@ -1671,52 +2031,19 @@ class RootTextNodeRenderable extends TextNodeRenderable {
|
|
|
1671
2031
|
}
|
|
1672
2032
|
|
|
1673
2033
|
// src/renderables/Text.ts
|
|
1674
|
-
class TextRenderable extends
|
|
1675
|
-
selectable = true;
|
|
2034
|
+
class TextRenderable extends TextBufferRenderable {
|
|
1676
2035
|
_text;
|
|
1677
2036
|
_hasManualStyledText = false;
|
|
1678
|
-
_defaultFg;
|
|
1679
|
-
_defaultBg;
|
|
1680
|
-
_defaultAttributes;
|
|
1681
|
-
_selectionBg;
|
|
1682
|
-
_selectionFg;
|
|
1683
|
-
_wrap = false;
|
|
1684
|
-
_wrapMode = "word";
|
|
1685
|
-
lastLocalSelection = null;
|
|
1686
|
-
textBuffer;
|
|
1687
|
-
_lineInfo = { lineStarts: [], lineWidths: [], maxLineWidth: 0 };
|
|
1688
2037
|
rootTextNode;
|
|
1689
|
-
|
|
1690
|
-
content: ""
|
|
1691
|
-
fg: RGBA.fromValues(1, 1, 1, 1),
|
|
1692
|
-
bg: RGBA.fromValues(0, 0, 0, 0),
|
|
1693
|
-
selectionBg: undefined,
|
|
1694
|
-
selectionFg: undefined,
|
|
1695
|
-
selectable: true,
|
|
1696
|
-
attributes: 0,
|
|
1697
|
-
wrap: true,
|
|
1698
|
-
wrapMode: "word"
|
|
2038
|
+
_contentDefaultOptions = {
|
|
2039
|
+
content: ""
|
|
1699
2040
|
};
|
|
1700
2041
|
constructor(ctx, options) {
|
|
1701
2042
|
super(ctx, options);
|
|
1702
|
-
const content = options.content ?? this.
|
|
2043
|
+
const content = options.content ?? this._contentDefaultOptions.content;
|
|
1703
2044
|
const styledText = typeof content === "string" ? stringToStyledText(content) : content;
|
|
1704
2045
|
this._text = styledText;
|
|
1705
|
-
this._hasManualStyledText =
|
|
1706
|
-
this._defaultFg = parseColor(options.fg ?? this._defaultOptions.fg);
|
|
1707
|
-
this._defaultBg = parseColor(options.bg ?? this._defaultOptions.bg);
|
|
1708
|
-
this._defaultAttributes = options.attributes ?? this._defaultOptions.attributes;
|
|
1709
|
-
this._selectionBg = options.selectionBg ? parseColor(options.selectionBg) : this._defaultOptions.selectionBg;
|
|
1710
|
-
this._selectionFg = options.selectionFg ? parseColor(options.selectionFg) : this._defaultOptions.selectionFg;
|
|
1711
|
-
this.selectable = options.selectable ?? this._defaultOptions.selectable;
|
|
1712
|
-
this._wrap = options.wrap ?? this._defaultOptions.wrap;
|
|
1713
|
-
this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
|
|
1714
|
-
this.textBuffer = TextBuffer.create(this._ctx.widthMethod);
|
|
1715
|
-
this.textBuffer.setWrapMode(this._wrapMode);
|
|
1716
|
-
this.setupMeasureFunc();
|
|
1717
|
-
this.textBuffer.setDefaultFg(this._defaultFg);
|
|
1718
|
-
this.textBuffer.setDefaultBg(this._defaultBg);
|
|
1719
|
-
this.textBuffer.setDefaultAttributes(this._defaultAttributes);
|
|
2046
|
+
this._hasManualStyledText = options.content !== undefined && content !== "";
|
|
1720
2047
|
this.rootTextNode = new RootTextNodeRenderable(ctx, {
|
|
1721
2048
|
id: `${this.id}-root`,
|
|
1722
2049
|
fg: this._defaultFg,
|
|
@@ -1724,11 +2051,6 @@ class TextRenderable extends Renderable {
|
|
|
1724
2051
|
attributes: this._defaultAttributes
|
|
1725
2052
|
}, this);
|
|
1726
2053
|
this.updateTextBuffer(styledText);
|
|
1727
|
-
this._text.mount(this);
|
|
1728
|
-
if (this._wrap && this.width > 0) {
|
|
1729
|
-
this.updateWrapWidth(this.width);
|
|
1730
|
-
}
|
|
1731
|
-
this.updateTextInfo();
|
|
1732
2054
|
}
|
|
1733
2055
|
updateTextBuffer(styledText) {
|
|
1734
2056
|
this.textBuffer.setStyledText(styledText);
|
|
@@ -1738,12 +2060,6 @@ class TextRenderable extends Renderable {
|
|
|
1738
2060
|
get content() {
|
|
1739
2061
|
return this._text;
|
|
1740
2062
|
}
|
|
1741
|
-
get plainText() {
|
|
1742
|
-
return this.textBuffer.getPlainText();
|
|
1743
|
-
}
|
|
1744
|
-
get textLength() {
|
|
1745
|
-
return this.textBuffer.length;
|
|
1746
|
-
}
|
|
1747
2063
|
get chunks() {
|
|
1748
2064
|
return this._text.chunks;
|
|
1749
2065
|
}
|
|
@@ -1755,166 +2071,26 @@ class TextRenderable extends Renderable {
|
|
|
1755
2071
|
const styledText = typeof value === "string" ? stringToStyledText(value) : value;
|
|
1756
2072
|
if (this._text !== styledText) {
|
|
1757
2073
|
this._text = styledText;
|
|
1758
|
-
styledText.mount(this);
|
|
1759
2074
|
this.updateTextBuffer(styledText);
|
|
1760
2075
|
this.updateTextInfo();
|
|
1761
2076
|
}
|
|
1762
2077
|
}
|
|
1763
|
-
get fg() {
|
|
1764
|
-
return this._defaultFg;
|
|
1765
|
-
}
|
|
1766
|
-
set fg(value) {
|
|
1767
|
-
const newColor = parseColor(value ?? this._defaultOptions.fg);
|
|
1768
|
-
this.rootTextNode.fg = newColor;
|
|
1769
|
-
if (this._defaultFg !== newColor) {
|
|
1770
|
-
this._defaultFg = newColor;
|
|
1771
|
-
this.textBuffer.setDefaultFg(this._defaultFg);
|
|
1772
|
-
this.rootTextNode.fg = newColor;
|
|
1773
|
-
this.requestRender();
|
|
1774
|
-
}
|
|
1775
|
-
}
|
|
1776
|
-
get selectionBg() {
|
|
1777
|
-
return this._selectionBg;
|
|
1778
|
-
}
|
|
1779
|
-
set selectionBg(value) {
|
|
1780
|
-
const newColor = value ? parseColor(value) : this._defaultOptions.selectionBg;
|
|
1781
|
-
if (this._selectionBg !== newColor) {
|
|
1782
|
-
this._selectionBg = newColor;
|
|
1783
|
-
if (this.lastLocalSelection) {
|
|
1784
|
-
this.updateLocalSelection(this.lastLocalSelection);
|
|
1785
|
-
}
|
|
1786
|
-
this.requestRender();
|
|
1787
|
-
}
|
|
1788
|
-
}
|
|
1789
|
-
get selectionFg() {
|
|
1790
|
-
return this._selectionFg;
|
|
1791
|
-
}
|
|
1792
|
-
set selectionFg(value) {
|
|
1793
|
-
const newColor = value ? parseColor(value) : this._defaultOptions.selectionFg;
|
|
1794
|
-
if (this._selectionFg !== newColor) {
|
|
1795
|
-
this._selectionFg = newColor;
|
|
1796
|
-
if (this.lastLocalSelection) {
|
|
1797
|
-
this.updateLocalSelection(this.lastLocalSelection);
|
|
1798
|
-
}
|
|
1799
|
-
this.requestRender();
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
get bg() {
|
|
1803
|
-
return this._defaultBg;
|
|
1804
|
-
}
|
|
1805
|
-
set bg(value) {
|
|
1806
|
-
const newColor = parseColor(value ?? this._defaultOptions.bg);
|
|
1807
|
-
this.rootTextNode.bg = newColor;
|
|
1808
|
-
if (this._defaultBg !== newColor) {
|
|
1809
|
-
this._defaultBg = newColor;
|
|
1810
|
-
this.textBuffer.setDefaultBg(this._defaultBg);
|
|
1811
|
-
this.rootTextNode.bg = newColor;
|
|
1812
|
-
this.requestRender();
|
|
1813
|
-
}
|
|
1814
|
-
}
|
|
1815
|
-
get attributes() {
|
|
1816
|
-
return this._defaultAttributes;
|
|
1817
|
-
}
|
|
1818
|
-
set attributes(value) {
|
|
1819
|
-
if (this._defaultAttributes !== value) {
|
|
1820
|
-
this._defaultAttributes = value;
|
|
1821
|
-
this.textBuffer.setDefaultAttributes(this._defaultAttributes);
|
|
1822
|
-
this.rootTextNode.attributes = value;
|
|
1823
|
-
this.requestRender();
|
|
1824
|
-
}
|
|
1825
|
-
}
|
|
1826
|
-
get wrap() {
|
|
1827
|
-
return this._wrap;
|
|
1828
|
-
}
|
|
1829
|
-
set wrap(value) {
|
|
1830
|
-
if (this._wrap !== value) {
|
|
1831
|
-
this._wrap = value;
|
|
1832
|
-
this.textBuffer.setWrapWidth(this._wrap ? this.width : null);
|
|
1833
|
-
this.requestRender();
|
|
1834
|
-
}
|
|
1835
|
-
}
|
|
1836
|
-
get wrapMode() {
|
|
1837
|
-
return this._wrapMode;
|
|
1838
|
-
}
|
|
1839
|
-
set wrapMode(value) {
|
|
1840
|
-
if (this._wrapMode !== value) {
|
|
1841
|
-
this._wrapMode = value;
|
|
1842
|
-
this.textBuffer.setWrapMode(this._wrapMode);
|
|
1843
|
-
this.requestRender();
|
|
1844
|
-
}
|
|
1845
|
-
}
|
|
1846
|
-
onResize(width, height) {
|
|
1847
|
-
if (this.lastLocalSelection) {
|
|
1848
|
-
const changed = this.updateLocalSelection(this.lastLocalSelection);
|
|
1849
|
-
if (changed) {
|
|
1850
|
-
this.requestRender();
|
|
1851
|
-
}
|
|
1852
|
-
}
|
|
1853
|
-
}
|
|
1854
|
-
updateLocalSelection(localSelection) {
|
|
1855
|
-
if (!localSelection?.isActive) {
|
|
1856
|
-
this.textBuffer.resetLocalSelection();
|
|
1857
|
-
return true;
|
|
1858
|
-
}
|
|
1859
|
-
return this.textBuffer.setLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg);
|
|
1860
|
-
}
|
|
1861
|
-
updateTextInfo() {
|
|
1862
|
-
if (this.lastLocalSelection) {
|
|
1863
|
-
const changed = this.updateLocalSelection(this.lastLocalSelection);
|
|
1864
|
-
if (changed) {
|
|
1865
|
-
this.requestRender();
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
this.yogaNode.markDirty();
|
|
1869
|
-
this.requestRender();
|
|
1870
|
-
}
|
|
1871
|
-
updateLineInfo() {
|
|
1872
|
-
const lineInfo = this.textBuffer.lineInfo;
|
|
1873
|
-
this._lineInfo.lineStarts = lineInfo.lineStarts;
|
|
1874
|
-
this._lineInfo.lineWidths = lineInfo.lineWidths;
|
|
1875
|
-
this._lineInfo.maxLineWidth = lineInfo.maxLineWidth;
|
|
1876
|
-
}
|
|
1877
|
-
updateWrapWidth(width) {
|
|
1878
|
-
this.textBuffer.setWrapWidth(width);
|
|
1879
|
-
this.updateLineInfo();
|
|
1880
|
-
}
|
|
1881
|
-
setupMeasureFunc() {
|
|
1882
|
-
const measureFunc = (width, widthMode, height, heightMode) => {
|
|
1883
|
-
if (this._wrap) {
|
|
1884
|
-
if (this.width !== width) {
|
|
1885
|
-
this.updateWrapWidth(width);
|
|
1886
|
-
}
|
|
1887
|
-
} else {
|
|
1888
|
-
this.updateLineInfo();
|
|
1889
|
-
}
|
|
1890
|
-
const measuredWidth = this._lineInfo.maxLineWidth;
|
|
1891
|
-
const measuredHeight = this._lineInfo.lineStarts.length;
|
|
1892
|
-
return {
|
|
1893
|
-
width: Math.max(1, measuredWidth),
|
|
1894
|
-
height: Math.max(1, measuredHeight)
|
|
1895
|
-
};
|
|
1896
|
-
};
|
|
1897
|
-
this.yogaNode.setMeasureFunc(measureFunc);
|
|
1898
|
-
}
|
|
1899
2078
|
insertChunk(chunk, index) {
|
|
1900
|
-
|
|
1901
|
-
this.updateTextInfo();
|
|
2079
|
+
super.insertChunk(chunk, index);
|
|
1902
2080
|
this.clearChunks(this._text);
|
|
1903
2081
|
}
|
|
1904
|
-
|
|
2082
|
+
removeChunkByObject(chunk) {
|
|
1905
2083
|
const index = this._text.chunks.indexOf(chunk);
|
|
1906
2084
|
if (index === -1)
|
|
1907
2085
|
return;
|
|
1908
|
-
|
|
1909
|
-
this.updateTextInfo();
|
|
2086
|
+
super.removeChunk(index);
|
|
1910
2087
|
this.clearChunks(this._text);
|
|
1911
2088
|
}
|
|
1912
|
-
|
|
2089
|
+
replaceChunkByObject(chunk, oldChunk) {
|
|
1913
2090
|
const index = this._text.chunks.indexOf(oldChunk);
|
|
1914
2091
|
if (index === -1)
|
|
1915
2092
|
return;
|
|
1916
|
-
|
|
1917
|
-
this.updateTextInfo();
|
|
2093
|
+
super.replaceChunk(index, chunk);
|
|
1918
2094
|
this.clearChunks(this._text);
|
|
1919
2095
|
}
|
|
1920
2096
|
updateTextFromNodes() {
|
|
@@ -1925,7 +2101,7 @@ class TextRenderable extends Renderable {
|
|
|
1925
2101
|
attributes: this._defaultAttributes
|
|
1926
2102
|
});
|
|
1927
2103
|
this.textBuffer.setStyledText(new StyledText(chunks));
|
|
1928
|
-
this.
|
|
2104
|
+
this.refreshLocalSelection();
|
|
1929
2105
|
this.yogaNode.markDirty();
|
|
1930
2106
|
}
|
|
1931
2107
|
}
|
|
@@ -1949,59 +2125,23 @@ class TextRenderable extends Renderable {
|
|
|
1949
2125
|
this.rootTextNode.clear();
|
|
1950
2126
|
const emptyStyledText = stringToStyledText("");
|
|
1951
2127
|
this._text = emptyStyledText;
|
|
1952
|
-
emptyStyledText.mount(this);
|
|
1953
2128
|
this.updateTextBuffer(emptyStyledText);
|
|
1954
2129
|
this.updateTextInfo();
|
|
1955
2130
|
this.requestRender();
|
|
1956
2131
|
}
|
|
1957
|
-
shouldStartSelection(x, y) {
|
|
1958
|
-
if (!this.selectable)
|
|
1959
|
-
return false;
|
|
1960
|
-
const localX = x - this.x;
|
|
1961
|
-
const localY = y - this.y;
|
|
1962
|
-
return localX >= 0 && localX < this.width && localY >= 0 && localY < this.height;
|
|
1963
|
-
}
|
|
1964
|
-
onSelectionChanged(selection) {
|
|
1965
|
-
const localSelection = convertGlobalToLocalSelection(selection, this.x, this.y);
|
|
1966
|
-
this.lastLocalSelection = localSelection;
|
|
1967
|
-
const changed = this.updateLocalSelection(localSelection);
|
|
1968
|
-
if (changed) {
|
|
1969
|
-
this.requestRender();
|
|
1970
|
-
}
|
|
1971
|
-
return this.hasSelection();
|
|
1972
|
-
}
|
|
1973
|
-
getSelectedText() {
|
|
1974
|
-
return this.textBuffer.getSelectedText();
|
|
1975
|
-
}
|
|
1976
|
-
hasSelection() {
|
|
1977
|
-
return this.textBuffer.hasSelection();
|
|
1978
|
-
}
|
|
1979
|
-
getSelection() {
|
|
1980
|
-
return this.textBuffer.getSelection();
|
|
1981
|
-
}
|
|
1982
2132
|
onLifecyclePass = () => {
|
|
1983
2133
|
this.updateTextFromNodes();
|
|
1984
2134
|
};
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
return;
|
|
1988
|
-
this.markClean();
|
|
1989
|
-
this._ctx.addToHitGrid(this.x, this.y, this.width, this.height, this.num);
|
|
1990
|
-
this.renderSelf(buffer);
|
|
2135
|
+
onFgChanged(newColor) {
|
|
2136
|
+
this.rootTextNode.fg = newColor;
|
|
1991
2137
|
}
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
width: this.width,
|
|
1998
|
-
height: this.height
|
|
1999
|
-
};
|
|
2000
|
-
buffer.drawTextBuffer(this.textBuffer, this.x, this.y, clipRect);
|
|
2001
|
-
}
|
|
2138
|
+
onBgChanged(newColor) {
|
|
2139
|
+
this.rootTextNode.bg = newColor;
|
|
2140
|
+
}
|
|
2141
|
+
onAttributesChanged(newAttributes) {
|
|
2142
|
+
this.rootTextNode.attributes = newAttributes;
|
|
2002
2143
|
}
|
|
2003
2144
|
destroy() {
|
|
2004
|
-
this.textBuffer.destroy();
|
|
2005
2145
|
this.rootTextNode.children.length = 0;
|
|
2006
2146
|
super.destroy();
|
|
2007
2147
|
}
|
|
@@ -4170,7 +4310,10 @@ export {
|
|
|
4170
4310
|
white,
|
|
4171
4311
|
vstyles,
|
|
4172
4312
|
visualizeRenderableTree,
|
|
4313
|
+
main as updateAssets,
|
|
4173
4314
|
underline,
|
|
4315
|
+
treeSitterToTextChunks,
|
|
4316
|
+
treeSitterToStyledText,
|
|
4174
4317
|
t,
|
|
4175
4318
|
stringToStyledText,
|
|
4176
4319
|
strikethrough,
|
|
@@ -4181,6 +4324,7 @@ export {
|
|
|
4181
4324
|
renderFontToFrameBuffer,
|
|
4182
4325
|
registerEnvVar,
|
|
4183
4326
|
red,
|
|
4327
|
+
pathToFiletype,
|
|
4184
4328
|
parseWrap,
|
|
4185
4329
|
parseUnit,
|
|
4186
4330
|
parsePositionType,
|
|
@@ -4213,6 +4357,8 @@ export {
|
|
|
4213
4357
|
hastToStyledText,
|
|
4214
4358
|
h,
|
|
4215
4359
|
green,
|
|
4360
|
+
getTreeSitterClient,
|
|
4361
|
+
getDataPaths,
|
|
4216
4362
|
getCharacterPositions,
|
|
4217
4363
|
getBorderSides,
|
|
4218
4364
|
getBorderFromSides,
|
|
@@ -4220,6 +4366,7 @@ export {
|
|
|
4220
4366
|
generateEnvColored,
|
|
4221
4367
|
fonts,
|
|
4222
4368
|
fg,
|
|
4369
|
+
extToFiletype,
|
|
4223
4370
|
envRegistry,
|
|
4224
4371
|
env,
|
|
4225
4372
|
engine,
|
|
@@ -4230,7 +4377,9 @@ export {
|
|
|
4230
4377
|
createTextAttributes,
|
|
4231
4378
|
createCliRenderer,
|
|
4232
4379
|
coordinateToCharacterIndex,
|
|
4380
|
+
convertThemeToStyles,
|
|
4233
4381
|
convertGlobalToLocalSelection,
|
|
4382
|
+
clearEnvCache,
|
|
4234
4383
|
capture,
|
|
4235
4384
|
brightYellow,
|
|
4236
4385
|
brightWhite,
|
|
@@ -4261,12 +4410,15 @@ export {
|
|
|
4261
4410
|
applyGrayscale,
|
|
4262
4411
|
applyChromaticAberration,
|
|
4263
4412
|
applyAsciiArt,
|
|
4413
|
+
addDefaultParsers,
|
|
4264
4414
|
exports_src as Yoga,
|
|
4265
4415
|
VignetteEffect,
|
|
4266
4416
|
VRenderable,
|
|
4417
|
+
TreeSitterClient,
|
|
4267
4418
|
Timeline,
|
|
4268
4419
|
TextRenderable,
|
|
4269
4420
|
TextNodeRenderable,
|
|
4421
|
+
TextBufferRenderable,
|
|
4270
4422
|
TextBuffer,
|
|
4271
4423
|
TextAttributes,
|
|
4272
4424
|
Text,
|
|
@@ -4305,7 +4457,9 @@ export {
|
|
|
4305
4457
|
FrameBuffer,
|
|
4306
4458
|
DistortionEffect,
|
|
4307
4459
|
DebugOverlayCorner,
|
|
4460
|
+
DataPathsManager,
|
|
4308
4461
|
ConsolePosition,
|
|
4462
|
+
CodeRenderable,
|
|
4309
4463
|
CliRenderer,
|
|
4310
4464
|
CliRenderEvents,
|
|
4311
4465
|
BrightnessEffect,
|
|
@@ -4322,5 +4476,5 @@ export {
|
|
|
4322
4476
|
ASCIIFont
|
|
4323
4477
|
};
|
|
4324
4478
|
|
|
4325
|
-
//# debugId=
|
|
4479
|
+
//# debugId=E18C5317B48F6C4864756E2164756E21
|
|
4326
4480
|
//# sourceMappingURL=index.js.map
|