@opentui/core 0.1.23 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/3d.js +1 -1
- package/3d.js.map +1 -1
- package/Renderable.d.ts +21 -21
- package/buffer.d.ts +3 -1
- package/{index-a6ydv6yb.js → index-0yx9rnxg.js} +974 -544
- package/index-0yx9rnxg.js.map +38 -0
- package/index.d.ts +1 -0
- package/index.js +345 -139
- package/index.js.map +10 -10
- package/lib/KeyHandler.d.ts +7 -3
- package/lib/index.d.ts +0 -1
- package/lib/parse.keypress-kitty.d.ts +2 -0
- package/lib/parse.keypress.d.ts +11 -1
- package/lib/renderable.validations.d.ts +12 -0
- package/package.json +14 -12
- package/renderables/ScrollBox.d.ts +3 -1
- package/renderables/Slider.d.ts +24 -11
- package/renderables/Text.d.ts +15 -3
- package/renderables/TextNode.d.ts +13 -4
- package/renderer.d.ts +16 -1
- package/testing/mock-mouse.d.ts +38 -0
- package/testing/test-renderer.d.ts +15 -3
- package/testing.d.ts +3 -0
- package/testing.js +343 -0
- package/testing.js.map +12 -0
- package/text-buffer.d.ts +8 -9
- package/types.d.ts +5 -0
- package/utils.d.ts +2 -0
- package/zig.d.ts +15 -10
- package/index-a6ydv6yb.js.map +0 -37
- package/lib/TrackedNode.d.ts +0 -36
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __getProtoOf = Object.getPrototypeOf;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
@@ -26,102 +27,29 @@ var __export = (target, all) => {
|
|
|
26
27
|
};
|
|
27
28
|
var __require = import.meta.require;
|
|
28
29
|
|
|
29
|
-
// src/
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
bottomT: "\u2569",
|
|
53
|
-
leftT: "\u2560",
|
|
54
|
-
rightT: "\u2563",
|
|
55
|
-
cross: "\u256C"
|
|
56
|
-
},
|
|
57
|
-
rounded: {
|
|
58
|
-
topLeft: "\u256D",
|
|
59
|
-
topRight: "\u256E",
|
|
60
|
-
bottomLeft: "\u2570",
|
|
61
|
-
bottomRight: "\u256F",
|
|
62
|
-
horizontal: "\u2500",
|
|
63
|
-
vertical: "\u2502",
|
|
64
|
-
topT: "\u252C",
|
|
65
|
-
bottomT: "\u2534",
|
|
66
|
-
leftT: "\u251C",
|
|
67
|
-
rightT: "\u2524",
|
|
68
|
-
cross: "\u253C"
|
|
69
|
-
},
|
|
70
|
-
heavy: {
|
|
71
|
-
topLeft: "\u250F",
|
|
72
|
-
topRight: "\u2513",
|
|
73
|
-
bottomLeft: "\u2517",
|
|
74
|
-
bottomRight: "\u251B",
|
|
75
|
-
horizontal: "\u2501",
|
|
76
|
-
vertical: "\u2503",
|
|
77
|
-
topT: "\u2533",
|
|
78
|
-
bottomT: "\u253B",
|
|
79
|
-
leftT: "\u2523",
|
|
80
|
-
rightT: "\u252B",
|
|
81
|
-
cross: "\u254B"
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
function getBorderFromSides(sides) {
|
|
85
|
-
const result = [];
|
|
86
|
-
if (sides.top)
|
|
87
|
-
result.push("top");
|
|
88
|
-
if (sides.right)
|
|
89
|
-
result.push("right");
|
|
90
|
-
if (sides.bottom)
|
|
91
|
-
result.push("bottom");
|
|
92
|
-
if (sides.left)
|
|
93
|
-
result.push("left");
|
|
94
|
-
return result.length > 0 ? result : false;
|
|
95
|
-
}
|
|
96
|
-
function getBorderSides(border) {
|
|
97
|
-
return border === true ? { top: true, right: true, bottom: true, left: true } : Array.isArray(border) ? {
|
|
98
|
-
top: border.includes("top"),
|
|
99
|
-
right: border.includes("right"),
|
|
100
|
-
bottom: border.includes("bottom"),
|
|
101
|
-
left: border.includes("left")
|
|
102
|
-
} : { top: false, right: false, bottom: false, left: false };
|
|
103
|
-
}
|
|
104
|
-
function borderCharsToArray(chars) {
|
|
105
|
-
const array = new Uint32Array(11);
|
|
106
|
-
array[0] = chars.topLeft.codePointAt(0);
|
|
107
|
-
array[1] = chars.topRight.codePointAt(0);
|
|
108
|
-
array[2] = chars.bottomLeft.codePointAt(0);
|
|
109
|
-
array[3] = chars.bottomRight.codePointAt(0);
|
|
110
|
-
array[4] = chars.horizontal.codePointAt(0);
|
|
111
|
-
array[5] = chars.vertical.codePointAt(0);
|
|
112
|
-
array[6] = chars.topT.codePointAt(0);
|
|
113
|
-
array[7] = chars.bottomT.codePointAt(0);
|
|
114
|
-
array[8] = chars.leftT.codePointAt(0);
|
|
115
|
-
array[9] = chars.rightT.codePointAt(0);
|
|
116
|
-
array[10] = chars.cross.codePointAt(0);
|
|
117
|
-
return array;
|
|
118
|
-
}
|
|
119
|
-
var BorderCharArrays = {
|
|
120
|
-
single: borderCharsToArray(BorderChars.single),
|
|
121
|
-
double: borderCharsToArray(BorderChars.double),
|
|
122
|
-
rounded: borderCharsToArray(BorderChars.rounded),
|
|
123
|
-
heavy: borderCharsToArray(BorderChars.heavy)
|
|
124
|
-
};
|
|
30
|
+
// ../../node_modules/yoga-layout/dist/src/index.js
|
|
31
|
+
var exports_src = {};
|
|
32
|
+
__export(exports_src, {
|
|
33
|
+
default: () => src_default,
|
|
34
|
+
Wrap: () => Wrap,
|
|
35
|
+
Unit: () => Unit,
|
|
36
|
+
PositionType: () => PositionType,
|
|
37
|
+
Overflow: () => Overflow,
|
|
38
|
+
NodeType: () => NodeType,
|
|
39
|
+
MeasureMode: () => MeasureMode,
|
|
40
|
+
LogLevel: () => LogLevel,
|
|
41
|
+
Justify: () => Justify,
|
|
42
|
+
Gutter: () => Gutter,
|
|
43
|
+
FlexDirection: () => FlexDirection,
|
|
44
|
+
ExperimentalFeature: () => ExperimentalFeature,
|
|
45
|
+
Errata: () => Errata,
|
|
46
|
+
Edge: () => Edge,
|
|
47
|
+
Display: () => Display,
|
|
48
|
+
Direction: () => Direction,
|
|
49
|
+
Dimension: () => Dimension,
|
|
50
|
+
BoxSizing: () => BoxSizing,
|
|
51
|
+
Align: () => Align
|
|
52
|
+
});
|
|
125
53
|
|
|
126
54
|
// ../../node_modules/yoga-layout/dist/binaries/yoga-wasm-base64-esm.js
|
|
127
55
|
var loadYoga = (() => {
|
|
@@ -1737,186 +1665,336 @@ function wrapAssembly(lib) {
|
|
|
1737
1665
|
var Yoga = wrapAssembly(await yoga_wasm_base64_esm_default());
|
|
1738
1666
|
var src_default = Yoga;
|
|
1739
1667
|
|
|
1740
|
-
// src/lib/
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1668
|
+
// src/lib/border.ts
|
|
1669
|
+
var BorderChars = {
|
|
1670
|
+
single: {
|
|
1671
|
+
topLeft: "\u250C",
|
|
1672
|
+
topRight: "\u2510",
|
|
1673
|
+
bottomLeft: "\u2514",
|
|
1674
|
+
bottomRight: "\u2518",
|
|
1675
|
+
horizontal: "\u2500",
|
|
1676
|
+
vertical: "\u2502",
|
|
1677
|
+
topT: "\u252C",
|
|
1678
|
+
bottomT: "\u2534",
|
|
1679
|
+
leftT: "\u251C",
|
|
1680
|
+
rightT: "\u2524",
|
|
1681
|
+
cross: "\u253C"
|
|
1682
|
+
},
|
|
1683
|
+
double: {
|
|
1684
|
+
topLeft: "\u2554",
|
|
1685
|
+
topRight: "\u2557",
|
|
1686
|
+
bottomLeft: "\u255A",
|
|
1687
|
+
bottomRight: "\u255D",
|
|
1688
|
+
horizontal: "\u2550",
|
|
1689
|
+
vertical: "\u2551",
|
|
1690
|
+
topT: "\u2566",
|
|
1691
|
+
bottomT: "\u2569",
|
|
1692
|
+
leftT: "\u2560",
|
|
1693
|
+
rightT: "\u2563",
|
|
1694
|
+
cross: "\u256C"
|
|
1695
|
+
},
|
|
1696
|
+
rounded: {
|
|
1697
|
+
topLeft: "\u256D",
|
|
1698
|
+
topRight: "\u256E",
|
|
1699
|
+
bottomLeft: "\u2570",
|
|
1700
|
+
bottomRight: "\u256F",
|
|
1701
|
+
horizontal: "\u2500",
|
|
1702
|
+
vertical: "\u2502",
|
|
1703
|
+
topT: "\u252C",
|
|
1704
|
+
bottomT: "\u2534",
|
|
1705
|
+
leftT: "\u251C",
|
|
1706
|
+
rightT: "\u2524",
|
|
1707
|
+
cross: "\u253C"
|
|
1708
|
+
},
|
|
1709
|
+
heavy: {
|
|
1710
|
+
topLeft: "\u250F",
|
|
1711
|
+
topRight: "\u2513",
|
|
1712
|
+
bottomLeft: "\u2517",
|
|
1713
|
+
bottomRight: "\u251B",
|
|
1714
|
+
horizontal: "\u2501",
|
|
1715
|
+
vertical: "\u2503",
|
|
1716
|
+
topT: "\u2533",
|
|
1717
|
+
bottomT: "\u253B",
|
|
1718
|
+
leftT: "\u2523",
|
|
1719
|
+
rightT: "\u252B",
|
|
1720
|
+
cross: "\u254B"
|
|
1775
1721
|
}
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1722
|
+
};
|
|
1723
|
+
function getBorderFromSides(sides) {
|
|
1724
|
+
const result = [];
|
|
1725
|
+
if (sides.top)
|
|
1726
|
+
result.push("top");
|
|
1727
|
+
if (sides.right)
|
|
1728
|
+
result.push("right");
|
|
1729
|
+
if (sides.bottom)
|
|
1730
|
+
result.push("bottom");
|
|
1731
|
+
if (sides.left)
|
|
1732
|
+
result.push("left");
|
|
1733
|
+
return result.length > 0 ? result : false;
|
|
1734
|
+
}
|
|
1735
|
+
function getBorderSides(border) {
|
|
1736
|
+
return border === true ? { top: true, right: true, bottom: true, left: true } : Array.isArray(border) ? {
|
|
1737
|
+
top: border.includes("top"),
|
|
1738
|
+
right: border.includes("right"),
|
|
1739
|
+
bottom: border.includes("bottom"),
|
|
1740
|
+
left: border.includes("left")
|
|
1741
|
+
} : { top: false, right: false, bottom: false, left: false };
|
|
1742
|
+
}
|
|
1743
|
+
function borderCharsToArray(chars) {
|
|
1744
|
+
const array = new Uint32Array(11);
|
|
1745
|
+
array[0] = chars.topLeft.codePointAt(0);
|
|
1746
|
+
array[1] = chars.topRight.codePointAt(0);
|
|
1747
|
+
array[2] = chars.bottomLeft.codePointAt(0);
|
|
1748
|
+
array[3] = chars.bottomRight.codePointAt(0);
|
|
1749
|
+
array[4] = chars.horizontal.codePointAt(0);
|
|
1750
|
+
array[5] = chars.vertical.codePointAt(0);
|
|
1751
|
+
array[6] = chars.topT.codePointAt(0);
|
|
1752
|
+
array[7] = chars.bottomT.codePointAt(0);
|
|
1753
|
+
array[8] = chars.leftT.codePointAt(0);
|
|
1754
|
+
array[9] = chars.rightT.codePointAt(0);
|
|
1755
|
+
array[10] = chars.cross.codePointAt(0);
|
|
1756
|
+
return array;
|
|
1757
|
+
}
|
|
1758
|
+
var BorderCharArrays = {
|
|
1759
|
+
single: borderCharsToArray(BorderChars.single),
|
|
1760
|
+
double: borderCharsToArray(BorderChars.double),
|
|
1761
|
+
rounded: borderCharsToArray(BorderChars.rounded),
|
|
1762
|
+
heavy: borderCharsToArray(BorderChars.heavy)
|
|
1763
|
+
};
|
|
1764
|
+
|
|
1765
|
+
// src/lib/parse.keypress.ts
|
|
1766
|
+
import { Buffer } from "buffer";
|
|
1767
|
+
|
|
1768
|
+
// src/lib/parse.keypress-kitty.ts
|
|
1769
|
+
var kittyKeyMap = {
|
|
1770
|
+
27: "escape",
|
|
1771
|
+
9: "tab",
|
|
1772
|
+
13: "enter",
|
|
1773
|
+
127: "backspace",
|
|
1774
|
+
57344: "escape",
|
|
1775
|
+
57345: "enter",
|
|
1776
|
+
57346: "tab",
|
|
1777
|
+
57347: "backspace",
|
|
1778
|
+
57348: "insert",
|
|
1779
|
+
57349: "delete",
|
|
1780
|
+
57350: "left",
|
|
1781
|
+
57351: "right",
|
|
1782
|
+
57352: "up",
|
|
1783
|
+
57353: "down",
|
|
1784
|
+
57354: "pageup",
|
|
1785
|
+
57355: "pagedown",
|
|
1786
|
+
57356: "home",
|
|
1787
|
+
57357: "end",
|
|
1788
|
+
57364: "f1",
|
|
1789
|
+
57365: "f2",
|
|
1790
|
+
57366: "f3",
|
|
1791
|
+
57367: "f4",
|
|
1792
|
+
57368: "f5",
|
|
1793
|
+
57369: "f6",
|
|
1794
|
+
57370: "f7",
|
|
1795
|
+
57371: "f8",
|
|
1796
|
+
57372: "f9",
|
|
1797
|
+
57373: "f10",
|
|
1798
|
+
57374: "f11",
|
|
1799
|
+
57375: "f12",
|
|
1800
|
+
57376: "f13",
|
|
1801
|
+
57377: "f14",
|
|
1802
|
+
57378: "f15",
|
|
1803
|
+
57379: "f16",
|
|
1804
|
+
57380: "f17",
|
|
1805
|
+
57381: "f18",
|
|
1806
|
+
57382: "f19",
|
|
1807
|
+
57383: "f20",
|
|
1808
|
+
57384: "f21",
|
|
1809
|
+
57385: "f22",
|
|
1810
|
+
57386: "f23",
|
|
1811
|
+
57387: "f24",
|
|
1812
|
+
57388: "f25",
|
|
1813
|
+
57389: "f26",
|
|
1814
|
+
57390: "f27",
|
|
1815
|
+
57391: "f28",
|
|
1816
|
+
57392: "f29",
|
|
1817
|
+
57393: "f30",
|
|
1818
|
+
57394: "f31",
|
|
1819
|
+
57395: "f32",
|
|
1820
|
+
57396: "f33",
|
|
1821
|
+
57397: "f34",
|
|
1822
|
+
57398: "f35",
|
|
1823
|
+
57400: "kp0",
|
|
1824
|
+
57401: "kp1",
|
|
1825
|
+
57402: "kp2",
|
|
1826
|
+
57403: "kp3",
|
|
1827
|
+
57404: "kp4",
|
|
1828
|
+
57405: "kp5",
|
|
1829
|
+
57406: "kp6",
|
|
1830
|
+
57407: "kp7",
|
|
1831
|
+
57408: "kp8",
|
|
1832
|
+
57409: "kp9",
|
|
1833
|
+
57410: "kpdecimal",
|
|
1834
|
+
57411: "kpdivide",
|
|
1835
|
+
57412: "kpmultiply",
|
|
1836
|
+
57413: "kpminus",
|
|
1837
|
+
57414: "kpplus",
|
|
1838
|
+
57415: "kpenter",
|
|
1839
|
+
57416: "kpequal",
|
|
1840
|
+
57428: "mediaplay",
|
|
1841
|
+
57429: "mediapause",
|
|
1842
|
+
57430: "mediaplaypause",
|
|
1843
|
+
57431: "mediareverse",
|
|
1844
|
+
57432: "mediastop",
|
|
1845
|
+
57433: "mediafastforward",
|
|
1846
|
+
57434: "mediarewind",
|
|
1847
|
+
57435: "medianext",
|
|
1848
|
+
57436: "mediaprev",
|
|
1849
|
+
57437: "mediarecord",
|
|
1850
|
+
57438: "volumedown",
|
|
1851
|
+
57439: "volumeup",
|
|
1852
|
+
57440: "mute",
|
|
1853
|
+
57441: "leftshift",
|
|
1854
|
+
57442: "leftctrl",
|
|
1855
|
+
57443: "leftalt",
|
|
1856
|
+
57444: "leftsuper",
|
|
1857
|
+
57445: "lefthyper",
|
|
1858
|
+
57446: "leftmeta",
|
|
1859
|
+
57447: "rightshift",
|
|
1860
|
+
57448: "rightctrl",
|
|
1861
|
+
57449: "rightalt",
|
|
1862
|
+
57450: "rightsuper",
|
|
1863
|
+
57451: "righthyper",
|
|
1864
|
+
57452: "rightmeta",
|
|
1865
|
+
57453: "iso_level3_shift",
|
|
1866
|
+
57454: "iso_level5_shift"
|
|
1867
|
+
};
|
|
1868
|
+
function fromKittyMods(mod) {
|
|
1869
|
+
return {
|
|
1870
|
+
shift: !!(mod & 1),
|
|
1871
|
+
alt: !!(mod & 2),
|
|
1872
|
+
ctrl: !!(mod & 4),
|
|
1873
|
+
super: !!(mod & 8),
|
|
1874
|
+
hyper: !!(mod & 16),
|
|
1875
|
+
meta: !!(mod & 32),
|
|
1876
|
+
capsLock: !!(mod & 64),
|
|
1877
|
+
numLock: !!(mod & 128)
|
|
1878
|
+
};
|
|
1879
|
+
}
|
|
1880
|
+
function parseKittyKeyboard(sequence) {
|
|
1881
|
+
const kittyRe = /^\x1b\[([^\x1b]+)u$/;
|
|
1882
|
+
const match = kittyRe.exec(sequence);
|
|
1883
|
+
if (!match)
|
|
1884
|
+
return null;
|
|
1885
|
+
const params = match[1];
|
|
1886
|
+
const fields = params.split(";");
|
|
1887
|
+
if (fields.length < 1)
|
|
1888
|
+
return null;
|
|
1889
|
+
const key = {
|
|
1890
|
+
name: "",
|
|
1891
|
+
ctrl: false,
|
|
1892
|
+
meta: false,
|
|
1893
|
+
shift: false,
|
|
1894
|
+
option: false,
|
|
1895
|
+
number: false,
|
|
1896
|
+
sequence,
|
|
1897
|
+
raw: sequence,
|
|
1898
|
+
eventType: "press",
|
|
1899
|
+
super: false,
|
|
1900
|
+
hyper: false,
|
|
1901
|
+
capsLock: false,
|
|
1902
|
+
numLock: false
|
|
1903
|
+
};
|
|
1904
|
+
let text = "";
|
|
1905
|
+
const field1 = fields[0]?.split(":") || [];
|
|
1906
|
+
const codepointStr = field1[0];
|
|
1907
|
+
if (!codepointStr)
|
|
1908
|
+
return null;
|
|
1909
|
+
const codepoint = parseInt(codepointStr, 10);
|
|
1910
|
+
if (isNaN(codepoint))
|
|
1911
|
+
return null;
|
|
1912
|
+
let shiftedCodepoint;
|
|
1913
|
+
let baseCodepoint;
|
|
1914
|
+
if (field1[1]) {
|
|
1915
|
+
const shifted = parseInt(field1[1], 10);
|
|
1916
|
+
if (!isNaN(shifted) && shifted > 0 && shifted <= 1114111) {
|
|
1917
|
+
shiftedCodepoint = shifted;
|
|
1788
1918
|
}
|
|
1789
|
-
return Math.floor(this.parent.yogaNode.getComputedHeight() * parseInt(height) / 100);
|
|
1790
1919
|
}
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
this.yogaNode.setWidthAuto();
|
|
1796
|
-
} else {
|
|
1797
|
-
this.yogaNode.setWidth(parsedWidth);
|
|
1920
|
+
if (field1[2]) {
|
|
1921
|
+
const base = parseInt(field1[2], 10);
|
|
1922
|
+
if (!isNaN(base) && base > 0 && base <= 1114111) {
|
|
1923
|
+
baseCodepoint = base;
|
|
1798
1924
|
}
|
|
1799
1925
|
}
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1926
|
+
const knownKey = kittyKeyMap[codepoint];
|
|
1927
|
+
if (knownKey) {
|
|
1928
|
+
key.name = knownKey;
|
|
1929
|
+
key.code = `[${codepoint}u`;
|
|
1930
|
+
} else {
|
|
1931
|
+
if (codepoint > 0 && codepoint <= 1114111) {
|
|
1932
|
+
const char = String.fromCodePoint(codepoint);
|
|
1933
|
+
key.name = char;
|
|
1934
|
+
if (baseCodepoint) {
|
|
1935
|
+
key.baseCode = baseCodepoint;
|
|
1936
|
+
}
|
|
1805
1937
|
} else {
|
|
1806
|
-
|
|
1938
|
+
return null;
|
|
1807
1939
|
}
|
|
1808
1940
|
}
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1941
|
+
if (fields[1]) {
|
|
1942
|
+
const field2 = fields[1].split(":");
|
|
1943
|
+
const modifierStr = field2[0];
|
|
1944
|
+
const eventTypeStr = field2[1];
|
|
1945
|
+
if (modifierStr) {
|
|
1946
|
+
const modifierMask = parseInt(modifierStr, 10);
|
|
1947
|
+
if (!isNaN(modifierMask) && modifierMask > 1) {
|
|
1948
|
+
const mods = fromKittyMods(modifierMask - 1);
|
|
1949
|
+
key.shift = mods.shift;
|
|
1950
|
+
key.ctrl = mods.ctrl;
|
|
1951
|
+
key.meta = mods.alt || mods.meta;
|
|
1952
|
+
key.option = mods.alt;
|
|
1953
|
+
key.super = mods.super;
|
|
1954
|
+
key.hyper = mods.hyper;
|
|
1955
|
+
key.capsLock = mods.capsLock;
|
|
1956
|
+
key.numLock = mods.numLock;
|
|
1957
|
+
}
|
|
1822
1958
|
}
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
return false;
|
|
1959
|
+
if (eventTypeStr === "1" || !eventTypeStr) {
|
|
1960
|
+
key.eventType = "press";
|
|
1961
|
+
} else if (eventTypeStr === "2") {
|
|
1962
|
+
key.eventType = "repeat";
|
|
1963
|
+
} else if (eventTypeStr === "3") {
|
|
1964
|
+
key.eventType = "release";
|
|
1965
|
+
} else {
|
|
1966
|
+
key.eventType = "press";
|
|
1832
1967
|
}
|
|
1833
|
-
this.children.splice(index, 1);
|
|
1834
|
-
this.yogaNode.removeChild(childNode.yogaNode);
|
|
1835
|
-
childNode.parent = null;
|
|
1836
|
-
return true;
|
|
1837
1968
|
}
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
childNode.parent = null;
|
|
1846
|
-
return childNode;
|
|
1847
|
-
}
|
|
1848
|
-
moveChild(childNode, newIndex) {
|
|
1849
|
-
const currentIndex = this.children.indexOf(childNode);
|
|
1850
|
-
if (currentIndex === -1) {
|
|
1851
|
-
throw new Error("Node is not a child of this parent");
|
|
1852
|
-
}
|
|
1853
|
-
const boundedNewIndex = Math.max(0, Math.min(newIndex, this.children.length - 1));
|
|
1854
|
-
if (currentIndex === boundedNewIndex) {
|
|
1855
|
-
return currentIndex;
|
|
1856
|
-
}
|
|
1857
|
-
this.children.splice(currentIndex, 1);
|
|
1858
|
-
this.children.splice(boundedNewIndex, 0, childNode);
|
|
1859
|
-
this.yogaNode.removeChild(childNode.yogaNode);
|
|
1860
|
-
this.yogaNode.insertChild(childNode.yogaNode, boundedNewIndex);
|
|
1861
|
-
return boundedNewIndex;
|
|
1862
|
-
}
|
|
1863
|
-
insertChild(childNode, index) {
|
|
1864
|
-
if (childNode.parent) {
|
|
1865
|
-
childNode.parent.removeChild(childNode);
|
|
1866
|
-
}
|
|
1867
|
-
childNode.parent = this;
|
|
1868
|
-
const boundedIndex = Math.max(0, Math.min(index, this.children.length));
|
|
1869
|
-
this.children.splice(boundedIndex, 0, childNode);
|
|
1870
|
-
this.yogaNode.insertChild(childNode.yogaNode, boundedIndex);
|
|
1871
|
-
try {
|
|
1872
|
-
childNode.yogaNode.setWidth(childNode.parseWidth(childNode._width));
|
|
1873
|
-
childNode.yogaNode.setHeight(childNode.parseHeight(childNode._height));
|
|
1874
|
-
} catch (e) {
|
|
1875
|
-
console.error("Error setting width and height", e);
|
|
1969
|
+
if (fields[2]) {
|
|
1970
|
+
const codepoints = fields[2].split(":");
|
|
1971
|
+
for (const cpStr of codepoints) {
|
|
1972
|
+
const cp = parseInt(cpStr, 10);
|
|
1973
|
+
if (!isNaN(cp) && cp > 0 && cp <= 1114111) {
|
|
1974
|
+
text += String.fromCodePoint(cp);
|
|
1975
|
+
}
|
|
1876
1976
|
}
|
|
1877
|
-
return boundedIndex;
|
|
1878
1977
|
}
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1978
|
+
if (text === "") {
|
|
1979
|
+
const isPrintable = key.name.length > 0 && !kittyKeyMap[codepoint];
|
|
1980
|
+
if (isPrintable) {
|
|
1981
|
+
if (key.shift && shiftedCodepoint) {
|
|
1982
|
+
text = String.fromCodePoint(shiftedCodepoint);
|
|
1983
|
+
} else {
|
|
1984
|
+
text = key.name;
|
|
1985
|
+
}
|
|
1885
1986
|
}
|
|
1886
|
-
return this.children[index];
|
|
1887
|
-
}
|
|
1888
|
-
setMetadata(key, value) {
|
|
1889
|
-
this.metadata[key] = value;
|
|
1890
|
-
}
|
|
1891
|
-
getMetadata(key) {
|
|
1892
|
-
return this.metadata[key];
|
|
1893
1987
|
}
|
|
1894
|
-
|
|
1895
|
-
|
|
1988
|
+
if (key.name === " " && key.shift && !key.ctrl && !key.meta) {
|
|
1989
|
+
text = " ";
|
|
1896
1990
|
}
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
}
|
|
1900
|
-
destroy() {
|
|
1901
|
-
if (this._destroyed) {
|
|
1902
|
-
return;
|
|
1903
|
-
}
|
|
1904
|
-
if (this.parent) {
|
|
1905
|
-
this.parent.removeChild(this);
|
|
1906
|
-
}
|
|
1907
|
-
try {
|
|
1908
|
-
this.yogaNode.free();
|
|
1909
|
-
} catch (e) {}
|
|
1910
|
-
this._destroyed = true;
|
|
1991
|
+
if (text) {
|
|
1992
|
+
key.sequence = text;
|
|
1911
1993
|
}
|
|
1912
|
-
|
|
1913
|
-
function createTrackedNode(metadata = {}, yogaConfig) {
|
|
1914
|
-
const yogaNode = src_default.Node.create(yogaConfig);
|
|
1915
|
-
return new TrackedNode(yogaNode, metadata);
|
|
1994
|
+
return key;
|
|
1916
1995
|
}
|
|
1917
1996
|
|
|
1918
1997
|
// src/lib/parse.keypress.ts
|
|
1919
|
-
import { Buffer } from "buffer";
|
|
1920
1998
|
var metaKeyCodeRe = /^(?:\x1b)([a-zA-Z0-9])$/;
|
|
1921
1999
|
var fnKeyRe = /^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/;
|
|
1922
2000
|
var keyName = {
|
|
@@ -2000,7 +2078,7 @@ var isShiftKey = (code) => {
|
|
|
2000
2078
|
var isCtrlKey = (code) => {
|
|
2001
2079
|
return ["Oa", "Ob", "Oc", "Od", "Oe", "[2^", "[3^", "[5^", "[6^", "[7^", "[8^"].includes(code);
|
|
2002
2080
|
};
|
|
2003
|
-
var parseKeypress = (s = "") => {
|
|
2081
|
+
var parseKeypress = (s = "", options = {}) => {
|
|
2004
2082
|
let parts;
|
|
2005
2083
|
if (Buffer.isBuffer(s)) {
|
|
2006
2084
|
if (s[0] > 127 && s[1] === undefined) {
|
|
@@ -2022,9 +2100,16 @@ var parseKeypress = (s = "") => {
|
|
|
2022
2100
|
option: false,
|
|
2023
2101
|
number: false,
|
|
2024
2102
|
sequence: s,
|
|
2025
|
-
raw: s
|
|
2103
|
+
raw: s,
|
|
2104
|
+
eventType: "press"
|
|
2026
2105
|
};
|
|
2027
2106
|
key.sequence = key.sequence || s || key.name;
|
|
2107
|
+
if (options.useKittyKeyboard && /^\x1b\[.*u$/.test(s)) {
|
|
2108
|
+
const kittyResult = parseKittyKeyboard(s);
|
|
2109
|
+
if (kittyResult) {
|
|
2110
|
+
return kittyResult;
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2028
2113
|
if (s === "\r") {
|
|
2029
2114
|
key.name = "return";
|
|
2030
2115
|
} else if (s === `
|
|
@@ -2064,15 +2149,21 @@ var parseKeypress = (s = "") => {
|
|
|
2064
2149
|
key.option = true;
|
|
2065
2150
|
}
|
|
2066
2151
|
const code = [parts[1], parts[2], parts[4], parts[6]].filter(Boolean).join("");
|
|
2067
|
-
const modifier = (parts[3] || parts[5] || 1) - 1;
|
|
2152
|
+
const modifier = parseInt(parts[3] || parts[5] || "1", 10) - 1;
|
|
2068
2153
|
key.ctrl = !!(modifier & 4);
|
|
2069
2154
|
key.meta = !!(modifier & 10);
|
|
2070
2155
|
key.shift = !!(modifier & 1);
|
|
2071
2156
|
key.option = !!(modifier & 2);
|
|
2072
2157
|
key.code = code;
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2158
|
+
const keyNameResult = keyName[code];
|
|
2159
|
+
if (keyNameResult) {
|
|
2160
|
+
key.name = keyNameResult;
|
|
2161
|
+
key.shift = isShiftKey(code) || key.shift;
|
|
2162
|
+
key.ctrl = isCtrlKey(code) || key.ctrl;
|
|
2163
|
+
} else {
|
|
2164
|
+
key.name = "";
|
|
2165
|
+
key.code = undefined;
|
|
2166
|
+
}
|
|
2076
2167
|
} else if (s === "\x1B[3~") {
|
|
2077
2168
|
key.name = "delete";
|
|
2078
2169
|
key.meta = false;
|
|
@@ -2082,7 +2173,7 @@ var parseKeypress = (s = "") => {
|
|
|
2082
2173
|
};
|
|
2083
2174
|
|
|
2084
2175
|
// src/lib/KeyHandler.ts
|
|
2085
|
-
import { EventEmitter
|
|
2176
|
+
import { EventEmitter } from "events";
|
|
2086
2177
|
|
|
2087
2178
|
// src/singleton.ts
|
|
2088
2179
|
var singletonCacheSymbol = Symbol.for("@opentui/core/singleton");
|
|
@@ -2095,27 +2186,44 @@ function singleton(key, factory) {
|
|
|
2095
2186
|
}
|
|
2096
2187
|
|
|
2097
2188
|
// src/lib/KeyHandler.ts
|
|
2098
|
-
class KeyHandler extends
|
|
2099
|
-
|
|
2189
|
+
class KeyHandler extends EventEmitter {
|
|
2190
|
+
stdin;
|
|
2191
|
+
useKittyKeyboard;
|
|
2192
|
+
constructor(stdin, useKittyKeyboard = false) {
|
|
2100
2193
|
super();
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2194
|
+
this.stdin = stdin || process.stdin;
|
|
2195
|
+
this.useKittyKeyboard = useKittyKeyboard;
|
|
2196
|
+
if (this.stdin.setRawMode) {
|
|
2197
|
+
this.stdin.setRawMode(true);
|
|
2198
|
+
}
|
|
2199
|
+
this.stdin.resume();
|
|
2200
|
+
this.stdin.setEncoding("utf8");
|
|
2201
|
+
this.stdin.on("data", (key) => {
|
|
2202
|
+
const parsedKey = parseKeypress(key, { useKittyKeyboard: this.useKittyKeyboard });
|
|
2203
|
+
switch (parsedKey.eventType) {
|
|
2204
|
+
case "press":
|
|
2205
|
+
this.emit("keypress", parsedKey);
|
|
2206
|
+
break;
|
|
2207
|
+
case "repeat":
|
|
2208
|
+
this.emit("keyrepeat", parsedKey);
|
|
2209
|
+
break;
|
|
2210
|
+
case "release":
|
|
2211
|
+
this.emit("keyrelease", parsedKey);
|
|
2212
|
+
break;
|
|
2213
|
+
default:
|
|
2214
|
+
this.emit("keypress", parsedKey);
|
|
2215
|
+
break;
|
|
2216
|
+
}
|
|
2109
2217
|
});
|
|
2110
2218
|
}
|
|
2111
2219
|
destroy() {
|
|
2112
|
-
|
|
2220
|
+
this.stdin.removeAllListeners("data");
|
|
2113
2221
|
}
|
|
2114
2222
|
}
|
|
2115
2223
|
var keyHandler = null;
|
|
2116
|
-
function getKeyHandler() {
|
|
2224
|
+
function getKeyHandler(useKittyKeyboard = false) {
|
|
2117
2225
|
if (!keyHandler) {
|
|
2118
|
-
keyHandler = singleton("KeyHandler", () => new KeyHandler);
|
|
2226
|
+
keyHandler = singleton("KeyHandler", () => new KeyHandler(process.stdin, useKittyKeyboard));
|
|
2119
2227
|
}
|
|
2120
2228
|
return keyHandler;
|
|
2121
2229
|
}
|
|
@@ -3936,6 +4044,31 @@ function createTextAttributes({
|
|
|
3936
4044
|
attributes |= TextAttributes.STRIKETHROUGH;
|
|
3937
4045
|
return attributes;
|
|
3938
4046
|
}
|
|
4047
|
+
function visualizeRenderableTree(renderable, maxDepth = 10) {
|
|
4048
|
+
function buildTreeLines(node, prefix = "", parentPrefix = "", isLastChild = true, depth = 0) {
|
|
4049
|
+
if (depth >= maxDepth) {
|
|
4050
|
+
return [`${prefix}${node.id} ... (max depth reached)`];
|
|
4051
|
+
}
|
|
4052
|
+
const lines = [];
|
|
4053
|
+
const children = node.getChildren();
|
|
4054
|
+
lines.push(`${prefix}${node.id}`);
|
|
4055
|
+
if (children.length > 0) {
|
|
4056
|
+
const lastChildIndex = children.length - 1;
|
|
4057
|
+
children.forEach((child, index) => {
|
|
4058
|
+
const childIsLast = index === lastChildIndex;
|
|
4059
|
+
const connector = childIsLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
4060
|
+
const childPrefix = parentPrefix + (isLastChild ? " " : "\u2502 ");
|
|
4061
|
+
const childLines = buildTreeLines(child, childPrefix + connector, childPrefix, childIsLast, depth + 1);
|
|
4062
|
+
lines.push(...childLines);
|
|
4063
|
+
});
|
|
4064
|
+
}
|
|
4065
|
+
return lines;
|
|
4066
|
+
}
|
|
4067
|
+
const treeLines = buildTreeLines(renderable);
|
|
4068
|
+
console.log(`Renderable Tree:
|
|
4069
|
+
` + treeLines.join(`
|
|
4070
|
+
`));
|
|
4071
|
+
}
|
|
3939
4072
|
|
|
3940
4073
|
// src/lib/styled-text.ts
|
|
3941
4074
|
var BrandedStyledText = Symbol.for("@opentui/core/StyledText");
|
|
@@ -4713,10 +4846,16 @@ class OptimizedBuffer {
|
|
|
4713
4846
|
_height;
|
|
4714
4847
|
respectAlpha = false;
|
|
4715
4848
|
_rawBuffers = null;
|
|
4849
|
+
_destroyed = false;
|
|
4716
4850
|
get ptr() {
|
|
4717
4851
|
return this.bufferPtr;
|
|
4718
4852
|
}
|
|
4853
|
+
guard() {
|
|
4854
|
+
if (this._destroyed)
|
|
4855
|
+
throw new Error(`Buffer ${this.id} is destroyed`);
|
|
4856
|
+
}
|
|
4719
4857
|
get buffers() {
|
|
4858
|
+
this.guard();
|
|
4720
4859
|
if (this._rawBuffers === null) {
|
|
4721
4860
|
const size = this._width * this._height;
|
|
4722
4861
|
const charPtr = this.lib.bufferGetCharPtr(this.bufferPtr);
|
|
@@ -4746,9 +4885,6 @@ class OptimizedBuffer {
|
|
|
4746
4885
|
const id = options.id && options.id.trim() !== "" ? options.id : "unnamed buffer";
|
|
4747
4886
|
return lib.createOptimizedBuffer(width, height, widthMethod, respectAlpha, id);
|
|
4748
4887
|
}
|
|
4749
|
-
coordsToIndex(x, y) {
|
|
4750
|
-
return y * this._width + x;
|
|
4751
|
-
}
|
|
4752
4888
|
get width() {
|
|
4753
4889
|
return this._width;
|
|
4754
4890
|
}
|
|
@@ -4756,22 +4892,35 @@ class OptimizedBuffer {
|
|
|
4756
4892
|
return this._height;
|
|
4757
4893
|
}
|
|
4758
4894
|
setRespectAlpha(respectAlpha) {
|
|
4895
|
+
this.guard();
|
|
4759
4896
|
this.lib.bufferSetRespectAlpha(this.bufferPtr, respectAlpha);
|
|
4760
4897
|
this.respectAlpha = respectAlpha;
|
|
4761
4898
|
}
|
|
4762
4899
|
getNativeId() {
|
|
4900
|
+
this.guard();
|
|
4763
4901
|
return this.lib.bufferGetId(this.bufferPtr);
|
|
4764
4902
|
}
|
|
4903
|
+
getRealCharBytes(addLineBreaks = false) {
|
|
4904
|
+
this.guard();
|
|
4905
|
+
const realSize = this.lib.bufferGetRealCharSize(this.bufferPtr);
|
|
4906
|
+
const outputBuffer = new Uint8Array(realSize);
|
|
4907
|
+
const bytesWritten = this.lib.bufferWriteResolvedChars(this.bufferPtr, outputBuffer, addLineBreaks);
|
|
4908
|
+
return outputBuffer.slice(0, bytesWritten);
|
|
4909
|
+
}
|
|
4765
4910
|
clear(bg2 = RGBA.fromValues(0, 0, 0, 1)) {
|
|
4911
|
+
this.guard();
|
|
4766
4912
|
this.lib.bufferClear(this.bufferPtr, bg2);
|
|
4767
4913
|
}
|
|
4768
4914
|
setCell(x, y, char, fg2, bg2, attributes = 0) {
|
|
4915
|
+
this.guard();
|
|
4769
4916
|
this.lib.bufferSetCell(this.bufferPtr, x, y, char, fg2, bg2, attributes);
|
|
4770
4917
|
}
|
|
4771
4918
|
setCellWithAlphaBlending(x, y, char, fg2, bg2, attributes = 0) {
|
|
4919
|
+
this.guard();
|
|
4772
4920
|
this.lib.bufferSetCellWithAlphaBlending(this.bufferPtr, x, y, char, fg2, bg2, attributes);
|
|
4773
4921
|
}
|
|
4774
4922
|
drawText(text, x, y, fg2, bg2, attributes = 0, selection2) {
|
|
4923
|
+
this.guard();
|
|
4775
4924
|
if (!selection2) {
|
|
4776
4925
|
this.lib.bufferDrawText(this.bufferPtr, text, x, y, fg2, bg2, attributes);
|
|
4777
4926
|
return;
|
|
@@ -4804,21 +4953,29 @@ class OptimizedBuffer {
|
|
|
4804
4953
|
this.lib.bufferFillRect(this.bufferPtr, x, y, width, height, bg2);
|
|
4805
4954
|
}
|
|
4806
4955
|
drawFrameBuffer(destX, destY, frameBuffer, sourceX, sourceY, sourceWidth, sourceHeight) {
|
|
4956
|
+
this.guard();
|
|
4807
4957
|
this.lib.drawFrameBuffer(this.bufferPtr, destX, destY, frameBuffer.ptr, sourceX, sourceY, sourceWidth, sourceHeight);
|
|
4808
4958
|
}
|
|
4809
4959
|
destroy() {
|
|
4960
|
+
if (this._destroyed)
|
|
4961
|
+
return;
|
|
4962
|
+
this._destroyed = true;
|
|
4810
4963
|
this.lib.destroyOptimizedBuffer(this.bufferPtr);
|
|
4811
4964
|
}
|
|
4812
4965
|
drawTextBuffer(textBuffer, x, y, clipRect) {
|
|
4966
|
+
this.guard();
|
|
4813
4967
|
this.lib.bufferDrawTextBuffer(this.bufferPtr, textBuffer.ptr, x, y, clipRect);
|
|
4814
4968
|
}
|
|
4815
4969
|
drawSuperSampleBuffer(x, y, pixelDataPtr, pixelDataLength, format, alignedBytesPerRow) {
|
|
4970
|
+
this.guard();
|
|
4816
4971
|
this.lib.bufferDrawSuperSampleBuffer(this.bufferPtr, x, y, pixelDataPtr, pixelDataLength, format, alignedBytesPerRow);
|
|
4817
4972
|
}
|
|
4818
4973
|
drawPackedBuffer(dataPtr, dataLen, posX, posY, terminalWidthCells, terminalHeightCells) {
|
|
4974
|
+
this.guard();
|
|
4819
4975
|
this.lib.bufferDrawPackedBuffer(this.bufferPtr, dataPtr, dataLen, posX, posY, terminalWidthCells, terminalHeightCells);
|
|
4820
4976
|
}
|
|
4821
4977
|
resize(width, height) {
|
|
4978
|
+
this.guard();
|
|
4822
4979
|
if (this._width === width && this._height === height)
|
|
4823
4980
|
return;
|
|
4824
4981
|
this._width = width;
|
|
@@ -4827,18 +4984,22 @@ class OptimizedBuffer {
|
|
|
4827
4984
|
this.lib.bufferResize(this.bufferPtr, width, height);
|
|
4828
4985
|
}
|
|
4829
4986
|
drawBox(options) {
|
|
4987
|
+
this.guard();
|
|
4830
4988
|
const style = options.borderStyle || "single";
|
|
4831
4989
|
const borderChars = options.customBorderChars ?? BorderCharArrays[style];
|
|
4832
4990
|
const packedOptions = packDrawOptions(options.border, options.shouldFill ?? false, options.titleAlignment || "left");
|
|
4833
4991
|
this.lib.bufferDrawBox(this.bufferPtr, options.x, options.y, options.width, options.height, borderChars, packedOptions, options.borderColor, options.backgroundColor, options.title ?? null);
|
|
4834
4992
|
}
|
|
4835
4993
|
pushScissorRect(x, y, width, height) {
|
|
4994
|
+
this.guard();
|
|
4836
4995
|
this.lib.bufferPushScissorRect(this.bufferPtr, x, y, width, height);
|
|
4837
4996
|
}
|
|
4838
4997
|
popScissorRect() {
|
|
4998
|
+
this.guard();
|
|
4839
4999
|
this.lib.bufferPopScissorRect(this.bufferPtr);
|
|
4840
5000
|
}
|
|
4841
5001
|
clearScissorRects() {
|
|
5002
|
+
this.guard();
|
|
4842
5003
|
this.lib.bufferClearScissorRects(this.bufferPtr);
|
|
4843
5004
|
}
|
|
4844
5005
|
}
|
|
@@ -4851,17 +5012,17 @@ if (!existsSync(targetLibPath)) {
|
|
|
4851
5012
|
}
|
|
4852
5013
|
function getOpenTUILib(libPath) {
|
|
4853
5014
|
const resolvedLibPath = libPath || targetLibPath;
|
|
4854
|
-
|
|
5015
|
+
const rawSymbols = dlopen(resolvedLibPath, {
|
|
4855
5016
|
setLogCallback: {
|
|
4856
5017
|
args: ["ptr"],
|
|
4857
5018
|
returns: "void"
|
|
4858
5019
|
},
|
|
4859
5020
|
createRenderer: {
|
|
4860
|
-
args: ["u32", "u32"],
|
|
5021
|
+
args: ["u32", "u32", "bool"],
|
|
4861
5022
|
returns: "ptr"
|
|
4862
5023
|
},
|
|
4863
5024
|
destroyRenderer: {
|
|
4864
|
-
args: ["ptr"
|
|
5025
|
+
args: ["ptr"],
|
|
4865
5026
|
returns: "void"
|
|
4866
5027
|
},
|
|
4867
5028
|
setUseThread: {
|
|
@@ -4948,6 +5109,14 @@ function getOpenTUILib(libPath) {
|
|
|
4948
5109
|
args: ["ptr", "ptr", "usize"],
|
|
4949
5110
|
returns: "usize"
|
|
4950
5111
|
},
|
|
5112
|
+
bufferGetRealCharSize: {
|
|
5113
|
+
args: ["ptr"],
|
|
5114
|
+
returns: "u32"
|
|
5115
|
+
},
|
|
5116
|
+
bufferWriteResolvedChars: {
|
|
5117
|
+
args: ["ptr", "ptr", "usize", "bool"],
|
|
5118
|
+
returns: "u32"
|
|
5119
|
+
},
|
|
4951
5120
|
bufferDrawText: {
|
|
4952
5121
|
args: ["ptr", "ptr", "u32", "u32", "u32", "ptr", "ptr", "u8"],
|
|
4953
5122
|
returns: "void"
|
|
@@ -5061,25 +5230,17 @@ function getOpenTUILib(libPath) {
|
|
|
5061
5230
|
returns: "void"
|
|
5062
5231
|
},
|
|
5063
5232
|
createTextBuffer: {
|
|
5064
|
-
args: ["
|
|
5233
|
+
args: ["u8"],
|
|
5065
5234
|
returns: "ptr"
|
|
5066
5235
|
},
|
|
5067
5236
|
destroyTextBuffer: {
|
|
5068
5237
|
args: ["ptr"],
|
|
5069
5238
|
returns: "void"
|
|
5070
5239
|
},
|
|
5071
|
-
textBufferGetCharPtr: {
|
|
5072
|
-
args: ["ptr"],
|
|
5073
|
-
returns: "ptr"
|
|
5074
|
-
},
|
|
5075
5240
|
textBufferGetLength: {
|
|
5076
5241
|
args: ["ptr"],
|
|
5077
5242
|
returns: "u32"
|
|
5078
5243
|
},
|
|
5079
|
-
textBufferResize: {
|
|
5080
|
-
args: ["ptr", "u32"],
|
|
5081
|
-
returns: "void"
|
|
5082
|
-
},
|
|
5083
5244
|
textBufferReset: {
|
|
5084
5245
|
args: ["ptr"],
|
|
5085
5246
|
returns: "void"
|
|
@@ -5112,10 +5273,6 @@ function getOpenTUILib(libPath) {
|
|
|
5112
5273
|
args: ["ptr", "ptr", "u32", "ptr", "ptr", "ptr"],
|
|
5113
5274
|
returns: "u32"
|
|
5114
5275
|
},
|
|
5115
|
-
textBufferGetCapacity: {
|
|
5116
|
-
args: ["ptr"],
|
|
5117
|
-
returns: "u32"
|
|
5118
|
-
},
|
|
5119
5276
|
textBufferFinalizeLineInfo: {
|
|
5120
5277
|
args: ["ptr"],
|
|
5121
5278
|
returns: "void"
|
|
@@ -5126,7 +5283,7 @@ function getOpenTUILib(libPath) {
|
|
|
5126
5283
|
},
|
|
5127
5284
|
textBufferGetLineInfoDirect: {
|
|
5128
5285
|
args: ["ptr", "ptr", "ptr"],
|
|
5129
|
-
returns: "
|
|
5286
|
+
returns: "u32"
|
|
5130
5287
|
},
|
|
5131
5288
|
textBufferGetSelectionInfo: {
|
|
5132
5289
|
args: ["ptr"],
|
|
@@ -5164,6 +5321,14 @@ function getOpenTUILib(libPath) {
|
|
|
5164
5321
|
args: ["ptr"],
|
|
5165
5322
|
returns: "usize"
|
|
5166
5323
|
},
|
|
5324
|
+
textBufferSetWrapWidth: {
|
|
5325
|
+
args: ["ptr", "u32"],
|
|
5326
|
+
returns: "void"
|
|
5327
|
+
},
|
|
5328
|
+
textBufferSetWrapMode: {
|
|
5329
|
+
args: ["ptr", "u8"],
|
|
5330
|
+
returns: "void"
|
|
5331
|
+
},
|
|
5167
5332
|
getArenaAllocatedBytes: {
|
|
5168
5333
|
args: [],
|
|
5169
5334
|
returns: "usize"
|
|
@@ -5181,6 +5346,115 @@ function getOpenTUILib(libPath) {
|
|
|
5181
5346
|
returns: "void"
|
|
5182
5347
|
}
|
|
5183
5348
|
});
|
|
5349
|
+
if (process.env.DEBUG_FFI === "true" || process.env.TRACE_FFI === "true") {
|
|
5350
|
+
return {
|
|
5351
|
+
symbols: convertToDebugSymbols(rawSymbols.symbols)
|
|
5352
|
+
};
|
|
5353
|
+
}
|
|
5354
|
+
return rawSymbols;
|
|
5355
|
+
}
|
|
5356
|
+
function convertToDebugSymbols(symbols) {
|
|
5357
|
+
const debugSymbols = {};
|
|
5358
|
+
const traceSymbols = {};
|
|
5359
|
+
let hasTracing = false;
|
|
5360
|
+
Object.entries(symbols).forEach(([key, value]) => {
|
|
5361
|
+
debugSymbols[key] = value;
|
|
5362
|
+
});
|
|
5363
|
+
if (process.env.DEBUG_FFI === "true") {
|
|
5364
|
+
Object.entries(symbols).forEach(([key, value]) => {
|
|
5365
|
+
if (typeof value === "function") {
|
|
5366
|
+
debugSymbols[key] = (...args) => {
|
|
5367
|
+
console.log(`${key}(${args.map((arg) => String(arg)).join(", ")})`);
|
|
5368
|
+
const result = value(...args);
|
|
5369
|
+
console.log(`${key} returned:`, String(result));
|
|
5370
|
+
return result;
|
|
5371
|
+
};
|
|
5372
|
+
}
|
|
5373
|
+
});
|
|
5374
|
+
}
|
|
5375
|
+
if (process.env.TRACE_FFI === "true") {
|
|
5376
|
+
hasTracing = true;
|
|
5377
|
+
Object.entries(symbols).forEach(([key, value]) => {
|
|
5378
|
+
if (typeof value === "function") {
|
|
5379
|
+
traceSymbols[key] = [];
|
|
5380
|
+
const originalFunc = debugSymbols[key];
|
|
5381
|
+
debugSymbols[key] = (...args) => {
|
|
5382
|
+
const start = performance.now();
|
|
5383
|
+
const result = originalFunc(...args);
|
|
5384
|
+
const end = performance.now();
|
|
5385
|
+
traceSymbols[key].push(end - start);
|
|
5386
|
+
return result;
|
|
5387
|
+
};
|
|
5388
|
+
}
|
|
5389
|
+
});
|
|
5390
|
+
}
|
|
5391
|
+
if (hasTracing) {
|
|
5392
|
+
process.on("exit", () => {
|
|
5393
|
+
const allStats = [];
|
|
5394
|
+
for (const [key, timings] of Object.entries(traceSymbols)) {
|
|
5395
|
+
if (!Array.isArray(timings) || timings.length === 0) {
|
|
5396
|
+
continue;
|
|
5397
|
+
}
|
|
5398
|
+
const sortedTimings = [...timings].sort((a, b) => a - b);
|
|
5399
|
+
const count = sortedTimings.length;
|
|
5400
|
+
const total = sortedTimings.reduce((acc, t2) => acc + t2, 0);
|
|
5401
|
+
const average = total / count;
|
|
5402
|
+
const min = sortedTimings[0];
|
|
5403
|
+
const max = sortedTimings[count - 1];
|
|
5404
|
+
const medianIndex = Math.floor(count / 2);
|
|
5405
|
+
const p90Index = Math.floor(count * 0.9);
|
|
5406
|
+
const p99Index = Math.floor(count * 0.99);
|
|
5407
|
+
const median = sortedTimings[medianIndex];
|
|
5408
|
+
const p90 = sortedTimings[Math.min(p90Index, count - 1)];
|
|
5409
|
+
const p99 = sortedTimings[Math.min(p99Index, count - 1)];
|
|
5410
|
+
allStats.push({
|
|
5411
|
+
name: key,
|
|
5412
|
+
count,
|
|
5413
|
+
total,
|
|
5414
|
+
average,
|
|
5415
|
+
min,
|
|
5416
|
+
max,
|
|
5417
|
+
median,
|
|
5418
|
+
p90,
|
|
5419
|
+
p99
|
|
5420
|
+
});
|
|
5421
|
+
}
|
|
5422
|
+
allStats.sort((a, b) => b.total - a.total);
|
|
5423
|
+
console.log(`
|
|
5424
|
+
--- OpenTUI FFI Call Performance ---`);
|
|
5425
|
+
console.log("Sorted by total time spent (descending)");
|
|
5426
|
+
console.log("-------------------------------------------------------------------------------------------------------------------------");
|
|
5427
|
+
if (allStats.length === 0) {
|
|
5428
|
+
console.log("No trace data collected or all symbols had zero calls.");
|
|
5429
|
+
} else {
|
|
5430
|
+
const nameHeader = "Symbol";
|
|
5431
|
+
const callsHeader = "Calls";
|
|
5432
|
+
const totalHeader = "Total (ms)";
|
|
5433
|
+
const avgHeader = "Avg (ms)";
|
|
5434
|
+
const minHeader = "Min (ms)";
|
|
5435
|
+
const maxHeader = "Max (ms)";
|
|
5436
|
+
const medHeader = "Med (ms)";
|
|
5437
|
+
const p90Header = "P90 (ms)";
|
|
5438
|
+
const p99Header = "P99 (ms)";
|
|
5439
|
+
const nameWidth = Math.max(nameHeader.length, ...allStats.map((s) => s.name.length));
|
|
5440
|
+
const countWidth = Math.max(callsHeader.length, ...allStats.map((s) => String(s.count).length));
|
|
5441
|
+
const totalWidth = Math.max(totalHeader.length, ...allStats.map((s) => s.total.toFixed(2).length));
|
|
5442
|
+
const avgWidth = Math.max(avgHeader.length, ...allStats.map((s) => s.average.toFixed(2).length));
|
|
5443
|
+
const minWidth = Math.max(minHeader.length, ...allStats.map((s) => s.min.toFixed(2).length));
|
|
5444
|
+
const maxWidth = Math.max(maxHeader.length, ...allStats.map((s) => s.max.toFixed(2).length));
|
|
5445
|
+
const medianWidth = Math.max(medHeader.length, ...allStats.map((s) => s.median.toFixed(2).length));
|
|
5446
|
+
const p90Width = Math.max(p90Header.length, ...allStats.map((s) => s.p90.toFixed(2).length));
|
|
5447
|
+
const p99Width = Math.max(p99Header.length, ...allStats.map((s) => s.p99.toFixed(2).length));
|
|
5448
|
+
console.log(`${nameHeader.padEnd(nameWidth)} | ${callsHeader.padStart(countWidth)} | ${totalHeader.padStart(totalWidth)} | ${avgHeader.padStart(avgWidth)} | ${minHeader.padStart(minWidth)} | ${maxHeader.padStart(maxWidth)} | ${medHeader.padStart(medianWidth)} | ${p90Header.padStart(p90Width)} | ${p99Header.padStart(p99Width)}`);
|
|
5449
|
+
console.log(`${"-".repeat(nameWidth)}-+-${"-".repeat(countWidth)}-+-${"-".repeat(totalWidth)}-+-${"-".repeat(avgWidth)}-+-${"-".repeat(minWidth)}-+-${"-".repeat(maxWidth)}-+-${"-".repeat(medianWidth)}-+-${"-".repeat(p90Width)}-+-${"-".repeat(p99Width)}`);
|
|
5450
|
+
allStats.forEach((stat) => {
|
|
5451
|
+
console.log(`${stat.name.padEnd(nameWidth)} | ${String(stat.count).padStart(countWidth)} | ${stat.total.toFixed(2).padStart(totalWidth)} | ${stat.average.toFixed(2).padStart(avgWidth)} | ${stat.min.toFixed(2).padStart(minWidth)} | ${stat.max.toFixed(2).padStart(maxWidth)} | ${stat.median.toFixed(2).padStart(medianWidth)} | ${stat.p90.toFixed(2).padStart(p90Width)} | ${stat.p99.toFixed(2).padStart(p99Width)}`);
|
|
5452
|
+
});
|
|
5453
|
+
}
|
|
5454
|
+
console.log("-------------------------------------------------------------------------------------------------------------------------");
|
|
5455
|
+
});
|
|
5456
|
+
}
|
|
5457
|
+
return debugSymbols;
|
|
5184
5458
|
}
|
|
5185
5459
|
var LogLevel2;
|
|
5186
5460
|
((LogLevel3) => {
|
|
@@ -5244,11 +5518,11 @@ class FFIRenderLib {
|
|
|
5244
5518
|
setLogCallback(callbackPtr) {
|
|
5245
5519
|
this.opentui.symbols.setLogCallback(callbackPtr);
|
|
5246
5520
|
}
|
|
5247
|
-
createRenderer(width, height) {
|
|
5248
|
-
return this.opentui.symbols.createRenderer(width, height);
|
|
5521
|
+
createRenderer(width, height, options = { testing: false }) {
|
|
5522
|
+
return this.opentui.symbols.createRenderer(width, height, options.testing);
|
|
5249
5523
|
}
|
|
5250
|
-
destroyRenderer(renderer
|
|
5251
|
-
this.opentui.symbols.destroyRenderer(renderer
|
|
5524
|
+
destroyRenderer(renderer) {
|
|
5525
|
+
this.opentui.symbols.destroyRenderer(renderer);
|
|
5252
5526
|
}
|
|
5253
5527
|
setUseThread(renderer, useThread) {
|
|
5254
5528
|
this.opentui.symbols.setUseThread(renderer, useThread);
|
|
@@ -5324,6 +5598,13 @@ class FFIRenderLib {
|
|
|
5324
5598
|
const len = typeof actualLen === "bigint" ? Number(actualLen) : actualLen;
|
|
5325
5599
|
return this.decoder.decode(outBuffer.slice(0, len));
|
|
5326
5600
|
}
|
|
5601
|
+
bufferGetRealCharSize(buffer) {
|
|
5602
|
+
return this.opentui.symbols.bufferGetRealCharSize(buffer);
|
|
5603
|
+
}
|
|
5604
|
+
bufferWriteResolvedChars(buffer, outputBuffer, addLineBreaks) {
|
|
5605
|
+
const bytesWritten = this.opentui.symbols.bufferWriteResolvedChars(buffer, outputBuffer, outputBuffer.length, addLineBreaks);
|
|
5606
|
+
return typeof bytesWritten === "bigint" ? Number(bytesWritten) : bytesWritten;
|
|
5607
|
+
}
|
|
5327
5608
|
getBufferWidth(buffer) {
|
|
5328
5609
|
return this.opentui.symbols.getBufferWidth(buffer);
|
|
5329
5610
|
}
|
|
@@ -5453,30 +5734,20 @@ class FFIRenderLib {
|
|
|
5453
5734
|
setupTerminal(renderer, useAlternateScreen) {
|
|
5454
5735
|
this.opentui.symbols.setupTerminal(renderer, useAlternateScreen);
|
|
5455
5736
|
}
|
|
5456
|
-
createTextBuffer(
|
|
5737
|
+
createTextBuffer(widthMethod) {
|
|
5457
5738
|
const widthMethodCode = widthMethod === "wcwidth" ? 0 : 1;
|
|
5458
|
-
const bufferPtr = this.opentui.symbols.createTextBuffer(
|
|
5739
|
+
const bufferPtr = this.opentui.symbols.createTextBuffer(widthMethodCode);
|
|
5459
5740
|
if (!bufferPtr) {
|
|
5460
|
-
throw new Error(`Failed to create TextBuffer
|
|
5741
|
+
throw new Error(`Failed to create TextBuffer`);
|
|
5461
5742
|
}
|
|
5462
|
-
return new TextBuffer(this, bufferPtr
|
|
5743
|
+
return new TextBuffer(this, bufferPtr);
|
|
5463
5744
|
}
|
|
5464
5745
|
destroyTextBuffer(buffer) {
|
|
5465
5746
|
this.opentui.symbols.destroyTextBuffer(buffer);
|
|
5466
5747
|
}
|
|
5467
|
-
textBufferGetCharPtr(buffer) {
|
|
5468
|
-
const ptr2 = this.opentui.symbols.textBufferGetCharPtr(buffer);
|
|
5469
|
-
if (!ptr2) {
|
|
5470
|
-
throw new Error("Failed to get TextBuffer char pointer");
|
|
5471
|
-
}
|
|
5472
|
-
return ptr2;
|
|
5473
|
-
}
|
|
5474
5748
|
textBufferGetLength(buffer) {
|
|
5475
5749
|
return this.opentui.symbols.textBufferGetLength(buffer);
|
|
5476
5750
|
}
|
|
5477
|
-
textBufferResize(buffer, newLength) {
|
|
5478
|
-
this.opentui.symbols.textBufferResize(buffer, newLength);
|
|
5479
|
-
}
|
|
5480
5751
|
textBufferReset(buffer) {
|
|
5481
5752
|
this.opentui.symbols.textBufferReset(buffer);
|
|
5482
5753
|
}
|
|
@@ -5507,9 +5778,6 @@ class FFIRenderLib {
|
|
|
5507
5778
|
const attrValue = attributes === null ? null : new Uint8Array([attributes]);
|
|
5508
5779
|
return this.opentui.symbols.textBufferWriteChunk(buffer, textBytes, textBytes.length, fg2 ? fg2.buffer : null, bg2 ? bg2.buffer : null, attrValue);
|
|
5509
5780
|
}
|
|
5510
|
-
textBufferGetCapacity(buffer) {
|
|
5511
|
-
return this.opentui.symbols.textBufferGetCapacity(buffer);
|
|
5512
|
-
}
|
|
5513
5781
|
textBufferFinalizeLineInfo(buffer) {
|
|
5514
5782
|
this.opentui.symbols.textBufferFinalizeLineInfo(buffer);
|
|
5515
5783
|
}
|
|
@@ -5517,7 +5785,7 @@ class FFIRenderLib {
|
|
|
5517
5785
|
return this.opentui.symbols.textBufferGetLineCount(buffer);
|
|
5518
5786
|
}
|
|
5519
5787
|
textBufferGetLineInfoDirect(buffer, lineStartsPtr, lineWidthsPtr) {
|
|
5520
|
-
this.opentui.symbols.textBufferGetLineInfoDirect(buffer, lineStartsPtr, lineWidthsPtr);
|
|
5788
|
+
return this.opentui.symbols.textBufferGetLineInfoDirect(buffer, lineStartsPtr, lineWidthsPtr);
|
|
5521
5789
|
}
|
|
5522
5790
|
textBufferGetSelection(buffer) {
|
|
5523
5791
|
const packedInfo = this.textBufferGetSelectionInfo(buffer);
|
|
@@ -5582,6 +5850,13 @@ class FFIRenderLib {
|
|
|
5582
5850
|
const result = this.opentui.symbols.textBufferGetChunkGroupCount(buffer);
|
|
5583
5851
|
return typeof result === "bigint" ? Number(result) : result;
|
|
5584
5852
|
}
|
|
5853
|
+
textBufferSetWrapWidth(buffer, width) {
|
|
5854
|
+
this.opentui.symbols.textBufferSetWrapWidth(buffer, width);
|
|
5855
|
+
}
|
|
5856
|
+
textBufferSetWrapMode(buffer, mode) {
|
|
5857
|
+
const modeValue = mode === "char" ? 0 : 1;
|
|
5858
|
+
this.opentui.symbols.textBufferSetWrapMode(buffer, modeValue);
|
|
5859
|
+
}
|
|
5585
5860
|
getArenaAllocatedBytes() {
|
|
5586
5861
|
const result = this.opentui.symbols.getArenaAllocatedBytes();
|
|
5587
5862
|
return typeof result === "bigint" ? Number(result) : result;
|
|
@@ -5589,12 +5864,13 @@ class FFIRenderLib {
|
|
|
5589
5864
|
textBufferGetLineInfo(buffer) {
|
|
5590
5865
|
const lineCount = this.textBufferGetLineCount(buffer);
|
|
5591
5866
|
if (lineCount === 0) {
|
|
5592
|
-
return { lineStarts: [], lineWidths: [] };
|
|
5867
|
+
return { lineStarts: [], lineWidths: [], maxLineWidth: 0 };
|
|
5593
5868
|
}
|
|
5594
5869
|
const lineStarts = new Uint32Array(lineCount);
|
|
5595
5870
|
const lineWidths = new Uint32Array(lineCount);
|
|
5596
|
-
this.textBufferGetLineInfoDirect(buffer, ptr(lineStarts), ptr(lineWidths));
|
|
5871
|
+
const maxLineWidth = this.textBufferGetLineInfoDirect(buffer, ptr(lineStarts), ptr(lineWidths));
|
|
5597
5872
|
return {
|
|
5873
|
+
maxLineWidth,
|
|
5598
5874
|
lineStarts: Array.from(lineStarts),
|
|
5599
5875
|
lineWidths: Array.from(lineWidths)
|
|
5600
5876
|
};
|
|
@@ -5669,53 +5945,58 @@ class TextBuffer {
|
|
|
5669
5945
|
lib;
|
|
5670
5946
|
bufferPtr;
|
|
5671
5947
|
_length = 0;
|
|
5672
|
-
_capacity;
|
|
5673
5948
|
_lineInfo;
|
|
5674
|
-
|
|
5949
|
+
_destroyed = false;
|
|
5950
|
+
constructor(lib, ptr2) {
|
|
5675
5951
|
this.lib = lib;
|
|
5676
5952
|
this.bufferPtr = ptr2;
|
|
5677
|
-
this._capacity = capacity;
|
|
5678
5953
|
}
|
|
5679
|
-
static create(
|
|
5954
|
+
static create(widthMethod) {
|
|
5680
5955
|
const lib = resolveRenderLib();
|
|
5681
|
-
return lib.createTextBuffer(
|
|
5956
|
+
return lib.createTextBuffer(widthMethod);
|
|
5957
|
+
}
|
|
5958
|
+
guard() {
|
|
5959
|
+
if (this._destroyed)
|
|
5960
|
+
throw new Error("TextBuffer is destroyed");
|
|
5682
5961
|
}
|
|
5683
5962
|
setStyledText(text) {
|
|
5963
|
+
this.guard();
|
|
5684
5964
|
this.lib.textBufferReset(this.bufferPtr);
|
|
5685
5965
|
this._length = 0;
|
|
5686
5966
|
this._lineInfo = undefined;
|
|
5687
5967
|
for (const chunk of text.chunks) {
|
|
5688
5968
|
const textBytes = this.lib.encoder.encode(chunk.text);
|
|
5689
|
-
|
|
5690
|
-
if (result & 1) {
|
|
5691
|
-
this._capacity = this.lib.textBufferGetCapacity(this.bufferPtr);
|
|
5692
|
-
}
|
|
5969
|
+
this.lib.textBufferWriteChunk(this.bufferPtr, textBytes, chunk.fg || null, chunk.bg || null, chunk.attributes ?? null);
|
|
5693
5970
|
}
|
|
5694
5971
|
this.lib.textBufferFinalizeLineInfo(this.bufferPtr);
|
|
5695
5972
|
this._length = this.lib.textBufferGetLength(this.bufferPtr);
|
|
5696
5973
|
}
|
|
5697
5974
|
setDefaultFg(fg2) {
|
|
5975
|
+
this.guard();
|
|
5698
5976
|
this.lib.textBufferSetDefaultFg(this.bufferPtr, fg2);
|
|
5699
5977
|
}
|
|
5700
5978
|
setDefaultBg(bg2) {
|
|
5979
|
+
this.guard();
|
|
5701
5980
|
this.lib.textBufferSetDefaultBg(this.bufferPtr, bg2);
|
|
5702
5981
|
}
|
|
5703
5982
|
setDefaultAttributes(attributes) {
|
|
5983
|
+
this.guard();
|
|
5704
5984
|
this.lib.textBufferSetDefaultAttributes(this.bufferPtr, attributes);
|
|
5705
5985
|
}
|
|
5706
5986
|
resetDefaults() {
|
|
5987
|
+
this.guard();
|
|
5707
5988
|
this.lib.textBufferResetDefaults(this.bufferPtr);
|
|
5708
5989
|
}
|
|
5709
5990
|
get length() {
|
|
5991
|
+
this.guard();
|
|
5710
5992
|
return this._length;
|
|
5711
5993
|
}
|
|
5712
|
-
get capacity() {
|
|
5713
|
-
return this._capacity;
|
|
5714
|
-
}
|
|
5715
5994
|
get ptr() {
|
|
5995
|
+
this.guard();
|
|
5716
5996
|
return this.bufferPtr;
|
|
5717
5997
|
}
|
|
5718
5998
|
getSelectedText() {
|
|
5999
|
+
this.guard();
|
|
5719
6000
|
if (this._length === 0)
|
|
5720
6001
|
return "";
|
|
5721
6002
|
const selectedBytes = this.lib.getSelectedTextBytes(this.bufferPtr, this.length * 4);
|
|
@@ -5724,6 +6005,7 @@ class TextBuffer {
|
|
|
5724
6005
|
return this.lib.decoder.decode(selectedBytes);
|
|
5725
6006
|
}
|
|
5726
6007
|
getPlainText() {
|
|
6008
|
+
this.guard();
|
|
5727
6009
|
if (this._length === 0)
|
|
5728
6010
|
return "";
|
|
5729
6011
|
const plainBytes = this.lib.getPlainTextBytes(this.bufferPtr, this.length * 4);
|
|
@@ -5732,72 +6014,87 @@ class TextBuffer {
|
|
|
5732
6014
|
return this.lib.decoder.decode(plainBytes);
|
|
5733
6015
|
}
|
|
5734
6016
|
get lineInfo() {
|
|
6017
|
+
this.guard();
|
|
5735
6018
|
if (!this._lineInfo) {
|
|
5736
6019
|
this._lineInfo = this.lib.textBufferGetLineInfo(this.bufferPtr);
|
|
5737
6020
|
}
|
|
5738
6021
|
return this._lineInfo;
|
|
5739
6022
|
}
|
|
5740
6023
|
setSelection(start, end, bgColor, fgColor) {
|
|
6024
|
+
this.guard();
|
|
5741
6025
|
this.lib.textBufferSetSelection(this.bufferPtr, start, end, bgColor || null, fgColor || null);
|
|
5742
6026
|
}
|
|
5743
6027
|
resetSelection() {
|
|
6028
|
+
this.guard();
|
|
5744
6029
|
this.lib.textBufferResetSelection(this.bufferPtr);
|
|
5745
6030
|
}
|
|
5746
6031
|
setLocalSelection(anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
|
|
6032
|
+
this.guard();
|
|
5747
6033
|
return this.lib.textBufferSetLocalSelection(this.bufferPtr, anchorX, anchorY, focusX, focusY, bgColor || null, fgColor || null);
|
|
5748
6034
|
}
|
|
5749
6035
|
resetLocalSelection() {
|
|
6036
|
+
this.guard();
|
|
5750
6037
|
this.lib.textBufferResetLocalSelection(this.bufferPtr);
|
|
5751
6038
|
}
|
|
5752
6039
|
getSelection() {
|
|
6040
|
+
this.guard();
|
|
5753
6041
|
return this.lib.textBufferGetSelection(this.bufferPtr);
|
|
5754
6042
|
}
|
|
5755
6043
|
hasSelection() {
|
|
6044
|
+
this.guard();
|
|
5756
6045
|
return this.getSelection() !== null;
|
|
5757
6046
|
}
|
|
5758
6047
|
insertChunkGroup(index, text, fg2, bg2, attributes) {
|
|
6048
|
+
this.guard();
|
|
5759
6049
|
const textBytes = this.lib.encoder.encode(text);
|
|
5760
6050
|
this.insertEncodedChunkGroup(index, textBytes, fg2, bg2, attributes);
|
|
5761
6051
|
}
|
|
5762
6052
|
insertEncodedChunkGroup(index, textBytes, fg2, bg2, attributes) {
|
|
6053
|
+
this.guard();
|
|
5763
6054
|
this._length = this.lib.textBufferInsertChunkGroup(this.bufferPtr, index, textBytes, fg2 || null, bg2 || null, attributes ?? null);
|
|
5764
6055
|
this._lineInfo = undefined;
|
|
5765
6056
|
}
|
|
5766
6057
|
removeChunkGroup(index) {
|
|
6058
|
+
this.guard();
|
|
5767
6059
|
this._length = this.lib.textBufferRemoveChunkGroup(this.bufferPtr, index);
|
|
5768
6060
|
this._lineInfo = undefined;
|
|
5769
6061
|
}
|
|
5770
6062
|
replaceChunkGroup(index, text, fg2, bg2, attributes) {
|
|
6063
|
+
this.guard();
|
|
5771
6064
|
const textBytes = this.lib.encoder.encode(text);
|
|
5772
6065
|
this.replaceEncodedChunkGroup(index, textBytes, fg2, bg2, attributes);
|
|
5773
6066
|
}
|
|
5774
6067
|
replaceEncodedChunkGroup(index, textBytes, fg2, bg2, attributes) {
|
|
6068
|
+
this.guard();
|
|
5775
6069
|
this._length = this.lib.textBufferReplaceChunkGroup(this.bufferPtr, index, textBytes, fg2 || null, bg2 || null, attributes ?? null);
|
|
5776
6070
|
this._lineInfo = undefined;
|
|
5777
6071
|
}
|
|
5778
6072
|
get chunkGroupCount() {
|
|
6073
|
+
this.guard();
|
|
5779
6074
|
return this.lib.textBufferGetChunkGroupCount(this.bufferPtr);
|
|
5780
6075
|
}
|
|
6076
|
+
setWrapWidth(width) {
|
|
6077
|
+
this.guard();
|
|
6078
|
+
this.lib.textBufferSetWrapWidth(this.bufferPtr, width ?? 0);
|
|
6079
|
+
this._lineInfo = undefined;
|
|
6080
|
+
}
|
|
6081
|
+
setWrapMode(mode) {
|
|
6082
|
+
this.guard();
|
|
6083
|
+
this.lib.textBufferSetWrapMode(this.bufferPtr, mode);
|
|
6084
|
+
this._lineInfo = undefined;
|
|
6085
|
+
}
|
|
5781
6086
|
destroy() {
|
|
6087
|
+
if (this._destroyed)
|
|
6088
|
+
return;
|
|
6089
|
+
this._destroyed = true;
|
|
5782
6090
|
this.lib.destroyTextBuffer(this.bufferPtr);
|
|
5783
6091
|
}
|
|
5784
6092
|
}
|
|
5785
6093
|
|
|
5786
6094
|
// src/Renderable.ts
|
|
5787
|
-
import { EventEmitter as
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
((LayoutEvents2) => {
|
|
5791
|
-
LayoutEvents2["LAYOUT_CHANGED"] = "layout-changed";
|
|
5792
|
-
LayoutEvents2["ADDED"] = "added";
|
|
5793
|
-
LayoutEvents2["REMOVED"] = "removed";
|
|
5794
|
-
LayoutEvents2["RESIZED"] = "resized";
|
|
5795
|
-
})(LayoutEvents ||= {});
|
|
5796
|
-
var RenderableEvents;
|
|
5797
|
-
((RenderableEvents2) => {
|
|
5798
|
-
RenderableEvents2["FOCUSED"] = "focused";
|
|
5799
|
-
RenderableEvents2["BLURRED"] = "blurred";
|
|
5800
|
-
})(RenderableEvents ||= {});
|
|
6095
|
+
import { EventEmitter as EventEmitter2 } from "events";
|
|
6096
|
+
|
|
6097
|
+
// src/lib/renderable.validations.ts
|
|
5801
6098
|
function validateOptions(id, options) {
|
|
5802
6099
|
if (typeof options.width === "number") {
|
|
5803
6100
|
if (options.width < 0) {
|
|
@@ -5869,20 +6166,43 @@ function isSizeType(value) {
|
|
|
5869
6166
|
}
|
|
5870
6167
|
return isValidPercentage(value);
|
|
5871
6168
|
}
|
|
6169
|
+
|
|
6170
|
+
// src/Renderable.ts
|
|
6171
|
+
var BrandedRenderable = Symbol.for("@opentui/core/Renderable");
|
|
6172
|
+
var LayoutEvents;
|
|
6173
|
+
((LayoutEvents2) => {
|
|
6174
|
+
LayoutEvents2["LAYOUT_CHANGED"] = "layout-changed";
|
|
6175
|
+
LayoutEvents2["ADDED"] = "added";
|
|
6176
|
+
LayoutEvents2["REMOVED"] = "removed";
|
|
6177
|
+
LayoutEvents2["RESIZED"] = "resized";
|
|
6178
|
+
})(LayoutEvents ||= {});
|
|
6179
|
+
var RenderableEvents;
|
|
6180
|
+
((RenderableEvents2) => {
|
|
6181
|
+
RenderableEvents2["FOCUSED"] = "focused";
|
|
6182
|
+
RenderableEvents2["BLURRED"] = "blurred";
|
|
6183
|
+
})(RenderableEvents ||= {});
|
|
5872
6184
|
function isRenderable(obj) {
|
|
5873
6185
|
return !!obj?.[BrandedRenderable];
|
|
5874
6186
|
}
|
|
5875
6187
|
|
|
5876
|
-
class BaseRenderable extends
|
|
6188
|
+
class BaseRenderable extends EventEmitter2 {
|
|
5877
6189
|
[BrandedRenderable] = true;
|
|
5878
6190
|
static renderableNumber = 1;
|
|
5879
|
-
|
|
6191
|
+
_id;
|
|
5880
6192
|
num;
|
|
5881
6193
|
_dirty = false;
|
|
6194
|
+
parent = null;
|
|
6195
|
+
_visible = true;
|
|
5882
6196
|
constructor(options) {
|
|
5883
6197
|
super();
|
|
5884
6198
|
this.num = BaseRenderable.renderableNumber++;
|
|
5885
|
-
this.
|
|
6199
|
+
this._id = options.id ?? `renderable-${this.num}`;
|
|
6200
|
+
}
|
|
6201
|
+
get id() {
|
|
6202
|
+
return this._id;
|
|
6203
|
+
}
|
|
6204
|
+
set id(value) {
|
|
6205
|
+
this._id = value;
|
|
5886
6206
|
}
|
|
5887
6207
|
get isDirty() {
|
|
5888
6208
|
return this._dirty;
|
|
@@ -5893,6 +6213,14 @@ class BaseRenderable extends EventEmitter3 {
|
|
|
5893
6213
|
markDirty() {
|
|
5894
6214
|
this._dirty = true;
|
|
5895
6215
|
}
|
|
6216
|
+
destroy() {}
|
|
6217
|
+
destroyRecursively() {}
|
|
6218
|
+
get visible() {
|
|
6219
|
+
return this._visible;
|
|
6220
|
+
}
|
|
6221
|
+
set visible(value) {
|
|
6222
|
+
this._visible = value;
|
|
6223
|
+
}
|
|
5896
6224
|
}
|
|
5897
6225
|
|
|
5898
6226
|
class Renderable extends BaseRenderable {
|
|
@@ -5908,13 +6236,11 @@ class Renderable extends BaseRenderable {
|
|
|
5908
6236
|
_widthValue = 0;
|
|
5909
6237
|
_heightValue = 0;
|
|
5910
6238
|
_zIndex;
|
|
5911
|
-
_visible;
|
|
5912
6239
|
selectable = false;
|
|
5913
6240
|
buffered;
|
|
5914
6241
|
frameBuffer = null;
|
|
5915
6242
|
_focusable = false;
|
|
5916
6243
|
_focused = false;
|
|
5917
|
-
keyHandler = getKeyHandler();
|
|
5918
6244
|
keypressHandler = null;
|
|
5919
6245
|
_live = false;
|
|
5920
6246
|
_liveCount = 0;
|
|
@@ -5922,17 +6248,19 @@ class Renderable extends BaseRenderable {
|
|
|
5922
6248
|
_mouseListener = null;
|
|
5923
6249
|
_mouseListeners = {};
|
|
5924
6250
|
_keyListeners = {};
|
|
5925
|
-
|
|
6251
|
+
yogaNode;
|
|
5926
6252
|
_positionType = "relative";
|
|
5927
6253
|
_overflow = "visible";
|
|
5928
6254
|
_position = {};
|
|
5929
|
-
|
|
5930
|
-
|
|
6255
|
+
renderableMapById = new Map;
|
|
6256
|
+
_childrenInLayoutOrder = [];
|
|
6257
|
+
_childrenInZIndexOrder = [];
|
|
5931
6258
|
needsZIndexSort = false;
|
|
5932
6259
|
parent = null;
|
|
5933
6260
|
childrenPrimarySortDirty = true;
|
|
5934
6261
|
childrenSortedByPrimaryAxis = [];
|
|
5935
6262
|
_newChildren = [];
|
|
6263
|
+
onLifecyclePass = null;
|
|
5936
6264
|
renderBefore;
|
|
5937
6265
|
renderAfter;
|
|
5938
6266
|
constructor(ctx, options) {
|
|
@@ -5955,14 +6283,24 @@ class Renderable extends BaseRenderable {
|
|
|
5955
6283
|
this.buffered = options.buffered ?? false;
|
|
5956
6284
|
this._live = options.live ?? false;
|
|
5957
6285
|
this._liveCount = this._live && this._visible ? 1 : 0;
|
|
5958
|
-
this.
|
|
5959
|
-
this.
|
|
6286
|
+
this.yogaNode = src_default.Node.create();
|
|
6287
|
+
this.yogaNode.setDisplay(this._visible ? Display.Flex : Display.None);
|
|
5960
6288
|
this.setupYogaProperties(options);
|
|
5961
6289
|
this.applyEventOptions(options);
|
|
5962
6290
|
if (this.buffered) {
|
|
5963
6291
|
this.createFrameBuffer();
|
|
5964
6292
|
}
|
|
5965
6293
|
}
|
|
6294
|
+
get id() {
|
|
6295
|
+
return this._id;
|
|
6296
|
+
}
|
|
6297
|
+
set id(value) {
|
|
6298
|
+
if (this.parent) {
|
|
6299
|
+
this.parent.renderableMapById.delete(this.id);
|
|
6300
|
+
this.parent.renderableMapById.set(value, this);
|
|
6301
|
+
}
|
|
6302
|
+
super.id = value;
|
|
6303
|
+
}
|
|
5966
6304
|
get focusable() {
|
|
5967
6305
|
return this._focusable;
|
|
5968
6306
|
}
|
|
@@ -5973,7 +6311,7 @@ class Renderable extends BaseRenderable {
|
|
|
5973
6311
|
return this._visible;
|
|
5974
6312
|
}
|
|
5975
6313
|
get primaryAxis() {
|
|
5976
|
-
const dir = this.
|
|
6314
|
+
const dir = this.yogaNode.getFlexDirection();
|
|
5977
6315
|
return dir === 2 || dir === 3 ? "row" : "column";
|
|
5978
6316
|
}
|
|
5979
6317
|
set visible(value) {
|
|
@@ -5981,7 +6319,7 @@ class Renderable extends BaseRenderable {
|
|
|
5981
6319
|
return;
|
|
5982
6320
|
const wasVisible = this._visible;
|
|
5983
6321
|
this._visible = value;
|
|
5984
|
-
this.
|
|
6322
|
+
this.yogaNode.setDisplay(value ? Display.Flex : Display.None);
|
|
5985
6323
|
if (this._live) {
|
|
5986
6324
|
if (!wasVisible && value) {
|
|
5987
6325
|
this.propagateLiveCount(1);
|
|
@@ -6018,7 +6356,7 @@ class Renderable extends BaseRenderable {
|
|
|
6018
6356
|
this.handleKeyPress(key);
|
|
6019
6357
|
}
|
|
6020
6358
|
};
|
|
6021
|
-
this.
|
|
6359
|
+
this.ctx.keyInput.on("keypress", this.keypressHandler);
|
|
6022
6360
|
this.emit("focused" /* FOCUSED */);
|
|
6023
6361
|
}
|
|
6024
6362
|
blur() {
|
|
@@ -6027,7 +6365,7 @@ class Renderable extends BaseRenderable {
|
|
|
6027
6365
|
this._focused = false;
|
|
6028
6366
|
this.requestRender();
|
|
6029
6367
|
if (this.keypressHandler) {
|
|
6030
|
-
this.
|
|
6368
|
+
this.ctx.keyInput.off("keypress", this.keypressHandler);
|
|
6031
6369
|
this.keypressHandler = null;
|
|
6032
6370
|
}
|
|
6033
6371
|
this.emit("blurred" /* BLURRED */);
|
|
@@ -6055,7 +6393,7 @@ class Renderable extends BaseRenderable {
|
|
|
6055
6393
|
this.parent?.propagateLiveCount(delta);
|
|
6056
6394
|
}
|
|
6057
6395
|
findDescendantById(id) {
|
|
6058
|
-
for (const child of this.
|
|
6396
|
+
for (const child of this._childrenInLayoutOrder) {
|
|
6059
6397
|
if (child.id === id)
|
|
6060
6398
|
return child;
|
|
6061
6399
|
const found = child.findDescendantById(id);
|
|
@@ -6146,7 +6484,7 @@ class Renderable extends BaseRenderable {
|
|
|
6146
6484
|
set width(value) {
|
|
6147
6485
|
if (isDimensionType(value)) {
|
|
6148
6486
|
this._width = value;
|
|
6149
|
-
this.
|
|
6487
|
+
this.yogaNode.setWidth(value);
|
|
6150
6488
|
this.requestRender();
|
|
6151
6489
|
}
|
|
6152
6490
|
}
|
|
@@ -6156,7 +6494,7 @@ class Renderable extends BaseRenderable {
|
|
|
6156
6494
|
set height(value) {
|
|
6157
6495
|
if (isDimensionType(value)) {
|
|
6158
6496
|
this._height = value;
|
|
6159
|
-
this.
|
|
6497
|
+
this.yogaNode.setHeight(value);
|
|
6160
6498
|
this.requestRender();
|
|
6161
6499
|
}
|
|
6162
6500
|
}
|
|
@@ -6174,17 +6512,17 @@ class Renderable extends BaseRenderable {
|
|
|
6174
6512
|
}
|
|
6175
6513
|
ensureZIndexSorted() {
|
|
6176
6514
|
if (this.needsZIndexSort) {
|
|
6177
|
-
this.
|
|
6515
|
+
this._childrenInZIndexOrder.sort((a, b) => a.zIndex > b.zIndex ? 1 : a.zIndex < b.zIndex ? -1 : 0);
|
|
6178
6516
|
this.needsZIndexSort = false;
|
|
6179
6517
|
}
|
|
6180
6518
|
}
|
|
6181
6519
|
getChildrenSortedByPrimaryAxis() {
|
|
6182
|
-
if (!this.childrenPrimarySortDirty && this.childrenSortedByPrimaryAxis.length === this.
|
|
6520
|
+
if (!this.childrenPrimarySortDirty && this.childrenSortedByPrimaryAxis.length === this._childrenInLayoutOrder.length) {
|
|
6183
6521
|
return this.childrenSortedByPrimaryAxis;
|
|
6184
6522
|
}
|
|
6185
|
-
const dir = this.
|
|
6523
|
+
const dir = this.yogaNode.getFlexDirection();
|
|
6186
6524
|
const axis = dir === 2 || dir === 3 ? "x" : "y";
|
|
6187
|
-
const sorted = [...this.
|
|
6525
|
+
const sorted = [...this._childrenInLayoutOrder];
|
|
6188
6526
|
sorted.sort((a, b) => {
|
|
6189
6527
|
const va = axis === "y" ? a.y : a.x;
|
|
6190
6528
|
const vb = axis === "y" ? b.y : b.x;
|
|
@@ -6195,7 +6533,7 @@ class Renderable extends BaseRenderable {
|
|
|
6195
6533
|
return this.childrenSortedByPrimaryAxis;
|
|
6196
6534
|
}
|
|
6197
6535
|
setupYogaProperties(options) {
|
|
6198
|
-
const node = this.
|
|
6536
|
+
const node = this.yogaNode;
|
|
6199
6537
|
if (isFlexBasisType(options.flexBasis)) {
|
|
6200
6538
|
node.setFlexBasis(options.flexBasis);
|
|
6201
6539
|
}
|
|
@@ -6233,11 +6571,11 @@ class Renderable extends BaseRenderable {
|
|
|
6233
6571
|
}
|
|
6234
6572
|
if (isDimensionType(options.width)) {
|
|
6235
6573
|
this._width = options.width;
|
|
6236
|
-
this.
|
|
6574
|
+
this.yogaNode.setWidth(options.width);
|
|
6237
6575
|
}
|
|
6238
6576
|
if (isDimensionType(options.height)) {
|
|
6239
6577
|
this._height = options.height;
|
|
6240
|
-
this.
|
|
6578
|
+
this.yogaNode.setHeight(options.height);
|
|
6241
6579
|
}
|
|
6242
6580
|
this._positionType = options.position === "absolute" ? "absolute" : "relative";
|
|
6243
6581
|
if (this._positionType !== "relative") {
|
|
@@ -6266,7 +6604,7 @@ class Renderable extends BaseRenderable {
|
|
|
6266
6604
|
this.setupMarginAndPadding(options);
|
|
6267
6605
|
}
|
|
6268
6606
|
setupMarginAndPadding(options) {
|
|
6269
|
-
const node = this.
|
|
6607
|
+
const node = this.yogaNode;
|
|
6270
6608
|
if (isMarginType(options.margin)) {
|
|
6271
6609
|
node.setMargin(Edge.Top, options.margin);
|
|
6272
6610
|
node.setMargin(Edge.Right, options.margin);
|
|
@@ -6308,7 +6646,7 @@ class Renderable extends BaseRenderable {
|
|
|
6308
6646
|
if (!isPositionTypeType(positionType) || this._positionType === positionType)
|
|
6309
6647
|
return;
|
|
6310
6648
|
this._positionType = positionType;
|
|
6311
|
-
this.
|
|
6649
|
+
this.yogaNode.setPositionType(parsePositionType(positionType));
|
|
6312
6650
|
this.requestRender();
|
|
6313
6651
|
}
|
|
6314
6652
|
get overflow() {
|
|
@@ -6318,7 +6656,7 @@ class Renderable extends BaseRenderable {
|
|
|
6318
6656
|
if (!isOverflowType(overflow) || this._overflow === overflow)
|
|
6319
6657
|
return;
|
|
6320
6658
|
this._overflow = overflow;
|
|
6321
|
-
this.
|
|
6659
|
+
this.yogaNode.setOverflow(parseOverflow(overflow));
|
|
6322
6660
|
this.requestRender();
|
|
6323
6661
|
}
|
|
6324
6662
|
setPosition(position) {
|
|
@@ -6326,7 +6664,7 @@ class Renderable extends BaseRenderable {
|
|
|
6326
6664
|
this.updateYogaPosition(position);
|
|
6327
6665
|
}
|
|
6328
6666
|
updateYogaPosition(position) {
|
|
6329
|
-
const node = this.
|
|
6667
|
+
const node = this.yogaNode;
|
|
6330
6668
|
const { top, right, bottom, left } = position;
|
|
6331
6669
|
if (isPositionType(top)) {
|
|
6332
6670
|
if (top === "auto") {
|
|
@@ -6359,66 +6697,66 @@ class Renderable extends BaseRenderable {
|
|
|
6359
6697
|
this.requestRender();
|
|
6360
6698
|
}
|
|
6361
6699
|
set flexGrow(grow) {
|
|
6362
|
-
this.
|
|
6700
|
+
this.yogaNode.setFlexGrow(grow);
|
|
6363
6701
|
this.requestRender();
|
|
6364
6702
|
}
|
|
6365
6703
|
set flexShrink(shrink) {
|
|
6366
|
-
this.
|
|
6704
|
+
this.yogaNode.setFlexShrink(shrink);
|
|
6367
6705
|
this.requestRender();
|
|
6368
6706
|
}
|
|
6369
6707
|
set flexDirection(direction) {
|
|
6370
|
-
this.
|
|
6708
|
+
this.yogaNode.setFlexDirection(parseFlexDirection(direction));
|
|
6371
6709
|
this.requestRender();
|
|
6372
6710
|
}
|
|
6373
6711
|
set flexWrap(wrap) {
|
|
6374
|
-
this.
|
|
6712
|
+
this.yogaNode.setFlexWrap(parseWrap(wrap));
|
|
6375
6713
|
this.requestRender();
|
|
6376
6714
|
}
|
|
6377
6715
|
set alignItems(alignItems) {
|
|
6378
|
-
this.
|
|
6716
|
+
this.yogaNode.setAlignItems(parseAlign(alignItems));
|
|
6379
6717
|
this.requestRender();
|
|
6380
6718
|
}
|
|
6381
6719
|
set justifyContent(justifyContent) {
|
|
6382
|
-
this.
|
|
6720
|
+
this.yogaNode.setJustifyContent(parseJustify(justifyContent));
|
|
6383
6721
|
this.requestRender();
|
|
6384
6722
|
}
|
|
6385
6723
|
set alignSelf(alignSelf) {
|
|
6386
|
-
this.
|
|
6724
|
+
this.yogaNode.setAlignSelf(parseAlign(alignSelf));
|
|
6387
6725
|
this.requestRender();
|
|
6388
6726
|
}
|
|
6389
6727
|
set flexBasis(basis) {
|
|
6390
6728
|
if (isFlexBasisType(basis)) {
|
|
6391
|
-
this.
|
|
6729
|
+
this.yogaNode.setFlexBasis(basis);
|
|
6392
6730
|
this.requestRender();
|
|
6393
6731
|
}
|
|
6394
6732
|
}
|
|
6395
6733
|
set minWidth(minWidth) {
|
|
6396
6734
|
if (isSizeType(minWidth)) {
|
|
6397
|
-
this.
|
|
6735
|
+
this.yogaNode.setMinWidth(minWidth);
|
|
6398
6736
|
this.requestRender();
|
|
6399
6737
|
}
|
|
6400
6738
|
}
|
|
6401
6739
|
set maxWidth(maxWidth) {
|
|
6402
6740
|
if (isSizeType(maxWidth)) {
|
|
6403
|
-
this.
|
|
6741
|
+
this.yogaNode.setMaxWidth(maxWidth);
|
|
6404
6742
|
this.requestRender();
|
|
6405
6743
|
}
|
|
6406
6744
|
}
|
|
6407
6745
|
set minHeight(minHeight) {
|
|
6408
6746
|
if (isSizeType(minHeight)) {
|
|
6409
|
-
this.
|
|
6747
|
+
this.yogaNode.setMinHeight(minHeight);
|
|
6410
6748
|
this.requestRender();
|
|
6411
6749
|
}
|
|
6412
6750
|
}
|
|
6413
6751
|
set maxHeight(maxHeight) {
|
|
6414
6752
|
if (isSizeType(maxHeight)) {
|
|
6415
|
-
this.
|
|
6753
|
+
this.yogaNode.setMaxHeight(maxHeight);
|
|
6416
6754
|
this.requestRender();
|
|
6417
6755
|
}
|
|
6418
6756
|
}
|
|
6419
6757
|
set margin(margin) {
|
|
6420
6758
|
if (isMarginType(margin)) {
|
|
6421
|
-
const node = this.
|
|
6759
|
+
const node = this.yogaNode;
|
|
6422
6760
|
node.setMargin(Edge.Top, margin);
|
|
6423
6761
|
node.setMargin(Edge.Right, margin);
|
|
6424
6762
|
node.setMargin(Edge.Bottom, margin);
|
|
@@ -6428,31 +6766,31 @@ class Renderable extends BaseRenderable {
|
|
|
6428
6766
|
}
|
|
6429
6767
|
set marginTop(margin) {
|
|
6430
6768
|
if (isMarginType(margin)) {
|
|
6431
|
-
this.
|
|
6769
|
+
this.yogaNode.setMargin(Edge.Top, margin);
|
|
6432
6770
|
this.requestRender();
|
|
6433
6771
|
}
|
|
6434
6772
|
}
|
|
6435
6773
|
set marginRight(margin) {
|
|
6436
6774
|
if (isMarginType(margin)) {
|
|
6437
|
-
this.
|
|
6775
|
+
this.yogaNode.setMargin(Edge.Right, margin);
|
|
6438
6776
|
this.requestRender();
|
|
6439
6777
|
}
|
|
6440
6778
|
}
|
|
6441
6779
|
set marginBottom(margin) {
|
|
6442
6780
|
if (isMarginType(margin)) {
|
|
6443
|
-
this.
|
|
6781
|
+
this.yogaNode.setMargin(Edge.Bottom, margin);
|
|
6444
6782
|
this.requestRender();
|
|
6445
6783
|
}
|
|
6446
6784
|
}
|
|
6447
6785
|
set marginLeft(margin) {
|
|
6448
6786
|
if (isMarginType(margin)) {
|
|
6449
|
-
this.
|
|
6787
|
+
this.yogaNode.setMargin(Edge.Left, margin);
|
|
6450
6788
|
this.requestRender();
|
|
6451
6789
|
}
|
|
6452
6790
|
}
|
|
6453
6791
|
set padding(padding) {
|
|
6454
6792
|
if (isPaddingType(padding)) {
|
|
6455
|
-
const node = this.
|
|
6793
|
+
const node = this.yogaNode;
|
|
6456
6794
|
node.setPadding(Edge.Top, padding);
|
|
6457
6795
|
node.setPadding(Edge.Right, padding);
|
|
6458
6796
|
node.setPadding(Edge.Bottom, padding);
|
|
@@ -6462,33 +6800,33 @@ class Renderable extends BaseRenderable {
|
|
|
6462
6800
|
}
|
|
6463
6801
|
set paddingTop(padding) {
|
|
6464
6802
|
if (isPaddingType(padding)) {
|
|
6465
|
-
this.
|
|
6803
|
+
this.yogaNode.setPadding(Edge.Top, padding);
|
|
6466
6804
|
this.requestRender();
|
|
6467
6805
|
}
|
|
6468
6806
|
}
|
|
6469
6807
|
set paddingRight(padding) {
|
|
6470
6808
|
if (isPaddingType(padding)) {
|
|
6471
|
-
this.
|
|
6809
|
+
this.yogaNode.setPadding(Edge.Right, padding);
|
|
6472
6810
|
this.requestRender();
|
|
6473
6811
|
}
|
|
6474
6812
|
}
|
|
6475
6813
|
set paddingBottom(padding) {
|
|
6476
6814
|
if (isPaddingType(padding)) {
|
|
6477
|
-
this.
|
|
6815
|
+
this.yogaNode.setPadding(Edge.Bottom, padding);
|
|
6478
6816
|
this.requestRender();
|
|
6479
6817
|
}
|
|
6480
6818
|
}
|
|
6481
6819
|
set paddingLeft(padding) {
|
|
6482
6820
|
if (isPaddingType(padding)) {
|
|
6483
|
-
this.
|
|
6821
|
+
this.yogaNode.setPadding(Edge.Left, padding);
|
|
6484
6822
|
this.requestRender();
|
|
6485
6823
|
}
|
|
6486
6824
|
}
|
|
6487
6825
|
getLayoutNode() {
|
|
6488
|
-
return this.
|
|
6826
|
+
return this.yogaNode;
|
|
6489
6827
|
}
|
|
6490
6828
|
updateFromLayout() {
|
|
6491
|
-
const layout = this.
|
|
6829
|
+
const layout = this.yogaNode.getComputedLayout();
|
|
6492
6830
|
const oldX = this._x;
|
|
6493
6831
|
const oldY = this._y;
|
|
6494
6832
|
this._x = layout.left;
|
|
@@ -6564,7 +6902,7 @@ class Renderable extends BaseRenderable {
|
|
|
6564
6902
|
}
|
|
6565
6903
|
return -1;
|
|
6566
6904
|
}
|
|
6567
|
-
if (this.
|
|
6905
|
+
if (this.renderableMapById.has(renderable.id)) {
|
|
6568
6906
|
console.warn(`A renderable with id ${renderable.id} already exists in ${this.id}, removing it`);
|
|
6569
6907
|
this.remove(renderable.id);
|
|
6570
6908
|
}
|
|
@@ -6572,16 +6910,22 @@ class Renderable extends BaseRenderable {
|
|
|
6572
6910
|
const childLayoutNode = renderable.getLayoutNode();
|
|
6573
6911
|
let insertedIndex;
|
|
6574
6912
|
if (index !== undefined) {
|
|
6575
|
-
|
|
6576
|
-
this.
|
|
6577
|
-
|
|
6913
|
+
insertedIndex = Math.max(0, Math.min(index, this._childrenInLayoutOrder.length));
|
|
6914
|
+
this._childrenInLayoutOrder.splice(index, 0, renderable);
|
|
6915
|
+
this._forceLayoutUpdateFor = this._childrenInLayoutOrder.slice(index);
|
|
6916
|
+
this.yogaNode.insertChild(childLayoutNode, insertedIndex);
|
|
6578
6917
|
} else {
|
|
6579
|
-
this.
|
|
6580
|
-
|
|
6918
|
+
insertedIndex = this._childrenInLayoutOrder.length;
|
|
6919
|
+
this._childrenInLayoutOrder.push(renderable);
|
|
6920
|
+
this.yogaNode.insertChild(childLayoutNode, insertedIndex);
|
|
6581
6921
|
}
|
|
6582
6922
|
this.needsZIndexSort = true;
|
|
6583
6923
|
this.childrenPrimarySortDirty = true;
|
|
6584
|
-
this.
|
|
6924
|
+
this.renderableMapById.set(renderable.id, renderable);
|
|
6925
|
+
this._childrenInZIndexOrder.push(renderable);
|
|
6926
|
+
if (typeof renderable.onLifecyclePass === "function") {
|
|
6927
|
+
this._ctx.registerLifecyclePass(renderable);
|
|
6928
|
+
}
|
|
6585
6929
|
this._newChildren.push(renderable);
|
|
6586
6930
|
if (renderable._liveCount > 0) {
|
|
6587
6931
|
this.propagateLiveCount(renderable._liveCount);
|
|
@@ -6590,6 +6934,9 @@ class Renderable extends BaseRenderable {
|
|
|
6590
6934
|
return insertedIndex;
|
|
6591
6935
|
}
|
|
6592
6936
|
insertBefore(obj, anchor) {
|
|
6937
|
+
if (!anchor) {
|
|
6938
|
+
return this.add(obj);
|
|
6939
|
+
}
|
|
6593
6940
|
if (!obj) {
|
|
6594
6941
|
return -1;
|
|
6595
6942
|
}
|
|
@@ -6597,60 +6944,91 @@ class Renderable extends BaseRenderable {
|
|
|
6597
6944
|
if (!renderable) {
|
|
6598
6945
|
return -1;
|
|
6599
6946
|
}
|
|
6600
|
-
if (
|
|
6601
|
-
|
|
6947
|
+
if (renderable.isDestroyed) {
|
|
6948
|
+
if (true) {
|
|
6949
|
+
console.warn(`Renderable with id ${renderable.id} was already destroyed, skipping insertBefore`);
|
|
6950
|
+
}
|
|
6951
|
+
return -1;
|
|
6602
6952
|
}
|
|
6603
6953
|
if (!isRenderable(anchor)) {
|
|
6604
6954
|
throw new Error("Anchor must be a Renderable");
|
|
6605
6955
|
}
|
|
6606
|
-
if (
|
|
6607
|
-
|
|
6956
|
+
if (anchor.isDestroyed) {
|
|
6957
|
+
if (true) {
|
|
6958
|
+
console.warn(`Anchor with id ${anchor.id} was already destroyed, skipping insertBefore`);
|
|
6959
|
+
}
|
|
6960
|
+
return -1;
|
|
6608
6961
|
}
|
|
6609
|
-
|
|
6610
|
-
if (anchorIndex === -1) {
|
|
6962
|
+
if (!this.renderableMapById.has(anchor.id)) {
|
|
6611
6963
|
throw new Error("Anchor does not exist");
|
|
6612
6964
|
}
|
|
6613
|
-
|
|
6965
|
+
if (renderable.parent === this) {
|
|
6966
|
+
this.yogaNode.removeChild(renderable.getLayoutNode());
|
|
6967
|
+
this._childrenInLayoutOrder.splice(this._childrenInLayoutOrder.indexOf(renderable), 1);
|
|
6968
|
+
} else if (renderable.parent) {
|
|
6969
|
+
this.replaceParent(renderable);
|
|
6970
|
+
this.needsZIndexSort = true;
|
|
6971
|
+
this.renderableMapById.set(renderable.id, renderable);
|
|
6972
|
+
if (typeof renderable.onLifecyclePass === "function") {
|
|
6973
|
+
this._ctx.registerLifecyclePass(renderable);
|
|
6974
|
+
}
|
|
6975
|
+
if (renderable._liveCount > 0) {
|
|
6976
|
+
this.propagateLiveCount(renderable._liveCount);
|
|
6977
|
+
}
|
|
6978
|
+
}
|
|
6979
|
+
this._newChildren.push(renderable);
|
|
6980
|
+
this.childrenPrimarySortDirty = true;
|
|
6981
|
+
const anchorIndex = this._childrenInLayoutOrder.indexOf(anchor);
|
|
6982
|
+
const insertedIndex = Math.max(0, Math.min(anchorIndex, this._childrenInLayoutOrder.length));
|
|
6983
|
+
this._forceLayoutUpdateFor = this._childrenInLayoutOrder.slice(insertedIndex);
|
|
6984
|
+
this._childrenInLayoutOrder.splice(insertedIndex, 0, renderable);
|
|
6985
|
+
this.yogaNode.insertChild(renderable.getLayoutNode(), insertedIndex);
|
|
6986
|
+
return insertedIndex;
|
|
6614
6987
|
}
|
|
6615
6988
|
getRenderable(id) {
|
|
6616
|
-
return this.
|
|
6989
|
+
return this.renderableMapById.get(id);
|
|
6617
6990
|
}
|
|
6618
6991
|
remove(id) {
|
|
6619
6992
|
if (!id) {
|
|
6620
6993
|
return;
|
|
6621
6994
|
}
|
|
6622
|
-
if (this.
|
|
6623
|
-
const obj = this.
|
|
6995
|
+
if (this.renderableMapById.has(id)) {
|
|
6996
|
+
const obj = this.renderableMapById.get(id);
|
|
6624
6997
|
if (obj) {
|
|
6625
6998
|
if (obj._liveCount > 0) {
|
|
6626
6999
|
this.propagateLiveCount(-obj._liveCount);
|
|
6627
7000
|
}
|
|
6628
7001
|
const childLayoutNode = obj.getLayoutNode();
|
|
6629
|
-
this.
|
|
7002
|
+
this.yogaNode.removeChild(childLayoutNode);
|
|
6630
7003
|
this.requestRender();
|
|
6631
7004
|
obj.onRemove();
|
|
6632
7005
|
obj.parent = null;
|
|
7006
|
+
this._ctx.unregisterLifecyclePass(obj);
|
|
7007
|
+
this.renderableMapById.delete(id);
|
|
7008
|
+
const index = this._childrenInLayoutOrder.findIndex((obj2) => obj2.id === id);
|
|
7009
|
+
if (index !== -1) {
|
|
7010
|
+
this._childrenInLayoutOrder.splice(index, 1);
|
|
7011
|
+
}
|
|
7012
|
+
const zIndexIndex = this._childrenInZIndexOrder.findIndex((obj2) => obj2.id === id);
|
|
7013
|
+
if (zIndexIndex !== -1) {
|
|
7014
|
+
this._childrenInZIndexOrder.splice(zIndexIndex, 1);
|
|
7015
|
+
}
|
|
7016
|
+
this.childrenPrimarySortDirty = true;
|
|
6633
7017
|
}
|
|
6634
|
-
this.renderableMap.delete(id);
|
|
6635
|
-
const index = this.renderableArray.findIndex((obj2) => obj2.id === id);
|
|
6636
|
-
if (index !== -1) {
|
|
6637
|
-
this.renderableArray.splice(index, 1);
|
|
6638
|
-
}
|
|
6639
|
-
this.childrenPrimarySortDirty = true;
|
|
6640
7018
|
}
|
|
6641
7019
|
}
|
|
6642
7020
|
onRemove() {}
|
|
6643
7021
|
getChildren() {
|
|
6644
|
-
return [...this.
|
|
7022
|
+
return [...this._childrenInLayoutOrder];
|
|
6645
7023
|
}
|
|
6646
7024
|
getChildrenCount() {
|
|
6647
|
-
return this.
|
|
7025
|
+
return this._childrenInLayoutOrder.length;
|
|
6648
7026
|
}
|
|
6649
7027
|
updateLayout(deltaTime, renderList = []) {
|
|
6650
7028
|
if (!this.visible)
|
|
6651
7029
|
return;
|
|
6652
|
-
this.updateFromLayout();
|
|
6653
7030
|
this.onUpdate(deltaTime);
|
|
7031
|
+
this.updateFromLayout();
|
|
6654
7032
|
renderList.push({ action: "render", renderable: this });
|
|
6655
7033
|
if (this._newChildren.length > 0) {
|
|
6656
7034
|
for (const child of this._newChildren) {
|
|
@@ -6702,7 +7080,7 @@ class Renderable extends BaseRenderable {
|
|
|
6702
7080
|
}
|
|
6703
7081
|
}
|
|
6704
7082
|
_getChildren() {
|
|
6705
|
-
return this.
|
|
7083
|
+
return this._childrenInZIndexOrder;
|
|
6706
7084
|
}
|
|
6707
7085
|
onUpdate(deltaTime) {}
|
|
6708
7086
|
getScissorRect() {
|
|
@@ -6729,19 +7107,21 @@ class Renderable extends BaseRenderable {
|
|
|
6729
7107
|
this.frameBuffer.destroy();
|
|
6730
7108
|
this.frameBuffer = null;
|
|
6731
7109
|
}
|
|
6732
|
-
for (const child of this.
|
|
7110
|
+
for (const child of this._childrenInLayoutOrder) {
|
|
6733
7111
|
this.remove(child.id);
|
|
6734
7112
|
}
|
|
6735
|
-
this.
|
|
6736
|
-
this.
|
|
7113
|
+
this._childrenInLayoutOrder = [];
|
|
7114
|
+
this.renderableMapById.clear();
|
|
6737
7115
|
Renderable.renderablesByNumber.delete(this.num);
|
|
6738
7116
|
this.blur();
|
|
6739
7117
|
this.removeAllListeners();
|
|
6740
7118
|
this.destroySelf();
|
|
6741
|
-
|
|
7119
|
+
try {
|
|
7120
|
+
this.yogaNode.free();
|
|
7121
|
+
} catch (e) {}
|
|
6742
7122
|
}
|
|
6743
7123
|
destroyRecursively() {
|
|
6744
|
-
for (const child of this.
|
|
7124
|
+
for (const child of this._childrenInLayoutOrder) {
|
|
6745
7125
|
child.destroyRecursively();
|
|
6746
7126
|
}
|
|
6747
7127
|
this.destroy();
|
|
@@ -6855,19 +7235,22 @@ class RootRenderable extends Renderable {
|
|
|
6855
7235
|
this.yogaConfig = src_default.Config.create();
|
|
6856
7236
|
this.yogaConfig.setUseWebDefaults(false);
|
|
6857
7237
|
this.yogaConfig.setPointScaleFactor(1);
|
|
6858
|
-
if (this.
|
|
6859
|
-
this.
|
|
7238
|
+
if (this.yogaNode) {
|
|
7239
|
+
this.yogaNode.free();
|
|
6860
7240
|
}
|
|
6861
|
-
this.
|
|
6862
|
-
this.
|
|
6863
|
-
this.
|
|
6864
|
-
this.
|
|
7241
|
+
this.yogaNode = src_default.Node.create(this.yogaConfig);
|
|
7242
|
+
this.yogaNode.setWidth(ctx.width);
|
|
7243
|
+
this.yogaNode.setHeight(ctx.height);
|
|
7244
|
+
this.yogaNode.setFlexDirection(FlexDirection.Column);
|
|
6865
7245
|
this.calculateLayout();
|
|
6866
7246
|
}
|
|
6867
7247
|
render(buffer, deltaTime) {
|
|
6868
7248
|
if (!this.visible)
|
|
6869
7249
|
return;
|
|
6870
|
-
|
|
7250
|
+
for (const renderable of this._ctx.getLifecyclePasses()) {
|
|
7251
|
+
renderable.onLifecyclePass?.call(renderable);
|
|
7252
|
+
}
|
|
7253
|
+
if (this.yogaNode.isDirty()) {
|
|
6871
7254
|
this.calculateLayout();
|
|
6872
7255
|
}
|
|
6873
7256
|
this.renderList.length = 0;
|
|
@@ -6897,7 +7280,7 @@ class RootRenderable extends Renderable {
|
|
|
6897
7280
|
}
|
|
6898
7281
|
}
|
|
6899
7282
|
calculateLayout() {
|
|
6900
|
-
this.
|
|
7283
|
+
this.yogaNode.calculateLayout(this.width, this.height, Direction.LTR);
|
|
6901
7284
|
this.emit("layout-changed" /* LAYOUT_CHANGED */);
|
|
6902
7285
|
}
|
|
6903
7286
|
resize(width, height) {
|
|
@@ -6905,11 +7288,7 @@ class RootRenderable extends Renderable {
|
|
|
6905
7288
|
this.height = height;
|
|
6906
7289
|
this.emit("resized" /* RESIZED */, { width, height });
|
|
6907
7290
|
}
|
|
6908
|
-
onUpdate(deltaTime) {}
|
|
6909
7291
|
destroySelf() {
|
|
6910
|
-
if (this.layoutNode) {
|
|
6911
|
-
this.layoutNode.destroy();
|
|
6912
|
-
}
|
|
6913
7292
|
try {
|
|
6914
7293
|
this.yogaConfig.free();
|
|
6915
7294
|
} catch (error) {}
|
|
@@ -7083,7 +7462,7 @@ function delegate(mapping, vnode) {
|
|
|
7083
7462
|
}
|
|
7084
7463
|
|
|
7085
7464
|
// src/console.ts
|
|
7086
|
-
import { EventEmitter as
|
|
7465
|
+
import { EventEmitter as EventEmitter4 } from "events";
|
|
7087
7466
|
import { Console } from "console";
|
|
7088
7467
|
import fs from "fs";
|
|
7089
7468
|
import path from "path";
|
|
@@ -7091,9 +7470,9 @@ import util2 from "util";
|
|
|
7091
7470
|
|
|
7092
7471
|
// src/lib/output.capture.ts
|
|
7093
7472
|
import { Writable } from "stream";
|
|
7094
|
-
import { EventEmitter as
|
|
7473
|
+
import { EventEmitter as EventEmitter3 } from "events";
|
|
7095
7474
|
|
|
7096
|
-
class Capture extends
|
|
7475
|
+
class Capture extends EventEmitter3 {
|
|
7097
7476
|
output = [];
|
|
7098
7477
|
constructor() {
|
|
7099
7478
|
super();
|
|
@@ -7157,7 +7536,7 @@ function getCallerInfo() {
|
|
|
7157
7536
|
}
|
|
7158
7537
|
var capture = singleton("ConsoleCapture", () => new Capture);
|
|
7159
7538
|
|
|
7160
|
-
class TerminalConsoleCache extends
|
|
7539
|
+
class TerminalConsoleCache extends EventEmitter4 {
|
|
7161
7540
|
_cachedLogs = [];
|
|
7162
7541
|
MAX_CACHE_SIZE = 1000;
|
|
7163
7542
|
_collectCallerInfo = false;
|
|
@@ -7278,7 +7657,7 @@ var DEFAULT_CONSOLE_OPTIONS = {
|
|
|
7278
7657
|
};
|
|
7279
7658
|
var INDENT_WIDTH = 2;
|
|
7280
7659
|
|
|
7281
|
-
class TerminalConsole extends
|
|
7660
|
+
class TerminalConsole extends EventEmitter4 {
|
|
7282
7661
|
isVisible = false;
|
|
7283
7662
|
isFocused = false;
|
|
7284
7663
|
renderer;
|
|
@@ -7769,7 +8148,7 @@ var ANSI = {
|
|
|
7769
8148
|
};
|
|
7770
8149
|
|
|
7771
8150
|
// src/renderer.ts
|
|
7772
|
-
import { EventEmitter as
|
|
8151
|
+
import { EventEmitter as EventEmitter5 } from "events";
|
|
7773
8152
|
|
|
7774
8153
|
// src/lib/objects-in-viewport.ts
|
|
7775
8154
|
function getObjectsInViewport(viewport, objects, direction = "column", padding = 10, minTriggerSize = 16) {
|
|
@@ -7927,7 +8306,7 @@ var CliRenderEvents;
|
|
|
7927
8306
|
((CliRenderEvents2) => {
|
|
7928
8307
|
CliRenderEvents2["DEBUG_OVERLAY_TOGGLE"] = "debugOverlay:toggle";
|
|
7929
8308
|
})(CliRenderEvents ||= {});
|
|
7930
|
-
class CliRenderer extends
|
|
8309
|
+
class CliRenderer extends EventEmitter5 {
|
|
7931
8310
|
static animationFrameId = 0;
|
|
7932
8311
|
lib;
|
|
7933
8312
|
rendererPtr;
|
|
@@ -7939,6 +8318,7 @@ class CliRenderer extends EventEmitter6 {
|
|
|
7939
8318
|
currentRenderBuffer;
|
|
7940
8319
|
_isRunning = false;
|
|
7941
8320
|
targetFps = 30;
|
|
8321
|
+
automaticMemorySnapshot = false;
|
|
7942
8322
|
memorySnapshotInterval;
|
|
7943
8323
|
memorySnapshotTimer = null;
|
|
7944
8324
|
lastMemorySnapshot = {
|
|
@@ -7981,6 +8361,7 @@ class CliRenderer extends EventEmitter6 {
|
|
|
7981
8361
|
};
|
|
7982
8362
|
_console;
|
|
7983
8363
|
_resolution = null;
|
|
8364
|
+
_keyHandler;
|
|
7984
8365
|
animationRequest = new Map;
|
|
7985
8366
|
resizeTimeoutId = null;
|
|
7986
8367
|
resizeDebounceDelay = 100;
|
|
@@ -8005,10 +8386,57 @@ class CliRenderer extends EventEmitter6 {
|
|
|
8005
8386
|
};
|
|
8006
8387
|
_useConsole = true;
|
|
8007
8388
|
mouseParser = new MouseParser;
|
|
8008
|
-
sigwinchHandler =
|
|
8389
|
+
sigwinchHandler = (() => {
|
|
8390
|
+
const width = this.stdout.columns || 80;
|
|
8391
|
+
const height = this.stdout.rows || 24;
|
|
8392
|
+
this.handleResize(width, height);
|
|
8393
|
+
}).bind(this);
|
|
8009
8394
|
_capabilities = null;
|
|
8010
8395
|
_latestPointer = { x: 0, y: 0 };
|
|
8011
8396
|
_currentFocusedRenderable = null;
|
|
8397
|
+
lifecyclePasses = new Set;
|
|
8398
|
+
handleError = ((error) => {
|
|
8399
|
+
this.stop();
|
|
8400
|
+
this.destroy();
|
|
8401
|
+
new Promise((resolve) => {
|
|
8402
|
+
setTimeout(() => {
|
|
8403
|
+
resolve(true);
|
|
8404
|
+
}, 100);
|
|
8405
|
+
}).then(() => {
|
|
8406
|
+
this.realStdoutWrite.call(this.stdout, `
|
|
8407
|
+
`.repeat(this._terminalHeight));
|
|
8408
|
+
this.realStdoutWrite.call(this.stdout, `
|
|
8409
|
+
=== FATAL ERROR OCCURRED ===
|
|
8410
|
+
`);
|
|
8411
|
+
this.realStdoutWrite.call(this.stdout, `Console cache:
|
|
8412
|
+
`);
|
|
8413
|
+
this.realStdoutWrite.call(this.stdout, this.console.getCachedLogs());
|
|
8414
|
+
this.realStdoutWrite.call(this.stdout, `
|
|
8415
|
+
Captured output:
|
|
8416
|
+
`);
|
|
8417
|
+
const capturedOutput = capture.claimOutput();
|
|
8418
|
+
if (capturedOutput) {
|
|
8419
|
+
this.realStdoutWrite.call(this.stdout, capturedOutput + `
|
|
8420
|
+
`);
|
|
8421
|
+
}
|
|
8422
|
+
this.realStdoutWrite.call(this.stdout, `
|
|
8423
|
+
Error details:
|
|
8424
|
+
`);
|
|
8425
|
+
this.realStdoutWrite.call(this.stdout, error.message || "unknown error");
|
|
8426
|
+
this.realStdoutWrite.call(this.stdout, `
|
|
8427
|
+
`);
|
|
8428
|
+
this.realStdoutWrite.call(this.stdout, error.stack || error.toString());
|
|
8429
|
+
this.realStdoutWrite.call(this.stdout, `
|
|
8430
|
+
`);
|
|
8431
|
+
process.exit(1);
|
|
8432
|
+
});
|
|
8433
|
+
}).bind(this);
|
|
8434
|
+
exitHandler = (() => {
|
|
8435
|
+
this.destroy();
|
|
8436
|
+
}).bind(this);
|
|
8437
|
+
warningHandler = ((warning) => {
|
|
8438
|
+
console.warn(JSON.stringify(warning.message, null, 2));
|
|
8439
|
+
}).bind(this);
|
|
8012
8440
|
constructor(lib, rendererPtr, stdin, stdout, width, height, config = {}) {
|
|
8013
8441
|
super();
|
|
8014
8442
|
this.stdin = stdin;
|
|
@@ -8031,7 +8459,7 @@ class CliRenderer extends EventEmitter6 {
|
|
|
8031
8459
|
this.exitOnCtrlC = config.exitOnCtrlC === undefined ? true : config.exitOnCtrlC;
|
|
8032
8460
|
this.resizeDebounceDelay = config.debounceDelay || 100;
|
|
8033
8461
|
this.targetFps = config.targetFps || 30;
|
|
8034
|
-
this.memorySnapshotInterval = config.memorySnapshotInterval
|
|
8462
|
+
this.memorySnapshotInterval = config.memorySnapshotInterval ?? 0;
|
|
8035
8463
|
this.gatherStats = config.gatherStats || false;
|
|
8036
8464
|
this.maxStatSamples = config.maxStatSamples || 300;
|
|
8037
8465
|
this.enableMouseMovement = config.enableMouseMovement || true;
|
|
@@ -8041,63 +8469,18 @@ class CliRenderer extends EventEmitter6 {
|
|
|
8041
8469
|
this.currentRenderBuffer = this.lib.getCurrentBuffer(this.rendererPtr);
|
|
8042
8470
|
this.postProcessFns = config.postProcessFns || [];
|
|
8043
8471
|
this.root = new RootRenderable(this);
|
|
8044
|
-
this.takeMemorySnapshot();
|
|
8045
8472
|
if (this.memorySnapshotInterval > 0) {
|
|
8046
8473
|
this.startMemorySnapshotTimer();
|
|
8047
8474
|
}
|
|
8048
8475
|
this.stdout.write = this.interceptStdoutWrite.bind(this);
|
|
8049
|
-
this.sigwinchHandler = () => {
|
|
8050
|
-
const width2 = this.stdout.columns || 80;
|
|
8051
|
-
const height2 = this.stdout.rows || 24;
|
|
8052
|
-
this.handleResize(width2, height2);
|
|
8053
|
-
};
|
|
8054
8476
|
process.on("SIGWINCH", this.sigwinchHandler);
|
|
8055
|
-
|
|
8056
|
-
|
|
8057
|
-
|
|
8058
|
-
|
|
8059
|
-
setTimeout(() => {
|
|
8060
|
-
resolve(true);
|
|
8061
|
-
}, 100);
|
|
8062
|
-
}).then(() => {
|
|
8063
|
-
this.realStdoutWrite.call(this.stdout, `
|
|
8064
|
-
`.repeat(this._terminalHeight));
|
|
8065
|
-
this.realStdoutWrite.call(this.stdout, `
|
|
8066
|
-
=== FATAL ERROR OCCURRED ===
|
|
8067
|
-
`);
|
|
8068
|
-
this.realStdoutWrite.call(this.stdout, `Console cache:
|
|
8069
|
-
`);
|
|
8070
|
-
this.realStdoutWrite.call(this.stdout, this.console.getCachedLogs());
|
|
8071
|
-
this.realStdoutWrite.call(this.stdout, `
|
|
8072
|
-
Captured output:
|
|
8073
|
-
`);
|
|
8074
|
-
const capturedOutput = capture.claimOutput();
|
|
8075
|
-
if (capturedOutput) {
|
|
8076
|
-
this.realStdoutWrite.call(this.stdout, capturedOutput + `
|
|
8077
|
-
`);
|
|
8078
|
-
}
|
|
8079
|
-
this.realStdoutWrite.call(this.stdout, `
|
|
8080
|
-
Error details:
|
|
8081
|
-
`);
|
|
8082
|
-
this.realStdoutWrite.call(this.stdout, error.message || "unknown error");
|
|
8083
|
-
this.realStdoutWrite.call(this.stdout, `
|
|
8084
|
-
`);
|
|
8085
|
-
this.realStdoutWrite.call(this.stdout, error.stack || error.toString());
|
|
8086
|
-
this.realStdoutWrite.call(this.stdout, `
|
|
8087
|
-
`);
|
|
8088
|
-
process.exit(1);
|
|
8089
|
-
});
|
|
8090
|
-
};
|
|
8091
|
-
process.on("warning", (warning) => {
|
|
8092
|
-
console.warn(JSON.stringify(warning.message, null, 2));
|
|
8093
|
-
});
|
|
8094
|
-
process.on("uncaughtException", handleError);
|
|
8095
|
-
process.on("unhandledRejection", handleError);
|
|
8096
|
-
process.on("exit", () => {
|
|
8097
|
-
this.destroy();
|
|
8098
|
-
});
|
|
8477
|
+
process.on("warning", this.warningHandler);
|
|
8478
|
+
process.on("uncaughtException", this.handleError);
|
|
8479
|
+
process.on("unhandledRejection", this.handleError);
|
|
8480
|
+
process.on("exit", this.exitHandler);
|
|
8099
8481
|
this._console = new TerminalConsole(this, config.consoleOptions);
|
|
8100
8482
|
this.useConsole = config.useConsole ?? true;
|
|
8483
|
+
this._keyHandler = new KeyHandler(this.stdin, config.useKittyKeyboard ?? false);
|
|
8101
8484
|
global.requestAnimationFrame = (callback) => {
|
|
8102
8485
|
const id = CliRenderer.animationFrameId++;
|
|
8103
8486
|
this.animationRequest.set(id, callback);
|
|
@@ -8119,6 +8502,16 @@ Error details:
|
|
|
8119
8502
|
}
|
|
8120
8503
|
};
|
|
8121
8504
|
}
|
|
8505
|
+
this.setupInput();
|
|
8506
|
+
}
|
|
8507
|
+
registerLifecyclePass(renderable) {
|
|
8508
|
+
this.lifecyclePasses.add(renderable);
|
|
8509
|
+
}
|
|
8510
|
+
unregisterLifecyclePass(renderable) {
|
|
8511
|
+
this.lifecyclePasses.delete(renderable);
|
|
8512
|
+
}
|
|
8513
|
+
getLifecyclePasses() {
|
|
8514
|
+
return this.lifecyclePasses;
|
|
8122
8515
|
}
|
|
8123
8516
|
get currentFocusedRenderable() {
|
|
8124
8517
|
return this._currentFocusedRenderable;
|
|
@@ -8172,6 +8565,9 @@ Error details:
|
|
|
8172
8565
|
get console() {
|
|
8173
8566
|
return this._console;
|
|
8174
8567
|
}
|
|
8568
|
+
get keyInput() {
|
|
8569
|
+
return this._keyHandler;
|
|
8570
|
+
}
|
|
8175
8571
|
get terminalWidth() {
|
|
8176
8572
|
return this._terminalWidth;
|
|
8177
8573
|
}
|
|
@@ -8260,7 +8656,6 @@ Error details:
|
|
|
8260
8656
|
return true;
|
|
8261
8657
|
};
|
|
8262
8658
|
disableStdoutInterception() {
|
|
8263
|
-
this.flushStdoutCache(this._splitHeight);
|
|
8264
8659
|
this.stdout.write = this.realStdoutWrite;
|
|
8265
8660
|
}
|
|
8266
8661
|
flushStdoutCache(space, force = false) {
|
|
@@ -8271,10 +8666,13 @@ Error details:
|
|
|
8271
8666
|
const flush = ANSI.moveCursorAndClear(rendererStartLine, 1);
|
|
8272
8667
|
const outputLine = this._terminalHeight - this._splitHeight;
|
|
8273
8668
|
const move = ANSI.moveCursor(outputLine, 1);
|
|
8274
|
-
|
|
8275
|
-
|
|
8669
|
+
let clear = "";
|
|
8670
|
+
if (space > 0) {
|
|
8671
|
+
const backgroundColor = this.backgroundColor.toInts();
|
|
8672
|
+
const newlines = " ".repeat(this.width) + `
|
|
8276
8673
|
`.repeat(space);
|
|
8277
|
-
|
|
8674
|
+
clear = ANSI.setRgbBackground(backgroundColor[0], backgroundColor[1], backgroundColor[2]) + newlines + ANSI.resetBackground;
|
|
8675
|
+
}
|
|
8278
8676
|
this.writeOut(flush + move + output + clear);
|
|
8279
8677
|
return true;
|
|
8280
8678
|
}
|
|
@@ -8323,32 +8721,35 @@ Error details:
|
|
|
8323
8721
|
if (this._useMouse) {
|
|
8324
8722
|
this.enableMouse();
|
|
8325
8723
|
}
|
|
8326
|
-
this.
|
|
8327
|
-
|
|
8328
|
-
|
|
8329
|
-
|
|
8330
|
-
|
|
8331
|
-
|
|
8332
|
-
|
|
8333
|
-
|
|
8334
|
-
|
|
8335
|
-
|
|
8336
|
-
|
|
8337
|
-
|
|
8338
|
-
|
|
8339
|
-
}
|
|
8340
|
-
if (this.exitOnCtrlC && str === "\x03") {
|
|
8341
|
-
process.nextTick(() => {
|
|
8342
|
-
process.exit();
|
|
8343
|
-
});
|
|
8344
|
-
return;
|
|
8345
|
-
}
|
|
8346
|
-
if (this._useMouse && this.handleMouseData(data)) {
|
|
8724
|
+
this.queryPixelResolution();
|
|
8725
|
+
}
|
|
8726
|
+
stdinListener = ((data) => {
|
|
8727
|
+
const str = data.toString();
|
|
8728
|
+
if (this.waitingForPixelResolution && /\x1b\[4;\d+;\d+t/.test(str)) {
|
|
8729
|
+
const match = str.match(/\x1b\[4;(\d+);(\d+)t/);
|
|
8730
|
+
if (match) {
|
|
8731
|
+
const resolution = {
|
|
8732
|
+
width: parseInt(match[2]),
|
|
8733
|
+
height: parseInt(match[1])
|
|
8734
|
+
};
|
|
8735
|
+
this._resolution = resolution;
|
|
8736
|
+
this.waitingForPixelResolution = false;
|
|
8347
8737
|
return;
|
|
8348
8738
|
}
|
|
8349
|
-
|
|
8350
|
-
|
|
8351
|
-
|
|
8739
|
+
}
|
|
8740
|
+
if (this.exitOnCtrlC && str === "\x03") {
|
|
8741
|
+
process.nextTick(() => {
|
|
8742
|
+
process.exit();
|
|
8743
|
+
});
|
|
8744
|
+
return;
|
|
8745
|
+
}
|
|
8746
|
+
if (this._useMouse && this.handleMouseData(data)) {
|
|
8747
|
+
return;
|
|
8748
|
+
}
|
|
8749
|
+
this.emit("key", data);
|
|
8750
|
+
}).bind(this);
|
|
8751
|
+
setupInput() {
|
|
8752
|
+
this.stdin.on("data", this.stdinListener);
|
|
8352
8753
|
}
|
|
8353
8754
|
handleMouseData(data) {
|
|
8354
8755
|
const mouseEvent = this.mouseParser.parseMouseEvent(data);
|
|
@@ -8375,7 +8776,7 @@ Error details:
|
|
|
8375
8776
|
this.lastOverRenderableNum = maybeRenderableId;
|
|
8376
8777
|
const maybeRenderable = Renderable.renderablesByNumber.get(maybeRenderableId);
|
|
8377
8778
|
if (mouseEvent.type === "down" && mouseEvent.button === 0 /* LEFT */ && !this.currentSelection?.isSelecting && !mouseEvent.modifiers.ctrl) {
|
|
8378
|
-
if (maybeRenderable && maybeRenderable.selectable && maybeRenderable.shouldStartSelection(mouseEvent.x, mouseEvent.y)) {
|
|
8779
|
+
if (maybeRenderable && maybeRenderable.selectable && !maybeRenderable.isDestroyed && maybeRenderable.shouldStartSelection(mouseEvent.x, mouseEvent.y)) {
|
|
8379
8780
|
this.startSelection(maybeRenderable, mouseEvent.x, mouseEvent.y);
|
|
8380
8781
|
const event2 = new MouseEvent(maybeRenderable, mouseEvent);
|
|
8381
8782
|
maybeRenderable.processMouseEvent(event2);
|
|
@@ -8463,6 +8864,8 @@ Error details:
|
|
|
8463
8864
|
return false;
|
|
8464
8865
|
}
|
|
8465
8866
|
takeMemorySnapshot() {
|
|
8867
|
+
if (this.isDestroyed)
|
|
8868
|
+
return;
|
|
8466
8869
|
const memoryUsage = process.memoryUsage();
|
|
8467
8870
|
this.lastMemorySnapshot = {
|
|
8468
8871
|
heapUsed: memoryUsage.heapUsed,
|
|
@@ -8473,13 +8876,17 @@ Error details:
|
|
|
8473
8876
|
this.emit("memory:snapshot", this.lastMemorySnapshot);
|
|
8474
8877
|
}
|
|
8475
8878
|
startMemorySnapshotTimer() {
|
|
8476
|
-
|
|
8477
|
-
clearInterval(this.memorySnapshotTimer);
|
|
8478
|
-
}
|
|
8879
|
+
this.stopMemorySnapshotTimer();
|
|
8479
8880
|
this.memorySnapshotTimer = setInterval(() => {
|
|
8480
8881
|
this.takeMemorySnapshot();
|
|
8481
8882
|
}, this.memorySnapshotInterval);
|
|
8482
8883
|
}
|
|
8884
|
+
stopMemorySnapshotTimer() {
|
|
8885
|
+
if (this.memorySnapshotTimer) {
|
|
8886
|
+
clearInterval(this.memorySnapshotTimer);
|
|
8887
|
+
this.memorySnapshotTimer = null;
|
|
8888
|
+
}
|
|
8889
|
+
}
|
|
8483
8890
|
setMemorySnapshotInterval(interval) {
|
|
8484
8891
|
this.memorySnapshotInterval = interval;
|
|
8485
8892
|
if (this._isRunning && interval > 0) {
|
|
@@ -8549,6 +8956,16 @@ Error details:
|
|
|
8549
8956
|
this.requestRender();
|
|
8550
8957
|
}
|
|
8551
8958
|
toggleDebugOverlay() {
|
|
8959
|
+
const willBeEnabled = !this.debugOverlay.enabled;
|
|
8960
|
+
if (willBeEnabled && !this.memorySnapshotInterval) {
|
|
8961
|
+
this.memorySnapshotInterval = 3000;
|
|
8962
|
+
this.startMemorySnapshotTimer();
|
|
8963
|
+
this.automaticMemorySnapshot = true;
|
|
8964
|
+
} else if (!willBeEnabled && this.automaticMemorySnapshot) {
|
|
8965
|
+
this.stopMemorySnapshotTimer();
|
|
8966
|
+
this.memorySnapshotInterval = 0;
|
|
8967
|
+
this.automaticMemorySnapshot = false;
|
|
8968
|
+
}
|
|
8552
8969
|
this.debugOverlay.enabled = !this.debugOverlay.enabled;
|
|
8553
8970
|
this.lib.setDebugOverlay(this.rendererPtr, this.debugOverlay.enabled, this.debugOverlay.corner);
|
|
8554
8971
|
this.emit("debugOverlay:toggle" /* DEBUG_OVERLAY_TOGGLE */, this.debugOverlay.enabled);
|
|
@@ -8675,19 +9092,32 @@ Error details:
|
|
|
8675
9092
|
}
|
|
8676
9093
|
}
|
|
8677
9094
|
destroy() {
|
|
8678
|
-
this.stdin.
|
|
9095
|
+
this.stdin.removeListener("data", this.stdinListener);
|
|
9096
|
+
process.removeListener("SIGWINCH", this.sigwinchHandler);
|
|
9097
|
+
process.removeListener("uncaughtException", this.handleError);
|
|
9098
|
+
process.removeListener("unhandledRejection", this.handleError);
|
|
9099
|
+
process.removeListener("exit", this.exitHandler);
|
|
9100
|
+
process.removeListener("warning", this.warningHandler);
|
|
9101
|
+
capture.removeListener("write", this.captureCallback);
|
|
9102
|
+
if (this.memorySnapshotTimer) {
|
|
9103
|
+
clearInterval(this.memorySnapshotTimer);
|
|
9104
|
+
}
|
|
9105
|
+
if (this.stdin.setRawMode) {
|
|
9106
|
+
this.stdin.setRawMode(false);
|
|
9107
|
+
}
|
|
8679
9108
|
if (this.isDestroyed)
|
|
8680
9109
|
return;
|
|
8681
9110
|
this.isDestroyed = true;
|
|
8682
9111
|
this.waitingForPixelResolution = false;
|
|
8683
9112
|
this.capturedRenderable = undefined;
|
|
8684
|
-
|
|
8685
|
-
|
|
8686
|
-
this.sigwinchHandler = null;
|
|
8687
|
-
}
|
|
9113
|
+
this.root.destroyRecursively();
|
|
9114
|
+
this._keyHandler.destroy();
|
|
8688
9115
|
this._console.deactivate();
|
|
8689
9116
|
this.disableStdoutInterception();
|
|
8690
|
-
|
|
9117
|
+
if (this._splitHeight > 0) {
|
|
9118
|
+
this.flushStdoutCache(this._splitHeight, true);
|
|
9119
|
+
}
|
|
9120
|
+
this.lib.destroyRenderer(this.rendererPtr);
|
|
8691
9121
|
}
|
|
8692
9122
|
startRenderLoop() {
|
|
8693
9123
|
if (!this._isRunning)
|
|
@@ -8820,7 +9250,7 @@ Error details:
|
|
|
8820
9250
|
clearSelection() {
|
|
8821
9251
|
if (this.currentSelection) {
|
|
8822
9252
|
for (const renderable of this.currentSelection.touchedRenderables) {
|
|
8823
|
-
if (renderable.selectable) {
|
|
9253
|
+
if (renderable.selectable && !renderable.isDestroyed) {
|
|
8824
9254
|
renderable.onSelectionChanged(null);
|
|
8825
9255
|
}
|
|
8826
9256
|
}
|
|
@@ -8911,7 +9341,7 @@ Error details:
|
|
|
8911
9341
|
}
|
|
8912
9342
|
}
|
|
8913
9343
|
|
|
8914
|
-
export { __toESM, __commonJS, __export, __require, Edge, Gutter,
|
|
9344
|
+
export { __toESM, __commonJS, __export, __require, Edge, Gutter, exports_src, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, nonAlphanumericKeys, parseKeypress, KeyHandler, getKeyHandler, RGBA, hexToRgb, rgbToHex, hsvToRgb, parseColor, fonts, measureText, getCharacterPositions, coordinateToCharacterIndex, renderFontToFrameBuffer, TextAttributes, DebugOverlayCorner, createTextAttributes, visualizeRenderableTree, isStyledText, StyledText, stringToStyledText, black, red, green, yellow, blue, magenta, cyan, white, brightBlack, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bold, italic, underline, strikethrough, dim, reverse, blink, fg, bg, t, SyntaxStyle, hastToStyledText, parseAlign, parseBoxSizing, parseDimension, parseDirection, parseDisplay, parseEdge, parseFlexDirection, parseGutter, parseJustify, parseLogLevel, parseMeasureMode, parseOverflow, parsePositionType, parseUnit, parseWrap, MouseParser, Selection, convertGlobalToLocalSelection, ASCIIFontSelectionHelper, TextBuffer, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, isValidPercentage, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, CliRenderer };
|
|
8915
9345
|
|
|
8916
|
-
//# debugId=
|
|
8917
|
-
//# sourceMappingURL=index-
|
|
9346
|
+
//# debugId=F7540B181A9A091164756E2164756E21
|
|
9347
|
+
//# sourceMappingURL=index-0yx9rnxg.js.map
|