@opentui/core 0.1.86 → 0.1.88
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/ThreeRenderable.d.ts +4 -4
- package/3d/WGPURenderer.d.ts +4 -4
- package/3d/animation/ExplodingSpriteEffect.d.ts +2 -2
- package/3d/animation/PhysicsExplodingSpriteEffect.d.ts +3 -3
- package/3d/animation/SpriteAnimator.d.ts +1 -1
- package/3d/animation/SpriteParticleGenerator.d.ts +1 -1
- package/3d/canvas.d.ts +2 -2
- package/3d/index.d.ts +12 -12
- package/3d/physics/PlanckPhysicsAdapter.d.ts +1 -1
- package/3d/physics/RapierPhysicsAdapter.d.ts +1 -1
- package/3d.d.ts +1 -1
- package/3d.js +4 -3
- package/3d.js.map +15 -15
- package/Renderable.d.ts +7 -7
- package/animation/Timeline.d.ts +1 -1
- package/buffer.d.ts +6 -6
- package/console.d.ts +7 -4
- package/edit-buffer.d.ts +4 -4
- package/editor-view.d.ts +4 -4
- package/index-e4hzc2j2.js +113 -0
- package/index-e4hzc2j2.js.map +10 -0
- package/{index-4sjb8n0n.js → index-nkrr8a4c.js} +2476 -1743
- package/index-nkrr8a4c.js.map +64 -0
- package/index-nyw5p3ep.js +12619 -0
- package/index-nyw5p3ep.js.map +43 -0
- package/index.d.ts +20 -17
- package/index.js +83 -11490
- package/index.js.map +3 -34
- package/lib/KeyHandler.d.ts +8 -8
- package/lib/ascii.font.d.ts +2 -2
- package/lib/border.d.ts +1 -1
- package/lib/clipboard.d.ts +1 -1
- package/lib/clock.d.ts +15 -0
- package/lib/extmarks-history.d.ts +1 -1
- package/lib/extmarks.d.ts +2 -2
- package/lib/hast-styled-text.d.ts +3 -3
- package/lib/index.d.ts +21 -19
- package/lib/objects-in-viewport.d.ts +1 -1
- package/lib/parse.keypress-kitty.d.ts +1 -1
- package/lib/parse.mouse.d.ts +2 -2
- package/lib/paste.d.ts +7 -0
- package/lib/renderable.validations.d.ts +2 -2
- package/lib/selection.d.ts +2 -2
- package/lib/stdin-parser.d.ts +76 -0
- package/lib/styled-text.d.ts +2 -2
- package/lib/terminal-palette.d.ts +11 -4
- package/lib/tree-sitter/client.d.ts +1 -1
- package/lib/tree-sitter/default-parsers.d.ts +1 -1
- package/lib/tree-sitter/download-utils.d.ts +1 -1
- package/lib/tree-sitter/index.d.ts +7 -7
- package/lib/tree-sitter-styled-text.d.ts +5 -5
- package/package.json +17 -7
- package/parser.worker.js +7 -7
- package/parser.worker.js.map +4 -4
- package/plugins/core-slot.d.ts +72 -0
- package/plugins/registry.d.ts +38 -0
- package/plugins/types.d.ts +34 -0
- package/post/filters.d.ts +1 -1
- package/renderables/ASCIIFont.d.ts +6 -6
- package/renderables/Box.d.ts +5 -5
- package/renderables/Code.d.ts +10 -8
- package/renderables/Diff.d.ts +13 -6
- package/renderables/EditBufferRenderable.d.ts +8 -8
- package/renderables/FrameBuffer.d.ts +3 -3
- package/renderables/Input.d.ts +3 -3
- package/renderables/LineNumberRenderable.d.ts +4 -4
- package/renderables/Markdown.d.ts +9 -9
- package/renderables/ScrollBar.d.ts +6 -6
- package/renderables/ScrollBox.d.ts +9 -8
- package/renderables/Select.d.ts +7 -7
- package/renderables/Slider.d.ts +1 -1
- package/renderables/TabSelect.d.ts +6 -6
- package/renderables/Text.d.ts +7 -7
- package/renderables/TextBufferRenderable.d.ts +9 -9
- package/renderables/TextNode.d.ts +6 -6
- package/renderables/Textarea.d.ts +7 -7
- package/renderables/TimeToFirstDraw.d.ts +24 -0
- package/renderables/__tests__/renderable-test-utils.d.ts +8 -3
- package/renderables/composition/VRenderable.d.ts +3 -3
- package/renderables/composition/constructs.d.ts +14 -14
- package/renderables/composition/vnode.d.ts +2 -2
- package/renderables/index.d.ts +22 -21
- package/renderer.d.ts +26 -17
- package/runtime-plugin-support.d.ts +3 -0
- package/runtime-plugin-support.js +29 -0
- package/runtime-plugin-support.js.map +10 -0
- package/runtime-plugin.d.ts +11 -0
- package/runtime-plugin.js +16 -0
- package/runtime-plugin.js.map +9 -0
- package/syntax-style.d.ts +2 -2
- package/testing/manual-clock.d.ts +16 -0
- package/testing/mock-keys.d.ts +2 -1
- package/testing/mock-mouse.d.ts +1 -1
- package/testing/mock-tree-sitter-client.d.ts +2 -2
- package/testing/test-recorder.d.ts +1 -1
- package/testing/test-renderer.d.ts +4 -4
- package/testing.d.ts +6 -6
- package/testing.js +12 -7
- package/testing.js.map +7 -7
- package/text-buffer-view.d.ts +4 -4
- package/text-buffer.d.ts +5 -5
- package/types.d.ts +13 -8
- package/utils.d.ts +1 -1
- package/zig-structs.d.ts +7 -7
- package/zig.d.ts +6 -6
- package/index-4sjb8n0n.js.map +0 -62
- package/lib/stdin-buffer.d.ts +0 -44
|
@@ -1793,600 +1793,9 @@ var BorderCharArrays = {
|
|
|
1793
1793
|
heavy: borderCharsToArray(BorderChars.heavy)
|
|
1794
1794
|
};
|
|
1795
1795
|
|
|
1796
|
-
// src/lib/parse.keypress.ts
|
|
1797
|
-
import { Buffer as Buffer2 } from "buffer";
|
|
1798
|
-
|
|
1799
|
-
// src/lib/parse.keypress-kitty.ts
|
|
1800
|
-
var kittyKeyMap = {
|
|
1801
|
-
27: "escape",
|
|
1802
|
-
9: "tab",
|
|
1803
|
-
13: "return",
|
|
1804
|
-
127: "backspace",
|
|
1805
|
-
57344: "escape",
|
|
1806
|
-
57345: "return",
|
|
1807
|
-
57346: "tab",
|
|
1808
|
-
57347: "backspace",
|
|
1809
|
-
57348: "insert",
|
|
1810
|
-
57349: "delete",
|
|
1811
|
-
57350: "left",
|
|
1812
|
-
57351: "right",
|
|
1813
|
-
57352: "up",
|
|
1814
|
-
57353: "down",
|
|
1815
|
-
57354: "pageup",
|
|
1816
|
-
57355: "pagedown",
|
|
1817
|
-
57356: "home",
|
|
1818
|
-
57357: "end",
|
|
1819
|
-
57364: "f1",
|
|
1820
|
-
57365: "f2",
|
|
1821
|
-
57366: "f3",
|
|
1822
|
-
57367: "f4",
|
|
1823
|
-
57368: "f5",
|
|
1824
|
-
57369: "f6",
|
|
1825
|
-
57370: "f7",
|
|
1826
|
-
57371: "f8",
|
|
1827
|
-
57372: "f9",
|
|
1828
|
-
57373: "f10",
|
|
1829
|
-
57374: "f11",
|
|
1830
|
-
57375: "f12",
|
|
1831
|
-
57376: "f13",
|
|
1832
|
-
57377: "f14",
|
|
1833
|
-
57378: "f15",
|
|
1834
|
-
57379: "f16",
|
|
1835
|
-
57380: "f17",
|
|
1836
|
-
57381: "f18",
|
|
1837
|
-
57382: "f19",
|
|
1838
|
-
57383: "f20",
|
|
1839
|
-
57384: "f21",
|
|
1840
|
-
57385: "f22",
|
|
1841
|
-
57386: "f23",
|
|
1842
|
-
57387: "f24",
|
|
1843
|
-
57388: "f25",
|
|
1844
|
-
57389: "f26",
|
|
1845
|
-
57390: "f27",
|
|
1846
|
-
57391: "f28",
|
|
1847
|
-
57392: "f29",
|
|
1848
|
-
57393: "f30",
|
|
1849
|
-
57394: "f31",
|
|
1850
|
-
57395: "f32",
|
|
1851
|
-
57396: "f33",
|
|
1852
|
-
57397: "f34",
|
|
1853
|
-
57398: "f35",
|
|
1854
|
-
57399: "kp0",
|
|
1855
|
-
57400: "kp1",
|
|
1856
|
-
57401: "kp2",
|
|
1857
|
-
57402: "kp3",
|
|
1858
|
-
57403: "kp4",
|
|
1859
|
-
57404: "kp5",
|
|
1860
|
-
57405: "kp6",
|
|
1861
|
-
57406: "kp7",
|
|
1862
|
-
57407: "kp8",
|
|
1863
|
-
57408: "kp9",
|
|
1864
|
-
57409: "kpdecimal",
|
|
1865
|
-
57410: "kpdivide",
|
|
1866
|
-
57411: "kpmultiply",
|
|
1867
|
-
57412: "kpminus",
|
|
1868
|
-
57413: "kpplus",
|
|
1869
|
-
57414: "kpenter",
|
|
1870
|
-
57415: "kpequal",
|
|
1871
|
-
57428: "mediaplay",
|
|
1872
|
-
57429: "mediapause",
|
|
1873
|
-
57430: "mediaplaypause",
|
|
1874
|
-
57431: "mediareverse",
|
|
1875
|
-
57432: "mediastop",
|
|
1876
|
-
57433: "mediafastforward",
|
|
1877
|
-
57434: "mediarewind",
|
|
1878
|
-
57435: "medianext",
|
|
1879
|
-
57436: "mediaprev",
|
|
1880
|
-
57437: "mediarecord",
|
|
1881
|
-
57438: "volumedown",
|
|
1882
|
-
57439: "volumeup",
|
|
1883
|
-
57440: "mute",
|
|
1884
|
-
57441: "leftshift",
|
|
1885
|
-
57442: "leftctrl",
|
|
1886
|
-
57443: "leftalt",
|
|
1887
|
-
57444: "leftsuper",
|
|
1888
|
-
57445: "lefthyper",
|
|
1889
|
-
57446: "leftmeta",
|
|
1890
|
-
57447: "rightshift",
|
|
1891
|
-
57448: "rightctrl",
|
|
1892
|
-
57449: "rightalt",
|
|
1893
|
-
57450: "rightsuper",
|
|
1894
|
-
57451: "righthyper",
|
|
1895
|
-
57452: "rightmeta",
|
|
1896
|
-
57453: "iso_level3_shift",
|
|
1897
|
-
57454: "iso_level5_shift"
|
|
1898
|
-
};
|
|
1899
|
-
function fromKittyMods(mod) {
|
|
1900
|
-
return {
|
|
1901
|
-
shift: !!(mod & 1),
|
|
1902
|
-
alt: !!(mod & 2),
|
|
1903
|
-
ctrl: !!(mod & 4),
|
|
1904
|
-
super: !!(mod & 8),
|
|
1905
|
-
hyper: !!(mod & 16),
|
|
1906
|
-
meta: !!(mod & 32),
|
|
1907
|
-
capsLock: !!(mod & 64),
|
|
1908
|
-
numLock: !!(mod & 128)
|
|
1909
|
-
};
|
|
1910
|
-
}
|
|
1911
|
-
var functionalKeyMap = {
|
|
1912
|
-
A: "up",
|
|
1913
|
-
B: "down",
|
|
1914
|
-
C: "right",
|
|
1915
|
-
D: "left",
|
|
1916
|
-
H: "home",
|
|
1917
|
-
F: "end",
|
|
1918
|
-
P: "f1",
|
|
1919
|
-
Q: "f2",
|
|
1920
|
-
R: "f3",
|
|
1921
|
-
S: "f4"
|
|
1922
|
-
};
|
|
1923
|
-
var tildeKeyMap = {
|
|
1924
|
-
"1": "home",
|
|
1925
|
-
"2": "insert",
|
|
1926
|
-
"3": "delete",
|
|
1927
|
-
"4": "end",
|
|
1928
|
-
"5": "pageup",
|
|
1929
|
-
"6": "pagedown",
|
|
1930
|
-
"7": "home",
|
|
1931
|
-
"8": "end",
|
|
1932
|
-
"11": "f1",
|
|
1933
|
-
"12": "f2",
|
|
1934
|
-
"13": "f3",
|
|
1935
|
-
"14": "f4",
|
|
1936
|
-
"15": "f5",
|
|
1937
|
-
"17": "f6",
|
|
1938
|
-
"18": "f7",
|
|
1939
|
-
"19": "f8",
|
|
1940
|
-
"20": "f9",
|
|
1941
|
-
"21": "f10",
|
|
1942
|
-
"23": "f11",
|
|
1943
|
-
"24": "f12"
|
|
1944
|
-
};
|
|
1945
|
-
function parseKittySpecialKey(sequence) {
|
|
1946
|
-
const specialKeyRe = /^\x1b\[(\d+);(\d+):(\d+)([A-Z~])$/;
|
|
1947
|
-
const match = specialKeyRe.exec(sequence);
|
|
1948
|
-
if (!match)
|
|
1949
|
-
return null;
|
|
1950
|
-
const keyNumOrOne = match[1];
|
|
1951
|
-
const modifierStr = match[2];
|
|
1952
|
-
const eventTypeStr = match[3];
|
|
1953
|
-
const terminator = match[4];
|
|
1954
|
-
let keyName;
|
|
1955
|
-
if (terminator === "~") {
|
|
1956
|
-
keyName = tildeKeyMap[keyNumOrOne];
|
|
1957
|
-
} else {
|
|
1958
|
-
if (keyNumOrOne !== "1")
|
|
1959
|
-
return null;
|
|
1960
|
-
keyName = functionalKeyMap[terminator];
|
|
1961
|
-
}
|
|
1962
|
-
if (!keyName)
|
|
1963
|
-
return null;
|
|
1964
|
-
const key = {
|
|
1965
|
-
name: keyName,
|
|
1966
|
-
ctrl: false,
|
|
1967
|
-
meta: false,
|
|
1968
|
-
shift: false,
|
|
1969
|
-
option: false,
|
|
1970
|
-
number: false,
|
|
1971
|
-
sequence,
|
|
1972
|
-
raw: sequence,
|
|
1973
|
-
eventType: "press",
|
|
1974
|
-
source: "kitty",
|
|
1975
|
-
super: false,
|
|
1976
|
-
hyper: false,
|
|
1977
|
-
capsLock: false,
|
|
1978
|
-
numLock: false
|
|
1979
|
-
};
|
|
1980
|
-
if (modifierStr) {
|
|
1981
|
-
const modifierMask = parseInt(modifierStr, 10);
|
|
1982
|
-
if (!isNaN(modifierMask) && modifierMask > 1) {
|
|
1983
|
-
const mods = fromKittyMods(modifierMask - 1);
|
|
1984
|
-
key.shift = mods.shift;
|
|
1985
|
-
key.ctrl = mods.ctrl;
|
|
1986
|
-
key.meta = mods.alt || mods.meta;
|
|
1987
|
-
key.option = mods.alt;
|
|
1988
|
-
key.super = mods.super;
|
|
1989
|
-
key.hyper = mods.hyper;
|
|
1990
|
-
key.capsLock = mods.capsLock;
|
|
1991
|
-
key.numLock = mods.numLock;
|
|
1992
|
-
}
|
|
1993
|
-
}
|
|
1994
|
-
if (eventTypeStr === "1" || !eventTypeStr) {
|
|
1995
|
-
key.eventType = "press";
|
|
1996
|
-
} else if (eventTypeStr === "2") {
|
|
1997
|
-
key.eventType = "press";
|
|
1998
|
-
key.repeated = true;
|
|
1999
|
-
} else if (eventTypeStr === "3") {
|
|
2000
|
-
key.eventType = "release";
|
|
2001
|
-
}
|
|
2002
|
-
return key;
|
|
2003
|
-
}
|
|
2004
|
-
function parseKittyKeyboard(sequence) {
|
|
2005
|
-
const specialResult = parseKittySpecialKey(sequence);
|
|
2006
|
-
if (specialResult)
|
|
2007
|
-
return specialResult;
|
|
2008
|
-
const kittyRe = /^\x1b\[([^\x1b]+)u$/;
|
|
2009
|
-
const match = kittyRe.exec(sequence);
|
|
2010
|
-
if (!match)
|
|
2011
|
-
return null;
|
|
2012
|
-
const params = match[1];
|
|
2013
|
-
const fields = params.split(";");
|
|
2014
|
-
if (fields.length < 1)
|
|
2015
|
-
return null;
|
|
2016
|
-
const key = {
|
|
2017
|
-
name: "",
|
|
2018
|
-
ctrl: false,
|
|
2019
|
-
meta: false,
|
|
2020
|
-
shift: false,
|
|
2021
|
-
option: false,
|
|
2022
|
-
number: false,
|
|
2023
|
-
sequence,
|
|
2024
|
-
raw: sequence,
|
|
2025
|
-
eventType: "press",
|
|
2026
|
-
source: "kitty",
|
|
2027
|
-
super: false,
|
|
2028
|
-
hyper: false,
|
|
2029
|
-
capsLock: false,
|
|
2030
|
-
numLock: false
|
|
2031
|
-
};
|
|
2032
|
-
let text = "";
|
|
2033
|
-
const field1 = fields[0]?.split(":") || [];
|
|
2034
|
-
const codepointStr = field1[0];
|
|
2035
|
-
if (!codepointStr)
|
|
2036
|
-
return null;
|
|
2037
|
-
const codepoint = parseInt(codepointStr, 10);
|
|
2038
|
-
if (isNaN(codepoint))
|
|
2039
|
-
return null;
|
|
2040
|
-
let shiftedCodepoint;
|
|
2041
|
-
let baseCodepoint;
|
|
2042
|
-
if (field1[1]) {
|
|
2043
|
-
const shifted = parseInt(field1[1], 10);
|
|
2044
|
-
if (!isNaN(shifted) && shifted > 0 && shifted <= 1114111) {
|
|
2045
|
-
shiftedCodepoint = shifted;
|
|
2046
|
-
}
|
|
2047
|
-
}
|
|
2048
|
-
if (field1[2]) {
|
|
2049
|
-
const base = parseInt(field1[2], 10);
|
|
2050
|
-
if (!isNaN(base) && base > 0 && base <= 1114111) {
|
|
2051
|
-
baseCodepoint = base;
|
|
2052
|
-
}
|
|
2053
|
-
}
|
|
2054
|
-
const knownKey = kittyKeyMap[codepoint];
|
|
2055
|
-
if (knownKey) {
|
|
2056
|
-
key.name = knownKey;
|
|
2057
|
-
key.code = `[${codepoint}u`;
|
|
2058
|
-
} else {
|
|
2059
|
-
if (codepoint > 0 && codepoint <= 1114111) {
|
|
2060
|
-
const char = String.fromCodePoint(codepoint);
|
|
2061
|
-
key.name = char;
|
|
2062
|
-
if (baseCodepoint) {
|
|
2063
|
-
key.baseCode = baseCodepoint;
|
|
2064
|
-
}
|
|
2065
|
-
} else {
|
|
2066
|
-
return null;
|
|
2067
|
-
}
|
|
2068
|
-
}
|
|
2069
|
-
if (fields[1]) {
|
|
2070
|
-
const field2 = fields[1].split(":");
|
|
2071
|
-
const modifierStr = field2[0];
|
|
2072
|
-
const eventTypeStr = field2[1];
|
|
2073
|
-
if (modifierStr) {
|
|
2074
|
-
const modifierMask = parseInt(modifierStr, 10);
|
|
2075
|
-
if (!isNaN(modifierMask) && modifierMask > 1) {
|
|
2076
|
-
const mods = fromKittyMods(modifierMask - 1);
|
|
2077
|
-
key.shift = mods.shift;
|
|
2078
|
-
key.ctrl = mods.ctrl;
|
|
2079
|
-
key.meta = mods.alt || mods.meta;
|
|
2080
|
-
key.option = mods.alt;
|
|
2081
|
-
key.super = mods.super;
|
|
2082
|
-
key.hyper = mods.hyper;
|
|
2083
|
-
key.capsLock = mods.capsLock;
|
|
2084
|
-
key.numLock = mods.numLock;
|
|
2085
|
-
}
|
|
2086
|
-
}
|
|
2087
|
-
if (eventTypeStr === "1" || !eventTypeStr) {
|
|
2088
|
-
key.eventType = "press";
|
|
2089
|
-
} else if (eventTypeStr === "2") {
|
|
2090
|
-
key.eventType = "press";
|
|
2091
|
-
key.repeated = true;
|
|
2092
|
-
} else if (eventTypeStr === "3") {
|
|
2093
|
-
key.eventType = "release";
|
|
2094
|
-
} else {
|
|
2095
|
-
key.eventType = "press";
|
|
2096
|
-
}
|
|
2097
|
-
}
|
|
2098
|
-
if (fields[2]) {
|
|
2099
|
-
const codepoints = fields[2].split(":");
|
|
2100
|
-
for (const cpStr of codepoints) {
|
|
2101
|
-
const cp = parseInt(cpStr, 10);
|
|
2102
|
-
if (!isNaN(cp) && cp > 0 && cp <= 1114111) {
|
|
2103
|
-
text += String.fromCodePoint(cp);
|
|
2104
|
-
}
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2107
|
-
if (text === "") {
|
|
2108
|
-
const isPrintable = key.name.length > 0 && !kittyKeyMap[codepoint];
|
|
2109
|
-
if (isPrintable) {
|
|
2110
|
-
if (key.shift && shiftedCodepoint) {
|
|
2111
|
-
text = String.fromCodePoint(shiftedCodepoint);
|
|
2112
|
-
} else if (key.shift && key.name.length === 1) {
|
|
2113
|
-
text = key.name.toLocaleUpperCase();
|
|
2114
|
-
} else {
|
|
2115
|
-
text = key.name;
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2118
|
-
}
|
|
2119
|
-
if (key.name === " " && key.shift && !key.ctrl && !key.meta) {
|
|
2120
|
-
text = " ";
|
|
2121
|
-
}
|
|
2122
|
-
if (text) {
|
|
2123
|
-
key.sequence = text;
|
|
2124
|
-
}
|
|
2125
|
-
return key;
|
|
2126
|
-
}
|
|
2127
|
-
|
|
2128
|
-
// src/lib/parse.keypress.ts
|
|
2129
|
-
var metaKeyCodeRe = /^(?:\x1b)([a-zA-Z0-9])$/;
|
|
2130
|
-
var fnKeyRe = /^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/;
|
|
2131
|
-
var keyName = {
|
|
2132
|
-
OP: "f1",
|
|
2133
|
-
OQ: "f2",
|
|
2134
|
-
OR: "f3",
|
|
2135
|
-
OS: "f4",
|
|
2136
|
-
"[11~": "f1",
|
|
2137
|
-
"[12~": "f2",
|
|
2138
|
-
"[13~": "f3",
|
|
2139
|
-
"[14~": "f4",
|
|
2140
|
-
"[[A": "f1",
|
|
2141
|
-
"[[B": "f2",
|
|
2142
|
-
"[[C": "f3",
|
|
2143
|
-
"[[D": "f4",
|
|
2144
|
-
"[[E": "f5",
|
|
2145
|
-
"[15~": "f5",
|
|
2146
|
-
"[17~": "f6",
|
|
2147
|
-
"[18~": "f7",
|
|
2148
|
-
"[19~": "f8",
|
|
2149
|
-
"[20~": "f9",
|
|
2150
|
-
"[21~": "f10",
|
|
2151
|
-
"[23~": "f11",
|
|
2152
|
-
"[24~": "f12",
|
|
2153
|
-
"[A": "up",
|
|
2154
|
-
"[B": "down",
|
|
2155
|
-
"[C": "right",
|
|
2156
|
-
"[D": "left",
|
|
2157
|
-
"[E": "clear",
|
|
2158
|
-
"[F": "end",
|
|
2159
|
-
"[H": "home",
|
|
2160
|
-
OA: "up",
|
|
2161
|
-
OB: "down",
|
|
2162
|
-
OC: "right",
|
|
2163
|
-
OD: "left",
|
|
2164
|
-
OE: "clear",
|
|
2165
|
-
OF: "end",
|
|
2166
|
-
OH: "home",
|
|
2167
|
-
"[1~": "home",
|
|
2168
|
-
"[2~": "insert",
|
|
2169
|
-
"[3~": "delete",
|
|
2170
|
-
"[4~": "end",
|
|
2171
|
-
"[5~": "pageup",
|
|
2172
|
-
"[6~": "pagedown",
|
|
2173
|
-
"[[5~": "pageup",
|
|
2174
|
-
"[[6~": "pagedown",
|
|
2175
|
-
"[7~": "home",
|
|
2176
|
-
"[8~": "end",
|
|
2177
|
-
"[a": "up",
|
|
2178
|
-
"[b": "down",
|
|
2179
|
-
"[c": "right",
|
|
2180
|
-
"[d": "left",
|
|
2181
|
-
"[e": "clear",
|
|
2182
|
-
f: "right",
|
|
2183
|
-
b: "left",
|
|
2184
|
-
p: "up",
|
|
2185
|
-
n: "down",
|
|
2186
|
-
"[2$": "insert",
|
|
2187
|
-
"[3$": "delete",
|
|
2188
|
-
"[5$": "pageup",
|
|
2189
|
-
"[6$": "pagedown",
|
|
2190
|
-
"[7$": "home",
|
|
2191
|
-
"[8$": "end",
|
|
2192
|
-
Oa: "up",
|
|
2193
|
-
Ob: "down",
|
|
2194
|
-
Oc: "right",
|
|
2195
|
-
Od: "left",
|
|
2196
|
-
Oe: "clear",
|
|
2197
|
-
"[2^": "insert",
|
|
2198
|
-
"[3^": "delete",
|
|
2199
|
-
"[5^": "pageup",
|
|
2200
|
-
"[6^": "pagedown",
|
|
2201
|
-
"[7^": "home",
|
|
2202
|
-
"[8^": "end",
|
|
2203
|
-
"[Z": "tab"
|
|
2204
|
-
};
|
|
2205
|
-
var nonAlphanumericKeys = [...Object.values(keyName), "backspace"];
|
|
2206
|
-
var isShiftKey = (code) => {
|
|
2207
|
-
return ["[a", "[b", "[c", "[d", "[e", "[2$", "[3$", "[5$", "[6$", "[7$", "[8$", "[Z"].includes(code);
|
|
2208
|
-
};
|
|
2209
|
-
var isCtrlKey = (code) => {
|
|
2210
|
-
return ["Oa", "Ob", "Oc", "Od", "Oe", "[2^", "[3^", "[5^", "[6^", "[7^", "[8^"].includes(code);
|
|
2211
|
-
};
|
|
2212
|
-
var modifyOtherKeysRe = /^\x1b\[27;(\d+);(\d+)~$/;
|
|
2213
|
-
var parseKeypress = (s = "", options = {}) => {
|
|
2214
|
-
let parts;
|
|
2215
|
-
if (Buffer2.isBuffer(s)) {
|
|
2216
|
-
if (s[0] > 127 && s[1] === undefined) {
|
|
2217
|
-
s[0] -= 128;
|
|
2218
|
-
s = "\x1B" + String(s);
|
|
2219
|
-
} else {
|
|
2220
|
-
s = String(s);
|
|
2221
|
-
}
|
|
2222
|
-
} else if (s !== undefined && typeof s !== "string") {
|
|
2223
|
-
s = String(s);
|
|
2224
|
-
} else if (!s) {
|
|
2225
|
-
s = "";
|
|
2226
|
-
}
|
|
2227
|
-
if (/^\x1b\[<\d+;\d+;\d+[Mm]$/.test(s)) {
|
|
2228
|
-
return null;
|
|
2229
|
-
}
|
|
2230
|
-
if (s.startsWith("\x1B[M") && s.length >= 6) {
|
|
2231
|
-
return null;
|
|
2232
|
-
}
|
|
2233
|
-
if (/^\x1b\[\d+;\d+;\d+t$/.test(s)) {
|
|
2234
|
-
return null;
|
|
2235
|
-
}
|
|
2236
|
-
if (/^\x1b\[\d+;\d+R$/.test(s)) {
|
|
2237
|
-
return null;
|
|
2238
|
-
}
|
|
2239
|
-
if (/^\x1b\[\?[\d;]+c$/.test(s)) {
|
|
2240
|
-
return null;
|
|
2241
|
-
}
|
|
2242
|
-
if (/^\x1b\[\?[\d;]+\$y$/.test(s)) {
|
|
2243
|
-
return null;
|
|
2244
|
-
}
|
|
2245
|
-
if (s === "\x1B[I" || s === "\x1B[O") {
|
|
2246
|
-
return null;
|
|
2247
|
-
}
|
|
2248
|
-
if (/^\x1b\][\d;].*(\x1b\\|\x07)$/.test(s)) {
|
|
2249
|
-
return null;
|
|
2250
|
-
}
|
|
2251
|
-
if (s === "\x1B[200~" || s === "\x1B[201~") {
|
|
2252
|
-
return null;
|
|
2253
|
-
}
|
|
2254
|
-
const key = {
|
|
2255
|
-
name: "",
|
|
2256
|
-
ctrl: false,
|
|
2257
|
-
meta: false,
|
|
2258
|
-
shift: false,
|
|
2259
|
-
option: false,
|
|
2260
|
-
number: false,
|
|
2261
|
-
sequence: s,
|
|
2262
|
-
raw: s,
|
|
2263
|
-
eventType: "press",
|
|
2264
|
-
source: "raw"
|
|
2265
|
-
};
|
|
2266
|
-
key.sequence = key.sequence || s || key.name;
|
|
2267
|
-
if (options.useKittyKeyboard) {
|
|
2268
|
-
const kittyResult = parseKittyKeyboard(s);
|
|
2269
|
-
if (kittyResult) {
|
|
2270
|
-
return kittyResult;
|
|
2271
|
-
}
|
|
2272
|
-
}
|
|
2273
|
-
const modifyOtherKeysMatch = modifyOtherKeysRe.exec(s);
|
|
2274
|
-
if (modifyOtherKeysMatch) {
|
|
2275
|
-
const modifier = parseInt(modifyOtherKeysMatch[1], 10) - 1;
|
|
2276
|
-
const charCode = parseInt(modifyOtherKeysMatch[2], 10);
|
|
2277
|
-
key.ctrl = !!(modifier & 4);
|
|
2278
|
-
key.meta = !!(modifier & 2);
|
|
2279
|
-
key.shift = !!(modifier & 1);
|
|
2280
|
-
key.option = !!(modifier & 2);
|
|
2281
|
-
key.super = !!(modifier & 8);
|
|
2282
|
-
key.hyper = !!(modifier & 16);
|
|
2283
|
-
if (charCode === 13) {
|
|
2284
|
-
key.name = "return";
|
|
2285
|
-
} else if (charCode === 27) {
|
|
2286
|
-
key.name = "escape";
|
|
2287
|
-
} else if (charCode === 9) {
|
|
2288
|
-
key.name = "tab";
|
|
2289
|
-
} else if (charCode === 32) {
|
|
2290
|
-
key.name = "space";
|
|
2291
|
-
} else if (charCode === 127 || charCode === 8) {
|
|
2292
|
-
key.name = "backspace";
|
|
2293
|
-
} else {
|
|
2294
|
-
const char = String.fromCharCode(charCode);
|
|
2295
|
-
key.name = char;
|
|
2296
|
-
key.sequence = char;
|
|
2297
|
-
if (charCode >= 48 && charCode <= 57) {
|
|
2298
|
-
key.number = true;
|
|
2299
|
-
}
|
|
2300
|
-
}
|
|
2301
|
-
return key;
|
|
2302
|
-
}
|
|
2303
|
-
if (s === "\r" || s === "\x1B\r") {
|
|
2304
|
-
key.name = "return";
|
|
2305
|
-
key.meta = s.length === 2;
|
|
2306
|
-
} else if (s === `
|
|
2307
|
-
` || s === `\x1B
|
|
2308
|
-
`) {
|
|
2309
|
-
key.name = "linefeed";
|
|
2310
|
-
key.meta = s.length === 2;
|
|
2311
|
-
} else if (s === "\t") {
|
|
2312
|
-
key.name = "tab";
|
|
2313
|
-
} else if (s === "\b" || s === "\x1B\b" || s === "\x7F" || s === "\x1B\x7F") {
|
|
2314
|
-
key.name = "backspace";
|
|
2315
|
-
key.meta = s.charAt(0) === "\x1B";
|
|
2316
|
-
} else if (s === "\x1B" || s === "\x1B\x1B") {
|
|
2317
|
-
key.name = "escape";
|
|
2318
|
-
key.meta = s.length === 2;
|
|
2319
|
-
} else if (s === " " || s === "\x1B ") {
|
|
2320
|
-
key.name = "space";
|
|
2321
|
-
key.meta = s.length === 2;
|
|
2322
|
-
} else if (s === "\x00") {
|
|
2323
|
-
key.name = "space";
|
|
2324
|
-
key.ctrl = true;
|
|
2325
|
-
} else if (s.length === 1 && s <= "\x1A") {
|
|
2326
|
-
key.name = String.fromCharCode(s.charCodeAt(0) + 97 - 1);
|
|
2327
|
-
key.ctrl = true;
|
|
2328
|
-
} else if (s.length === 1 && s >= "0" && s <= "9") {
|
|
2329
|
-
key.name = s;
|
|
2330
|
-
key.number = true;
|
|
2331
|
-
} else if (s.length === 1 && s >= "a" && s <= "z") {
|
|
2332
|
-
key.name = s;
|
|
2333
|
-
} else if (s.length === 1 && s >= "A" && s <= "Z") {
|
|
2334
|
-
key.name = s.toLowerCase();
|
|
2335
|
-
key.shift = true;
|
|
2336
|
-
} else if (s.length === 1) {
|
|
2337
|
-
key.name = s;
|
|
2338
|
-
} else if (parts = metaKeyCodeRe.exec(s)) {
|
|
2339
|
-
key.meta = true;
|
|
2340
|
-
const char = parts[1];
|
|
2341
|
-
const isUpperCase = /^[A-Z]$/.test(char);
|
|
2342
|
-
if (char === "F") {
|
|
2343
|
-
key.name = "right";
|
|
2344
|
-
} else if (char === "B") {
|
|
2345
|
-
key.name = "left";
|
|
2346
|
-
} else if (isUpperCase) {
|
|
2347
|
-
key.shift = true;
|
|
2348
|
-
key.name = char;
|
|
2349
|
-
} else {
|
|
2350
|
-
key.name = char;
|
|
2351
|
-
}
|
|
2352
|
-
} else if (s.length === 2 && s[0] === "\x1B" && s[1] <= "\x1A") {
|
|
2353
|
-
key.meta = true;
|
|
2354
|
-
key.ctrl = true;
|
|
2355
|
-
key.name = String.fromCharCode(s.charCodeAt(1) + 97 - 1);
|
|
2356
|
-
} else if (parts = fnKeyRe.exec(s)) {
|
|
2357
|
-
const segs = [...s];
|
|
2358
|
-
if (segs[0] === "\x1B" && segs[1] === "\x1B") {
|
|
2359
|
-
key.option = true;
|
|
2360
|
-
key.meta = true;
|
|
2361
|
-
}
|
|
2362
|
-
const code = [parts[1], parts[2], parts[4], parts[6]].filter(Boolean).join("");
|
|
2363
|
-
const modifier = parseInt(parts[3] || parts[5] || "1", 10) - 1;
|
|
2364
|
-
key.ctrl = !!(modifier & 4);
|
|
2365
|
-
key.meta = !!(modifier & 2);
|
|
2366
|
-
key.shift = !!(modifier & 1);
|
|
2367
|
-
key.option = !!(modifier & 2);
|
|
2368
|
-
key.super = !!(modifier & 8);
|
|
2369
|
-
key.hyper = !!(modifier & 16);
|
|
2370
|
-
key.code = code;
|
|
2371
|
-
const keyNameResult = keyName[code];
|
|
2372
|
-
if (keyNameResult) {
|
|
2373
|
-
key.name = keyNameResult;
|
|
2374
|
-
key.shift = isShiftKey(code) || key.shift;
|
|
2375
|
-
key.ctrl = isCtrlKey(code) || key.ctrl;
|
|
2376
|
-
} else {
|
|
2377
|
-
key.name = "";
|
|
2378
|
-
key.code = undefined;
|
|
2379
|
-
}
|
|
2380
|
-
} else if (s === "\x1B[3~") {
|
|
2381
|
-
key.name = "delete";
|
|
2382
|
-
key.meta = false;
|
|
2383
|
-
key.code = "[3~";
|
|
2384
|
-
}
|
|
2385
|
-
return key;
|
|
2386
|
-
};
|
|
2387
|
-
|
|
2388
1796
|
// src/lib/KeyHandler.ts
|
|
2389
1797
|
import { EventEmitter } from "events";
|
|
1798
|
+
|
|
2390
1799
|
class KeyEvent {
|
|
2391
1800
|
name;
|
|
2392
1801
|
ctrl;
|
|
@@ -2441,11 +1850,14 @@ class KeyEvent {
|
|
|
2441
1850
|
}
|
|
2442
1851
|
|
|
2443
1852
|
class PasteEvent {
|
|
2444
|
-
|
|
1853
|
+
type = "paste";
|
|
1854
|
+
bytes;
|
|
1855
|
+
metadata;
|
|
2445
1856
|
_defaultPrevented = false;
|
|
2446
1857
|
_propagationStopped = false;
|
|
2447
|
-
constructor(
|
|
2448
|
-
this.
|
|
1858
|
+
constructor(bytes, metadata) {
|
|
1859
|
+
this.bytes = bytes;
|
|
1860
|
+
this.metadata = metadata;
|
|
2449
1861
|
}
|
|
2450
1862
|
get defaultPrevented() {
|
|
2451
1863
|
return this._defaultPrevented;
|
|
@@ -2462,16 +1874,7 @@ class PasteEvent {
|
|
|
2462
1874
|
}
|
|
2463
1875
|
|
|
2464
1876
|
class KeyHandler extends EventEmitter {
|
|
2465
|
-
|
|
2466
|
-
constructor(useKittyKeyboard = false) {
|
|
2467
|
-
super();
|
|
2468
|
-
this.useKittyKeyboard = useKittyKeyboard;
|
|
2469
|
-
}
|
|
2470
|
-
processInput(data) {
|
|
2471
|
-
const parsedKey = parseKeypress(data, { useKittyKeyboard: this.useKittyKeyboard });
|
|
2472
|
-
if (!parsedKey) {
|
|
2473
|
-
return false;
|
|
2474
|
-
}
|
|
1877
|
+
processParsedKey(parsedKey) {
|
|
2475
1878
|
try {
|
|
2476
1879
|
switch (parsedKey.eventType) {
|
|
2477
1880
|
case "press":
|
|
@@ -2485,15 +1888,14 @@ class KeyHandler extends EventEmitter {
|
|
|
2485
1888
|
break;
|
|
2486
1889
|
}
|
|
2487
1890
|
} catch (error) {
|
|
2488
|
-
console.error(`[KeyHandler] Error processing
|
|
1891
|
+
console.error(`[KeyHandler] Error processing parsed key:`, error);
|
|
2489
1892
|
return true;
|
|
2490
1893
|
}
|
|
2491
1894
|
return true;
|
|
2492
1895
|
}
|
|
2493
|
-
processPaste(
|
|
1896
|
+
processPaste(bytes, metadata) {
|
|
2494
1897
|
try {
|
|
2495
|
-
|
|
2496
|
-
this.emit("paste", new PasteEvent(cleanedData));
|
|
1898
|
+
this.emit("paste", new PasteEvent(bytes, metadata));
|
|
2497
1899
|
} catch (error) {
|
|
2498
1900
|
console.error(`[KeyHandler] Error processing paste:`, error);
|
|
2499
1901
|
}
|
|
@@ -2502,9 +1904,6 @@ class KeyHandler extends EventEmitter {
|
|
|
2502
1904
|
|
|
2503
1905
|
class InternalKeyHandler extends KeyHandler {
|
|
2504
1906
|
renderableHandlers = new Map;
|
|
2505
|
-
constructor(useKittyKeyboard = false) {
|
|
2506
|
-
super(useKittyKeyboard);
|
|
2507
|
-
}
|
|
2508
1907
|
emit(event, ...args) {
|
|
2509
1908
|
return this.emitWithPriority(event, ...args);
|
|
2510
1909
|
}
|
|
@@ -5448,785 +4847,1169 @@ var pallet_default = {
|
|
|
5448
4847
|
}
|
|
5449
4848
|
};
|
|
5450
4849
|
|
|
5451
|
-
// src/lib/ascii.font.ts
|
|
5452
|
-
var fonts = {
|
|
5453
|
-
tiny: tiny_default,
|
|
5454
|
-
block: block_default,
|
|
5455
|
-
shade: shade_default,
|
|
5456
|
-
slick: slick_default,
|
|
5457
|
-
huge: huge_default,
|
|
5458
|
-
grid: grid_default,
|
|
5459
|
-
pallet: pallet_default
|
|
5460
|
-
};
|
|
5461
|
-
var parsedFonts = {};
|
|
5462
|
-
function parseColorTags(text) {
|
|
5463
|
-
const segments = [];
|
|
5464
|
-
let currentIndex = 0;
|
|
5465
|
-
const colorTagRegex = /<c(\d+)>(.*?)<\/c\d+>/g;
|
|
5466
|
-
let lastIndex = 0;
|
|
5467
|
-
let match;
|
|
5468
|
-
while ((match = colorTagRegex.exec(text)) !== null) {
|
|
5469
|
-
if (match.index > lastIndex) {
|
|
5470
|
-
const plainText = text.slice(lastIndex, match.index);
|
|
5471
|
-
if (plainText) {
|
|
5472
|
-
segments.push({ text: plainText, colorIndex: 0 });
|
|
5473
|
-
}
|
|
4850
|
+
// src/lib/ascii.font.ts
|
|
4851
|
+
var fonts = {
|
|
4852
|
+
tiny: tiny_default,
|
|
4853
|
+
block: block_default,
|
|
4854
|
+
shade: shade_default,
|
|
4855
|
+
slick: slick_default,
|
|
4856
|
+
huge: huge_default,
|
|
4857
|
+
grid: grid_default,
|
|
4858
|
+
pallet: pallet_default
|
|
4859
|
+
};
|
|
4860
|
+
var parsedFonts = {};
|
|
4861
|
+
function parseColorTags(text) {
|
|
4862
|
+
const segments = [];
|
|
4863
|
+
let currentIndex = 0;
|
|
4864
|
+
const colorTagRegex = /<c(\d+)>(.*?)<\/c\d+>/g;
|
|
4865
|
+
let lastIndex = 0;
|
|
4866
|
+
let match;
|
|
4867
|
+
while ((match = colorTagRegex.exec(text)) !== null) {
|
|
4868
|
+
if (match.index > lastIndex) {
|
|
4869
|
+
const plainText = text.slice(lastIndex, match.index);
|
|
4870
|
+
if (plainText) {
|
|
4871
|
+
segments.push({ text: plainText, colorIndex: 0 });
|
|
4872
|
+
}
|
|
4873
|
+
}
|
|
4874
|
+
const colorIndex = parseInt(match[1]) - 1;
|
|
4875
|
+
const taggedText = match[2];
|
|
4876
|
+
segments.push({ text: taggedText, colorIndex: Math.max(0, colorIndex) });
|
|
4877
|
+
lastIndex = match.index + match[0].length;
|
|
4878
|
+
}
|
|
4879
|
+
if (lastIndex < text.length) {
|
|
4880
|
+
const remainingText = text.slice(lastIndex);
|
|
4881
|
+
if (remainingText) {
|
|
4882
|
+
segments.push({ text: remainingText, colorIndex: 0 });
|
|
4883
|
+
}
|
|
4884
|
+
}
|
|
4885
|
+
return segments;
|
|
4886
|
+
}
|
|
4887
|
+
function getParsedFont(fontKey) {
|
|
4888
|
+
if (!parsedFonts[fontKey]) {
|
|
4889
|
+
const fontDef = fonts[fontKey];
|
|
4890
|
+
const parsedChars = {};
|
|
4891
|
+
for (const [char, lines] of Object.entries(fontDef.chars)) {
|
|
4892
|
+
parsedChars[char] = lines.map((line) => parseColorTags(line));
|
|
4893
|
+
}
|
|
4894
|
+
parsedFonts[fontKey] = {
|
|
4895
|
+
...fontDef,
|
|
4896
|
+
colors: fontDef.colors || 1,
|
|
4897
|
+
chars: parsedChars
|
|
4898
|
+
};
|
|
4899
|
+
}
|
|
4900
|
+
return parsedFonts[fontKey];
|
|
4901
|
+
}
|
|
4902
|
+
function measureText({ text, font = "tiny" }) {
|
|
4903
|
+
const fontDef = getParsedFont(font);
|
|
4904
|
+
if (!fontDef) {
|
|
4905
|
+
console.warn(`Font '${font}' not found`);
|
|
4906
|
+
return { width: 0, height: 0 };
|
|
4907
|
+
}
|
|
4908
|
+
let currentX = 0;
|
|
4909
|
+
for (let i = 0;i < text.length; i++) {
|
|
4910
|
+
const char = text[i].toUpperCase();
|
|
4911
|
+
const charDef = fontDef.chars[char];
|
|
4912
|
+
if (!charDef) {
|
|
4913
|
+
const spaceChar = fontDef.chars[" "];
|
|
4914
|
+
if (spaceChar && spaceChar[0]) {
|
|
4915
|
+
let spaceWidth = 0;
|
|
4916
|
+
for (const segment of spaceChar[0]) {
|
|
4917
|
+
spaceWidth += segment.text.length;
|
|
4918
|
+
}
|
|
4919
|
+
currentX += spaceWidth;
|
|
4920
|
+
} else {
|
|
4921
|
+
currentX += 1;
|
|
4922
|
+
}
|
|
4923
|
+
continue;
|
|
4924
|
+
}
|
|
4925
|
+
let charWidth = 0;
|
|
4926
|
+
if (charDef[0]) {
|
|
4927
|
+
for (const segment of charDef[0]) {
|
|
4928
|
+
charWidth += segment.text.length;
|
|
4929
|
+
}
|
|
4930
|
+
}
|
|
4931
|
+
currentX += charWidth;
|
|
4932
|
+
if (i < text.length - 1) {
|
|
4933
|
+
currentX += fontDef.letterspace_size;
|
|
4934
|
+
}
|
|
4935
|
+
}
|
|
4936
|
+
return {
|
|
4937
|
+
width: currentX,
|
|
4938
|
+
height: fontDef.lines
|
|
4939
|
+
};
|
|
4940
|
+
}
|
|
4941
|
+
function getCharacterPositions(text, font = "tiny") {
|
|
4942
|
+
const fontDef = getParsedFont(font);
|
|
4943
|
+
if (!fontDef) {
|
|
4944
|
+
return [0];
|
|
4945
|
+
}
|
|
4946
|
+
const positions = [0];
|
|
4947
|
+
let currentX = 0;
|
|
4948
|
+
for (let i = 0;i < text.length; i++) {
|
|
4949
|
+
const char = text[i].toUpperCase();
|
|
4950
|
+
const charDef = fontDef.chars[char];
|
|
4951
|
+
let charWidth = 0;
|
|
4952
|
+
if (!charDef) {
|
|
4953
|
+
const spaceChar = fontDef.chars[" "];
|
|
4954
|
+
if (spaceChar && spaceChar[0]) {
|
|
4955
|
+
for (const segment of spaceChar[0]) {
|
|
4956
|
+
charWidth += segment.text.length;
|
|
4957
|
+
}
|
|
4958
|
+
} else {
|
|
4959
|
+
charWidth = 1;
|
|
4960
|
+
}
|
|
4961
|
+
} else if (charDef[0]) {
|
|
4962
|
+
for (const segment of charDef[0]) {
|
|
4963
|
+
charWidth += segment.text.length;
|
|
4964
|
+
}
|
|
4965
|
+
}
|
|
4966
|
+
currentX += charWidth;
|
|
4967
|
+
if (i < text.length - 1) {
|
|
4968
|
+
currentX += fontDef.letterspace_size;
|
|
4969
|
+
}
|
|
4970
|
+
positions.push(currentX);
|
|
4971
|
+
}
|
|
4972
|
+
return positions;
|
|
4973
|
+
}
|
|
4974
|
+
function coordinateToCharacterIndex(x, text, font = "tiny") {
|
|
4975
|
+
const positions = getCharacterPositions(text, font);
|
|
4976
|
+
if (x < 0) {
|
|
4977
|
+
return 0;
|
|
4978
|
+
}
|
|
4979
|
+
for (let i = 0;i < positions.length - 1; i++) {
|
|
4980
|
+
const currentPos = positions[i];
|
|
4981
|
+
const nextPos = positions[i + 1];
|
|
4982
|
+
if (x >= currentPos && x < nextPos) {
|
|
4983
|
+
const charMidpoint = currentPos + (nextPos - currentPos) / 2;
|
|
4984
|
+
return x < charMidpoint ? i : i + 1;
|
|
4985
|
+
}
|
|
4986
|
+
}
|
|
4987
|
+
if (positions.length > 0 && x >= positions[positions.length - 1]) {
|
|
4988
|
+
return text.length;
|
|
4989
|
+
}
|
|
4990
|
+
return 0;
|
|
4991
|
+
}
|
|
4992
|
+
function renderFontToFrameBuffer(buffer, {
|
|
4993
|
+
text,
|
|
4994
|
+
x = 0,
|
|
4995
|
+
y = 0,
|
|
4996
|
+
color = [RGBA.fromInts(255, 255, 255, 255)],
|
|
4997
|
+
backgroundColor = RGBA.fromInts(0, 0, 0, 255),
|
|
4998
|
+
font = "tiny"
|
|
4999
|
+
}) {
|
|
5000
|
+
const width = buffer.width;
|
|
5001
|
+
const height = buffer.height;
|
|
5002
|
+
const fontDef = getParsedFont(font);
|
|
5003
|
+
if (!fontDef) {
|
|
5004
|
+
console.warn(`Font '${font}' not found`);
|
|
5005
|
+
return { width: 0, height: 0 };
|
|
5006
|
+
}
|
|
5007
|
+
const colors = Array.isArray(color) ? color : [color];
|
|
5008
|
+
if (y < 0 || y + fontDef.lines > height) {
|
|
5009
|
+
return { width: 0, height: fontDef.lines };
|
|
5010
|
+
}
|
|
5011
|
+
let currentX = x;
|
|
5012
|
+
const startX = x;
|
|
5013
|
+
for (let i = 0;i < text.length; i++) {
|
|
5014
|
+
const char = text[i].toUpperCase();
|
|
5015
|
+
const charDef = fontDef.chars[char];
|
|
5016
|
+
if (!charDef) {
|
|
5017
|
+
const spaceChar = fontDef.chars[" "];
|
|
5018
|
+
if (spaceChar && spaceChar[0]) {
|
|
5019
|
+
let spaceWidth = 0;
|
|
5020
|
+
for (const segment of spaceChar[0]) {
|
|
5021
|
+
spaceWidth += segment.text.length;
|
|
5022
|
+
}
|
|
5023
|
+
currentX += spaceWidth;
|
|
5024
|
+
} else {
|
|
5025
|
+
currentX += 1;
|
|
5026
|
+
}
|
|
5027
|
+
continue;
|
|
5028
|
+
}
|
|
5029
|
+
let charWidth = 0;
|
|
5030
|
+
if (charDef[0]) {
|
|
5031
|
+
for (const segment of charDef[0]) {
|
|
5032
|
+
charWidth += segment.text.length;
|
|
5033
|
+
}
|
|
5034
|
+
}
|
|
5035
|
+
if (currentX >= width)
|
|
5036
|
+
break;
|
|
5037
|
+
if (currentX + charWidth < 0) {
|
|
5038
|
+
currentX += charWidth + fontDef.letterspace_size;
|
|
5039
|
+
continue;
|
|
5040
|
+
}
|
|
5041
|
+
for (let lineIdx = 0;lineIdx < fontDef.lines && lineIdx < charDef.length; lineIdx++) {
|
|
5042
|
+
const segments = charDef[lineIdx];
|
|
5043
|
+
const renderY = y + lineIdx;
|
|
5044
|
+
if (renderY >= 0 && renderY < height) {
|
|
5045
|
+
let segmentX = currentX;
|
|
5046
|
+
for (const segment of segments) {
|
|
5047
|
+
const segmentColor = colors[segment.colorIndex] || colors[0];
|
|
5048
|
+
for (let charIdx = 0;charIdx < segment.text.length; charIdx++) {
|
|
5049
|
+
const renderX = segmentX + charIdx;
|
|
5050
|
+
if (renderX >= 0 && renderX < width) {
|
|
5051
|
+
const fontChar = segment.text[charIdx];
|
|
5052
|
+
if (fontChar !== " ") {
|
|
5053
|
+
buffer.setCellWithAlphaBlending(renderX, renderY, fontChar, parseColor(segmentColor), parseColor(backgroundColor));
|
|
5054
|
+
}
|
|
5055
|
+
}
|
|
5056
|
+
}
|
|
5057
|
+
segmentX += segment.text.length;
|
|
5058
|
+
}
|
|
5059
|
+
}
|
|
5060
|
+
}
|
|
5061
|
+
currentX += charWidth;
|
|
5062
|
+
if (i < text.length - 1) {
|
|
5063
|
+
currentX += fontDef.letterspace_size;
|
|
5064
|
+
}
|
|
5065
|
+
}
|
|
5066
|
+
return {
|
|
5067
|
+
width: currentX - startX,
|
|
5068
|
+
height: fontDef.lines
|
|
5069
|
+
};
|
|
5070
|
+
}
|
|
5071
|
+
|
|
5072
|
+
// src/types.ts
|
|
5073
|
+
var TextAttributes = {
|
|
5074
|
+
NONE: 0,
|
|
5075
|
+
BOLD: 1 << 0,
|
|
5076
|
+
DIM: 1 << 1,
|
|
5077
|
+
ITALIC: 1 << 2,
|
|
5078
|
+
UNDERLINE: 1 << 3,
|
|
5079
|
+
BLINK: 1 << 4,
|
|
5080
|
+
INVERSE: 1 << 5,
|
|
5081
|
+
HIDDEN: 1 << 6,
|
|
5082
|
+
STRIKETHROUGH: 1 << 7
|
|
5083
|
+
};
|
|
5084
|
+
var ATTRIBUTE_BASE_BITS = 8;
|
|
5085
|
+
var ATTRIBUTE_BASE_MASK = 255;
|
|
5086
|
+
function getBaseAttributes(attr) {
|
|
5087
|
+
return attr & ATTRIBUTE_BASE_MASK;
|
|
5088
|
+
}
|
|
5089
|
+
var DebugOverlayCorner;
|
|
5090
|
+
((DebugOverlayCorner2) => {
|
|
5091
|
+
DebugOverlayCorner2[DebugOverlayCorner2["topLeft"] = 0] = "topLeft";
|
|
5092
|
+
DebugOverlayCorner2[DebugOverlayCorner2["topRight"] = 1] = "topRight";
|
|
5093
|
+
DebugOverlayCorner2[DebugOverlayCorner2["bottomLeft"] = 2] = "bottomLeft";
|
|
5094
|
+
DebugOverlayCorner2[DebugOverlayCorner2["bottomRight"] = 3] = "bottomRight";
|
|
5095
|
+
})(DebugOverlayCorner ||= {});
|
|
5096
|
+
|
|
5097
|
+
// src/utils.ts
|
|
5098
|
+
function createTextAttributes({
|
|
5099
|
+
bold = false,
|
|
5100
|
+
italic = false,
|
|
5101
|
+
underline = false,
|
|
5102
|
+
dim = false,
|
|
5103
|
+
blink = false,
|
|
5104
|
+
inverse = false,
|
|
5105
|
+
hidden = false,
|
|
5106
|
+
strikethrough = false
|
|
5107
|
+
} = {}) {
|
|
5108
|
+
let attributes = TextAttributes.NONE;
|
|
5109
|
+
if (bold)
|
|
5110
|
+
attributes |= TextAttributes.BOLD;
|
|
5111
|
+
if (italic)
|
|
5112
|
+
attributes |= TextAttributes.ITALIC;
|
|
5113
|
+
if (underline)
|
|
5114
|
+
attributes |= TextAttributes.UNDERLINE;
|
|
5115
|
+
if (dim)
|
|
5116
|
+
attributes |= TextAttributes.DIM;
|
|
5117
|
+
if (blink)
|
|
5118
|
+
attributes |= TextAttributes.BLINK;
|
|
5119
|
+
if (inverse)
|
|
5120
|
+
attributes |= TextAttributes.INVERSE;
|
|
5121
|
+
if (hidden)
|
|
5122
|
+
attributes |= TextAttributes.HIDDEN;
|
|
5123
|
+
if (strikethrough)
|
|
5124
|
+
attributes |= TextAttributes.STRIKETHROUGH;
|
|
5125
|
+
return attributes;
|
|
5126
|
+
}
|
|
5127
|
+
var ATTRIBUTE_BASE_MASK2 = 255;
|
|
5128
|
+
var LINK_ID_SHIFT = 8;
|
|
5129
|
+
var LINK_ID_PAYLOAD_MASK = 16777215;
|
|
5130
|
+
function attributesWithLink(baseAttributes, linkId) {
|
|
5131
|
+
const base = baseAttributes & ATTRIBUTE_BASE_MASK2;
|
|
5132
|
+
const linkBits = (linkId & LINK_ID_PAYLOAD_MASK) << LINK_ID_SHIFT;
|
|
5133
|
+
return base | linkBits;
|
|
5134
|
+
}
|
|
5135
|
+
function getLinkId(attributes) {
|
|
5136
|
+
return attributes >>> LINK_ID_SHIFT & LINK_ID_PAYLOAD_MASK;
|
|
5137
|
+
}
|
|
5138
|
+
function visualizeRenderableTree(renderable, maxDepth = 10) {
|
|
5139
|
+
function buildTreeLines(node, prefix = "", parentPrefix = "", isLastChild = true, depth = 0) {
|
|
5140
|
+
if (depth >= maxDepth) {
|
|
5141
|
+
return [`${prefix}${node.id} ... (max depth reached)`];
|
|
5474
5142
|
}
|
|
5475
|
-
const
|
|
5476
|
-
const
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5143
|
+
const lines = [];
|
|
5144
|
+
const children = node.getChildren();
|
|
5145
|
+
lines.push(`${prefix}${node.id}`);
|
|
5146
|
+
if (children.length > 0) {
|
|
5147
|
+
const lastChildIndex = children.length - 1;
|
|
5148
|
+
children.forEach((child, index) => {
|
|
5149
|
+
const childIsLast = index === lastChildIndex;
|
|
5150
|
+
const connector = childIsLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
5151
|
+
const childPrefix = parentPrefix + (isLastChild ? " " : "\u2502 ");
|
|
5152
|
+
const childLines = buildTreeLines(child, childPrefix + connector, childPrefix, childIsLast, depth + 1);
|
|
5153
|
+
lines.push(...childLines);
|
|
5154
|
+
});
|
|
5484
5155
|
}
|
|
5156
|
+
return lines;
|
|
5485
5157
|
}
|
|
5486
|
-
|
|
5158
|
+
const treeLines = buildTreeLines(renderable);
|
|
5159
|
+
console.log(`Renderable Tree:
|
|
5160
|
+
` + treeLines.join(`
|
|
5161
|
+
`));
|
|
5487
5162
|
}
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5163
|
+
|
|
5164
|
+
// src/lib/styled-text.ts
|
|
5165
|
+
var BrandedStyledText = Symbol.for("@opentui/core/StyledText");
|
|
5166
|
+
function isStyledText(obj) {
|
|
5167
|
+
return obj && obj[BrandedStyledText];
|
|
5168
|
+
}
|
|
5169
|
+
|
|
5170
|
+
class StyledText {
|
|
5171
|
+
[BrandedStyledText] = true;
|
|
5172
|
+
chunks;
|
|
5173
|
+
constructor(chunks) {
|
|
5174
|
+
this.chunks = chunks;
|
|
5500
5175
|
}
|
|
5501
|
-
return parsedFonts[fontKey];
|
|
5502
5176
|
}
|
|
5503
|
-
function
|
|
5504
|
-
const
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5177
|
+
function stringToStyledText(content) {
|
|
5178
|
+
const chunk = {
|
|
5179
|
+
__isChunk: true,
|
|
5180
|
+
text: content
|
|
5181
|
+
};
|
|
5182
|
+
return new StyledText([chunk]);
|
|
5183
|
+
}
|
|
5184
|
+
function applyStyle(input, style) {
|
|
5185
|
+
if (typeof input === "object" && "__isChunk" in input) {
|
|
5186
|
+
const existingChunk = input;
|
|
5187
|
+
const fg = style.fg ? parseColor(style.fg) : existingChunk.fg;
|
|
5188
|
+
const bg = style.bg ? parseColor(style.bg) : existingChunk.bg;
|
|
5189
|
+
const newAttrs = createTextAttributes(style);
|
|
5190
|
+
const mergedAttrs = existingChunk.attributes ? existingChunk.attributes | newAttrs : newAttrs;
|
|
5191
|
+
return {
|
|
5192
|
+
__isChunk: true,
|
|
5193
|
+
text: existingChunk.text,
|
|
5194
|
+
fg,
|
|
5195
|
+
bg,
|
|
5196
|
+
attributes: mergedAttrs,
|
|
5197
|
+
link: existingChunk.link
|
|
5198
|
+
};
|
|
5199
|
+
} else {
|
|
5200
|
+
const plainTextStr = String(input);
|
|
5201
|
+
const fg = style.fg ? parseColor(style.fg) : undefined;
|
|
5202
|
+
const bg = style.bg ? parseColor(style.bg) : undefined;
|
|
5203
|
+
const attributes = createTextAttributes(style);
|
|
5204
|
+
return {
|
|
5205
|
+
__isChunk: true,
|
|
5206
|
+
text: plainTextStr,
|
|
5207
|
+
fg,
|
|
5208
|
+
bg,
|
|
5209
|
+
attributes
|
|
5210
|
+
};
|
|
5508
5211
|
}
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5212
|
+
}
|
|
5213
|
+
var black = (input) => applyStyle(input, { fg: "black" });
|
|
5214
|
+
var red = (input) => applyStyle(input, { fg: "red" });
|
|
5215
|
+
var green = (input) => applyStyle(input, { fg: "green" });
|
|
5216
|
+
var yellow = (input) => applyStyle(input, { fg: "yellow" });
|
|
5217
|
+
var blue = (input) => applyStyle(input, { fg: "blue" });
|
|
5218
|
+
var magenta = (input) => applyStyle(input, { fg: "magenta" });
|
|
5219
|
+
var cyan = (input) => applyStyle(input, { fg: "cyan" });
|
|
5220
|
+
var white = (input) => applyStyle(input, { fg: "white" });
|
|
5221
|
+
var brightBlack = (input) => applyStyle(input, { fg: "brightBlack" });
|
|
5222
|
+
var brightRed = (input) => applyStyle(input, { fg: "brightRed" });
|
|
5223
|
+
var brightGreen = (input) => applyStyle(input, { fg: "brightGreen" });
|
|
5224
|
+
var brightYellow = (input) => applyStyle(input, { fg: "brightYellow" });
|
|
5225
|
+
var brightBlue = (input) => applyStyle(input, { fg: "brightBlue" });
|
|
5226
|
+
var brightMagenta = (input) => applyStyle(input, { fg: "brightMagenta" });
|
|
5227
|
+
var brightCyan = (input) => applyStyle(input, { fg: "brightCyan" });
|
|
5228
|
+
var brightWhite = (input) => applyStyle(input, { fg: "brightWhite" });
|
|
5229
|
+
var bgBlack = (input) => applyStyle(input, { bg: "black" });
|
|
5230
|
+
var bgRed = (input) => applyStyle(input, { bg: "red" });
|
|
5231
|
+
var bgGreen = (input) => applyStyle(input, { bg: "green" });
|
|
5232
|
+
var bgYellow = (input) => applyStyle(input, { bg: "yellow" });
|
|
5233
|
+
var bgBlue = (input) => applyStyle(input, { bg: "blue" });
|
|
5234
|
+
var bgMagenta = (input) => applyStyle(input, { bg: "magenta" });
|
|
5235
|
+
var bgCyan = (input) => applyStyle(input, { bg: "cyan" });
|
|
5236
|
+
var bgWhite = (input) => applyStyle(input, { bg: "white" });
|
|
5237
|
+
var bold = (input) => applyStyle(input, { bold: true });
|
|
5238
|
+
var italic = (input) => applyStyle(input, { italic: true });
|
|
5239
|
+
var underline = (input) => applyStyle(input, { underline: true });
|
|
5240
|
+
var strikethrough = (input) => applyStyle(input, { strikethrough: true });
|
|
5241
|
+
var dim = (input) => applyStyle(input, { dim: true });
|
|
5242
|
+
var reverse = (input) => applyStyle(input, { reverse: true });
|
|
5243
|
+
var blink = (input) => applyStyle(input, { blink: true });
|
|
5244
|
+
var fg = (color) => (input) => applyStyle(input, { fg: color });
|
|
5245
|
+
var bg = (color) => (input) => applyStyle(input, { bg: color });
|
|
5246
|
+
var link = (url) => (input) => {
|
|
5247
|
+
const chunk = typeof input === "object" && "__isChunk" in input ? input : {
|
|
5248
|
+
__isChunk: true,
|
|
5249
|
+
text: String(input)
|
|
5250
|
+
};
|
|
5251
|
+
return {
|
|
5252
|
+
...chunk,
|
|
5253
|
+
link: { url }
|
|
5254
|
+
};
|
|
5255
|
+
};
|
|
5256
|
+
function t(strings, ...values) {
|
|
5257
|
+
const chunks = [];
|
|
5258
|
+
for (let i = 0;i < strings.length; i++) {
|
|
5259
|
+
const raw = strings[i];
|
|
5260
|
+
if (raw) {
|
|
5261
|
+
chunks.push({
|
|
5262
|
+
__isChunk: true,
|
|
5263
|
+
text: raw,
|
|
5264
|
+
attributes: 0
|
|
5265
|
+
});
|
|
5525
5266
|
}
|
|
5526
|
-
|
|
5527
|
-
if (
|
|
5528
|
-
|
|
5529
|
-
|
|
5267
|
+
const val = values[i];
|
|
5268
|
+
if (typeof val === "object" && "__isChunk" in val) {
|
|
5269
|
+
chunks.push(val);
|
|
5270
|
+
} else if (val !== undefined) {
|
|
5271
|
+
const plainTextStr = String(val);
|
|
5272
|
+
chunks.push({
|
|
5273
|
+
__isChunk: true,
|
|
5274
|
+
text: plainTextStr,
|
|
5275
|
+
attributes: 0
|
|
5276
|
+
});
|
|
5277
|
+
}
|
|
5278
|
+
}
|
|
5279
|
+
return new StyledText(chunks);
|
|
5280
|
+
}
|
|
5281
|
+
|
|
5282
|
+
// src/lib/hast-styled-text.ts
|
|
5283
|
+
function hastToTextChunks(node, syntaxStyle, parentStyles = []) {
|
|
5284
|
+
const chunks = [];
|
|
5285
|
+
if (node.type === "text") {
|
|
5286
|
+
const stylesToMerge = parentStyles.length > 0 ? parentStyles : ["default"];
|
|
5287
|
+
const mergedStyle = syntaxStyle.mergeStyles(...stylesToMerge);
|
|
5288
|
+
chunks.push({
|
|
5289
|
+
__isChunk: true,
|
|
5290
|
+
text: node.value,
|
|
5291
|
+
fg: mergedStyle.fg,
|
|
5292
|
+
bg: mergedStyle.bg,
|
|
5293
|
+
attributes: mergedStyle.attributes
|
|
5294
|
+
});
|
|
5295
|
+
} else if (node.type === "element") {
|
|
5296
|
+
let currentStyles = [...parentStyles];
|
|
5297
|
+
if (node.properties?.className) {
|
|
5298
|
+
const classes = node.properties.className.split(" ");
|
|
5299
|
+
for (const cls of classes) {
|
|
5300
|
+
currentStyles.push(cls);
|
|
5530
5301
|
}
|
|
5531
5302
|
}
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
currentX += fontDef.letterspace_size;
|
|
5303
|
+
for (const child of node.children) {
|
|
5304
|
+
chunks.push(...hastToTextChunks(child, syntaxStyle, currentStyles));
|
|
5535
5305
|
}
|
|
5536
5306
|
}
|
|
5537
|
-
return
|
|
5538
|
-
width: currentX,
|
|
5539
|
-
height: fontDef.lines
|
|
5540
|
-
};
|
|
5307
|
+
return chunks;
|
|
5541
5308
|
}
|
|
5542
|
-
function
|
|
5543
|
-
const
|
|
5544
|
-
|
|
5545
|
-
|
|
5309
|
+
function hastToStyledText(hast, syntaxStyle) {
|
|
5310
|
+
const chunks = hastToTextChunks(hast, syntaxStyle);
|
|
5311
|
+
return new StyledText(chunks);
|
|
5312
|
+
}
|
|
5313
|
+
|
|
5314
|
+
// src/lib/clock.ts
|
|
5315
|
+
class SystemClock {
|
|
5316
|
+
now() {
|
|
5317
|
+
return Date.now();
|
|
5546
5318
|
}
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
}
|
|
5559
|
-
} else {
|
|
5560
|
-
charWidth = 1;
|
|
5561
|
-
}
|
|
5562
|
-
} else if (charDef[0]) {
|
|
5563
|
-
for (const segment of charDef[0]) {
|
|
5564
|
-
charWidth += segment.text.length;
|
|
5565
|
-
}
|
|
5566
|
-
}
|
|
5567
|
-
currentX += charWidth;
|
|
5568
|
-
if (i < text.length - 1) {
|
|
5569
|
-
currentX += fontDef.letterspace_size;
|
|
5570
|
-
}
|
|
5571
|
-
positions.push(currentX);
|
|
5319
|
+
setTimeout(fn, delayMs) {
|
|
5320
|
+
return globalThis.setTimeout(fn, delayMs);
|
|
5321
|
+
}
|
|
5322
|
+
clearTimeout(handle) {
|
|
5323
|
+
globalThis.clearTimeout(handle);
|
|
5324
|
+
}
|
|
5325
|
+
setInterval(fn, delayMs) {
|
|
5326
|
+
return globalThis.setInterval(fn, delayMs);
|
|
5327
|
+
}
|
|
5328
|
+
clearInterval(handle) {
|
|
5329
|
+
globalThis.clearInterval(handle);
|
|
5572
5330
|
}
|
|
5573
|
-
return positions;
|
|
5574
5331
|
}
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5332
|
+
|
|
5333
|
+
// src/lib/parse.keypress.ts
|
|
5334
|
+
import { Buffer as Buffer2 } from "buffer";
|
|
5335
|
+
|
|
5336
|
+
// src/lib/parse.keypress-kitty.ts
|
|
5337
|
+
var kittyKeyMap = {
|
|
5338
|
+
27: "escape",
|
|
5339
|
+
9: "tab",
|
|
5340
|
+
13: "return",
|
|
5341
|
+
127: "backspace",
|
|
5342
|
+
57344: "escape",
|
|
5343
|
+
57345: "return",
|
|
5344
|
+
57346: "tab",
|
|
5345
|
+
57347: "backspace",
|
|
5346
|
+
57348: "insert",
|
|
5347
|
+
57349: "delete",
|
|
5348
|
+
57350: "left",
|
|
5349
|
+
57351: "right",
|
|
5350
|
+
57352: "up",
|
|
5351
|
+
57353: "down",
|
|
5352
|
+
57354: "pageup",
|
|
5353
|
+
57355: "pagedown",
|
|
5354
|
+
57356: "home",
|
|
5355
|
+
57357: "end",
|
|
5356
|
+
57358: "capslock",
|
|
5357
|
+
57359: "scrolllock",
|
|
5358
|
+
57360: "numlock",
|
|
5359
|
+
57361: "printscreen",
|
|
5360
|
+
57362: "pause",
|
|
5361
|
+
57363: "menu",
|
|
5362
|
+
57364: "f1",
|
|
5363
|
+
57365: "f2",
|
|
5364
|
+
57366: "f3",
|
|
5365
|
+
57367: "f4",
|
|
5366
|
+
57368: "f5",
|
|
5367
|
+
57369: "f6",
|
|
5368
|
+
57370: "f7",
|
|
5369
|
+
57371: "f8",
|
|
5370
|
+
57372: "f9",
|
|
5371
|
+
57373: "f10",
|
|
5372
|
+
57374: "f11",
|
|
5373
|
+
57375: "f12",
|
|
5374
|
+
57376: "f13",
|
|
5375
|
+
57377: "f14",
|
|
5376
|
+
57378: "f15",
|
|
5377
|
+
57379: "f16",
|
|
5378
|
+
57380: "f17",
|
|
5379
|
+
57381: "f18",
|
|
5380
|
+
57382: "f19",
|
|
5381
|
+
57383: "f20",
|
|
5382
|
+
57384: "f21",
|
|
5383
|
+
57385: "f22",
|
|
5384
|
+
57386: "f23",
|
|
5385
|
+
57387: "f24",
|
|
5386
|
+
57388: "f25",
|
|
5387
|
+
57389: "f26",
|
|
5388
|
+
57390: "f27",
|
|
5389
|
+
57391: "f28",
|
|
5390
|
+
57392: "f29",
|
|
5391
|
+
57393: "f30",
|
|
5392
|
+
57394: "f31",
|
|
5393
|
+
57395: "f32",
|
|
5394
|
+
57396: "f33",
|
|
5395
|
+
57397: "f34",
|
|
5396
|
+
57398: "f35",
|
|
5397
|
+
57399: "kp0",
|
|
5398
|
+
57400: "kp1",
|
|
5399
|
+
57401: "kp2",
|
|
5400
|
+
57402: "kp3",
|
|
5401
|
+
57403: "kp4",
|
|
5402
|
+
57404: "kp5",
|
|
5403
|
+
57405: "kp6",
|
|
5404
|
+
57406: "kp7",
|
|
5405
|
+
57407: "kp8",
|
|
5406
|
+
57408: "kp9",
|
|
5407
|
+
57409: "kpdecimal",
|
|
5408
|
+
57410: "kpdivide",
|
|
5409
|
+
57411: "kpmultiply",
|
|
5410
|
+
57412: "kpminus",
|
|
5411
|
+
57413: "kpplus",
|
|
5412
|
+
57414: "kpenter",
|
|
5413
|
+
57415: "kpequal",
|
|
5414
|
+
57416: "kpseparator",
|
|
5415
|
+
57417: "kpleft",
|
|
5416
|
+
57418: "kpright",
|
|
5417
|
+
57419: "kpup",
|
|
5418
|
+
57420: "kpdown",
|
|
5419
|
+
57421: "kppageup",
|
|
5420
|
+
57422: "kppagedown",
|
|
5421
|
+
57423: "kphome",
|
|
5422
|
+
57424: "kpend",
|
|
5423
|
+
57425: "kpinsert",
|
|
5424
|
+
57426: "kpdelete",
|
|
5425
|
+
57427: "clear",
|
|
5426
|
+
57428: "mediaplay",
|
|
5427
|
+
57429: "mediapause",
|
|
5428
|
+
57430: "mediaplaypause",
|
|
5429
|
+
57431: "mediareverse",
|
|
5430
|
+
57432: "mediastop",
|
|
5431
|
+
57433: "mediafastforward",
|
|
5432
|
+
57434: "mediarewind",
|
|
5433
|
+
57435: "medianext",
|
|
5434
|
+
57436: "mediaprev",
|
|
5435
|
+
57437: "mediarecord",
|
|
5436
|
+
57438: "volumedown",
|
|
5437
|
+
57439: "volumeup",
|
|
5438
|
+
57440: "mute",
|
|
5439
|
+
57441: "leftshift",
|
|
5440
|
+
57442: "leftctrl",
|
|
5441
|
+
57443: "leftalt",
|
|
5442
|
+
57444: "leftsuper",
|
|
5443
|
+
57445: "lefthyper",
|
|
5444
|
+
57446: "leftmeta",
|
|
5445
|
+
57447: "rightshift",
|
|
5446
|
+
57448: "rightctrl",
|
|
5447
|
+
57449: "rightalt",
|
|
5448
|
+
57450: "rightsuper",
|
|
5449
|
+
57451: "righthyper",
|
|
5450
|
+
57452: "rightmeta",
|
|
5451
|
+
57453: "iso_level3_shift",
|
|
5452
|
+
57454: "iso_level5_shift"
|
|
5453
|
+
};
|
|
5454
|
+
function fromKittyMods(mod) {
|
|
5455
|
+
return {
|
|
5456
|
+
shift: !!(mod & 1),
|
|
5457
|
+
alt: !!(mod & 2),
|
|
5458
|
+
ctrl: !!(mod & 4),
|
|
5459
|
+
super: !!(mod & 8),
|
|
5460
|
+
hyper: !!(mod & 16),
|
|
5461
|
+
meta: !!(mod & 32),
|
|
5462
|
+
capsLock: !!(mod & 64),
|
|
5463
|
+
numLock: !!(mod & 128)
|
|
5464
|
+
};
|
|
5465
|
+
}
|
|
5466
|
+
var functionalKeyMap = {
|
|
5467
|
+
A: "up",
|
|
5468
|
+
B: "down",
|
|
5469
|
+
C: "right",
|
|
5470
|
+
D: "left",
|
|
5471
|
+
H: "home",
|
|
5472
|
+
F: "end",
|
|
5473
|
+
E: "clear",
|
|
5474
|
+
P: "f1",
|
|
5475
|
+
Q: "f2",
|
|
5476
|
+
S: "f4"
|
|
5477
|
+
};
|
|
5478
|
+
var tildeKeyMap = {
|
|
5479
|
+
"1": "home",
|
|
5480
|
+
"2": "insert",
|
|
5481
|
+
"3": "delete",
|
|
5482
|
+
"4": "end",
|
|
5483
|
+
"5": "pageup",
|
|
5484
|
+
"6": "pagedown",
|
|
5485
|
+
"7": "home",
|
|
5486
|
+
"8": "end",
|
|
5487
|
+
"11": "f1",
|
|
5488
|
+
"12": "f2",
|
|
5489
|
+
"13": "f3",
|
|
5490
|
+
"14": "f4",
|
|
5491
|
+
"15": "f5",
|
|
5492
|
+
"17": "f6",
|
|
5493
|
+
"18": "f7",
|
|
5494
|
+
"19": "f8",
|
|
5495
|
+
"20": "f9",
|
|
5496
|
+
"21": "f10",
|
|
5497
|
+
"23": "f11",
|
|
5498
|
+
"24": "f12",
|
|
5499
|
+
"29": "menu",
|
|
5500
|
+
"57427": "clear"
|
|
5501
|
+
};
|
|
5502
|
+
function parseKittySpecialKey(sequence) {
|
|
5503
|
+
const specialKeyRe = /^\x1b\[(\d+);(\d+):(\d+)([A-Z~])$/;
|
|
5504
|
+
const match = specialKeyRe.exec(sequence);
|
|
5505
|
+
if (!match)
|
|
5506
|
+
return null;
|
|
5507
|
+
const keyNumOrOne = match[1];
|
|
5508
|
+
const modifierStr = match[2];
|
|
5509
|
+
const eventTypeStr = match[3];
|
|
5510
|
+
const terminator = match[4];
|
|
5511
|
+
let keyName;
|
|
5512
|
+
if (terminator === "~") {
|
|
5513
|
+
keyName = tildeKeyMap[keyNumOrOne];
|
|
5514
|
+
} else {
|
|
5515
|
+
if (keyNumOrOne !== "1")
|
|
5516
|
+
return null;
|
|
5517
|
+
keyName = functionalKeyMap[terminator];
|
|
5579
5518
|
}
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5519
|
+
if (!keyName)
|
|
5520
|
+
return null;
|
|
5521
|
+
const key = {
|
|
5522
|
+
name: keyName,
|
|
5523
|
+
ctrl: false,
|
|
5524
|
+
meta: false,
|
|
5525
|
+
shift: false,
|
|
5526
|
+
option: false,
|
|
5527
|
+
number: false,
|
|
5528
|
+
sequence,
|
|
5529
|
+
raw: sequence,
|
|
5530
|
+
eventType: "press",
|
|
5531
|
+
source: "kitty",
|
|
5532
|
+
super: false,
|
|
5533
|
+
hyper: false,
|
|
5534
|
+
capsLock: false,
|
|
5535
|
+
numLock: false
|
|
5536
|
+
};
|
|
5537
|
+
if (modifierStr) {
|
|
5538
|
+
const modifierMask = parseInt(modifierStr, 10);
|
|
5539
|
+
if (!isNaN(modifierMask) && modifierMask > 1) {
|
|
5540
|
+
const mods = fromKittyMods(modifierMask - 1);
|
|
5541
|
+
key.shift = mods.shift;
|
|
5542
|
+
key.ctrl = mods.ctrl;
|
|
5543
|
+
key.meta = mods.alt || mods.meta;
|
|
5544
|
+
key.option = mods.alt;
|
|
5545
|
+
key.super = mods.super;
|
|
5546
|
+
key.hyper = mods.hyper;
|
|
5547
|
+
key.capsLock = mods.capsLock;
|
|
5548
|
+
key.numLock = mods.numLock;
|
|
5586
5549
|
}
|
|
5587
5550
|
}
|
|
5588
|
-
if (
|
|
5589
|
-
|
|
5551
|
+
if (eventTypeStr === "1" || !eventTypeStr) {
|
|
5552
|
+
key.eventType = "press";
|
|
5553
|
+
} else if (eventTypeStr === "2") {
|
|
5554
|
+
key.eventType = "press";
|
|
5555
|
+
key.repeated = true;
|
|
5556
|
+
} else if (eventTypeStr === "3") {
|
|
5557
|
+
key.eventType = "release";
|
|
5590
5558
|
}
|
|
5591
|
-
return
|
|
5559
|
+
return key;
|
|
5592
5560
|
}
|
|
5593
|
-
function
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
const
|
|
5602
|
-
const
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5561
|
+
function parseKittyKeyboard(sequence) {
|
|
5562
|
+
const specialResult = parseKittySpecialKey(sequence);
|
|
5563
|
+
if (specialResult)
|
|
5564
|
+
return specialResult;
|
|
5565
|
+
const kittyRe = /^\x1b\[([^\x1b]+)u$/;
|
|
5566
|
+
const match = kittyRe.exec(sequence);
|
|
5567
|
+
if (!match)
|
|
5568
|
+
return null;
|
|
5569
|
+
const params = match[1];
|
|
5570
|
+
const fields = params.split(";");
|
|
5571
|
+
if (fields.length < 1)
|
|
5572
|
+
return null;
|
|
5573
|
+
const key = {
|
|
5574
|
+
name: "",
|
|
5575
|
+
ctrl: false,
|
|
5576
|
+
meta: false,
|
|
5577
|
+
shift: false,
|
|
5578
|
+
option: false,
|
|
5579
|
+
number: false,
|
|
5580
|
+
sequence,
|
|
5581
|
+
raw: sequence,
|
|
5582
|
+
eventType: "press",
|
|
5583
|
+
source: "kitty",
|
|
5584
|
+
super: false,
|
|
5585
|
+
hyper: false,
|
|
5586
|
+
capsLock: false,
|
|
5587
|
+
numLock: false
|
|
5588
|
+
};
|
|
5589
|
+
let text = "";
|
|
5590
|
+
const field1 = fields[0]?.split(":") || [];
|
|
5591
|
+
const codepointStr = field1[0];
|
|
5592
|
+
if (!codepointStr)
|
|
5593
|
+
return null;
|
|
5594
|
+
const codepoint = parseInt(codepointStr, 10);
|
|
5595
|
+
if (isNaN(codepoint))
|
|
5596
|
+
return null;
|
|
5597
|
+
let shiftedCodepoint;
|
|
5598
|
+
let baseCodepoint;
|
|
5599
|
+
if (field1[1]) {
|
|
5600
|
+
const shifted = parseInt(field1[1], 10);
|
|
5601
|
+
if (!isNaN(shifted) && shifted > 0 && shifted <= 1114111) {
|
|
5602
|
+
shiftedCodepoint = shifted;
|
|
5635
5603
|
}
|
|
5636
|
-
|
|
5637
|
-
|
|
5638
|
-
|
|
5639
|
-
|
|
5640
|
-
|
|
5604
|
+
}
|
|
5605
|
+
if (field1[2]) {
|
|
5606
|
+
const base = parseInt(field1[2], 10);
|
|
5607
|
+
if (!isNaN(base) && base > 0 && base <= 1114111) {
|
|
5608
|
+
baseCodepoint = base;
|
|
5641
5609
|
}
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
}
|
|
5656
|
-
}
|
|
5657
|
-
}
|
|
5658
|
-
segmentX += segment.text.length;
|
|
5659
|
-
}
|
|
5610
|
+
}
|
|
5611
|
+
const knownKey = kittyKeyMap[codepoint];
|
|
5612
|
+
if (knownKey) {
|
|
5613
|
+
key.name = knownKey;
|
|
5614
|
+
key.code = `[${codepoint}u`;
|
|
5615
|
+
} else if (codepoint === 0) {
|
|
5616
|
+
key.name = "";
|
|
5617
|
+
} else {
|
|
5618
|
+
if (codepoint > 0 && codepoint <= 1114111) {
|
|
5619
|
+
const char = String.fromCodePoint(codepoint);
|
|
5620
|
+
key.name = char;
|
|
5621
|
+
if (baseCodepoint) {
|
|
5622
|
+
key.baseCode = baseCodepoint;
|
|
5660
5623
|
}
|
|
5661
|
-
}
|
|
5662
|
-
|
|
5663
|
-
if (i < text.length - 1) {
|
|
5664
|
-
currentX += fontDef.letterspace_size;
|
|
5624
|
+
} else {
|
|
5625
|
+
return null;
|
|
5665
5626
|
}
|
|
5666
5627
|
}
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
};
|
|
5685
|
-
var ATTRIBUTE_BASE_BITS = 8;
|
|
5686
|
-
var ATTRIBUTE_BASE_MASK = 255;
|
|
5687
|
-
function getBaseAttributes(attr) {
|
|
5688
|
-
return attr & ATTRIBUTE_BASE_MASK;
|
|
5689
|
-
}
|
|
5690
|
-
var DebugOverlayCorner;
|
|
5691
|
-
((DebugOverlayCorner2) => {
|
|
5692
|
-
DebugOverlayCorner2[DebugOverlayCorner2["topLeft"] = 0] = "topLeft";
|
|
5693
|
-
DebugOverlayCorner2[DebugOverlayCorner2["topRight"] = 1] = "topRight";
|
|
5694
|
-
DebugOverlayCorner2[DebugOverlayCorner2["bottomLeft"] = 2] = "bottomLeft";
|
|
5695
|
-
DebugOverlayCorner2[DebugOverlayCorner2["bottomRight"] = 3] = "bottomRight";
|
|
5696
|
-
})(DebugOverlayCorner ||= {});
|
|
5697
|
-
|
|
5698
|
-
// src/utils.ts
|
|
5699
|
-
function createTextAttributes({
|
|
5700
|
-
bold = false,
|
|
5701
|
-
italic = false,
|
|
5702
|
-
underline = false,
|
|
5703
|
-
dim = false,
|
|
5704
|
-
blink = false,
|
|
5705
|
-
inverse = false,
|
|
5706
|
-
hidden = false,
|
|
5707
|
-
strikethrough = false
|
|
5708
|
-
} = {}) {
|
|
5709
|
-
let attributes = TextAttributes.NONE;
|
|
5710
|
-
if (bold)
|
|
5711
|
-
attributes |= TextAttributes.BOLD;
|
|
5712
|
-
if (italic)
|
|
5713
|
-
attributes |= TextAttributes.ITALIC;
|
|
5714
|
-
if (underline)
|
|
5715
|
-
attributes |= TextAttributes.UNDERLINE;
|
|
5716
|
-
if (dim)
|
|
5717
|
-
attributes |= TextAttributes.DIM;
|
|
5718
|
-
if (blink)
|
|
5719
|
-
attributes |= TextAttributes.BLINK;
|
|
5720
|
-
if (inverse)
|
|
5721
|
-
attributes |= TextAttributes.INVERSE;
|
|
5722
|
-
if (hidden)
|
|
5723
|
-
attributes |= TextAttributes.HIDDEN;
|
|
5724
|
-
if (strikethrough)
|
|
5725
|
-
attributes |= TextAttributes.STRIKETHROUGH;
|
|
5726
|
-
return attributes;
|
|
5727
|
-
}
|
|
5728
|
-
var ATTRIBUTE_BASE_MASK2 = 255;
|
|
5729
|
-
var LINK_ID_SHIFT = 8;
|
|
5730
|
-
var LINK_ID_PAYLOAD_MASK = 16777215;
|
|
5731
|
-
function attributesWithLink(baseAttributes, linkId) {
|
|
5732
|
-
const base = baseAttributes & ATTRIBUTE_BASE_MASK2;
|
|
5733
|
-
const linkBits = (linkId & LINK_ID_PAYLOAD_MASK) << LINK_ID_SHIFT;
|
|
5734
|
-
return base | linkBits;
|
|
5735
|
-
}
|
|
5736
|
-
function getLinkId(attributes) {
|
|
5737
|
-
return attributes >>> LINK_ID_SHIFT & LINK_ID_PAYLOAD_MASK;
|
|
5738
|
-
}
|
|
5739
|
-
function visualizeRenderableTree(renderable, maxDepth = 10) {
|
|
5740
|
-
function buildTreeLines(node, prefix = "", parentPrefix = "", isLastChild = true, depth = 0) {
|
|
5741
|
-
if (depth >= maxDepth) {
|
|
5742
|
-
return [`${prefix}${node.id} ... (max depth reached)`];
|
|
5628
|
+
if (fields[1]) {
|
|
5629
|
+
const field2 = fields[1].split(":");
|
|
5630
|
+
const modifierStr = field2[0];
|
|
5631
|
+
const eventTypeStr = field2[1];
|
|
5632
|
+
if (modifierStr) {
|
|
5633
|
+
const modifierMask = parseInt(modifierStr, 10);
|
|
5634
|
+
if (!isNaN(modifierMask) && modifierMask > 1) {
|
|
5635
|
+
const mods = fromKittyMods(modifierMask - 1);
|
|
5636
|
+
key.shift = mods.shift;
|
|
5637
|
+
key.ctrl = mods.ctrl;
|
|
5638
|
+
key.meta = mods.alt || mods.meta;
|
|
5639
|
+
key.option = mods.alt;
|
|
5640
|
+
key.super = mods.super;
|
|
5641
|
+
key.hyper = mods.hyper;
|
|
5642
|
+
key.capsLock = mods.capsLock;
|
|
5643
|
+
key.numLock = mods.numLock;
|
|
5644
|
+
}
|
|
5743
5645
|
}
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
const childLines = buildTreeLines(child, childPrefix + connector, childPrefix, childIsLast, depth + 1);
|
|
5754
|
-
lines.push(...childLines);
|
|
5755
|
-
});
|
|
5646
|
+
if (eventTypeStr === "1" || !eventTypeStr) {
|
|
5647
|
+
key.eventType = "press";
|
|
5648
|
+
} else if (eventTypeStr === "2") {
|
|
5649
|
+
key.eventType = "press";
|
|
5650
|
+
key.repeated = true;
|
|
5651
|
+
} else if (eventTypeStr === "3") {
|
|
5652
|
+
key.eventType = "release";
|
|
5653
|
+
} else {
|
|
5654
|
+
key.eventType = "press";
|
|
5756
5655
|
}
|
|
5757
|
-
return lines;
|
|
5758
|
-
}
|
|
5759
|
-
const treeLines = buildTreeLines(renderable);
|
|
5760
|
-
console.log(`Renderable Tree:
|
|
5761
|
-
` + treeLines.join(`
|
|
5762
|
-
`));
|
|
5763
|
-
}
|
|
5764
|
-
|
|
5765
|
-
// src/lib/styled-text.ts
|
|
5766
|
-
var BrandedStyledText = Symbol.for("@opentui/core/StyledText");
|
|
5767
|
-
function isStyledText(obj) {
|
|
5768
|
-
return obj && obj[BrandedStyledText];
|
|
5769
|
-
}
|
|
5770
|
-
|
|
5771
|
-
class StyledText {
|
|
5772
|
-
[BrandedStyledText] = true;
|
|
5773
|
-
chunks;
|
|
5774
|
-
constructor(chunks) {
|
|
5775
|
-
this.chunks = chunks;
|
|
5776
5656
|
}
|
|
5777
|
-
|
|
5778
|
-
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
}
|
|
5785
|
-
function applyStyle(input, style) {
|
|
5786
|
-
if (typeof input === "object" && "__isChunk" in input) {
|
|
5787
|
-
const existingChunk = input;
|
|
5788
|
-
const fg = style.fg ? parseColor(style.fg) : existingChunk.fg;
|
|
5789
|
-
const bg = style.bg ? parseColor(style.bg) : existingChunk.bg;
|
|
5790
|
-
const newAttrs = createTextAttributes(style);
|
|
5791
|
-
const mergedAttrs = existingChunk.attributes ? existingChunk.attributes | newAttrs : newAttrs;
|
|
5792
|
-
return {
|
|
5793
|
-
__isChunk: true,
|
|
5794
|
-
text: existingChunk.text,
|
|
5795
|
-
fg,
|
|
5796
|
-
bg,
|
|
5797
|
-
attributes: mergedAttrs,
|
|
5798
|
-
link: existingChunk.link
|
|
5799
|
-
};
|
|
5800
|
-
} else {
|
|
5801
|
-
const plainTextStr = String(input);
|
|
5802
|
-
const fg = style.fg ? parseColor(style.fg) : undefined;
|
|
5803
|
-
const bg = style.bg ? parseColor(style.bg) : undefined;
|
|
5804
|
-
const attributes = createTextAttributes(style);
|
|
5805
|
-
return {
|
|
5806
|
-
__isChunk: true,
|
|
5807
|
-
text: plainTextStr,
|
|
5808
|
-
fg,
|
|
5809
|
-
bg,
|
|
5810
|
-
attributes
|
|
5811
|
-
};
|
|
5657
|
+
if (fields[2]) {
|
|
5658
|
+
const codepoints = fields[2].split(":");
|
|
5659
|
+
for (const cpStr of codepoints) {
|
|
5660
|
+
const cp = parseInt(cpStr, 10);
|
|
5661
|
+
if (!isNaN(cp) && cp > 0 && cp <= 1114111) {
|
|
5662
|
+
text += String.fromCodePoint(cp);
|
|
5663
|
+
}
|
|
5664
|
+
}
|
|
5812
5665
|
}
|
|
5813
|
-
|
|
5814
|
-
|
|
5815
|
-
|
|
5816
|
-
|
|
5817
|
-
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
var brightRed = (input) => applyStyle(input, { fg: "brightRed" });
|
|
5824
|
-
var brightGreen = (input) => applyStyle(input, { fg: "brightGreen" });
|
|
5825
|
-
var brightYellow = (input) => applyStyle(input, { fg: "brightYellow" });
|
|
5826
|
-
var brightBlue = (input) => applyStyle(input, { fg: "brightBlue" });
|
|
5827
|
-
var brightMagenta = (input) => applyStyle(input, { fg: "brightMagenta" });
|
|
5828
|
-
var brightCyan = (input) => applyStyle(input, { fg: "brightCyan" });
|
|
5829
|
-
var brightWhite = (input) => applyStyle(input, { fg: "brightWhite" });
|
|
5830
|
-
var bgBlack = (input) => applyStyle(input, { bg: "black" });
|
|
5831
|
-
var bgRed = (input) => applyStyle(input, { bg: "red" });
|
|
5832
|
-
var bgGreen = (input) => applyStyle(input, { bg: "green" });
|
|
5833
|
-
var bgYellow = (input) => applyStyle(input, { bg: "yellow" });
|
|
5834
|
-
var bgBlue = (input) => applyStyle(input, { bg: "blue" });
|
|
5835
|
-
var bgMagenta = (input) => applyStyle(input, { bg: "magenta" });
|
|
5836
|
-
var bgCyan = (input) => applyStyle(input, { bg: "cyan" });
|
|
5837
|
-
var bgWhite = (input) => applyStyle(input, { bg: "white" });
|
|
5838
|
-
var bold = (input) => applyStyle(input, { bold: true });
|
|
5839
|
-
var italic = (input) => applyStyle(input, { italic: true });
|
|
5840
|
-
var underline = (input) => applyStyle(input, { underline: true });
|
|
5841
|
-
var strikethrough = (input) => applyStyle(input, { strikethrough: true });
|
|
5842
|
-
var dim = (input) => applyStyle(input, { dim: true });
|
|
5843
|
-
var reverse = (input) => applyStyle(input, { reverse: true });
|
|
5844
|
-
var blink = (input) => applyStyle(input, { blink: true });
|
|
5845
|
-
var fg = (color) => (input) => applyStyle(input, { fg: color });
|
|
5846
|
-
var bg = (color) => (input) => applyStyle(input, { bg: color });
|
|
5847
|
-
var link = (url) => (input) => {
|
|
5848
|
-
const chunk = typeof input === "object" && "__isChunk" in input ? input : {
|
|
5849
|
-
__isChunk: true,
|
|
5850
|
-
text: String(input)
|
|
5851
|
-
};
|
|
5852
|
-
return {
|
|
5853
|
-
...chunk,
|
|
5854
|
-
link: { url }
|
|
5855
|
-
};
|
|
5856
|
-
};
|
|
5857
|
-
function t(strings, ...values) {
|
|
5858
|
-
const chunks = [];
|
|
5859
|
-
for (let i = 0;i < strings.length; i++) {
|
|
5860
|
-
const raw = strings[i];
|
|
5861
|
-
if (raw) {
|
|
5862
|
-
chunks.push({
|
|
5863
|
-
__isChunk: true,
|
|
5864
|
-
text: raw,
|
|
5865
|
-
attributes: 0
|
|
5866
|
-
});
|
|
5666
|
+
if (text === "") {
|
|
5667
|
+
const isPrintable = key.name.length > 0 && !kittyKeyMap[codepoint];
|
|
5668
|
+
if (isPrintable) {
|
|
5669
|
+
if (key.shift && shiftedCodepoint) {
|
|
5670
|
+
text = String.fromCodePoint(shiftedCodepoint);
|
|
5671
|
+
} else if (key.shift && key.name.length === 1) {
|
|
5672
|
+
text = key.name.toLocaleUpperCase();
|
|
5673
|
+
} else {
|
|
5674
|
+
text = key.name;
|
|
5675
|
+
}
|
|
5867
5676
|
}
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
text: plainTextStr,
|
|
5876
|
-
attributes: 0
|
|
5877
|
-
});
|
|
5677
|
+
}
|
|
5678
|
+
if (key.name === " " && key.shift && !key.ctrl && !key.meta) {
|
|
5679
|
+
text = " ";
|
|
5680
|
+
}
|
|
5681
|
+
if (text) {
|
|
5682
|
+
if (codepoint === 0) {
|
|
5683
|
+
key.name = text;
|
|
5878
5684
|
}
|
|
5685
|
+
key.sequence = text;
|
|
5879
5686
|
}
|
|
5880
|
-
|
|
5687
|
+
if (codepoint === 0 && text === "") {
|
|
5688
|
+
return null;
|
|
5689
|
+
}
|
|
5690
|
+
return key;
|
|
5881
5691
|
}
|
|
5882
5692
|
|
|
5883
|
-
// src/lib/
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5693
|
+
// src/lib/parse.keypress.ts
|
|
5694
|
+
var metaKeyCodeRe = /^(?:\x1b)([a-zA-Z0-9])$/;
|
|
5695
|
+
var fnKeyRe = /^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/;
|
|
5696
|
+
var keyName = {
|
|
5697
|
+
OP: "f1",
|
|
5698
|
+
OQ: "f2",
|
|
5699
|
+
OR: "f3",
|
|
5700
|
+
OS: "f4",
|
|
5701
|
+
"[11~": "f1",
|
|
5702
|
+
"[12~": "f2",
|
|
5703
|
+
"[13~": "f3",
|
|
5704
|
+
"[14~": "f4",
|
|
5705
|
+
"[[A": "f1",
|
|
5706
|
+
"[[B": "f2",
|
|
5707
|
+
"[[C": "f3",
|
|
5708
|
+
"[[D": "f4",
|
|
5709
|
+
"[[E": "f5",
|
|
5710
|
+
"[15~": "f5",
|
|
5711
|
+
"[17~": "f6",
|
|
5712
|
+
"[18~": "f7",
|
|
5713
|
+
"[19~": "f8",
|
|
5714
|
+
"[20~": "f9",
|
|
5715
|
+
"[21~": "f10",
|
|
5716
|
+
"[23~": "f11",
|
|
5717
|
+
"[24~": "f12",
|
|
5718
|
+
"[29~": "menu",
|
|
5719
|
+
"[57427~": "clear",
|
|
5720
|
+
"[A": "up",
|
|
5721
|
+
"[B": "down",
|
|
5722
|
+
"[C": "right",
|
|
5723
|
+
"[D": "left",
|
|
5724
|
+
"[E": "clear",
|
|
5725
|
+
"[F": "end",
|
|
5726
|
+
"[H": "home",
|
|
5727
|
+
"[P": "f1",
|
|
5728
|
+
"[Q": "f2",
|
|
5729
|
+
"[S": "f4",
|
|
5730
|
+
OA: "up",
|
|
5731
|
+
OB: "down",
|
|
5732
|
+
OC: "right",
|
|
5733
|
+
OD: "left",
|
|
5734
|
+
OE: "clear",
|
|
5735
|
+
OF: "end",
|
|
5736
|
+
OH: "home",
|
|
5737
|
+
"[1~": "home",
|
|
5738
|
+
"[2~": "insert",
|
|
5739
|
+
"[3~": "delete",
|
|
5740
|
+
"[4~": "end",
|
|
5741
|
+
"[5~": "pageup",
|
|
5742
|
+
"[6~": "pagedown",
|
|
5743
|
+
"[[5~": "pageup",
|
|
5744
|
+
"[[6~": "pagedown",
|
|
5745
|
+
"[7~": "home",
|
|
5746
|
+
"[8~": "end",
|
|
5747
|
+
"[a": "up",
|
|
5748
|
+
"[b": "down",
|
|
5749
|
+
"[c": "right",
|
|
5750
|
+
"[d": "left",
|
|
5751
|
+
"[e": "clear",
|
|
5752
|
+
f: "right",
|
|
5753
|
+
b: "left",
|
|
5754
|
+
p: "up",
|
|
5755
|
+
n: "down",
|
|
5756
|
+
"[2$": "insert",
|
|
5757
|
+
"[3$": "delete",
|
|
5758
|
+
"[5$": "pageup",
|
|
5759
|
+
"[6$": "pagedown",
|
|
5760
|
+
"[7$": "home",
|
|
5761
|
+
"[8$": "end",
|
|
5762
|
+
Oa: "up",
|
|
5763
|
+
Ob: "down",
|
|
5764
|
+
Oc: "right",
|
|
5765
|
+
Od: "left",
|
|
5766
|
+
Oe: "clear",
|
|
5767
|
+
"[2^": "insert",
|
|
5768
|
+
"[3^": "delete",
|
|
5769
|
+
"[5^": "pageup",
|
|
5770
|
+
"[6^": "pagedown",
|
|
5771
|
+
"[7^": "home",
|
|
5772
|
+
"[8^": "end",
|
|
5773
|
+
"[Z": "tab"
|
|
5774
|
+
};
|
|
5775
|
+
var nonAlphanumericKeys = [...Object.values(keyName), "backspace"];
|
|
5776
|
+
var isShiftKey = (code) => {
|
|
5777
|
+
return ["[a", "[b", "[c", "[d", "[e", "[2$", "[3$", "[5$", "[6$", "[7$", "[8$", "[Z"].includes(code);
|
|
5778
|
+
};
|
|
5779
|
+
var isCtrlKey = (code) => {
|
|
5780
|
+
return ["Oa", "Ob", "Oc", "Od", "Oe", "[2^", "[3^", "[5^", "[6^", "[7^", "[8^"].includes(code);
|
|
5781
|
+
};
|
|
5782
|
+
var modifyOtherKeysRe = /^\x1b\[27;(\d+);(\d+)~$/;
|
|
5783
|
+
var parseKeypress = (s = "", options = {}) => {
|
|
5784
|
+
let parts;
|
|
5785
|
+
if (Buffer2.isBuffer(s)) {
|
|
5786
|
+
if (s[0] > 127 && s[1] === undefined) {
|
|
5787
|
+
s[0] -= 128;
|
|
5788
|
+
s = "\x1B" + String(s);
|
|
5789
|
+
} else {
|
|
5790
|
+
s = String(s);
|
|
5906
5791
|
}
|
|
5792
|
+
} else if (s !== undefined && typeof s !== "string") {
|
|
5793
|
+
s = String(s);
|
|
5794
|
+
} else if (!s) {
|
|
5795
|
+
s = "";
|
|
5907
5796
|
}
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
function hastToStyledText(hast, syntaxStyle) {
|
|
5911
|
-
const chunks = hastToTextChunks(hast, syntaxStyle);
|
|
5912
|
-
return new StyledText(chunks);
|
|
5913
|
-
}
|
|
5914
|
-
|
|
5915
|
-
// src/lib/scroll-acceleration.ts
|
|
5916
|
-
class LinearScrollAccel {
|
|
5917
|
-
tick(_now) {
|
|
5918
|
-
return 1;
|
|
5919
|
-
}
|
|
5920
|
-
reset() {}
|
|
5921
|
-
}
|
|
5922
|
-
|
|
5923
|
-
class MacOSScrollAccel {
|
|
5924
|
-
opts;
|
|
5925
|
-
lastTickTime = 0;
|
|
5926
|
-
velocityHistory = [];
|
|
5927
|
-
historySize = 3;
|
|
5928
|
-
streakTimeout = 150;
|
|
5929
|
-
minTickInterval = 6;
|
|
5930
|
-
constructor(opts = {}) {
|
|
5931
|
-
this.opts = opts;
|
|
5797
|
+
if (/^\x1b\[<\d+;\d+;\d+[Mm]$/.test(s)) {
|
|
5798
|
+
return null;
|
|
5932
5799
|
}
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
const tau = this.opts.tau ?? 3;
|
|
5936
|
-
const maxMultiplier = this.opts.maxMultiplier ?? 6;
|
|
5937
|
-
const dt = this.lastTickTime ? now - this.lastTickTime : Infinity;
|
|
5938
|
-
if (dt === Infinity || dt > this.streakTimeout) {
|
|
5939
|
-
this.lastTickTime = now;
|
|
5940
|
-
this.velocityHistory = [];
|
|
5941
|
-
return 1;
|
|
5942
|
-
}
|
|
5943
|
-
if (dt < this.minTickInterval) {
|
|
5944
|
-
return 1;
|
|
5945
|
-
}
|
|
5946
|
-
this.lastTickTime = now;
|
|
5947
|
-
this.velocityHistory.push(dt);
|
|
5948
|
-
if (this.velocityHistory.length > this.historySize) {
|
|
5949
|
-
this.velocityHistory.shift();
|
|
5950
|
-
}
|
|
5951
|
-
const avgInterval = this.velocityHistory.reduce((a, b) => a + b, 0) / this.velocityHistory.length;
|
|
5952
|
-
const referenceInterval = 100;
|
|
5953
|
-
const velocity = referenceInterval / avgInterval;
|
|
5954
|
-
const x = velocity / tau;
|
|
5955
|
-
const multiplier = 1 + A * (Math.exp(x) - 1);
|
|
5956
|
-
return Math.min(multiplier, maxMultiplier);
|
|
5800
|
+
if (/^\[<\d+;\d+;\d+[Mm]$/.test(s)) {
|
|
5801
|
+
return null;
|
|
5957
5802
|
}
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
this.velocityHistory = [];
|
|
5803
|
+
if (/^\x1b\[<[\d;]*$/.test(s)) {
|
|
5804
|
+
return null;
|
|
5961
5805
|
}
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
// src/lib/stdin-buffer.ts
|
|
5965
|
-
import { EventEmitter as EventEmitter2 } from "events";
|
|
5966
|
-
var ESC = "\x1B";
|
|
5967
|
-
var BRACKETED_PASTE_START = "\x1B[200~";
|
|
5968
|
-
var BRACKETED_PASTE_END = "\x1B[201~";
|
|
5969
|
-
function isCompleteSequence(data) {
|
|
5970
|
-
if (!data.startsWith(ESC)) {
|
|
5971
|
-
return "not-escape";
|
|
5806
|
+
if (/^\[<[\d;]*$/.test(s)) {
|
|
5807
|
+
return null;
|
|
5972
5808
|
}
|
|
5973
|
-
if (
|
|
5974
|
-
return
|
|
5809
|
+
if (s.startsWith("\x1B[M") && s.length >= 6) {
|
|
5810
|
+
return null;
|
|
5975
5811
|
}
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
return isCompleteSequence(afterEsc);
|
|
5812
|
+
if (/^\x1b\[\d+;\d+;\d+t$/.test(s)) {
|
|
5813
|
+
return null;
|
|
5979
5814
|
}
|
|
5980
|
-
if (
|
|
5981
|
-
|
|
5982
|
-
return data.length >= 6 ? "complete" : "incomplete";
|
|
5983
|
-
}
|
|
5984
|
-
return isCompleteCsiSequence(data);
|
|
5815
|
+
if (/^\x1b\[\d+;\d+R$/.test(s)) {
|
|
5816
|
+
return null;
|
|
5985
5817
|
}
|
|
5986
|
-
if (
|
|
5987
|
-
return
|
|
5818
|
+
if (/^\x1b\[\?[\d;]+c$/.test(s)) {
|
|
5819
|
+
return null;
|
|
5988
5820
|
}
|
|
5989
|
-
if (
|
|
5990
|
-
return
|
|
5821
|
+
if (/^\x1b\[\?[\d;]+\$y$/.test(s)) {
|
|
5822
|
+
return null;
|
|
5991
5823
|
}
|
|
5992
|
-
if (
|
|
5993
|
-
return
|
|
5824
|
+
if (s === "\x1B[I" || s === "\x1B[O") {
|
|
5825
|
+
return null;
|
|
5994
5826
|
}
|
|
5995
|
-
if (
|
|
5996
|
-
return
|
|
5827
|
+
if (/^\x1b\][\d;].*(\x1b\\|\x07)$/.test(s)) {
|
|
5828
|
+
return null;
|
|
5997
5829
|
}
|
|
5998
|
-
if (
|
|
5999
|
-
return
|
|
5830
|
+
if (s === "\x1B[200~" || s === "\x1B[201~") {
|
|
5831
|
+
return null;
|
|
6000
5832
|
}
|
|
6001
|
-
|
|
6002
|
-
|
|
6003
|
-
|
|
6004
|
-
|
|
6005
|
-
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
}
|
|
6019
|
-
if (lastChar === "M" || lastChar === "m") {
|
|
6020
|
-
const parts = payload.slice(1, -1).split(";");
|
|
6021
|
-
if (parts.length === 3 && parts.every((p) => /^\d+$/.test(p))) {
|
|
6022
|
-
return "complete";
|
|
6023
|
-
}
|
|
6024
|
-
}
|
|
6025
|
-
return "incomplete";
|
|
5833
|
+
const key = {
|
|
5834
|
+
name: "",
|
|
5835
|
+
ctrl: false,
|
|
5836
|
+
meta: false,
|
|
5837
|
+
shift: false,
|
|
5838
|
+
option: false,
|
|
5839
|
+
number: false,
|
|
5840
|
+
sequence: s,
|
|
5841
|
+
raw: s,
|
|
5842
|
+
eventType: "press",
|
|
5843
|
+
source: "raw"
|
|
5844
|
+
};
|
|
5845
|
+
key.sequence = key.sequence || s || key.name;
|
|
5846
|
+
if (options.useKittyKeyboard) {
|
|
5847
|
+
const kittyResult = parseKittyKeyboard(s);
|
|
5848
|
+
if (kittyResult) {
|
|
5849
|
+
return kittyResult;
|
|
6026
5850
|
}
|
|
6027
|
-
return "complete";
|
|
6028
|
-
}
|
|
6029
|
-
return "incomplete";
|
|
6030
|
-
}
|
|
6031
|
-
function isCompleteOscSequence(data) {
|
|
6032
|
-
if (!data.startsWith(ESC + "]")) {
|
|
6033
|
-
return "complete";
|
|
6034
|
-
}
|
|
6035
|
-
if (data.endsWith(ESC + "\\") || data.endsWith("\x07")) {
|
|
6036
|
-
return "complete";
|
|
6037
|
-
}
|
|
6038
|
-
return "incomplete";
|
|
6039
|
-
}
|
|
6040
|
-
function isCompleteDcsSequence(data) {
|
|
6041
|
-
if (!data.startsWith(ESC + "P")) {
|
|
6042
|
-
return "complete";
|
|
6043
|
-
}
|
|
6044
|
-
if (data.endsWith(ESC + "\\")) {
|
|
6045
|
-
return "complete";
|
|
6046
|
-
}
|
|
6047
|
-
return "incomplete";
|
|
6048
|
-
}
|
|
6049
|
-
function isCompleteApcSequence(data) {
|
|
6050
|
-
if (!data.startsWith(ESC + "_")) {
|
|
6051
|
-
return "complete";
|
|
6052
|
-
}
|
|
6053
|
-
if (data.endsWith(ESC + "\\")) {
|
|
6054
|
-
return "complete";
|
|
6055
5851
|
}
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
if (
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
if (candidate === ESC + ESC) {
|
|
6077
|
-
const nextChar = remaining[seqEnd];
|
|
6078
|
-
if (seqEnd < remaining.length && !isNestedEscapeSequenceStart(nextChar)) {
|
|
6079
|
-
sequences.push(candidate);
|
|
6080
|
-
pos += seqEnd;
|
|
6081
|
-
break;
|
|
6082
|
-
}
|
|
6083
|
-
}
|
|
6084
|
-
seqEnd++;
|
|
6085
|
-
} else {
|
|
6086
|
-
sequences.push(candidate);
|
|
6087
|
-
pos += seqEnd;
|
|
6088
|
-
break;
|
|
6089
|
-
}
|
|
6090
|
-
}
|
|
6091
|
-
if (seqEnd > remaining.length) {
|
|
6092
|
-
return { sequences, remainder: remaining };
|
|
6093
|
-
}
|
|
5852
|
+
const modifyOtherKeysMatch = modifyOtherKeysRe.exec(s);
|
|
5853
|
+
if (modifyOtherKeysMatch) {
|
|
5854
|
+
const modifier = parseInt(modifyOtherKeysMatch[1], 10) - 1;
|
|
5855
|
+
const charCode = parseInt(modifyOtherKeysMatch[2], 10);
|
|
5856
|
+
key.ctrl = !!(modifier & 4);
|
|
5857
|
+
key.meta = !!(modifier & 2);
|
|
5858
|
+
key.shift = !!(modifier & 1);
|
|
5859
|
+
key.option = !!(modifier & 2);
|
|
5860
|
+
key.super = !!(modifier & 8);
|
|
5861
|
+
key.hyper = !!(modifier & 16);
|
|
5862
|
+
if (charCode === 13) {
|
|
5863
|
+
key.name = "return";
|
|
5864
|
+
} else if (charCode === 27) {
|
|
5865
|
+
key.name = "escape";
|
|
5866
|
+
} else if (charCode === 9) {
|
|
5867
|
+
key.name = "tab";
|
|
5868
|
+
} else if (charCode === 32) {
|
|
5869
|
+
key.name = "space";
|
|
5870
|
+
} else if (charCode === 127 || charCode === 8) {
|
|
5871
|
+
key.name = "backspace";
|
|
6094
5872
|
} else {
|
|
6095
|
-
const
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6099
|
-
|
|
6100
|
-
const next = remaining.charCodeAt(1);
|
|
6101
|
-
if (next >= 56320 && next <= 57343) {
|
|
6102
|
-
sequences.push(remaining.slice(0, 2));
|
|
6103
|
-
pos += 2;
|
|
6104
|
-
} else {
|
|
6105
|
-
sequences.push(remaining[0]);
|
|
6106
|
-
pos++;
|
|
6107
|
-
}
|
|
6108
|
-
} else {
|
|
6109
|
-
sequences.push(remaining[0]);
|
|
6110
|
-
pos++;
|
|
5873
|
+
const char = String.fromCharCode(charCode);
|
|
5874
|
+
key.name = char;
|
|
5875
|
+
key.sequence = char;
|
|
5876
|
+
if (charCode >= 48 && charCode <= 57) {
|
|
5877
|
+
key.number = true;
|
|
6111
5878
|
}
|
|
6112
5879
|
}
|
|
5880
|
+
return key;
|
|
6113
5881
|
}
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6125
|
-
|
|
6126
|
-
|
|
6127
|
-
|
|
6128
|
-
|
|
6129
|
-
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
5882
|
+
if (s === "\r" || s === "\x1B\r") {
|
|
5883
|
+
key.name = "return";
|
|
5884
|
+
key.meta = s.length === 2;
|
|
5885
|
+
} else if (s === `
|
|
5886
|
+
` || s === `\x1B
|
|
5887
|
+
`) {
|
|
5888
|
+
key.name = "linefeed";
|
|
5889
|
+
key.meta = s.length === 2;
|
|
5890
|
+
} else if (s === "\t") {
|
|
5891
|
+
key.name = "tab";
|
|
5892
|
+
} else if (s === "\b" || s === "\x1B\b" || s === "\x7F" || s === "\x1B\x7F") {
|
|
5893
|
+
key.name = "backspace";
|
|
5894
|
+
key.meta = s.charAt(0) === "\x1B";
|
|
5895
|
+
} else if (s === "\x1B" || s === "\x1B\x1B") {
|
|
5896
|
+
key.name = "escape";
|
|
5897
|
+
key.meta = s.length === 2;
|
|
5898
|
+
} else if (s === " " || s === "\x1B ") {
|
|
5899
|
+
key.name = "space";
|
|
5900
|
+
key.meta = s.length === 2;
|
|
5901
|
+
} else if (s === "\x00") {
|
|
5902
|
+
key.name = "space";
|
|
5903
|
+
key.ctrl = true;
|
|
5904
|
+
} else if (s.length === 1 && s <= "\x1A") {
|
|
5905
|
+
key.name = String.fromCharCode(s.charCodeAt(0) + 97 - 1);
|
|
5906
|
+
key.ctrl = true;
|
|
5907
|
+
} else if (s.length === 1 && s >= "0" && s <= "9") {
|
|
5908
|
+
key.name = s;
|
|
5909
|
+
key.number = true;
|
|
5910
|
+
} else if (s.length === 1 && s >= "a" && s <= "z") {
|
|
5911
|
+
key.name = s;
|
|
5912
|
+
} else if (s.length === 1 && s >= "A" && s <= "Z") {
|
|
5913
|
+
key.name = s.toLowerCase();
|
|
5914
|
+
key.shift = true;
|
|
5915
|
+
} else if (s.length === 1 || s.length === 2 && s.codePointAt(0) > 65535) {
|
|
5916
|
+
key.name = s;
|
|
5917
|
+
} else if (parts = metaKeyCodeRe.exec(s)) {
|
|
5918
|
+
key.meta = true;
|
|
5919
|
+
const char = parts[1];
|
|
5920
|
+
const isUpperCase = /^[A-Z]$/.test(char);
|
|
5921
|
+
if (char === "F") {
|
|
5922
|
+
key.name = "right";
|
|
5923
|
+
} else if (char === "B") {
|
|
5924
|
+
key.name = "left";
|
|
5925
|
+
} else if (isUpperCase) {
|
|
5926
|
+
key.shift = true;
|
|
5927
|
+
key.name = char;
|
|
6140
5928
|
} else {
|
|
6141
|
-
|
|
6142
|
-
}
|
|
6143
|
-
if (str.length === 0 && this.buffer.length === 0) {
|
|
6144
|
-
this.emit("data", "");
|
|
6145
|
-
return;
|
|
6146
|
-
}
|
|
6147
|
-
this.buffer += str;
|
|
6148
|
-
if (this.pasteMode) {
|
|
6149
|
-
this.pasteBuffer += this.buffer;
|
|
6150
|
-
this.buffer = "";
|
|
6151
|
-
const endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);
|
|
6152
|
-
if (endIndex !== -1) {
|
|
6153
|
-
const pastedContent = this.pasteBuffer.slice(0, endIndex);
|
|
6154
|
-
const remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);
|
|
6155
|
-
this.pasteMode = false;
|
|
6156
|
-
this.pasteBuffer = "";
|
|
6157
|
-
this.emit("paste", pastedContent);
|
|
6158
|
-
if (remaining.length > 0) {
|
|
6159
|
-
this.process(remaining);
|
|
6160
|
-
}
|
|
6161
|
-
}
|
|
6162
|
-
return;
|
|
6163
|
-
}
|
|
6164
|
-
const startIndex = this.buffer.indexOf(BRACKETED_PASTE_START);
|
|
6165
|
-
if (startIndex !== -1) {
|
|
6166
|
-
if (startIndex > 0) {
|
|
6167
|
-
const beforePaste = this.buffer.slice(0, startIndex);
|
|
6168
|
-
const result2 = extractCompleteSequences(beforePaste);
|
|
6169
|
-
for (const sequence of result2.sequences) {
|
|
6170
|
-
this.emit("data", sequence);
|
|
6171
|
-
}
|
|
6172
|
-
}
|
|
6173
|
-
this.buffer = this.buffer.slice(startIndex + BRACKETED_PASTE_START.length);
|
|
6174
|
-
this.pasteMode = true;
|
|
6175
|
-
this.pasteBuffer = this.buffer;
|
|
6176
|
-
this.buffer = "";
|
|
6177
|
-
const endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);
|
|
6178
|
-
if (endIndex !== -1) {
|
|
6179
|
-
const pastedContent = this.pasteBuffer.slice(0, endIndex);
|
|
6180
|
-
const remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);
|
|
6181
|
-
this.pasteMode = false;
|
|
6182
|
-
this.pasteBuffer = "";
|
|
6183
|
-
this.emit("paste", pastedContent);
|
|
6184
|
-
if (remaining.length > 0) {
|
|
6185
|
-
this.process(remaining);
|
|
6186
|
-
}
|
|
6187
|
-
}
|
|
6188
|
-
return;
|
|
5929
|
+
key.name = char;
|
|
6189
5930
|
}
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
5931
|
+
} else if (s.length === 2 && s[0] === "\x1B" && s[1] <= "\x1A") {
|
|
5932
|
+
key.meta = true;
|
|
5933
|
+
key.ctrl = true;
|
|
5934
|
+
key.name = String.fromCharCode(s.charCodeAt(1) + 97 - 1);
|
|
5935
|
+
} else if (parts = fnKeyRe.exec(s)) {
|
|
5936
|
+
const segs = [...s];
|
|
5937
|
+
if (segs[0] === "\x1B" && segs[1] === "\x1B") {
|
|
5938
|
+
key.option = true;
|
|
5939
|
+
key.meta = true;
|
|
6194
5940
|
}
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
5941
|
+
const code = [parts[1], parts[2], parts[4], parts[6]].filter(Boolean).join("");
|
|
5942
|
+
const modifier = parseInt(parts[3] || parts[5] || "1", 10) - 1;
|
|
5943
|
+
key.ctrl = key.ctrl || !!(modifier & 4);
|
|
5944
|
+
key.meta = key.meta || !!(modifier & 2);
|
|
5945
|
+
key.shift = key.shift || !!(modifier & 1);
|
|
5946
|
+
key.option = key.option || !!(modifier & 2);
|
|
5947
|
+
key.super = !!(modifier & 8);
|
|
5948
|
+
key.hyper = !!(modifier & 16);
|
|
5949
|
+
key.code = code;
|
|
5950
|
+
const keyNameResult = keyName[code];
|
|
5951
|
+
if (keyNameResult) {
|
|
5952
|
+
key.name = keyNameResult;
|
|
5953
|
+
key.shift = isShiftKey(code) || key.shift;
|
|
5954
|
+
key.ctrl = isCtrlKey(code) || key.ctrl;
|
|
5955
|
+
} else {
|
|
5956
|
+
key.name = "";
|
|
5957
|
+
key.code = undefined;
|
|
6202
5958
|
}
|
|
5959
|
+
} else if (s === "\x1B[3~") {
|
|
5960
|
+
key.name = "delete";
|
|
5961
|
+
key.meta = false;
|
|
5962
|
+
key.code = "[3~";
|
|
5963
|
+
}
|
|
5964
|
+
return key;
|
|
5965
|
+
};
|
|
5966
|
+
|
|
5967
|
+
// src/lib/scroll-acceleration.ts
|
|
5968
|
+
class LinearScrollAccel {
|
|
5969
|
+
tick(_now) {
|
|
5970
|
+
return 1;
|
|
5971
|
+
}
|
|
5972
|
+
reset() {}
|
|
5973
|
+
}
|
|
5974
|
+
|
|
5975
|
+
class MacOSScrollAccel {
|
|
5976
|
+
opts;
|
|
5977
|
+
lastTickTime = 0;
|
|
5978
|
+
velocityHistory = [];
|
|
5979
|
+
historySize = 3;
|
|
5980
|
+
streakTimeout = 150;
|
|
5981
|
+
minTickInterval = 6;
|
|
5982
|
+
constructor(opts = {}) {
|
|
5983
|
+
this.opts = opts;
|
|
6203
5984
|
}
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
5985
|
+
tick(now = Date.now()) {
|
|
5986
|
+
const A = this.opts.A ?? 0.8;
|
|
5987
|
+
const tau = this.opts.tau ?? 3;
|
|
5988
|
+
const maxMultiplier = this.opts.maxMultiplier ?? 6;
|
|
5989
|
+
const dt = this.lastTickTime ? now - this.lastTickTime : Infinity;
|
|
5990
|
+
if (dt === Infinity || dt > this.streakTimeout) {
|
|
5991
|
+
this.lastTickTime = now;
|
|
5992
|
+
this.velocityHistory = [];
|
|
5993
|
+
return 1;
|
|
6208
5994
|
}
|
|
6209
|
-
if (this.
|
|
6210
|
-
return
|
|
5995
|
+
if (dt < this.minTickInterval) {
|
|
5996
|
+
return 1;
|
|
6211
5997
|
}
|
|
6212
|
-
|
|
6213
|
-
this.
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
clear() {
|
|
6217
|
-
if (this.timeout) {
|
|
6218
|
-
clearTimeout(this.timeout);
|
|
6219
|
-
this.timeout = null;
|
|
5998
|
+
this.lastTickTime = now;
|
|
5999
|
+
this.velocityHistory.push(dt);
|
|
6000
|
+
if (this.velocityHistory.length > this.historySize) {
|
|
6001
|
+
this.velocityHistory.shift();
|
|
6220
6002
|
}
|
|
6221
|
-
this.
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
return
|
|
6003
|
+
const avgInterval = this.velocityHistory.reduce((a, b) => a + b, 0) / this.velocityHistory.length;
|
|
6004
|
+
const referenceInterval = 100;
|
|
6005
|
+
const velocity = referenceInterval / avgInterval;
|
|
6006
|
+
const x = velocity / tau;
|
|
6007
|
+
const multiplier = 1 + A * (Math.exp(x) - 1);
|
|
6008
|
+
return Math.min(multiplier, maxMultiplier);
|
|
6227
6009
|
}
|
|
6228
|
-
|
|
6229
|
-
this.
|
|
6010
|
+
reset() {
|
|
6011
|
+
this.lastTickTime = 0;
|
|
6012
|
+
this.velocityHistory = [];
|
|
6230
6013
|
}
|
|
6231
6014
|
}
|
|
6232
6015
|
|
|
@@ -6533,7 +6316,8 @@ class MouseParser {
|
|
|
6533
6316
|
this.mouseButtonsPressed.clear();
|
|
6534
6317
|
}
|
|
6535
6318
|
decodeInput(data) {
|
|
6536
|
-
|
|
6319
|
+
const buf = Buffer.isBuffer(data) ? data : Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
6320
|
+
return buf.toString("latin1");
|
|
6537
6321
|
}
|
|
6538
6322
|
parseMouseEvent(data) {
|
|
6539
6323
|
const str = this.decodeInput(data);
|
|
@@ -6853,200 +6637,1068 @@ class ASCIIFontSelectionHelper {
|
|
|
6853
6637
|
startCharIndex = coordinateToCharacterIndex(selStart.x, text, font);
|
|
6854
6638
|
}
|
|
6855
6639
|
}
|
|
6856
|
-
if (selEnd.y < 0) {
|
|
6857
|
-
this.localSelection = null;
|
|
6858
|
-
return previousSelection !== null;
|
|
6859
|
-
} else if (selEnd.y >= 0 && selEnd.y <= height - 1) {
|
|
6860
|
-
if (selEnd.x >= 0) {
|
|
6861
|
-
endCharIndex = coordinateToCharacterIndex(selEnd.x, text, font);
|
|
6862
|
-
} else {
|
|
6863
|
-
endCharIndex = 0;
|
|
6640
|
+
if (selEnd.y < 0) {
|
|
6641
|
+
this.localSelection = null;
|
|
6642
|
+
return previousSelection !== null;
|
|
6643
|
+
} else if (selEnd.y >= 0 && selEnd.y <= height - 1) {
|
|
6644
|
+
if (selEnd.x >= 0) {
|
|
6645
|
+
endCharIndex = coordinateToCharacterIndex(selEnd.x, text, font);
|
|
6646
|
+
} else {
|
|
6647
|
+
endCharIndex = 0;
|
|
6648
|
+
}
|
|
6649
|
+
}
|
|
6650
|
+
if (startCharIndex < endCharIndex && startCharIndex >= 0 && endCharIndex <= text.length) {
|
|
6651
|
+
this.localSelection = { start: startCharIndex, end: endCharIndex };
|
|
6652
|
+
} else {
|
|
6653
|
+
this.localSelection = null;
|
|
6654
|
+
}
|
|
6655
|
+
return previousSelection?.start !== this.localSelection?.start || previousSelection?.end !== this.localSelection?.end;
|
|
6656
|
+
}
|
|
6657
|
+
}
|
|
6658
|
+
|
|
6659
|
+
// src/lib/singleton.ts
|
|
6660
|
+
var singletonCacheSymbol = Symbol.for("@opentui/core/singleton");
|
|
6661
|
+
function singleton(key, factory) {
|
|
6662
|
+
const bag = globalThis[singletonCacheSymbol] ??= {};
|
|
6663
|
+
if (!(key in bag)) {
|
|
6664
|
+
bag[key] = factory();
|
|
6665
|
+
}
|
|
6666
|
+
return bag[key];
|
|
6667
|
+
}
|
|
6668
|
+
function destroySingleton(key) {
|
|
6669
|
+
const bag = globalThis[singletonCacheSymbol];
|
|
6670
|
+
if (bag && key in bag) {
|
|
6671
|
+
delete bag[key];
|
|
6672
|
+
}
|
|
6673
|
+
}
|
|
6674
|
+
function hasSingleton(key) {
|
|
6675
|
+
const bag = globalThis[singletonCacheSymbol];
|
|
6676
|
+
return bag && key in bag;
|
|
6677
|
+
}
|
|
6678
|
+
|
|
6679
|
+
// src/lib/env.ts
|
|
6680
|
+
var envRegistry = singleton("env-registry", () => ({}));
|
|
6681
|
+
function registerEnvVar(config) {
|
|
6682
|
+
const existing = envRegistry[config.name];
|
|
6683
|
+
if (existing) {
|
|
6684
|
+
if (existing.description !== config.description || existing.type !== config.type || existing.default !== config.default) {
|
|
6685
|
+
throw new Error(`Environment variable "${config.name}" is already registered with different configuration. ` + `Existing: ${JSON.stringify(existing)}, New: ${JSON.stringify(config)}`);
|
|
6686
|
+
}
|
|
6687
|
+
return;
|
|
6688
|
+
}
|
|
6689
|
+
envRegistry[config.name] = config;
|
|
6690
|
+
}
|
|
6691
|
+
function normalizeBoolean(value) {
|
|
6692
|
+
const lowerValue = value.toLowerCase();
|
|
6693
|
+
return ["true", "1", "on", "yes"].includes(lowerValue);
|
|
6694
|
+
}
|
|
6695
|
+
function parseEnvValue(config) {
|
|
6696
|
+
const envValue = process.env[config.name];
|
|
6697
|
+
if (envValue === undefined && config.default !== undefined) {
|
|
6698
|
+
return config.default;
|
|
6699
|
+
}
|
|
6700
|
+
if (envValue === undefined) {
|
|
6701
|
+
throw new Error(`Required environment variable ${config.name} is not set. ${config.description}`);
|
|
6702
|
+
}
|
|
6703
|
+
switch (config.type) {
|
|
6704
|
+
case "boolean":
|
|
6705
|
+
return typeof envValue === "boolean" ? envValue : normalizeBoolean(envValue);
|
|
6706
|
+
case "number":
|
|
6707
|
+
const numValue = Number(envValue);
|
|
6708
|
+
if (isNaN(numValue)) {
|
|
6709
|
+
throw new Error(`Environment variable ${config.name} must be a valid number, got: ${envValue}`);
|
|
6710
|
+
}
|
|
6711
|
+
return numValue;
|
|
6712
|
+
case "string":
|
|
6713
|
+
default:
|
|
6714
|
+
return envValue;
|
|
6715
|
+
}
|
|
6716
|
+
}
|
|
6717
|
+
|
|
6718
|
+
class EnvStore {
|
|
6719
|
+
parsedValues = new Map;
|
|
6720
|
+
get(key) {
|
|
6721
|
+
if (this.parsedValues.has(key)) {
|
|
6722
|
+
return this.parsedValues.get(key);
|
|
6723
|
+
}
|
|
6724
|
+
if (!(key in envRegistry)) {
|
|
6725
|
+
throw new Error(`Environment variable ${key} is not registered.`);
|
|
6726
|
+
}
|
|
6727
|
+
try {
|
|
6728
|
+
const value = parseEnvValue(envRegistry[key]);
|
|
6729
|
+
this.parsedValues.set(key, value);
|
|
6730
|
+
return value;
|
|
6731
|
+
} catch (error) {
|
|
6732
|
+
throw new Error(`Failed to parse env var ${key}: ${error instanceof Error ? error.message : String(error)}`);
|
|
6733
|
+
}
|
|
6734
|
+
}
|
|
6735
|
+
has(key) {
|
|
6736
|
+
return key in envRegistry;
|
|
6737
|
+
}
|
|
6738
|
+
clearCache() {
|
|
6739
|
+
this.parsedValues.clear();
|
|
6740
|
+
}
|
|
6741
|
+
}
|
|
6742
|
+
var envStore = singleton("env-store", () => new EnvStore);
|
|
6743
|
+
function clearEnvCache() {
|
|
6744
|
+
envStore.clearCache();
|
|
6745
|
+
}
|
|
6746
|
+
function generateEnvMarkdown() {
|
|
6747
|
+
const configs = Object.values(envRegistry);
|
|
6748
|
+
if (configs.length === 0) {
|
|
6749
|
+
return `# Environment Variables
|
|
6750
|
+
|
|
6751
|
+
No environment variables registered.
|
|
6752
|
+
`;
|
|
6753
|
+
}
|
|
6754
|
+
let markdown = `# Environment Variables
|
|
6755
|
+
|
|
6756
|
+
`;
|
|
6757
|
+
for (const config of configs) {
|
|
6758
|
+
markdown += `## ${config.name}
|
|
6759
|
+
|
|
6760
|
+
`;
|
|
6761
|
+
markdown += `${config.description}
|
|
6762
|
+
|
|
6763
|
+
`;
|
|
6764
|
+
markdown += `**Type:** \`${config.type || "string"}\`
|
|
6765
|
+
`;
|
|
6766
|
+
if (config.default !== undefined) {
|
|
6767
|
+
const defaultValue = typeof config.default === "string" ? `"${config.default}"` : String(config.default);
|
|
6768
|
+
markdown += `**Default:** \`${defaultValue}\`
|
|
6769
|
+
`;
|
|
6770
|
+
} else {
|
|
6771
|
+
markdown += `**Default:** *Required*
|
|
6772
|
+
`;
|
|
6773
|
+
}
|
|
6774
|
+
markdown += `
|
|
6775
|
+
`;
|
|
6776
|
+
}
|
|
6777
|
+
return markdown;
|
|
6778
|
+
}
|
|
6779
|
+
function generateEnvColored() {
|
|
6780
|
+
const configs = Object.values(envRegistry);
|
|
6781
|
+
if (configs.length === 0) {
|
|
6782
|
+
return `\x1B[1;36mEnvironment Variables\x1B[0m
|
|
6783
|
+
|
|
6784
|
+
No environment variables registered.
|
|
6785
|
+
`;
|
|
6786
|
+
}
|
|
6787
|
+
let output = `\x1B[1;36mEnvironment Variables\x1B[0m
|
|
6788
|
+
|
|
6789
|
+
`;
|
|
6790
|
+
for (const config of configs) {
|
|
6791
|
+
output += `\x1B[1;33m${config.name}\x1B[0m
|
|
6792
|
+
`;
|
|
6793
|
+
output += `${config.description}
|
|
6794
|
+
`;
|
|
6795
|
+
output += `\x1B[32mType:\x1B[0m \x1B[36m${config.type || "string"}\x1B[0m
|
|
6796
|
+
`;
|
|
6797
|
+
if (config.default !== undefined) {
|
|
6798
|
+
const defaultValue = typeof config.default === "string" ? `"${config.default}"` : String(config.default);
|
|
6799
|
+
output += `\x1B[32mDefault:\x1B[0m \x1B[35m${defaultValue}\x1B[0m
|
|
6800
|
+
`;
|
|
6801
|
+
} else {
|
|
6802
|
+
output += `\x1B[32mDefault:\x1B[0m \x1B[31mRequired\x1B[0m
|
|
6803
|
+
`;
|
|
6804
|
+
}
|
|
6805
|
+
output += `
|
|
6806
|
+
`;
|
|
6807
|
+
}
|
|
6808
|
+
return output;
|
|
6809
|
+
}
|
|
6810
|
+
var env = new Proxy({}, {
|
|
6811
|
+
get(target, prop) {
|
|
6812
|
+
if (typeof prop !== "string") {
|
|
6813
|
+
return;
|
|
6814
|
+
}
|
|
6815
|
+
return envStore.get(prop);
|
|
6816
|
+
},
|
|
6817
|
+
has(target, prop) {
|
|
6818
|
+
return envStore.has(prop);
|
|
6819
|
+
},
|
|
6820
|
+
ownKeys() {
|
|
6821
|
+
return Object.keys(envRegistry);
|
|
6822
|
+
},
|
|
6823
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
6824
|
+
if (envStore.has(prop)) {
|
|
6825
|
+
return {
|
|
6826
|
+
enumerable: true,
|
|
6827
|
+
configurable: true,
|
|
6828
|
+
get: () => envStore.get(prop)
|
|
6829
|
+
};
|
|
6830
|
+
}
|
|
6831
|
+
return;
|
|
6832
|
+
}
|
|
6833
|
+
});
|
|
6834
|
+
|
|
6835
|
+
// src/lib/stdin-parser.ts
|
|
6836
|
+
import { Buffer as Buffer3 } from "buffer";
|
|
6837
|
+
var DEFAULT_TIMEOUT_MS = 10;
|
|
6838
|
+
var DEFAULT_MAX_PENDING_BYTES = 64 * 1024;
|
|
6839
|
+
var INITIAL_PENDING_CAPACITY = 256;
|
|
6840
|
+
var ESC = 27;
|
|
6841
|
+
var BEL = 7;
|
|
6842
|
+
var BRACKETED_PASTE_START = Buffer3.from("\x1B[200~");
|
|
6843
|
+
var BRACKETED_PASTE_END = Buffer3.from("\x1B[201~");
|
|
6844
|
+
var EMPTY_BYTES = new Uint8Array(0);
|
|
6845
|
+
var KEY_DECODER = new TextDecoder;
|
|
6846
|
+
var RXVT_DOLLAR_CSI_RE = /^\x1b\[\d+\$$/;
|
|
6847
|
+
var SYSTEM_CLOCK = new SystemClock;
|
|
6848
|
+
|
|
6849
|
+
class ByteQueue {
|
|
6850
|
+
buf;
|
|
6851
|
+
start = 0;
|
|
6852
|
+
end = 0;
|
|
6853
|
+
constructor(capacity = INITIAL_PENDING_CAPACITY) {
|
|
6854
|
+
this.buf = new Uint8Array(capacity);
|
|
6855
|
+
}
|
|
6856
|
+
get length() {
|
|
6857
|
+
return this.end - this.start;
|
|
6858
|
+
}
|
|
6859
|
+
get capacity() {
|
|
6860
|
+
return this.buf.length;
|
|
6861
|
+
}
|
|
6862
|
+
view() {
|
|
6863
|
+
return this.buf.subarray(this.start, this.end);
|
|
6864
|
+
}
|
|
6865
|
+
take() {
|
|
6866
|
+
const chunk = this.view();
|
|
6867
|
+
this.start = 0;
|
|
6868
|
+
this.end = 0;
|
|
6869
|
+
return chunk;
|
|
6870
|
+
}
|
|
6871
|
+
append(chunk) {
|
|
6872
|
+
if (chunk.length === 0) {
|
|
6873
|
+
return;
|
|
6874
|
+
}
|
|
6875
|
+
this.ensureCapacity(this.length + chunk.length);
|
|
6876
|
+
this.buf.set(chunk, this.end);
|
|
6877
|
+
this.end += chunk.length;
|
|
6878
|
+
}
|
|
6879
|
+
consume(count) {
|
|
6880
|
+
if (count <= 0) {
|
|
6881
|
+
return;
|
|
6882
|
+
}
|
|
6883
|
+
if (count >= this.length) {
|
|
6884
|
+
this.start = 0;
|
|
6885
|
+
this.end = 0;
|
|
6886
|
+
return;
|
|
6887
|
+
}
|
|
6888
|
+
this.start += count;
|
|
6889
|
+
if (this.start >= this.buf.length / 2) {
|
|
6890
|
+
this.buf.copyWithin(0, this.start, this.end);
|
|
6891
|
+
this.end -= this.start;
|
|
6892
|
+
this.start = 0;
|
|
6893
|
+
}
|
|
6894
|
+
}
|
|
6895
|
+
clear() {
|
|
6896
|
+
this.start = 0;
|
|
6897
|
+
this.end = 0;
|
|
6898
|
+
}
|
|
6899
|
+
reset(capacity = INITIAL_PENDING_CAPACITY) {
|
|
6900
|
+
this.buf = new Uint8Array(capacity);
|
|
6901
|
+
this.start = 0;
|
|
6902
|
+
this.end = 0;
|
|
6903
|
+
}
|
|
6904
|
+
ensureCapacity(requiredLength) {
|
|
6905
|
+
const currentLength = this.length;
|
|
6906
|
+
if (requiredLength <= this.buf.length) {
|
|
6907
|
+
const availableAtEnd = this.buf.length - this.end;
|
|
6908
|
+
if (availableAtEnd >= requiredLength - currentLength) {
|
|
6909
|
+
return;
|
|
6910
|
+
}
|
|
6911
|
+
this.buf.copyWithin(0, this.start, this.end);
|
|
6912
|
+
this.end = currentLength;
|
|
6913
|
+
this.start = 0;
|
|
6914
|
+
if (requiredLength <= this.buf.length) {
|
|
6915
|
+
return;
|
|
6864
6916
|
}
|
|
6865
6917
|
}
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
this.localSelection = null;
|
|
6918
|
+
let nextCapacity = this.buf.length;
|
|
6919
|
+
while (nextCapacity < requiredLength) {
|
|
6920
|
+
nextCapacity *= 2;
|
|
6870
6921
|
}
|
|
6871
|
-
|
|
6922
|
+
const next = new Uint8Array(nextCapacity);
|
|
6923
|
+
next.set(this.view(), 0);
|
|
6924
|
+
this.buf = next;
|
|
6925
|
+
this.start = 0;
|
|
6926
|
+
this.end = currentLength;
|
|
6872
6927
|
}
|
|
6873
6928
|
}
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
|
|
6877
|
-
function singleton(key, factory) {
|
|
6878
|
-
const bag = globalThis[singletonCacheSymbol] ??= {};
|
|
6879
|
-
if (!(key in bag)) {
|
|
6880
|
-
bag[key] = factory();
|
|
6929
|
+
function normalizePositiveOption(value, fallback) {
|
|
6930
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
6931
|
+
return fallback;
|
|
6881
6932
|
}
|
|
6882
|
-
return
|
|
6933
|
+
return Math.floor(value);
|
|
6883
6934
|
}
|
|
6884
|
-
function
|
|
6885
|
-
|
|
6886
|
-
|
|
6887
|
-
|
|
6935
|
+
function utf8SequenceLength(first) {
|
|
6936
|
+
if (first < 128)
|
|
6937
|
+
return 1;
|
|
6938
|
+
if (first >= 194 && first <= 223)
|
|
6939
|
+
return 2;
|
|
6940
|
+
if (first >= 224 && first <= 239)
|
|
6941
|
+
return 3;
|
|
6942
|
+
if (first >= 240 && first <= 244)
|
|
6943
|
+
return 4;
|
|
6944
|
+
return 0;
|
|
6945
|
+
}
|
|
6946
|
+
function bytesEqual(left, right) {
|
|
6947
|
+
if (left.length !== right.length) {
|
|
6948
|
+
return false;
|
|
6949
|
+
}
|
|
6950
|
+
for (let index = 0;index < left.length; index += 1) {
|
|
6951
|
+
if (left[index] !== right[index]) {
|
|
6952
|
+
return false;
|
|
6953
|
+
}
|
|
6888
6954
|
}
|
|
6955
|
+
return true;
|
|
6889
6956
|
}
|
|
6890
|
-
function
|
|
6891
|
-
|
|
6892
|
-
|
|
6957
|
+
function isMouseSgrSequence(sequence) {
|
|
6958
|
+
if (sequence.length < 7) {
|
|
6959
|
+
return false;
|
|
6960
|
+
}
|
|
6961
|
+
if (sequence[0] !== ESC || sequence[1] !== 91 || sequence[2] !== 60) {
|
|
6962
|
+
return false;
|
|
6963
|
+
}
|
|
6964
|
+
const final = sequence[sequence.length - 1];
|
|
6965
|
+
if (final !== 77 && final !== 109) {
|
|
6966
|
+
return false;
|
|
6967
|
+
}
|
|
6968
|
+
let part = 0;
|
|
6969
|
+
let hasDigit = false;
|
|
6970
|
+
for (let index = 3;index < sequence.length - 1; index += 1) {
|
|
6971
|
+
const byte = sequence[index];
|
|
6972
|
+
if (byte >= 48 && byte <= 57) {
|
|
6973
|
+
hasDigit = true;
|
|
6974
|
+
continue;
|
|
6975
|
+
}
|
|
6976
|
+
if (byte === 59 && hasDigit && part < 2) {
|
|
6977
|
+
part += 1;
|
|
6978
|
+
hasDigit = false;
|
|
6979
|
+
continue;
|
|
6980
|
+
}
|
|
6981
|
+
return false;
|
|
6982
|
+
}
|
|
6983
|
+
return part === 2 && hasDigit;
|
|
6893
6984
|
}
|
|
6894
|
-
|
|
6895
|
-
|
|
6896
|
-
|
|
6897
|
-
|
|
6898
|
-
|
|
6899
|
-
|
|
6900
|
-
|
|
6901
|
-
|
|
6985
|
+
function concatBytes(left, right) {
|
|
6986
|
+
if (left.length === 0) {
|
|
6987
|
+
return right;
|
|
6988
|
+
}
|
|
6989
|
+
if (right.length === 0) {
|
|
6990
|
+
return left;
|
|
6991
|
+
}
|
|
6992
|
+
const combined = new Uint8Array(left.length + right.length);
|
|
6993
|
+
combined.set(left, 0);
|
|
6994
|
+
combined.set(right, left.length);
|
|
6995
|
+
return combined;
|
|
6996
|
+
}
|
|
6997
|
+
function indexOfBytes(haystack, needle) {
|
|
6998
|
+
if (needle.length === 0) {
|
|
6999
|
+
return 0;
|
|
7000
|
+
}
|
|
7001
|
+
const limit = haystack.length - needle.length;
|
|
7002
|
+
for (let offset = 0;offset <= limit; offset += 1) {
|
|
7003
|
+
let matched = true;
|
|
7004
|
+
for (let index = 0;index < needle.length; index += 1) {
|
|
7005
|
+
if (haystack[offset + index] !== needle[index]) {
|
|
7006
|
+
matched = false;
|
|
7007
|
+
break;
|
|
7008
|
+
}
|
|
7009
|
+
}
|
|
7010
|
+
if (matched) {
|
|
7011
|
+
return offset;
|
|
6902
7012
|
}
|
|
6903
|
-
return;
|
|
6904
7013
|
}
|
|
6905
|
-
|
|
7014
|
+
return -1;
|
|
6906
7015
|
}
|
|
6907
|
-
function
|
|
6908
|
-
|
|
6909
|
-
return ["true", "1", "on", "yes"].includes(lowerValue);
|
|
7016
|
+
function decodeLatin1(bytes) {
|
|
7017
|
+
return Buffer3.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("latin1");
|
|
6910
7018
|
}
|
|
6911
|
-
function
|
|
6912
|
-
|
|
6913
|
-
|
|
6914
|
-
|
|
7019
|
+
function decodeUtf8(bytes) {
|
|
7020
|
+
return KEY_DECODER.decode(bytes);
|
|
7021
|
+
}
|
|
7022
|
+
function createPasteCollector() {
|
|
7023
|
+
return {
|
|
7024
|
+
tail: EMPTY_BYTES,
|
|
7025
|
+
parts: [],
|
|
7026
|
+
totalLength: 0
|
|
7027
|
+
};
|
|
7028
|
+
}
|
|
7029
|
+
function joinPasteBytes(parts, totalLength) {
|
|
7030
|
+
if (totalLength === 0) {
|
|
7031
|
+
return EMPTY_BYTES;
|
|
6915
7032
|
}
|
|
6916
|
-
if (
|
|
6917
|
-
|
|
7033
|
+
if (parts.length === 1) {
|
|
7034
|
+
return parts[0];
|
|
6918
7035
|
}
|
|
6919
|
-
|
|
6920
|
-
|
|
6921
|
-
|
|
6922
|
-
|
|
6923
|
-
|
|
6924
|
-
|
|
6925
|
-
|
|
7036
|
+
const bytes = new Uint8Array(totalLength);
|
|
7037
|
+
let offset = 0;
|
|
7038
|
+
for (const part of parts) {
|
|
7039
|
+
bytes.set(part, offset);
|
|
7040
|
+
offset += part.length;
|
|
7041
|
+
}
|
|
7042
|
+
return bytes;
|
|
7043
|
+
}
|
|
7044
|
+
|
|
7045
|
+
class StdinParser {
|
|
7046
|
+
pending = new ByteQueue(INITIAL_PENDING_CAPACITY);
|
|
7047
|
+
events = [];
|
|
7048
|
+
timeoutMs;
|
|
7049
|
+
maxPendingBytes;
|
|
7050
|
+
armTimeouts;
|
|
7051
|
+
onTimeoutFlush;
|
|
7052
|
+
useKittyKeyboard;
|
|
7053
|
+
mouseParser = new MouseParser;
|
|
7054
|
+
clock;
|
|
7055
|
+
timeoutId = null;
|
|
7056
|
+
destroyed = false;
|
|
7057
|
+
pendingSinceMs = null;
|
|
7058
|
+
forceFlush = false;
|
|
7059
|
+
justFlushedEsc = false;
|
|
7060
|
+
state = { tag: "ground" };
|
|
7061
|
+
cursor = 0;
|
|
7062
|
+
unitStart = 0;
|
|
7063
|
+
paste = null;
|
|
7064
|
+
constructor(options = {}) {
|
|
7065
|
+
this.timeoutMs = normalizePositiveOption(options.timeoutMs, DEFAULT_TIMEOUT_MS);
|
|
7066
|
+
this.maxPendingBytes = normalizePositiveOption(options.maxPendingBytes, DEFAULT_MAX_PENDING_BYTES);
|
|
7067
|
+
this.armTimeouts = options.armTimeouts ?? true;
|
|
7068
|
+
this.onTimeoutFlush = options.onTimeoutFlush ?? null;
|
|
7069
|
+
this.useKittyKeyboard = options.useKittyKeyboard ?? true;
|
|
7070
|
+
this.clock = options.clock ?? SYSTEM_CLOCK;
|
|
7071
|
+
}
|
|
7072
|
+
get bufferCapacity() {
|
|
7073
|
+
return this.pending.capacity;
|
|
7074
|
+
}
|
|
7075
|
+
push(data) {
|
|
7076
|
+
this.ensureAlive();
|
|
7077
|
+
if (data.length === 0) {
|
|
7078
|
+
this.emitKeyOrResponse("unknown", "");
|
|
7079
|
+
return;
|
|
7080
|
+
}
|
|
7081
|
+
let remainder = data;
|
|
7082
|
+
while (remainder.length > 0) {
|
|
7083
|
+
if (this.paste) {
|
|
7084
|
+
remainder = this.consumePasteBytes(remainder);
|
|
7085
|
+
continue;
|
|
7086
|
+
}
|
|
7087
|
+
const immediatePasteStartIndex = this.state.tag === "ground" && this.pending.length === 0 ? indexOfBytes(remainder, BRACKETED_PASTE_START) : -1;
|
|
7088
|
+
const appendEnd = immediatePasteStartIndex === -1 ? remainder.length : immediatePasteStartIndex + BRACKETED_PASTE_START.length;
|
|
7089
|
+
this.pending.append(remainder.subarray(0, appendEnd));
|
|
7090
|
+
remainder = remainder.subarray(appendEnd);
|
|
7091
|
+
this.scanPending();
|
|
7092
|
+
if (this.paste && this.pending.length > 0) {
|
|
7093
|
+
remainder = this.consumePasteBytes(this.takePendingBytes());
|
|
7094
|
+
continue;
|
|
7095
|
+
}
|
|
7096
|
+
if (!this.paste && this.pending.length > this.maxPendingBytes) {
|
|
7097
|
+
this.flushPendingOverflow();
|
|
7098
|
+
this.scanPending();
|
|
7099
|
+
if (this.paste && this.pending.length > 0) {
|
|
7100
|
+
remainder = this.consumePasteBytes(this.takePendingBytes());
|
|
7101
|
+
}
|
|
7102
|
+
}
|
|
7103
|
+
}
|
|
7104
|
+
this.reconcileTimeoutState();
|
|
7105
|
+
}
|
|
7106
|
+
read() {
|
|
7107
|
+
this.ensureAlive();
|
|
7108
|
+
if (this.events.length === 0 && this.forceFlush) {
|
|
7109
|
+
this.scanPending();
|
|
7110
|
+
this.reconcileTimeoutState();
|
|
7111
|
+
}
|
|
7112
|
+
return this.events.shift() ?? null;
|
|
7113
|
+
}
|
|
7114
|
+
drain(onEvent) {
|
|
7115
|
+
this.ensureAlive();
|
|
7116
|
+
while (true) {
|
|
7117
|
+
if (this.destroyed) {
|
|
7118
|
+
return;
|
|
7119
|
+
}
|
|
7120
|
+
const event = this.read();
|
|
7121
|
+
if (!event) {
|
|
7122
|
+
return;
|
|
7123
|
+
}
|
|
7124
|
+
onEvent(event);
|
|
7125
|
+
}
|
|
7126
|
+
}
|
|
7127
|
+
flushTimeout(nowMsValue = this.clock.now()) {
|
|
7128
|
+
this.ensureAlive();
|
|
7129
|
+
if (this.paste || this.pendingSinceMs === null || this.pending.length === 0) {
|
|
7130
|
+
return;
|
|
7131
|
+
}
|
|
7132
|
+
if (nowMsValue < this.pendingSinceMs || nowMsValue - this.pendingSinceMs < this.timeoutMs) {
|
|
7133
|
+
return;
|
|
7134
|
+
}
|
|
7135
|
+
this.forceFlush = true;
|
|
7136
|
+
}
|
|
7137
|
+
reset() {
|
|
7138
|
+
if (this.destroyed) {
|
|
7139
|
+
return;
|
|
7140
|
+
}
|
|
7141
|
+
this.clearTimeout();
|
|
7142
|
+
this.resetState();
|
|
7143
|
+
}
|
|
7144
|
+
resetMouseState() {
|
|
7145
|
+
this.ensureAlive();
|
|
7146
|
+
this.mouseParser.reset();
|
|
7147
|
+
}
|
|
7148
|
+
destroy() {
|
|
7149
|
+
if (this.destroyed) {
|
|
7150
|
+
return;
|
|
7151
|
+
}
|
|
7152
|
+
this.clearTimeout();
|
|
7153
|
+
this.destroyed = true;
|
|
7154
|
+
this.resetState();
|
|
7155
|
+
}
|
|
7156
|
+
ensureAlive() {
|
|
7157
|
+
if (this.destroyed) {
|
|
7158
|
+
throw new Error("StdinParser has been destroyed");
|
|
7159
|
+
}
|
|
7160
|
+
}
|
|
7161
|
+
scanPending() {
|
|
7162
|
+
while (!this.paste) {
|
|
7163
|
+
const bytes = this.pending.view();
|
|
7164
|
+
if (this.state.tag === "ground" && this.cursor >= bytes.length) {
|
|
7165
|
+
this.pending.clear();
|
|
7166
|
+
this.cursor = 0;
|
|
7167
|
+
this.unitStart = 0;
|
|
7168
|
+
this.pendingSinceMs = null;
|
|
7169
|
+
this.forceFlush = false;
|
|
7170
|
+
return;
|
|
7171
|
+
}
|
|
7172
|
+
const byte = this.cursor < bytes.length ? bytes[this.cursor] : -1;
|
|
7173
|
+
switch (this.state.tag) {
|
|
7174
|
+
case "ground": {
|
|
7175
|
+
this.unitStart = this.cursor;
|
|
7176
|
+
if (this.justFlushedEsc) {
|
|
7177
|
+
if (byte === 91) {
|
|
7178
|
+
this.justFlushedEsc = false;
|
|
7179
|
+
this.cursor += 1;
|
|
7180
|
+
this.state = { tag: "esc_recovery" };
|
|
7181
|
+
continue;
|
|
7182
|
+
}
|
|
7183
|
+
this.justFlushedEsc = false;
|
|
7184
|
+
}
|
|
7185
|
+
if (byte === ESC) {
|
|
7186
|
+
this.cursor += 1;
|
|
7187
|
+
this.state = { tag: "esc" };
|
|
7188
|
+
continue;
|
|
7189
|
+
}
|
|
7190
|
+
if (byte < 128) {
|
|
7191
|
+
this.emitKeyOrResponse("unknown", decodeUtf8(bytes.subarray(this.cursor, this.cursor + 1)));
|
|
7192
|
+
this.consumePrefix(this.cursor + 1);
|
|
7193
|
+
continue;
|
|
7194
|
+
}
|
|
7195
|
+
const expected = utf8SequenceLength(byte);
|
|
7196
|
+
if (expected === 0) {
|
|
7197
|
+
if (!this.forceFlush && this.cursor + 1 === bytes.length) {
|
|
7198
|
+
this.markPending();
|
|
7199
|
+
return;
|
|
7200
|
+
}
|
|
7201
|
+
this.emitLegacyHighByte(byte);
|
|
7202
|
+
this.consumePrefix(this.cursor + 1);
|
|
7203
|
+
continue;
|
|
7204
|
+
}
|
|
7205
|
+
this.cursor += 1;
|
|
7206
|
+
this.state = { tag: "utf8", expected, seen: 1 };
|
|
7207
|
+
continue;
|
|
7208
|
+
}
|
|
7209
|
+
case "utf8": {
|
|
7210
|
+
if (this.cursor >= bytes.length) {
|
|
7211
|
+
if (!this.forceFlush) {
|
|
7212
|
+
this.markPending();
|
|
7213
|
+
return;
|
|
7214
|
+
}
|
|
7215
|
+
this.emitLegacyHighByte(bytes[this.unitStart]);
|
|
7216
|
+
this.state = { tag: "ground" };
|
|
7217
|
+
this.consumePrefix(this.unitStart + 1);
|
|
7218
|
+
continue;
|
|
7219
|
+
}
|
|
7220
|
+
if ((byte & 192) !== 128) {
|
|
7221
|
+
this.emitLegacyHighByte(bytes[this.unitStart]);
|
|
7222
|
+
this.state = { tag: "ground" };
|
|
7223
|
+
this.consumePrefix(this.unitStart + 1);
|
|
7224
|
+
continue;
|
|
7225
|
+
}
|
|
7226
|
+
const nextSeen = this.state.seen + 1;
|
|
7227
|
+
this.cursor += 1;
|
|
7228
|
+
if (nextSeen < this.state.expected) {
|
|
7229
|
+
this.state = { tag: "utf8", expected: this.state.expected, seen: nextSeen };
|
|
7230
|
+
continue;
|
|
7231
|
+
}
|
|
7232
|
+
this.emitKeyOrResponse("unknown", decodeUtf8(bytes.subarray(this.unitStart, this.cursor)));
|
|
7233
|
+
this.state = { tag: "ground" };
|
|
7234
|
+
this.consumePrefix(this.cursor);
|
|
7235
|
+
continue;
|
|
7236
|
+
}
|
|
7237
|
+
case "esc": {
|
|
7238
|
+
if (this.cursor >= bytes.length) {
|
|
7239
|
+
if (!this.forceFlush) {
|
|
7240
|
+
this.markPending();
|
|
7241
|
+
return;
|
|
7242
|
+
}
|
|
7243
|
+
const flushedLoneEsc = this.cursor === this.unitStart + 1 && bytes[this.unitStart] === ESC;
|
|
7244
|
+
this.emitKeyOrResponse("unknown", decodeUtf8(bytes.subarray(this.unitStart, this.cursor)));
|
|
7245
|
+
this.justFlushedEsc = flushedLoneEsc;
|
|
7246
|
+
this.state = { tag: "ground" };
|
|
7247
|
+
this.consumePrefix(this.cursor);
|
|
7248
|
+
continue;
|
|
7249
|
+
}
|
|
7250
|
+
switch (byte) {
|
|
7251
|
+
case 91:
|
|
7252
|
+
this.cursor += 1;
|
|
7253
|
+
this.state = { tag: "csi" };
|
|
7254
|
+
continue;
|
|
7255
|
+
case 79:
|
|
7256
|
+
this.cursor += 1;
|
|
7257
|
+
this.state = { tag: "ss3" };
|
|
7258
|
+
continue;
|
|
7259
|
+
case 93:
|
|
7260
|
+
this.cursor += 1;
|
|
7261
|
+
this.state = { tag: "osc", sawEsc: false };
|
|
7262
|
+
continue;
|
|
7263
|
+
case 80:
|
|
7264
|
+
this.cursor += 1;
|
|
7265
|
+
this.state = { tag: "dcs", sawEsc: false };
|
|
7266
|
+
continue;
|
|
7267
|
+
case 95:
|
|
7268
|
+
this.cursor += 1;
|
|
7269
|
+
this.state = { tag: "apc", sawEsc: false };
|
|
7270
|
+
continue;
|
|
7271
|
+
case ESC:
|
|
7272
|
+
this.cursor += 1;
|
|
7273
|
+
continue;
|
|
7274
|
+
default:
|
|
7275
|
+
this.cursor += 1;
|
|
7276
|
+
this.emitKeyOrResponse("unknown", decodeUtf8(bytes.subarray(this.unitStart, this.cursor)));
|
|
7277
|
+
this.state = { tag: "ground" };
|
|
7278
|
+
this.consumePrefix(this.cursor);
|
|
7279
|
+
continue;
|
|
7280
|
+
}
|
|
7281
|
+
}
|
|
7282
|
+
case "ss3": {
|
|
7283
|
+
if (this.cursor >= bytes.length) {
|
|
7284
|
+
if (!this.forceFlush) {
|
|
7285
|
+
this.markPending();
|
|
7286
|
+
return;
|
|
7287
|
+
}
|
|
7288
|
+
this.emitOpaqueResponse("unknown", bytes.subarray(this.unitStart, this.cursor));
|
|
7289
|
+
this.state = { tag: "ground" };
|
|
7290
|
+
this.consumePrefix(this.cursor);
|
|
7291
|
+
continue;
|
|
7292
|
+
}
|
|
7293
|
+
if (byte === ESC) {
|
|
7294
|
+
this.emitOpaqueResponse("unknown", bytes.subarray(this.unitStart, this.cursor));
|
|
7295
|
+
this.state = { tag: "ground" };
|
|
7296
|
+
this.consumePrefix(this.cursor);
|
|
7297
|
+
continue;
|
|
7298
|
+
}
|
|
7299
|
+
this.cursor += 1;
|
|
7300
|
+
this.emitKeyOrResponse("unknown", decodeUtf8(bytes.subarray(this.unitStart, this.cursor)));
|
|
7301
|
+
this.state = { tag: "ground" };
|
|
7302
|
+
this.consumePrefix(this.cursor);
|
|
7303
|
+
continue;
|
|
7304
|
+
}
|
|
7305
|
+
case "esc_recovery": {
|
|
7306
|
+
if (this.cursor >= bytes.length) {
|
|
7307
|
+
if (!this.forceFlush) {
|
|
7308
|
+
this.markPending();
|
|
7309
|
+
return;
|
|
7310
|
+
}
|
|
7311
|
+
this.emitKeyOrResponse("unknown", decodeUtf8(bytes.subarray(this.unitStart, this.cursor)));
|
|
7312
|
+
this.state = { tag: "ground" };
|
|
7313
|
+
this.consumePrefix(this.cursor);
|
|
7314
|
+
continue;
|
|
7315
|
+
}
|
|
7316
|
+
if (byte === 60) {
|
|
7317
|
+
this.cursor += 1;
|
|
7318
|
+
this.state = { tag: "esc_less_mouse" };
|
|
7319
|
+
continue;
|
|
7320
|
+
}
|
|
7321
|
+
if (byte === 77) {
|
|
7322
|
+
this.cursor += 1;
|
|
7323
|
+
this.state = { tag: "esc_less_x10_mouse" };
|
|
7324
|
+
continue;
|
|
7325
|
+
}
|
|
7326
|
+
this.emitKeyOrResponse("unknown", decodeUtf8(bytes.subarray(this.unitStart, this.unitStart + 1)));
|
|
7327
|
+
this.state = { tag: "ground" };
|
|
7328
|
+
this.consumePrefix(this.unitStart + 1);
|
|
7329
|
+
continue;
|
|
7330
|
+
}
|
|
7331
|
+
case "csi": {
|
|
7332
|
+
if (this.cursor >= bytes.length) {
|
|
7333
|
+
if (!this.forceFlush) {
|
|
7334
|
+
this.markPending();
|
|
7335
|
+
return;
|
|
7336
|
+
}
|
|
7337
|
+
this.emitOpaqueResponse("unknown", bytes.subarray(this.unitStart, this.cursor));
|
|
7338
|
+
this.state = { tag: "ground" };
|
|
7339
|
+
this.consumePrefix(this.cursor);
|
|
7340
|
+
continue;
|
|
7341
|
+
}
|
|
7342
|
+
if (byte === ESC) {
|
|
7343
|
+
this.emitOpaqueResponse("unknown", bytes.subarray(this.unitStart, this.cursor));
|
|
7344
|
+
this.state = { tag: "ground" };
|
|
7345
|
+
this.consumePrefix(this.cursor);
|
|
7346
|
+
continue;
|
|
7347
|
+
}
|
|
7348
|
+
if (byte === 77 && this.cursor === this.unitStart + 2) {
|
|
7349
|
+
const end = this.cursor + 4;
|
|
7350
|
+
if (bytes.length < end) {
|
|
7351
|
+
if (!this.forceFlush) {
|
|
7352
|
+
this.markPending();
|
|
7353
|
+
return;
|
|
7354
|
+
}
|
|
7355
|
+
this.emitOpaqueResponse("unknown", bytes.subarray(this.unitStart, bytes.length));
|
|
7356
|
+
this.state = { tag: "ground" };
|
|
7357
|
+
this.consumePrefix(bytes.length);
|
|
7358
|
+
continue;
|
|
7359
|
+
}
|
|
7360
|
+
this.emitMouse(bytes.subarray(this.unitStart, end), "x10");
|
|
7361
|
+
this.state = { tag: "ground" };
|
|
7362
|
+
this.consumePrefix(end);
|
|
7363
|
+
continue;
|
|
7364
|
+
}
|
|
7365
|
+
if (byte === 36) {
|
|
7366
|
+
const candidateEnd = this.cursor + 1;
|
|
7367
|
+
const candidate = decodeUtf8(bytes.subarray(this.unitStart, candidateEnd));
|
|
7368
|
+
if (RXVT_DOLLAR_CSI_RE.test(candidate)) {
|
|
7369
|
+
this.emitKeyOrResponse("csi", candidate);
|
|
7370
|
+
this.state = { tag: "ground" };
|
|
7371
|
+
this.consumePrefix(candidateEnd);
|
|
7372
|
+
continue;
|
|
7373
|
+
}
|
|
7374
|
+
if (!this.forceFlush && candidateEnd >= bytes.length) {
|
|
7375
|
+
this.markPending();
|
|
7376
|
+
return;
|
|
7377
|
+
}
|
|
7378
|
+
}
|
|
7379
|
+
if (byte === 91 && this.cursor === this.unitStart + 2) {
|
|
7380
|
+
this.cursor += 1;
|
|
7381
|
+
continue;
|
|
7382
|
+
}
|
|
7383
|
+
if (byte >= 64 && byte <= 126) {
|
|
7384
|
+
const end = this.cursor + 1;
|
|
7385
|
+
const rawBytes = bytes.subarray(this.unitStart, end);
|
|
7386
|
+
if (bytesEqual(rawBytes, BRACKETED_PASTE_START)) {
|
|
7387
|
+
this.state = { tag: "ground" };
|
|
7388
|
+
this.consumePrefix(end);
|
|
7389
|
+
this.paste = createPasteCollector();
|
|
7390
|
+
continue;
|
|
7391
|
+
}
|
|
7392
|
+
if (isMouseSgrSequence(rawBytes)) {
|
|
7393
|
+
this.emitMouse(rawBytes, "sgr");
|
|
7394
|
+
this.state = { tag: "ground" };
|
|
7395
|
+
this.consumePrefix(end);
|
|
7396
|
+
continue;
|
|
7397
|
+
}
|
|
7398
|
+
this.emitKeyOrResponse("csi", decodeUtf8(rawBytes));
|
|
7399
|
+
this.state = { tag: "ground" };
|
|
7400
|
+
this.consumePrefix(end);
|
|
7401
|
+
continue;
|
|
7402
|
+
}
|
|
7403
|
+
this.cursor += 1;
|
|
7404
|
+
continue;
|
|
7405
|
+
}
|
|
7406
|
+
case "osc": {
|
|
7407
|
+
if (this.cursor >= bytes.length) {
|
|
7408
|
+
if (!this.forceFlush) {
|
|
7409
|
+
this.markPending();
|
|
7410
|
+
return;
|
|
7411
|
+
}
|
|
7412
|
+
this.emitOpaqueResponse("unknown", bytes.subarray(this.unitStart, this.cursor));
|
|
7413
|
+
this.state = { tag: "ground" };
|
|
7414
|
+
this.consumePrefix(this.cursor);
|
|
7415
|
+
continue;
|
|
7416
|
+
}
|
|
7417
|
+
if (this.state.sawEsc) {
|
|
7418
|
+
if (byte === 92) {
|
|
7419
|
+
const end = this.cursor + 1;
|
|
7420
|
+
this.emitOpaqueResponse("osc", bytes.subarray(this.unitStart, end));
|
|
7421
|
+
this.state = { tag: "ground" };
|
|
7422
|
+
this.consumePrefix(end);
|
|
7423
|
+
continue;
|
|
7424
|
+
}
|
|
7425
|
+
this.state = { tag: "osc", sawEsc: false };
|
|
7426
|
+
continue;
|
|
7427
|
+
}
|
|
7428
|
+
if (byte === BEL) {
|
|
7429
|
+
const end = this.cursor + 1;
|
|
7430
|
+
this.emitOpaqueResponse("osc", bytes.subarray(this.unitStart, end));
|
|
7431
|
+
this.state = { tag: "ground" };
|
|
7432
|
+
this.consumePrefix(end);
|
|
7433
|
+
continue;
|
|
7434
|
+
}
|
|
7435
|
+
if (byte === ESC) {
|
|
7436
|
+
this.cursor += 1;
|
|
7437
|
+
this.state = { tag: "osc", sawEsc: true };
|
|
7438
|
+
continue;
|
|
7439
|
+
}
|
|
7440
|
+
this.cursor += 1;
|
|
7441
|
+
continue;
|
|
7442
|
+
}
|
|
7443
|
+
case "dcs": {
|
|
7444
|
+
if (this.cursor >= bytes.length) {
|
|
7445
|
+
if (!this.forceFlush) {
|
|
7446
|
+
this.markPending();
|
|
7447
|
+
return;
|
|
7448
|
+
}
|
|
7449
|
+
this.emitOpaqueResponse("unknown", bytes.subarray(this.unitStart, this.cursor));
|
|
7450
|
+
this.state = { tag: "ground" };
|
|
7451
|
+
this.consumePrefix(this.cursor);
|
|
7452
|
+
continue;
|
|
7453
|
+
}
|
|
7454
|
+
if (this.state.sawEsc) {
|
|
7455
|
+
if (byte === 92) {
|
|
7456
|
+
const end = this.cursor + 1;
|
|
7457
|
+
this.emitOpaqueResponse("dcs", bytes.subarray(this.unitStart, end));
|
|
7458
|
+
this.state = { tag: "ground" };
|
|
7459
|
+
this.consumePrefix(end);
|
|
7460
|
+
continue;
|
|
7461
|
+
}
|
|
7462
|
+
this.state = { tag: "dcs", sawEsc: false };
|
|
7463
|
+
continue;
|
|
7464
|
+
}
|
|
7465
|
+
if (byte === ESC) {
|
|
7466
|
+
this.cursor += 1;
|
|
7467
|
+
this.state = { tag: "dcs", sawEsc: true };
|
|
7468
|
+
continue;
|
|
7469
|
+
}
|
|
7470
|
+
this.cursor += 1;
|
|
7471
|
+
continue;
|
|
7472
|
+
}
|
|
7473
|
+
case "apc": {
|
|
7474
|
+
if (this.cursor >= bytes.length) {
|
|
7475
|
+
if (!this.forceFlush) {
|
|
7476
|
+
this.markPending();
|
|
7477
|
+
return;
|
|
7478
|
+
}
|
|
7479
|
+
this.emitOpaqueResponse("unknown", bytes.subarray(this.unitStart, this.cursor));
|
|
7480
|
+
this.state = { tag: "ground" };
|
|
7481
|
+
this.consumePrefix(this.cursor);
|
|
7482
|
+
continue;
|
|
7483
|
+
}
|
|
7484
|
+
if (this.state.sawEsc) {
|
|
7485
|
+
if (byte === 92) {
|
|
7486
|
+
const end = this.cursor + 1;
|
|
7487
|
+
this.emitOpaqueResponse("apc", bytes.subarray(this.unitStart, end));
|
|
7488
|
+
this.state = { tag: "ground" };
|
|
7489
|
+
this.consumePrefix(end);
|
|
7490
|
+
continue;
|
|
7491
|
+
}
|
|
7492
|
+
this.state = { tag: "apc", sawEsc: false };
|
|
7493
|
+
continue;
|
|
7494
|
+
}
|
|
7495
|
+
if (byte === ESC) {
|
|
7496
|
+
this.cursor += 1;
|
|
7497
|
+
this.state = { tag: "apc", sawEsc: true };
|
|
7498
|
+
continue;
|
|
7499
|
+
}
|
|
7500
|
+
this.cursor += 1;
|
|
7501
|
+
continue;
|
|
7502
|
+
}
|
|
7503
|
+
case "esc_less_mouse": {
|
|
7504
|
+
if (this.cursor >= bytes.length) {
|
|
7505
|
+
if (!this.forceFlush) {
|
|
7506
|
+
this.markPending();
|
|
7507
|
+
return;
|
|
7508
|
+
}
|
|
7509
|
+
this.emitOpaqueResponse("unknown", bytes.subarray(this.unitStart, this.cursor));
|
|
7510
|
+
this.state = { tag: "ground" };
|
|
7511
|
+
this.consumePrefix(this.cursor);
|
|
7512
|
+
continue;
|
|
7513
|
+
}
|
|
7514
|
+
if (byte >= 48 && byte <= 57 || byte === 59) {
|
|
7515
|
+
this.cursor += 1;
|
|
7516
|
+
continue;
|
|
7517
|
+
}
|
|
7518
|
+
if (byte === 77 || byte === 109) {
|
|
7519
|
+
const end = this.cursor + 1;
|
|
7520
|
+
this.emitOpaqueResponse("unknown", bytes.subarray(this.unitStart, end));
|
|
7521
|
+
this.state = { tag: "ground" };
|
|
7522
|
+
this.consumePrefix(end);
|
|
7523
|
+
continue;
|
|
7524
|
+
}
|
|
7525
|
+
this.emitOpaqueResponse("unknown", bytes.subarray(this.unitStart, this.cursor));
|
|
7526
|
+
this.state = { tag: "ground" };
|
|
7527
|
+
this.consumePrefix(this.cursor);
|
|
7528
|
+
continue;
|
|
7529
|
+
}
|
|
7530
|
+
case "esc_less_x10_mouse": {
|
|
7531
|
+
const end = this.unitStart + 5;
|
|
7532
|
+
if (bytes.length < end) {
|
|
7533
|
+
if (!this.forceFlush) {
|
|
7534
|
+
this.markPending();
|
|
7535
|
+
return;
|
|
7536
|
+
}
|
|
7537
|
+
this.emitOpaqueResponse("unknown", bytes.subarray(this.unitStart, bytes.length));
|
|
7538
|
+
this.state = { tag: "ground" };
|
|
7539
|
+
this.consumePrefix(bytes.length);
|
|
7540
|
+
continue;
|
|
7541
|
+
}
|
|
7542
|
+
this.emitOpaqueResponse("unknown", bytes.subarray(this.unitStart, end));
|
|
7543
|
+
this.state = { tag: "ground" };
|
|
7544
|
+
this.consumePrefix(end);
|
|
7545
|
+
continue;
|
|
7546
|
+
}
|
|
6926
7547
|
}
|
|
6927
|
-
return numValue;
|
|
6928
|
-
case "string":
|
|
6929
|
-
default:
|
|
6930
|
-
return envValue;
|
|
6931
|
-
}
|
|
6932
|
-
}
|
|
6933
|
-
|
|
6934
|
-
class EnvStore {
|
|
6935
|
-
parsedValues = new Map;
|
|
6936
|
-
get(key) {
|
|
6937
|
-
if (this.parsedValues.has(key)) {
|
|
6938
|
-
return this.parsedValues.get(key);
|
|
6939
|
-
}
|
|
6940
|
-
if (!(key in envRegistry)) {
|
|
6941
|
-
throw new Error(`Environment variable ${key} is not registered.`);
|
|
6942
7548
|
}
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
7549
|
+
}
|
|
7550
|
+
emitKeyOrResponse(protocol, raw) {
|
|
7551
|
+
const parsed = parseKeypress(raw, { useKittyKeyboard: this.useKittyKeyboard });
|
|
7552
|
+
if (parsed) {
|
|
7553
|
+
this.events.push({
|
|
7554
|
+
type: "key",
|
|
7555
|
+
raw: parsed.raw,
|
|
7556
|
+
key: parsed
|
|
7557
|
+
});
|
|
7558
|
+
return;
|
|
6949
7559
|
}
|
|
7560
|
+
this.events.push({
|
|
7561
|
+
type: "response",
|
|
7562
|
+
protocol,
|
|
7563
|
+
sequence: raw
|
|
7564
|
+
});
|
|
6950
7565
|
}
|
|
6951
|
-
|
|
6952
|
-
|
|
7566
|
+
emitMouse(rawBytes, encoding) {
|
|
7567
|
+
const event = this.mouseParser.parseMouseEvent(rawBytes);
|
|
7568
|
+
if (!event) {
|
|
7569
|
+
this.emitOpaqueResponse("unknown", rawBytes);
|
|
7570
|
+
return;
|
|
7571
|
+
}
|
|
7572
|
+
this.events.push({
|
|
7573
|
+
type: "mouse",
|
|
7574
|
+
raw: decodeLatin1(rawBytes),
|
|
7575
|
+
encoding,
|
|
7576
|
+
event
|
|
7577
|
+
});
|
|
6953
7578
|
}
|
|
6954
|
-
|
|
6955
|
-
|
|
7579
|
+
emitLegacyHighByte(byte) {
|
|
7580
|
+
const parsed = parseKeypress(Buffer3.from([byte]), { useKittyKeyboard: this.useKittyKeyboard });
|
|
7581
|
+
if (parsed) {
|
|
7582
|
+
this.events.push({
|
|
7583
|
+
type: "key",
|
|
7584
|
+
raw: parsed.raw,
|
|
7585
|
+
key: parsed
|
|
7586
|
+
});
|
|
7587
|
+
return;
|
|
7588
|
+
}
|
|
7589
|
+
this.events.push({
|
|
7590
|
+
type: "response",
|
|
7591
|
+
protocol: "unknown",
|
|
7592
|
+
sequence: String.fromCharCode(byte)
|
|
7593
|
+
});
|
|
6956
7594
|
}
|
|
6957
|
-
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
const configs = Object.values(envRegistry);
|
|
6964
|
-
if (configs.length === 0) {
|
|
6965
|
-
return `# Environment Variables
|
|
6966
|
-
|
|
6967
|
-
No environment variables registered.
|
|
6968
|
-
`;
|
|
7595
|
+
emitOpaqueResponse(protocol, rawBytes) {
|
|
7596
|
+
this.events.push({
|
|
7597
|
+
type: "response",
|
|
7598
|
+
protocol,
|
|
7599
|
+
sequence: decodeLatin1(rawBytes)
|
|
7600
|
+
});
|
|
6969
7601
|
}
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
|
|
6977
|
-
|
|
6978
|
-
|
|
6979
|
-
|
|
6980
|
-
|
|
6981
|
-
|
|
6982
|
-
|
|
6983
|
-
|
|
6984
|
-
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
|
|
6988
|
-
`;
|
|
7602
|
+
consumePrefix(endExclusive) {
|
|
7603
|
+
this.pending.consume(endExclusive);
|
|
7604
|
+
this.cursor = 0;
|
|
7605
|
+
this.unitStart = 0;
|
|
7606
|
+
this.pendingSinceMs = null;
|
|
7607
|
+
this.forceFlush = false;
|
|
7608
|
+
}
|
|
7609
|
+
takePendingBytes() {
|
|
7610
|
+
const buffered = this.pending.take();
|
|
7611
|
+
this.cursor = 0;
|
|
7612
|
+
this.unitStart = 0;
|
|
7613
|
+
this.pendingSinceMs = null;
|
|
7614
|
+
this.forceFlush = false;
|
|
7615
|
+
return buffered;
|
|
7616
|
+
}
|
|
7617
|
+
flushPendingOverflow() {
|
|
7618
|
+
if (this.pending.length === 0) {
|
|
7619
|
+
return;
|
|
6989
7620
|
}
|
|
6990
|
-
|
|
6991
|
-
|
|
6992
|
-
|
|
6993
|
-
|
|
6994
|
-
|
|
6995
|
-
|
|
6996
|
-
|
|
6997
|
-
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7001
|
-
|
|
7621
|
+
this.emitOpaqueResponse("unknown", this.pending.view());
|
|
7622
|
+
this.pending.clear();
|
|
7623
|
+
this.cursor = 0;
|
|
7624
|
+
this.unitStart = 0;
|
|
7625
|
+
this.pendingSinceMs = null;
|
|
7626
|
+
this.forceFlush = false;
|
|
7627
|
+
this.state = { tag: "ground" };
|
|
7628
|
+
}
|
|
7629
|
+
markPending() {
|
|
7630
|
+
this.pendingSinceMs = this.clock.now();
|
|
7631
|
+
}
|
|
7632
|
+
consumePasteBytes(chunk) {
|
|
7633
|
+
const paste = this.paste;
|
|
7634
|
+
const combined = concatBytes(paste.tail, chunk);
|
|
7635
|
+
const endIndex = indexOfBytes(combined, BRACKETED_PASTE_END);
|
|
7636
|
+
if (endIndex !== -1) {
|
|
7637
|
+
this.pushPasteBytes(combined.subarray(0, endIndex));
|
|
7638
|
+
this.events.push({
|
|
7639
|
+
type: "paste",
|
|
7640
|
+
bytes: joinPasteBytes(paste.parts, paste.totalLength)
|
|
7641
|
+
});
|
|
7642
|
+
this.paste = null;
|
|
7643
|
+
return combined.subarray(endIndex + BRACKETED_PASTE_END.length);
|
|
7644
|
+
}
|
|
7645
|
+
const keep = Math.min(BRACKETED_PASTE_END.length - 1, combined.length);
|
|
7646
|
+
const stableLength = combined.length - keep;
|
|
7647
|
+
if (stableLength > 0) {
|
|
7648
|
+
this.pushPasteBytes(combined.subarray(0, stableLength));
|
|
7649
|
+
}
|
|
7650
|
+
paste.tail = Uint8Array.from(combined.subarray(stableLength));
|
|
7651
|
+
return EMPTY_BYTES;
|
|
7002
7652
|
}
|
|
7003
|
-
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
for (const config of configs) {
|
|
7007
|
-
output += `\x1B[1;33m${config.name}\x1B[0m
|
|
7008
|
-
`;
|
|
7009
|
-
output += `${config.description}
|
|
7010
|
-
`;
|
|
7011
|
-
output += `\x1B[32mType:\x1B[0m \x1B[36m${config.type || "string"}\x1B[0m
|
|
7012
|
-
`;
|
|
7013
|
-
if (config.default !== undefined) {
|
|
7014
|
-
const defaultValue = typeof config.default === "string" ? `"${config.default}"` : String(config.default);
|
|
7015
|
-
output += `\x1B[32mDefault:\x1B[0m \x1B[35m${defaultValue}\x1B[0m
|
|
7016
|
-
`;
|
|
7017
|
-
} else {
|
|
7018
|
-
output += `\x1B[32mDefault:\x1B[0m \x1B[31mRequired\x1B[0m
|
|
7019
|
-
`;
|
|
7653
|
+
pushPasteBytes(bytes) {
|
|
7654
|
+
if (bytes.length === 0) {
|
|
7655
|
+
return;
|
|
7020
7656
|
}
|
|
7021
|
-
|
|
7022
|
-
|
|
7657
|
+
this.paste.parts.push(Uint8Array.from(bytes));
|
|
7658
|
+
this.paste.totalLength += bytes.length;
|
|
7023
7659
|
}
|
|
7024
|
-
|
|
7025
|
-
|
|
7026
|
-
var env = new Proxy({}, {
|
|
7027
|
-
get(target, prop) {
|
|
7028
|
-
if (typeof prop !== "string") {
|
|
7660
|
+
reconcileTimeoutState() {
|
|
7661
|
+
if (!this.armTimeouts) {
|
|
7029
7662
|
return;
|
|
7030
7663
|
}
|
|
7031
|
-
|
|
7032
|
-
|
|
7033
|
-
|
|
7034
|
-
return envStore.has(prop);
|
|
7035
|
-
},
|
|
7036
|
-
ownKeys() {
|
|
7037
|
-
return Object.keys(envRegistry);
|
|
7038
|
-
},
|
|
7039
|
-
getOwnPropertyDescriptor(target, prop) {
|
|
7040
|
-
if (envStore.has(prop)) {
|
|
7041
|
-
return {
|
|
7042
|
-
enumerable: true,
|
|
7043
|
-
configurable: true,
|
|
7044
|
-
get: () => envStore.get(prop)
|
|
7045
|
-
};
|
|
7664
|
+
if (this.paste || this.pendingSinceMs === null || this.pending.length === 0) {
|
|
7665
|
+
this.clearTimeout();
|
|
7666
|
+
return;
|
|
7046
7667
|
}
|
|
7047
|
-
|
|
7668
|
+
this.clearTimeout();
|
|
7669
|
+
this.timeoutId = this.clock.setTimeout(() => {
|
|
7670
|
+
this.timeoutId = null;
|
|
7671
|
+
if (this.destroyed) {
|
|
7672
|
+
return;
|
|
7673
|
+
}
|
|
7674
|
+
try {
|
|
7675
|
+
this.flushTimeout(this.clock.now());
|
|
7676
|
+
this.onTimeoutFlush?.();
|
|
7677
|
+
} catch (error) {
|
|
7678
|
+
console.error("stdin parser timeout flush failed", error);
|
|
7679
|
+
}
|
|
7680
|
+
}, this.timeoutMs);
|
|
7048
7681
|
}
|
|
7049
|
-
|
|
7682
|
+
clearTimeout() {
|
|
7683
|
+
if (!this.timeoutId) {
|
|
7684
|
+
return;
|
|
7685
|
+
}
|
|
7686
|
+
this.clock.clearTimeout(this.timeoutId);
|
|
7687
|
+
this.timeoutId = null;
|
|
7688
|
+
}
|
|
7689
|
+
resetState() {
|
|
7690
|
+
this.pending.reset(INITIAL_PENDING_CAPACITY);
|
|
7691
|
+
this.events.length = 0;
|
|
7692
|
+
this.pendingSinceMs = null;
|
|
7693
|
+
this.forceFlush = false;
|
|
7694
|
+
this.justFlushedEsc = false;
|
|
7695
|
+
this.state = { tag: "ground" };
|
|
7696
|
+
this.cursor = 0;
|
|
7697
|
+
this.unitStart = 0;
|
|
7698
|
+
this.paste = null;
|
|
7699
|
+
this.mouseParser.reset();
|
|
7700
|
+
}
|
|
7701
|
+
}
|
|
7050
7702
|
|
|
7051
7703
|
// src/lib/tree-sitter-styled-text.ts
|
|
7052
7704
|
registerEnvVar({ name: "OTUI_TS_STYLE_WARN", default: false, description: "Enable warnings for missing syntax styles" });
|
|
@@ -7262,7 +7914,7 @@ async function treeSitterToStyledText(content, filetype, syntaxStyle, client, op
|
|
|
7262
7914
|
}
|
|
7263
7915
|
|
|
7264
7916
|
// src/lib/tree-sitter/client.ts
|
|
7265
|
-
import { EventEmitter as
|
|
7917
|
+
import { EventEmitter as EventEmitter2 } from "events";
|
|
7266
7918
|
|
|
7267
7919
|
// src/lib/debounce.ts
|
|
7268
7920
|
var TIMERS_MAP = new Map;
|
|
@@ -7477,7 +8129,7 @@ function addDefaultParsers(parsers) {
|
|
|
7477
8129
|
}
|
|
7478
8130
|
var isUrl = (path) => path.startsWith("http://") || path.startsWith("https://");
|
|
7479
8131
|
|
|
7480
|
-
class TreeSitterClient extends
|
|
8132
|
+
class TreeSitterClient extends EventEmitter2 {
|
|
7481
8133
|
initialized = false;
|
|
7482
8134
|
worker;
|
|
7483
8135
|
buffers = new Map;
|
|
@@ -7929,7 +8581,7 @@ class TreeSitterClient extends EventEmitter3 {
|
|
|
7929
8581
|
// src/lib/data-paths.ts
|
|
7930
8582
|
import os from "os";
|
|
7931
8583
|
import path from "path";
|
|
7932
|
-
import { EventEmitter as
|
|
8584
|
+
import { EventEmitter as EventEmitter3 } from "events";
|
|
7933
8585
|
|
|
7934
8586
|
// src/lib/validate-dir-name.ts
|
|
7935
8587
|
function isValidDirectoryName(name) {
|
|
@@ -7993,7 +8645,7 @@ registerEnvVar({
|
|
|
7993
8645
|
default: ""
|
|
7994
8646
|
});
|
|
7995
8647
|
|
|
7996
|
-
class DataPathsManager extends
|
|
8648
|
+
class DataPathsManager extends EventEmitter3 {
|
|
7997
8649
|
_appName;
|
|
7998
8650
|
_globalConfigPath;
|
|
7999
8651
|
_globalConfigFile;
|
|
@@ -8125,11 +8777,11 @@ function pathToFiletype(path2) {
|
|
|
8125
8777
|
}
|
|
8126
8778
|
|
|
8127
8779
|
// src/lib/tree-sitter/assets/update.ts
|
|
8128
|
-
import { readFile, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
8780
|
+
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
8129
8781
|
import * as path3 from "path";
|
|
8130
8782
|
|
|
8131
8783
|
// src/lib/tree-sitter/download-utils.ts
|
|
8132
|
-
import { mkdir, writeFile } from "fs/promises";
|
|
8784
|
+
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
8133
8785
|
import * as path2 from "path";
|
|
8134
8786
|
|
|
8135
8787
|
class DownloadUtils {
|
|
@@ -8155,7 +8807,7 @@ class DownloadUtils {
|
|
|
8155
8807
|
const cacheFile = path2.join(cacheDir, cacheSubdir, cacheFileName);
|
|
8156
8808
|
await mkdir(path2.dirname(cacheFile), { recursive: true });
|
|
8157
8809
|
try {
|
|
8158
|
-
const cachedContent = await
|
|
8810
|
+
const cachedContent = await readFile(cacheFile);
|
|
8159
8811
|
if (cachedContent.byteLength > 0) {
|
|
8160
8812
|
console.log(`Loaded from cache: ${cacheFile} (${source})`);
|
|
8161
8813
|
return { content: cachedContent, filePath: cacheFile };
|
|
@@ -8167,7 +8819,7 @@ class DownloadUtils {
|
|
|
8167
8819
|
if (!response.ok) {
|
|
8168
8820
|
return { error: `Failed to fetch from ${source}: ${response.statusText}` };
|
|
8169
8821
|
}
|
|
8170
|
-
const content = await response.arrayBuffer();
|
|
8822
|
+
const content = Buffer.from(await response.arrayBuffer());
|
|
8171
8823
|
try {
|
|
8172
8824
|
await writeFile(cacheFile, Buffer.from(content));
|
|
8173
8825
|
console.log(`Cached: ${source}`);
|
|
@@ -8181,7 +8833,7 @@ class DownloadUtils {
|
|
|
8181
8833
|
} else {
|
|
8182
8834
|
try {
|
|
8183
8835
|
console.log(`Loading from local path: ${source}`);
|
|
8184
|
-
const content = await
|
|
8836
|
+
const content = await readFile(source);
|
|
8185
8837
|
return { content, filePath: source };
|
|
8186
8838
|
} catch (error) {
|
|
8187
8839
|
return { error: `Error loading from local path ${source}: ${error}` };
|
|
@@ -8198,7 +8850,7 @@ class DownloadUtils {
|
|
|
8198
8850
|
if (!response.ok) {
|
|
8199
8851
|
return { error: `Failed to fetch from ${source}: ${response.statusText}` };
|
|
8200
8852
|
}
|
|
8201
|
-
const content = await response.arrayBuffer();
|
|
8853
|
+
const content = Buffer.from(await response.arrayBuffer());
|
|
8202
8854
|
await writeFile(targetPath, Buffer.from(content));
|
|
8203
8855
|
console.log(`Downloaded: ${source} -> ${targetPath}`);
|
|
8204
8856
|
return { content, filePath: targetPath };
|
|
@@ -8208,7 +8860,7 @@ class DownloadUtils {
|
|
|
8208
8860
|
} else {
|
|
8209
8861
|
try {
|
|
8210
8862
|
console.log(`Copying from local path: ${source}`);
|
|
8211
|
-
const content = await
|
|
8863
|
+
const content = await readFile(source);
|
|
8212
8864
|
await writeFile(targetPath, Buffer.from(content));
|
|
8213
8865
|
return { content, filePath: targetPath };
|
|
8214
8866
|
} catch (error) {
|
|
@@ -8259,7 +8911,7 @@ async function loadConfig(configPath) {
|
|
|
8259
8911
|
ext = path3.extname(resolvedConfigPath);
|
|
8260
8912
|
}
|
|
8261
8913
|
if (ext === ".json") {
|
|
8262
|
-
const configContent = await
|
|
8914
|
+
const configContent = await readFile2(resolvedConfigPath, "utf-8");
|
|
8263
8915
|
return JSON.parse(configContent);
|
|
8264
8916
|
} else if (ext === ".ts" || ext === ".js") {
|
|
8265
8917
|
const { default: configContent } = await import(resolvedConfigPath);
|
|
@@ -8287,7 +8939,7 @@ async function downloadAndCombineQueries(filetype, queryUrls, assetsDir, outputP
|
|
|
8287
8939
|
console.log(` Using local query ${i + 1}/${queryUrls.length}: ${queryUrl}`);
|
|
8288
8940
|
try {
|
|
8289
8941
|
const localPath = path3.resolve(path3.dirname(configPath), queryUrl);
|
|
8290
|
-
const content = await
|
|
8942
|
+
const content = await readFile2(localPath, "utf-8");
|
|
8291
8943
|
if (content.trim()) {
|
|
8292
8944
|
queryContents.push(content);
|
|
8293
8945
|
console.log(` \u2713 Loaded ${content.split(`
|
|
@@ -9149,6 +9801,7 @@ function createExtmarksController(editBuffer, editorView) {
|
|
|
9149
9801
|
}
|
|
9150
9802
|
|
|
9151
9803
|
// src/lib/terminal-palette.ts
|
|
9804
|
+
var SYSTEM_CLOCK2 = new SystemClock;
|
|
9152
9805
|
var OSC4_RESPONSE = /\x1b]4;(\d+);(?:(?:rgb:)([0-9a-fA-F]+)\/([0-9a-fA-F]+)\/([0-9a-fA-F]+)|#([0-9a-fA-F]{6}))(?:\x07|\x1b\\)/g;
|
|
9153
9806
|
var OSC_SPECIAL_RESPONSE = /\x1b](\d+);(?:(?:rgb:)([0-9a-fA-F]+)\/([0-9a-fA-F]+)\/([0-9a-fA-F]+)|#([0-9a-fA-F]{6}))(?:\x07|\x1b\\)/g;
|
|
9154
9807
|
function scaleComponent(comp) {
|
|
@@ -9172,80 +9825,138 @@ class TerminalPalette {
|
|
|
9172
9825
|
stdin;
|
|
9173
9826
|
stdout;
|
|
9174
9827
|
writeFn;
|
|
9175
|
-
|
|
9176
|
-
activeTimers = [];
|
|
9828
|
+
activeQuerySessions = [];
|
|
9177
9829
|
inLegacyTmux;
|
|
9178
|
-
|
|
9830
|
+
oscSource;
|
|
9831
|
+
clock;
|
|
9832
|
+
constructor(stdin, stdout, writeFn, isLegacyTmux, oscSource, clock) {
|
|
9179
9833
|
this.stdin = stdin;
|
|
9180
9834
|
this.stdout = stdout;
|
|
9181
9835
|
this.writeFn = writeFn || ((data) => stdout.write(data));
|
|
9182
9836
|
this.inLegacyTmux = isLegacyTmux ?? false;
|
|
9837
|
+
this.oscSource = oscSource;
|
|
9838
|
+
this.clock = clock ?? SYSTEM_CLOCK2;
|
|
9183
9839
|
}
|
|
9184
9840
|
writeOsc(osc) {
|
|
9185
9841
|
const data = this.inLegacyTmux ? wrapForTmux(osc) : osc;
|
|
9186
9842
|
return this.writeFn(data);
|
|
9187
9843
|
}
|
|
9188
9844
|
cleanup() {
|
|
9189
|
-
for (const
|
|
9190
|
-
|
|
9845
|
+
for (const cleanupSession of [...this.activeQuerySessions]) {
|
|
9846
|
+
cleanupSession();
|
|
9191
9847
|
}
|
|
9192
|
-
this.
|
|
9193
|
-
|
|
9194
|
-
|
|
9848
|
+
this.activeQuerySessions = [];
|
|
9849
|
+
}
|
|
9850
|
+
subscribeInput(handler) {
|
|
9851
|
+
if (this.oscSource) {
|
|
9852
|
+
return this.oscSource.subscribeOsc((sequence) => {
|
|
9853
|
+
handler(sequence);
|
|
9854
|
+
});
|
|
9195
9855
|
}
|
|
9196
|
-
this.
|
|
9856
|
+
this.stdin.on("data", handler);
|
|
9857
|
+
return () => {
|
|
9858
|
+
this.stdin.removeListener("data", handler);
|
|
9859
|
+
};
|
|
9860
|
+
}
|
|
9861
|
+
createQuerySession() {
|
|
9862
|
+
const timers = new Set;
|
|
9863
|
+
const subscriptions = new Set;
|
|
9864
|
+
let closed = false;
|
|
9865
|
+
const cleanup = () => {
|
|
9866
|
+
if (closed)
|
|
9867
|
+
return;
|
|
9868
|
+
closed = true;
|
|
9869
|
+
for (const timer of timers) {
|
|
9870
|
+
this.clock.clearTimeout(timer);
|
|
9871
|
+
}
|
|
9872
|
+
timers.clear();
|
|
9873
|
+
for (const unsubscribe of subscriptions) {
|
|
9874
|
+
unsubscribe();
|
|
9875
|
+
}
|
|
9876
|
+
subscriptions.clear();
|
|
9877
|
+
const idx = this.activeQuerySessions.indexOf(cleanup);
|
|
9878
|
+
if (idx !== -1)
|
|
9879
|
+
this.activeQuerySessions.splice(idx, 1);
|
|
9880
|
+
};
|
|
9881
|
+
this.activeQuerySessions.push(cleanup);
|
|
9882
|
+
return {
|
|
9883
|
+
setTimer: (fn, ms) => {
|
|
9884
|
+
const timer = this.clock.setTimeout(fn, ms);
|
|
9885
|
+
timers.add(timer);
|
|
9886
|
+
return timer;
|
|
9887
|
+
},
|
|
9888
|
+
resetTimer: (existing, fn, ms) => {
|
|
9889
|
+
if (existing) {
|
|
9890
|
+
this.clock.clearTimeout(existing);
|
|
9891
|
+
timers.delete(existing);
|
|
9892
|
+
}
|
|
9893
|
+
const timer = this.clock.setTimeout(fn, ms);
|
|
9894
|
+
timers.add(timer);
|
|
9895
|
+
return timer;
|
|
9896
|
+
},
|
|
9897
|
+
subscribeInput: (handler) => {
|
|
9898
|
+
const unsubscribe = this.subscribeInput(handler);
|
|
9899
|
+
subscriptions.add(unsubscribe);
|
|
9900
|
+
return () => {
|
|
9901
|
+
if (!subscriptions.has(unsubscribe))
|
|
9902
|
+
return;
|
|
9903
|
+
subscriptions.delete(unsubscribe);
|
|
9904
|
+
unsubscribe();
|
|
9905
|
+
};
|
|
9906
|
+
},
|
|
9907
|
+
cleanup
|
|
9908
|
+
};
|
|
9197
9909
|
}
|
|
9198
9910
|
async detectOSCSupport(timeoutMs = 300) {
|
|
9199
9911
|
const out = this.stdout;
|
|
9200
|
-
|
|
9201
|
-
if (!out.isTTY || !inp.isTTY)
|
|
9912
|
+
if (!out.isTTY || !this.stdin.isTTY)
|
|
9202
9913
|
return false;
|
|
9203
9914
|
return new Promise((resolve4) => {
|
|
9915
|
+
const session = this.createQuerySession();
|
|
9204
9916
|
let buffer = "";
|
|
9917
|
+
let settled = false;
|
|
9918
|
+
const finish = (supported) => {
|
|
9919
|
+
if (settled)
|
|
9920
|
+
return;
|
|
9921
|
+
settled = true;
|
|
9922
|
+
session.cleanup();
|
|
9923
|
+
resolve4(supported);
|
|
9924
|
+
};
|
|
9205
9925
|
const onData = (chunk) => {
|
|
9206
9926
|
buffer += chunk.toString();
|
|
9207
9927
|
OSC4_RESPONSE.lastIndex = 0;
|
|
9208
9928
|
if (OSC4_RESPONSE.test(buffer)) {
|
|
9209
|
-
|
|
9210
|
-
resolve4(true);
|
|
9929
|
+
finish(true);
|
|
9211
9930
|
}
|
|
9212
9931
|
};
|
|
9213
|
-
|
|
9214
|
-
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
const cleanup = () => {
|
|
9218
|
-
clearTimeout(timer);
|
|
9219
|
-
inp.removeListener("data", onData);
|
|
9220
|
-
const listenerIdx = this.activeListeners.findIndex((l) => l.handler === onData);
|
|
9221
|
-
if (listenerIdx !== -1)
|
|
9222
|
-
this.activeListeners.splice(listenerIdx, 1);
|
|
9223
|
-
const timerIdx = this.activeTimers.indexOf(timer);
|
|
9224
|
-
if (timerIdx !== -1)
|
|
9225
|
-
this.activeTimers.splice(timerIdx, 1);
|
|
9226
|
-
};
|
|
9227
|
-
const timer = setTimeout(onTimeout, timeoutMs);
|
|
9228
|
-
this.activeTimers.push(timer);
|
|
9229
|
-
inp.on("data", onData);
|
|
9230
|
-
this.activeListeners.push({ event: "data", handler: onData });
|
|
9932
|
+
session.setTimer(() => {
|
|
9933
|
+
finish(false);
|
|
9934
|
+
}, timeoutMs);
|
|
9935
|
+
session.subscribeInput(onData);
|
|
9231
9936
|
this.writeOsc("\x1B]4;0;?\x07");
|
|
9232
9937
|
});
|
|
9233
9938
|
}
|
|
9234
9939
|
async queryPalette(indices, timeoutMs = 1200) {
|
|
9235
9940
|
const out = this.stdout;
|
|
9236
|
-
const inp = this.stdin;
|
|
9237
9941
|
const results = new Map;
|
|
9238
9942
|
indices.forEach((i) => results.set(i, null));
|
|
9239
|
-
if (!out.isTTY || !
|
|
9943
|
+
if (!out.isTTY || !this.stdin.isTTY) {
|
|
9240
9944
|
return results;
|
|
9241
9945
|
}
|
|
9242
9946
|
return new Promise((resolve4) => {
|
|
9947
|
+
const session = this.createQuerySession();
|
|
9243
9948
|
let buffer = "";
|
|
9244
|
-
let lastResponseTime = Date.now();
|
|
9245
9949
|
let idleTimer = null;
|
|
9950
|
+
let settled = false;
|
|
9951
|
+
const finish = () => {
|
|
9952
|
+
if (settled)
|
|
9953
|
+
return;
|
|
9954
|
+
settled = true;
|
|
9955
|
+
session.cleanup();
|
|
9956
|
+
resolve4(results);
|
|
9957
|
+
};
|
|
9246
9958
|
const onData = (chunk) => {
|
|
9247
9959
|
buffer += chunk.toString();
|
|
9248
|
-
lastResponseTime = Date.now();
|
|
9249
9960
|
let m;
|
|
9250
9961
|
OSC4_RESPONSE.lastIndex = 0;
|
|
9251
9962
|
while (m = OSC4_RESPONSE.exec(buffer)) {
|
|
@@ -9257,50 +9968,18 @@ class TerminalPalette {
|
|
|
9257
9968
|
buffer = buffer.slice(-4096);
|
|
9258
9969
|
const done = [...results.values()].filter((v) => v !== null).length;
|
|
9259
9970
|
if (done === results.size) {
|
|
9260
|
-
|
|
9261
|
-
resolve4(results);
|
|
9971
|
+
finish();
|
|
9262
9972
|
return;
|
|
9263
9973
|
}
|
|
9264
|
-
|
|
9265
|
-
clearTimeout(idleTimer);
|
|
9266
|
-
idleTimer = setTimeout(() => {
|
|
9267
|
-
cleanup();
|
|
9268
|
-
resolve4(results);
|
|
9269
|
-
}, 150);
|
|
9270
|
-
if (idleTimer)
|
|
9271
|
-
this.activeTimers.push(idleTimer);
|
|
9272
|
-
};
|
|
9273
|
-
const onTimeout = () => {
|
|
9274
|
-
cleanup();
|
|
9275
|
-
resolve4(results);
|
|
9276
|
-
};
|
|
9277
|
-
const cleanup = () => {
|
|
9278
|
-
clearTimeout(timer);
|
|
9279
|
-
if (idleTimer)
|
|
9280
|
-
clearTimeout(idleTimer);
|
|
9281
|
-
inp.removeListener("data", onData);
|
|
9282
|
-
const listenerIdx = this.activeListeners.findIndex((l) => l.handler === onData);
|
|
9283
|
-
if (listenerIdx !== -1)
|
|
9284
|
-
this.activeListeners.splice(listenerIdx, 1);
|
|
9285
|
-
const timerIdx = this.activeTimers.indexOf(timer);
|
|
9286
|
-
if (timerIdx !== -1)
|
|
9287
|
-
this.activeTimers.splice(timerIdx, 1);
|
|
9288
|
-
if (idleTimer) {
|
|
9289
|
-
const idleTimerIdx = this.activeTimers.indexOf(idleTimer);
|
|
9290
|
-
if (idleTimerIdx !== -1)
|
|
9291
|
-
this.activeTimers.splice(idleTimerIdx, 1);
|
|
9292
|
-
}
|
|
9974
|
+
idleTimer = session.resetTimer(idleTimer, finish, 150);
|
|
9293
9975
|
};
|
|
9294
|
-
|
|
9295
|
-
|
|
9296
|
-
inp.on("data", onData);
|
|
9297
|
-
this.activeListeners.push({ event: "data", handler: onData });
|
|
9976
|
+
session.setTimer(finish, timeoutMs);
|
|
9977
|
+
session.subscribeInput(onData);
|
|
9298
9978
|
this.writeOsc(indices.map((i) => `\x1B]4;${i};?\x07`).join(""));
|
|
9299
9979
|
});
|
|
9300
9980
|
}
|
|
9301
9981
|
async querySpecialColors(timeoutMs = 1200) {
|
|
9302
9982
|
const out = this.stdout;
|
|
9303
|
-
const inp = this.stdin;
|
|
9304
9983
|
const results = {
|
|
9305
9984
|
10: null,
|
|
9306
9985
|
11: null,
|
|
@@ -9312,12 +9991,21 @@ class TerminalPalette {
|
|
|
9312
9991
|
17: null,
|
|
9313
9992
|
19: null
|
|
9314
9993
|
};
|
|
9315
|
-
if (!out.isTTY || !
|
|
9994
|
+
if (!out.isTTY || !this.stdin.isTTY) {
|
|
9316
9995
|
return results;
|
|
9317
9996
|
}
|
|
9318
9997
|
return new Promise((resolve4) => {
|
|
9998
|
+
const session = this.createQuerySession();
|
|
9319
9999
|
let buffer = "";
|
|
9320
10000
|
let idleTimer = null;
|
|
10001
|
+
let settled = false;
|
|
10002
|
+
const finish = () => {
|
|
10003
|
+
if (settled)
|
|
10004
|
+
return;
|
|
10005
|
+
settled = true;
|
|
10006
|
+
session.cleanup();
|
|
10007
|
+
resolve4(results);
|
|
10008
|
+
};
|
|
9321
10009
|
const onData = (chunk) => {
|
|
9322
10010
|
buffer += chunk.toString();
|
|
9323
10011
|
let updated = false;
|
|
@@ -9334,46 +10022,15 @@ class TerminalPalette {
|
|
|
9334
10022
|
buffer = buffer.slice(-4096);
|
|
9335
10023
|
const done = Object.values(results).filter((v) => v !== null).length;
|
|
9336
10024
|
if (done === Object.keys(results).length) {
|
|
9337
|
-
|
|
9338
|
-
resolve4(results);
|
|
10025
|
+
finish();
|
|
9339
10026
|
return;
|
|
9340
10027
|
}
|
|
9341
10028
|
if (!updated)
|
|
9342
10029
|
return;
|
|
9343
|
-
|
|
9344
|
-
clearTimeout(idleTimer);
|
|
9345
|
-
idleTimer = setTimeout(() => {
|
|
9346
|
-
cleanup();
|
|
9347
|
-
resolve4(results);
|
|
9348
|
-
}, 150);
|
|
9349
|
-
if (idleTimer)
|
|
9350
|
-
this.activeTimers.push(idleTimer);
|
|
9351
|
-
};
|
|
9352
|
-
const onTimeout = () => {
|
|
9353
|
-
cleanup();
|
|
9354
|
-
resolve4(results);
|
|
10030
|
+
idleTimer = session.resetTimer(idleTimer, finish, 150);
|
|
9355
10031
|
};
|
|
9356
|
-
|
|
9357
|
-
|
|
9358
|
-
if (idleTimer)
|
|
9359
|
-
clearTimeout(idleTimer);
|
|
9360
|
-
inp.removeListener("data", onData);
|
|
9361
|
-
const listenerIdx = this.activeListeners.findIndex((l) => l.handler === onData);
|
|
9362
|
-
if (listenerIdx !== -1)
|
|
9363
|
-
this.activeListeners.splice(listenerIdx, 1);
|
|
9364
|
-
const timerIdx = this.activeTimers.indexOf(timer);
|
|
9365
|
-
if (timerIdx !== -1)
|
|
9366
|
-
this.activeTimers.splice(timerIdx, 1);
|
|
9367
|
-
if (idleTimer) {
|
|
9368
|
-
const idleTimerIdx = this.activeTimers.indexOf(idleTimer);
|
|
9369
|
-
if (idleTimerIdx !== -1)
|
|
9370
|
-
this.activeTimers.splice(idleTimerIdx, 1);
|
|
9371
|
-
}
|
|
9372
|
-
};
|
|
9373
|
-
const timer = setTimeout(onTimeout, timeoutMs);
|
|
9374
|
-
this.activeTimers.push(timer);
|
|
9375
|
-
inp.on("data", onData);
|
|
9376
|
-
this.activeListeners.push({ event: "data", handler: onData });
|
|
10032
|
+
session.setTimer(finish, timeoutMs);
|
|
10033
|
+
session.subscribeInput(onData);
|
|
9377
10034
|
this.writeOsc([
|
|
9378
10035
|
"\x1B]10;?\x07",
|
|
9379
10036
|
"\x1B]11;?\x07",
|
|
@@ -9423,8 +10080,17 @@ class TerminalPalette {
|
|
|
9423
10080
|
};
|
|
9424
10081
|
}
|
|
9425
10082
|
}
|
|
9426
|
-
function createTerminalPalette(stdin, stdout, writeFn, isLegacyTmux) {
|
|
9427
|
-
return new TerminalPalette(stdin, stdout, writeFn, isLegacyTmux);
|
|
10083
|
+
function createTerminalPalette(stdin, stdout, writeFn, isLegacyTmux, oscSource, clock) {
|
|
10084
|
+
return new TerminalPalette(stdin, stdout, writeFn, isLegacyTmux, oscSource, clock);
|
|
10085
|
+
}
|
|
10086
|
+
|
|
10087
|
+
// src/lib/paste.ts
|
|
10088
|
+
var PASTE_TEXT_DECODER = new TextDecoder;
|
|
10089
|
+
function decodePasteBytes(bytes) {
|
|
10090
|
+
return PASTE_TEXT_DECODER.decode(bytes);
|
|
10091
|
+
}
|
|
10092
|
+
function stripAnsiSequences(text) {
|
|
10093
|
+
return Bun.stripANSI(text);
|
|
9428
10094
|
}
|
|
9429
10095
|
|
|
9430
10096
|
// src/lib/detect-links.ts
|
|
@@ -9470,8 +10136,8 @@ function detectLinks(chunks, context) {
|
|
|
9470
10136
|
}
|
|
9471
10137
|
// src/zig.ts
|
|
9472
10138
|
import { dlopen, toArrayBuffer as toArrayBuffer4, JSCallback, ptr as ptr4 } from "bun:ffi";
|
|
9473
|
-
import { existsSync as existsSync2 } from "fs";
|
|
9474
|
-
import { EventEmitter as
|
|
10139
|
+
import { existsSync as existsSync2, writeFileSync } from "fs";
|
|
10140
|
+
import { EventEmitter as EventEmitter4 } from "events";
|
|
9475
10141
|
|
|
9476
10142
|
// src/buffer.ts
|
|
9477
10143
|
import { toArrayBuffer, ptr } from "bun:ffi";
|
|
@@ -10463,19 +11129,19 @@ var EncodedCharStruct = defineStruct([
|
|
|
10463
11129
|
["char", "u32"]
|
|
10464
11130
|
]);
|
|
10465
11131
|
var LineInfoStruct = defineStruct([
|
|
10466
|
-
["
|
|
10467
|
-
["
|
|
10468
|
-
["
|
|
10469
|
-
["
|
|
11132
|
+
["startCols", ["u32"]],
|
|
11133
|
+
["startColsLen", "u32", { lengthOf: "startCols" }],
|
|
11134
|
+
["widthCols", ["u32"]],
|
|
11135
|
+
["widthColsLen", "u32", { lengthOf: "widthCols" }],
|
|
10470
11136
|
["sources", ["u32"]],
|
|
10471
11137
|
["sourcesLen", "u32", { lengthOf: "sources" }],
|
|
10472
11138
|
["wraps", ["u32"]],
|
|
10473
11139
|
["wrapsLen", "u32", { lengthOf: "wraps" }],
|
|
10474
|
-
["
|
|
11140
|
+
["widthColsMax", "u32"]
|
|
10475
11141
|
]);
|
|
10476
11142
|
var MeasureResultStruct = defineStruct([
|
|
10477
11143
|
["lineCount", "u32"],
|
|
10478
|
-
["
|
|
11144
|
+
["widthColsMax", "u32"]
|
|
10479
11145
|
]);
|
|
10480
11146
|
var CursorStateStruct = defineStruct([
|
|
10481
11147
|
["x", "u32"],
|
|
@@ -10602,11 +11268,11 @@ registerEnvVar({
|
|
|
10602
11268
|
type: "boolean",
|
|
10603
11269
|
default: false
|
|
10604
11270
|
});
|
|
10605
|
-
var CURSOR_STYLE_TO_ID = { block: 0, line: 1, underline: 2 };
|
|
10606
|
-
var CURSOR_ID_TO_STYLE = ["block", "line", "underline"];
|
|
11271
|
+
var CURSOR_STYLE_TO_ID = { block: 0, line: 1, underline: 2, default: 3 };
|
|
11272
|
+
var CURSOR_ID_TO_STYLE = ["block", "line", "underline", "default"];
|
|
10607
11273
|
var MOUSE_STYLE_TO_ID = { default: 0, pointer: 1, text: 2, crosshair: 3, move: 4, "not-allowed": 5 };
|
|
10608
11274
|
var globalTraceSymbols = null;
|
|
10609
|
-
var
|
|
11275
|
+
var globalFFILogPath = null;
|
|
10610
11276
|
var exitHandlerRegistered = false;
|
|
10611
11277
|
function toPointer(value) {
|
|
10612
11278
|
if (typeof value === "bigint") {
|
|
@@ -11595,24 +12261,21 @@ function convertToDebugSymbols(symbols) {
|
|
|
11595
12261
|
if (!globalTraceSymbols) {
|
|
11596
12262
|
globalTraceSymbols = {};
|
|
11597
12263
|
}
|
|
11598
|
-
if (env.OTUI_DEBUG_FFI && !
|
|
12264
|
+
if (env.OTUI_DEBUG_FFI && !globalFFILogPath) {
|
|
11599
12265
|
const now = new Date;
|
|
11600
12266
|
const timestamp = now.toISOString().replace(/[:.]/g, "-").replace(/T/, "_").split("Z")[0];
|
|
11601
|
-
|
|
11602
|
-
globalFFILogWriter = Bun.file(logFilePath).writer();
|
|
12267
|
+
globalFFILogPath = `ffi_otui_debug_${timestamp}.log`;
|
|
11603
12268
|
}
|
|
11604
12269
|
const debugSymbols = {};
|
|
11605
12270
|
let hasTracing = false;
|
|
11606
12271
|
Object.entries(symbols).forEach(([key, value]) => {
|
|
11607
12272
|
debugSymbols[key] = value;
|
|
11608
12273
|
});
|
|
11609
|
-
if (env.OTUI_DEBUG_FFI &&
|
|
11610
|
-
const
|
|
12274
|
+
if (env.OTUI_DEBUG_FFI && globalFFILogPath) {
|
|
12275
|
+
const logPath = globalFFILogPath;
|
|
11611
12276
|
const writeSync = (msg) => {
|
|
11612
|
-
|
|
11613
|
-
|
|
11614
|
-
writer.write(buffer);
|
|
11615
|
-
writer.flush();
|
|
12277
|
+
writeFileSync(logPath, msg + `
|
|
12278
|
+
`, { flag: "a" });
|
|
11616
12279
|
};
|
|
11617
12280
|
Object.entries(symbols).forEach(([key, value]) => {
|
|
11618
12281
|
if (typeof value === "function") {
|
|
@@ -11646,11 +12309,6 @@ function convertToDebugSymbols(symbols) {
|
|
|
11646
12309
|
if ((env.OTUI_DEBUG_FFI || env.OTUI_TRACE_FFI) && !exitHandlerRegistered) {
|
|
11647
12310
|
exitHandlerRegistered = true;
|
|
11648
12311
|
process.on("exit", () => {
|
|
11649
|
-
try {
|
|
11650
|
-
if (globalFFILogWriter) {
|
|
11651
|
-
globalFFILogWriter.end();
|
|
11652
|
-
}
|
|
11653
|
-
} catch (e) {}
|
|
11654
12312
|
if (globalTraceSymbols) {
|
|
11655
12313
|
const allStats = [];
|
|
11656
12314
|
for (const [key, timings] of Object.entries(globalTraceSymbols)) {
|
|
@@ -11703,15 +12361,15 @@ function convertToDebugSymbols(symbols) {
|
|
|
11703
12361
|
const countWidth = Math.max(callsHeader.length, ...allStats.map((s) => String(s.count).length));
|
|
11704
12362
|
const totalWidth = Math.max(totalHeader.length, ...allStats.map((s) => s.total.toFixed(2).length));
|
|
11705
12363
|
const avgWidth = Math.max(avgHeader.length, ...allStats.map((s) => s.average.toFixed(2).length));
|
|
11706
|
-
const
|
|
11707
|
-
const
|
|
12364
|
+
const statWidthMin = Math.max(minHeader.length, ...allStats.map((s) => s.min.toFixed(2).length));
|
|
12365
|
+
const statWidthMax = Math.max(maxHeader.length, ...allStats.map((s) => s.max.toFixed(2).length));
|
|
11708
12366
|
const medianWidth = Math.max(medHeader.length, ...allStats.map((s) => s.median.toFixed(2).length));
|
|
11709
12367
|
const p90Width = Math.max(p90Header.length, ...allStats.map((s) => s.p90.toFixed(2).length));
|
|
11710
12368
|
const p99Width = Math.max(p99Header.length, ...allStats.map((s) => s.p99.toFixed(2).length));
|
|
11711
|
-
lines.push(`${nameHeader.padEnd(nameWidth)} | ${callsHeader.padStart(countWidth)} | ${totalHeader.padStart(totalWidth)} | ${avgHeader.padStart(avgWidth)} | ${minHeader.padStart(
|
|
11712
|
-
lines.push(`${"-".repeat(nameWidth)}-+-${"-".repeat(countWidth)}-+-${"-".repeat(totalWidth)}-+-${"-".repeat(avgWidth)}-+-${"-".repeat(
|
|
12369
|
+
lines.push(`${nameHeader.padEnd(nameWidth)} | ${callsHeader.padStart(countWidth)} | ${totalHeader.padStart(totalWidth)} | ${avgHeader.padStart(avgWidth)} | ${minHeader.padStart(statWidthMin)} | ${maxHeader.padStart(statWidthMax)} | ${medHeader.padStart(medianWidth)} | ${p90Header.padStart(p90Width)} | ${p99Header.padStart(p99Width)}`);
|
|
12370
|
+
lines.push(`${"-".repeat(nameWidth)}-+-${"-".repeat(countWidth)}-+-${"-".repeat(totalWidth)}-+-${"-".repeat(avgWidth)}-+-${"-".repeat(statWidthMin)}-+-${"-".repeat(statWidthMax)}-+-${"-".repeat(medianWidth)}-+-${"-".repeat(p90Width)}-+-${"-".repeat(p99Width)}`);
|
|
11713
12371
|
allStats.forEach((stat) => {
|
|
11714
|
-
lines.push(`${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(
|
|
12372
|
+
lines.push(`${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(statWidthMin)} | ${stat.max.toFixed(2).padStart(statWidthMax)} | ${stat.median.toFixed(2).padStart(medianWidth)} | ${stat.p90.toFixed(2).padStart(p90Width)} | ${stat.p99.toFixed(2).padStart(p99Width)}`);
|
|
11715
12373
|
});
|
|
11716
12374
|
}
|
|
11717
12375
|
lines.push("-------------------------------------------------------------------------------------------------------------------------");
|
|
@@ -11745,7 +12403,7 @@ class FFIRenderLib {
|
|
|
11745
12403
|
decoder = new TextDecoder;
|
|
11746
12404
|
logCallbackWrapper;
|
|
11747
12405
|
eventCallbackWrapper;
|
|
11748
|
-
_nativeEvents = new
|
|
12406
|
+
_nativeEvents = new EventEmitter4;
|
|
11749
12407
|
_anyEventHandlers = [];
|
|
11750
12408
|
nativeSpanFeedCallbackWrapper = null;
|
|
11751
12409
|
nativeSpanFeedHandlers = new Map;
|
|
@@ -12351,10 +13009,13 @@ class FFIRenderLib {
|
|
|
12351
13009
|
const outBuffer = new ArrayBuffer(LineInfoStruct.size);
|
|
12352
13010
|
this.textBufferViewGetLineInfoDirect(view, ptr4(outBuffer));
|
|
12353
13011
|
const struct = LineInfoStruct.unpack(outBuffer);
|
|
13012
|
+
const lineStartCols = struct.startCols;
|
|
13013
|
+
const lineWidthCols = struct.widthCols;
|
|
13014
|
+
const lineWidthColsMax = struct.widthColsMax;
|
|
12354
13015
|
return {
|
|
12355
|
-
|
|
12356
|
-
|
|
12357
|
-
|
|
13016
|
+
lineStartCols,
|
|
13017
|
+
lineWidthCols,
|
|
13018
|
+
lineWidthColsMax,
|
|
12358
13019
|
lineSources: struct.sources,
|
|
12359
13020
|
lineWraps: struct.wraps
|
|
12360
13021
|
};
|
|
@@ -12363,10 +13024,13 @@ class FFIRenderLib {
|
|
|
12363
13024
|
const outBuffer = new ArrayBuffer(LineInfoStruct.size);
|
|
12364
13025
|
this.textBufferViewGetLogicalLineInfoDirect(view, ptr4(outBuffer));
|
|
12365
13026
|
const struct = LineInfoStruct.unpack(outBuffer);
|
|
13027
|
+
const lineStartCols = struct.startCols;
|
|
13028
|
+
const lineWidthCols = struct.widthCols;
|
|
13029
|
+
const lineWidthColsMax = struct.widthColsMax;
|
|
12366
13030
|
return {
|
|
12367
|
-
|
|
12368
|
-
|
|
12369
|
-
|
|
13031
|
+
lineStartCols,
|
|
13032
|
+
lineWidthCols,
|
|
13033
|
+
lineWidthColsMax,
|
|
12370
13034
|
lineSources: struct.sources,
|
|
12371
13035
|
lineWraps: struct.wraps
|
|
12372
13036
|
};
|
|
@@ -12542,10 +13206,13 @@ class FFIRenderLib {
|
|
|
12542
13206
|
const outBuffer = new ArrayBuffer(LineInfoStruct.size);
|
|
12543
13207
|
this.opentui.symbols.editorViewGetLineInfoDirect(view, ptr4(outBuffer));
|
|
12544
13208
|
const struct = LineInfoStruct.unpack(outBuffer);
|
|
13209
|
+
const lineStartCols = struct.startCols;
|
|
13210
|
+
const lineWidthCols = struct.widthCols;
|
|
13211
|
+
const lineWidthColsMax = struct.widthColsMax;
|
|
12545
13212
|
return {
|
|
12546
|
-
|
|
12547
|
-
|
|
12548
|
-
|
|
13213
|
+
lineStartCols,
|
|
13214
|
+
lineWidthCols,
|
|
13215
|
+
lineWidthColsMax,
|
|
12549
13216
|
lineSources: struct.sources,
|
|
12550
13217
|
lineWraps: struct.wraps
|
|
12551
13218
|
};
|
|
@@ -12554,10 +13221,13 @@ class FFIRenderLib {
|
|
|
12554
13221
|
const outBuffer = new ArrayBuffer(LineInfoStruct.size);
|
|
12555
13222
|
this.opentui.symbols.editorViewGetLogicalLineInfoDirect(view, ptr4(outBuffer));
|
|
12556
13223
|
const struct = LineInfoStruct.unpack(outBuffer);
|
|
13224
|
+
const lineStartCols = struct.startCols;
|
|
13225
|
+
const lineWidthCols = struct.widthCols;
|
|
13226
|
+
const lineWidthColsMax = struct.widthColsMax;
|
|
12557
13227
|
return {
|
|
12558
|
-
|
|
12559
|
-
|
|
12560
|
-
|
|
13228
|
+
lineStartCols,
|
|
13229
|
+
lineWidthCols,
|
|
13230
|
+
lineWidthColsMax,
|
|
12561
13231
|
lineSources: struct.sources,
|
|
12562
13232
|
lineWraps: struct.wraps
|
|
12563
13233
|
};
|
|
@@ -13240,7 +13910,7 @@ class TextBuffer {
|
|
|
13240
13910
|
}
|
|
13241
13911
|
|
|
13242
13912
|
// src/Renderable.ts
|
|
13243
|
-
import { EventEmitter as
|
|
13913
|
+
import { EventEmitter as EventEmitter5 } from "events";
|
|
13244
13914
|
|
|
13245
13915
|
// src/lib/renderable.validations.ts
|
|
13246
13916
|
function validateOptions(id, options) {
|
|
@@ -13333,7 +14003,7 @@ function isRenderable(obj) {
|
|
|
13333
14003
|
return !!obj?.[BrandedRenderable];
|
|
13334
14004
|
}
|
|
13335
14005
|
|
|
13336
|
-
class BaseRenderable extends
|
|
14006
|
+
class BaseRenderable extends EventEmitter5 {
|
|
13337
14007
|
[BrandedRenderable] = true;
|
|
13338
14008
|
static renderableNumber = 1;
|
|
13339
14009
|
_id;
|
|
@@ -14715,7 +15385,7 @@ function delegate(mapping, vnode) {
|
|
|
14715
15385
|
}
|
|
14716
15386
|
|
|
14717
15387
|
// src/console.ts
|
|
14718
|
-
import { EventEmitter as
|
|
15388
|
+
import { EventEmitter as EventEmitter7 } from "events";
|
|
14719
15389
|
import { Console } from "console";
|
|
14720
15390
|
import fs from "fs";
|
|
14721
15391
|
import path4 from "path";
|
|
@@ -14723,9 +15393,9 @@ import util2 from "util";
|
|
|
14723
15393
|
|
|
14724
15394
|
// src/lib/output.capture.ts
|
|
14725
15395
|
import { Writable } from "stream";
|
|
14726
|
-
import { EventEmitter as
|
|
15396
|
+
import { EventEmitter as EventEmitter6 } from "events";
|
|
14727
15397
|
|
|
14728
|
-
class Capture extends
|
|
15398
|
+
class Capture extends EventEmitter6 {
|
|
14729
15399
|
output = [];
|
|
14730
15400
|
constructor() {
|
|
14731
15401
|
super();
|
|
@@ -14854,7 +15524,7 @@ registerEnvVar({
|
|
|
14854
15524
|
default: false
|
|
14855
15525
|
});
|
|
14856
15526
|
|
|
14857
|
-
class TerminalConsoleCache extends
|
|
15527
|
+
class TerminalConsoleCache extends EventEmitter7 {
|
|
14858
15528
|
_cachedLogs = [];
|
|
14859
15529
|
MAX_CACHE_SIZE = 1000;
|
|
14860
15530
|
_collectCallerInfo = false;
|
|
@@ -14998,7 +15668,7 @@ var DEFAULT_CONSOLE_OPTIONS = {
|
|
|
14998
15668
|
};
|
|
14999
15669
|
var INDENT_WIDTH = 2;
|
|
15000
15670
|
|
|
15001
|
-
class TerminalConsole extends
|
|
15671
|
+
class TerminalConsole extends EventEmitter7 {
|
|
15002
15672
|
isVisible = false;
|
|
15003
15673
|
isFocused = false;
|
|
15004
15674
|
renderer;
|
|
@@ -15027,6 +15697,7 @@ class TerminalConsole extends EventEmitter8 {
|
|
|
15027
15697
|
height: 0
|
|
15028
15698
|
};
|
|
15029
15699
|
_autoScrollInterval = null;
|
|
15700
|
+
clock;
|
|
15030
15701
|
_keyBindingsMap;
|
|
15031
15702
|
_keyAliasMap;
|
|
15032
15703
|
_keyBindings;
|
|
@@ -15066,6 +15737,7 @@ class TerminalConsole extends EventEmitter8 {
|
|
|
15066
15737
|
constructor(renderer, options = {}) {
|
|
15067
15738
|
super();
|
|
15068
15739
|
this.renderer = renderer;
|
|
15740
|
+
this.clock = options.clock ?? new SystemClock;
|
|
15069
15741
|
this.options = { ...DEFAULT_CONSOLE_OPTIONS, ...options };
|
|
15070
15742
|
this.keyHandler = this.handleKeyPress.bind(this);
|
|
15071
15743
|
this._debugModeEnabled = this.options.startInDebugMode;
|
|
@@ -15621,13 +16293,13 @@ class TerminalConsole extends EventEmitter8 {
|
|
|
15621
16293
|
}
|
|
15622
16294
|
stopAutoScroll() {
|
|
15623
16295
|
if (this._autoScrollInterval !== null) {
|
|
15624
|
-
clearInterval(this._autoScrollInterval);
|
|
16296
|
+
this.clock.clearInterval(this._autoScrollInterval);
|
|
15625
16297
|
this._autoScrollInterval = null;
|
|
15626
16298
|
}
|
|
15627
16299
|
}
|
|
15628
16300
|
startAutoScroll(direction) {
|
|
15629
16301
|
this.stopAutoScroll();
|
|
15630
|
-
this._autoScrollInterval = setInterval(() => {
|
|
16302
|
+
this._autoScrollInterval = this.clock.setInterval(() => {
|
|
15631
16303
|
if (direction === "up") {
|
|
15632
16304
|
if (this.scrollTopIndex > 0) {
|
|
15633
16305
|
this.scrollTopIndex--;
|
|
@@ -15841,7 +16513,7 @@ class Clipboard {
|
|
|
15841
16513
|
}
|
|
15842
16514
|
|
|
15843
16515
|
// src/renderer.ts
|
|
15844
|
-
import { EventEmitter as
|
|
16516
|
+
import { EventEmitter as EventEmitter8 } from "events";
|
|
15845
16517
|
|
|
15846
16518
|
// src/lib/objects-in-viewport.ts
|
|
15847
16519
|
function getObjectsInViewport(viewport, objects, direction = "column", padding = 10, minTriggerSize = 16) {
|
|
@@ -16036,6 +16708,7 @@ var KITTY_FLAG_EVENT_TYPES = 2;
|
|
|
16036
16708
|
var KITTY_FLAG_ALTERNATE_KEYS = 4;
|
|
16037
16709
|
var KITTY_FLAG_ALL_KEYS_AS_ESCAPES = 8;
|
|
16038
16710
|
var KITTY_FLAG_REPORT_TEXT = 16;
|
|
16711
|
+
var DEFAULT_STDIN_PARSER_MAX_BUFFER_BYTES = 64 * 1024 * 1024;
|
|
16039
16712
|
function buildKittyKeyboardFlags(config) {
|
|
16040
16713
|
if (!config) {
|
|
16041
16714
|
return 0;
|
|
@@ -16169,7 +16842,7 @@ var RendererControlState;
|
|
|
16169
16842
|
RendererControlState2["EXPLICIT_STOPPED"] = "explicit_stopped";
|
|
16170
16843
|
})(RendererControlState ||= {});
|
|
16171
16844
|
|
|
16172
|
-
class CliRenderer extends
|
|
16845
|
+
class CliRenderer extends EventEmitter8 {
|
|
16173
16846
|
static animationFrameId = 0;
|
|
16174
16847
|
lib;
|
|
16175
16848
|
rendererPtr;
|
|
@@ -16204,6 +16877,7 @@ class CliRenderer extends EventEmitter9 {
|
|
|
16204
16877
|
postProcessFns = [];
|
|
16205
16878
|
backgroundColor = RGBA.fromInts(0, 0, 0, 0);
|
|
16206
16879
|
waitingForPixelResolution = false;
|
|
16880
|
+
clock;
|
|
16207
16881
|
rendering = false;
|
|
16208
16882
|
renderingNative = false;
|
|
16209
16883
|
renderTimeout = null;
|
|
@@ -16231,7 +16905,9 @@ class CliRenderer extends EventEmitter9 {
|
|
|
16231
16905
|
_console;
|
|
16232
16906
|
_resolution = null;
|
|
16233
16907
|
_keyHandler;
|
|
16234
|
-
|
|
16908
|
+
stdinParser = null;
|
|
16909
|
+
oscSubscribers = new Set;
|
|
16910
|
+
hasLoggedStdinParserError = false;
|
|
16235
16911
|
animationRequest = new Map;
|
|
16236
16912
|
resizeTimeoutId = null;
|
|
16237
16913
|
capabilityTimeoutId = null;
|
|
@@ -16260,7 +16936,6 @@ class CliRenderer extends EventEmitter9 {
|
|
|
16260
16936
|
}
|
|
16261
16937
|
};
|
|
16262
16938
|
_useConsole = true;
|
|
16263
|
-
mouseParser = new MouseParser;
|
|
16264
16939
|
sigwinchHandler = (() => {
|
|
16265
16940
|
const width = this.stdout.columns || 80;
|
|
16266
16941
|
const height = this.stdout.rows || 24;
|
|
@@ -16279,7 +16954,7 @@ class CliRenderer extends EventEmitter9 {
|
|
|
16279
16954
|
_paletteDetectionPromise = null;
|
|
16280
16955
|
_onDestroy;
|
|
16281
16956
|
_themeMode = null;
|
|
16282
|
-
|
|
16957
|
+
sequenceHandlers = [];
|
|
16283
16958
|
prependedInputHandlers = [];
|
|
16284
16959
|
shouldRestoreModesOnNextFocus = false;
|
|
16285
16960
|
idleResolvers = [];
|
|
@@ -16396,7 +17071,7 @@ Captured output:
|
|
|
16396
17071
|
process.on("beforeExit", this.exitHandler);
|
|
16397
17072
|
const kittyConfig = config.useKittyKeyboard ?? {};
|
|
16398
17073
|
const useKittyForParsing = kittyConfig !== null;
|
|
16399
|
-
this._keyHandler = new InternalKeyHandler
|
|
17074
|
+
this._keyHandler = new InternalKeyHandler;
|
|
16400
17075
|
this._keyHandler.on("keypress", (event) => {
|
|
16401
17076
|
if (this.exitOnCtrlC && event.name === "c" && event.ctrl) {
|
|
16402
17077
|
process.nextTick(() => {
|
|
@@ -16406,8 +17081,22 @@ Captured output:
|
|
|
16406
17081
|
}
|
|
16407
17082
|
});
|
|
16408
17083
|
this.addExitListeners();
|
|
16409
|
-
this.
|
|
16410
|
-
|
|
17084
|
+
this.clock = config.clock ?? new SystemClock;
|
|
17085
|
+
const stdinParserMaxBufferBytes = config.stdinParserMaxBufferBytes ?? DEFAULT_STDIN_PARSER_MAX_BUFFER_BYTES;
|
|
17086
|
+
this.stdinParser = new StdinParser({
|
|
17087
|
+
timeoutMs: 10,
|
|
17088
|
+
maxPendingBytes: stdinParserMaxBufferBytes,
|
|
17089
|
+
armTimeouts: true,
|
|
17090
|
+
onTimeoutFlush: () => {
|
|
17091
|
+
this.drainStdinParser();
|
|
17092
|
+
},
|
|
17093
|
+
useKittyKeyboard: useKittyForParsing,
|
|
17094
|
+
clock: this.clock
|
|
17095
|
+
});
|
|
17096
|
+
this._console = new TerminalConsole(this, {
|
|
17097
|
+
...config.consoleOptions ?? {},
|
|
17098
|
+
clock: this.clock
|
|
17099
|
+
});
|
|
16411
17100
|
this.useConsole = config.useConsole ?? true;
|
|
16412
17101
|
this._openConsoleOnError = config.openConsoleOnError ?? true;
|
|
16413
17102
|
this._onDestroy = config.onDestroy;
|
|
@@ -16521,14 +17210,14 @@ Captured output:
|
|
|
16521
17210
|
}
|
|
16522
17211
|
if (!this.updateScheduled && !this.renderTimeout) {
|
|
16523
17212
|
this.updateScheduled = true;
|
|
16524
|
-
const now =
|
|
17213
|
+
const now = this.clock.now();
|
|
16525
17214
|
const elapsed = now - this.lastTime;
|
|
16526
17215
|
const delay = Math.max(this.minTargetFrameTime - elapsed, 0);
|
|
16527
17216
|
if (delay === 0) {
|
|
16528
17217
|
process.nextTick(() => this.activateFrame());
|
|
16529
17218
|
return;
|
|
16530
17219
|
}
|
|
16531
|
-
setTimeout(() => this.activateFrame(), delay);
|
|
17220
|
+
this.clock.setTimeout(() => this.activateFrame(), delay);
|
|
16532
17221
|
}
|
|
16533
17222
|
}
|
|
16534
17223
|
async activateFrame() {
|
|
@@ -16714,7 +17403,7 @@ Captured output:
|
|
|
16714
17403
|
disableMouse() {
|
|
16715
17404
|
this._useMouse = false;
|
|
16716
17405
|
this.setCapturedRenderable(undefined);
|
|
16717
|
-
this.
|
|
17406
|
+
this.stdinParser?.resetMouseState();
|
|
16718
17407
|
this.lib.disableMouse(this.rendererPtr);
|
|
16719
17408
|
}
|
|
16720
17409
|
enableKittyKeyboard(flags = 3) {
|
|
@@ -16741,7 +17430,7 @@ Captured output:
|
|
|
16741
17430
|
this.automaticMemorySnapshot = true;
|
|
16742
17431
|
}
|
|
16743
17432
|
}
|
|
16744
|
-
this.capabilityTimeoutId = setTimeout(() => {
|
|
17433
|
+
this.capabilityTimeoutId = this.clock.setTimeout(() => {
|
|
16745
17434
|
this.capabilityTimeoutId = null;
|
|
16746
17435
|
this.removeInputHandler(this.capabilityHandler);
|
|
16747
17436
|
}, 5000);
|
|
@@ -16750,20 +17439,31 @@ Captured output:
|
|
|
16750
17439
|
}
|
|
16751
17440
|
this.queryPixelResolution();
|
|
16752
17441
|
}
|
|
16753
|
-
stdinListener = ((
|
|
16754
|
-
|
|
17442
|
+
stdinListener = ((chunk) => {
|
|
17443
|
+
const data = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
17444
|
+
if (!this.stdinParser)
|
|
16755
17445
|
return;
|
|
17446
|
+
try {
|
|
17447
|
+
this.stdinParser.push(data);
|
|
17448
|
+
this.drainStdinParser();
|
|
17449
|
+
} catch (error) {
|
|
17450
|
+
this.handleStdinParserFailure(error);
|
|
16756
17451
|
}
|
|
16757
|
-
this._stdinBuffer.process(data);
|
|
16758
17452
|
}).bind(this);
|
|
16759
17453
|
addInputHandler(handler) {
|
|
16760
|
-
this.
|
|
17454
|
+
this.sequenceHandlers.push(handler);
|
|
16761
17455
|
}
|
|
16762
17456
|
prependInputHandler(handler) {
|
|
16763
|
-
this.
|
|
17457
|
+
this.sequenceHandlers.unshift(handler);
|
|
16764
17458
|
}
|
|
16765
17459
|
removeInputHandler(handler) {
|
|
16766
|
-
this.
|
|
17460
|
+
this.sequenceHandlers = this.sequenceHandlers.filter((candidate) => candidate !== handler);
|
|
17461
|
+
}
|
|
17462
|
+
subscribeOsc(handler) {
|
|
17463
|
+
this.oscSubscribers.add(handler);
|
|
17464
|
+
return () => {
|
|
17465
|
+
this.oscSubscribers.delete(handler);
|
|
17466
|
+
};
|
|
16767
17467
|
}
|
|
16768
17468
|
capabilityHandler = ((sequence) => {
|
|
16769
17469
|
if (isCapabilityResponse(sequence)) {
|
|
@@ -16807,6 +17507,67 @@ Captured output:
|
|
|
16807
17507
|
}
|
|
16808
17508
|
return false;
|
|
16809
17509
|
}).bind(this);
|
|
17510
|
+
dispatchSequenceHandlers(sequence) {
|
|
17511
|
+
if (this._debugModeEnabled) {
|
|
17512
|
+
this._debugInputs.push({
|
|
17513
|
+
timestamp: new Date().toISOString(),
|
|
17514
|
+
sequence
|
|
17515
|
+
});
|
|
17516
|
+
}
|
|
17517
|
+
for (const handler of this.sequenceHandlers) {
|
|
17518
|
+
if (handler(sequence)) {
|
|
17519
|
+
return true;
|
|
17520
|
+
}
|
|
17521
|
+
}
|
|
17522
|
+
return false;
|
|
17523
|
+
}
|
|
17524
|
+
drainStdinParser() {
|
|
17525
|
+
if (!this.stdinParser)
|
|
17526
|
+
return;
|
|
17527
|
+
this.stdinParser.drain((event) => {
|
|
17528
|
+
this.handleStdinEvent(event);
|
|
17529
|
+
});
|
|
17530
|
+
}
|
|
17531
|
+
handleStdinEvent(event) {
|
|
17532
|
+
switch (event.type) {
|
|
17533
|
+
case "key":
|
|
17534
|
+
if (this.dispatchSequenceHandlers(event.raw)) {
|
|
17535
|
+
return;
|
|
17536
|
+
}
|
|
17537
|
+
this._keyHandler.processParsedKey(event.key);
|
|
17538
|
+
return;
|
|
17539
|
+
case "mouse":
|
|
17540
|
+
if (this._useMouse && this.processSingleMouseEvent(event.event)) {
|
|
17541
|
+
return;
|
|
17542
|
+
}
|
|
17543
|
+
this.dispatchSequenceHandlers(event.raw);
|
|
17544
|
+
return;
|
|
17545
|
+
case "paste":
|
|
17546
|
+
this._keyHandler.processPaste(event.bytes, event.metadata);
|
|
17547
|
+
return;
|
|
17548
|
+
case "response":
|
|
17549
|
+
if (event.protocol === "osc") {
|
|
17550
|
+
for (const subscriber of this.oscSubscribers) {
|
|
17551
|
+
subscriber(event.sequence);
|
|
17552
|
+
}
|
|
17553
|
+
}
|
|
17554
|
+
this.dispatchSequenceHandlers(event.sequence);
|
|
17555
|
+
return;
|
|
17556
|
+
}
|
|
17557
|
+
}
|
|
17558
|
+
handleStdinParserFailure(error) {
|
|
17559
|
+
if (!this.hasLoggedStdinParserError) {
|
|
17560
|
+
this.hasLoggedStdinParserError = true;
|
|
17561
|
+
if (true) {
|
|
17562
|
+
console.error("[stdin-parser-error] parser failure, resetting parser", error);
|
|
17563
|
+
}
|
|
17564
|
+
}
|
|
17565
|
+
try {
|
|
17566
|
+
this.stdinParser?.reset();
|
|
17567
|
+
} catch (resetError) {
|
|
17568
|
+
console.error("stdin parser reset failed after parser error", resetError);
|
|
17569
|
+
}
|
|
17570
|
+
}
|
|
16810
17571
|
setupInput() {
|
|
16811
17572
|
for (const handler of this.prependedInputHandlers) {
|
|
16812
17573
|
this.addInputHandler(handler);
|
|
@@ -16825,31 +17586,11 @@ Captured output:
|
|
|
16825
17586
|
this.addInputHandler(this.capabilityHandler);
|
|
16826
17587
|
this.addInputHandler(this.focusHandler);
|
|
16827
17588
|
this.addInputHandler(this.themeModeHandler);
|
|
16828
|
-
this.addInputHandler((sequence) => {
|
|
16829
|
-
return this._keyHandler.processInput(sequence);
|
|
16830
|
-
});
|
|
16831
17589
|
if (this.stdin.setRawMode) {
|
|
16832
17590
|
this.stdin.setRawMode(true);
|
|
16833
17591
|
}
|
|
16834
17592
|
this.stdin.resume();
|
|
16835
|
-
this.stdin.setEncoding("utf8");
|
|
16836
17593
|
this.stdin.on("data", this.stdinListener);
|
|
16837
|
-
this._stdinBuffer.on("data", (sequence) => {
|
|
16838
|
-
if (this._debugModeEnabled) {
|
|
16839
|
-
this._debugInputs.push({
|
|
16840
|
-
timestamp: new Date().toISOString(),
|
|
16841
|
-
sequence
|
|
16842
|
-
});
|
|
16843
|
-
}
|
|
16844
|
-
for (const handler of this.inputHandlers) {
|
|
16845
|
-
if (handler(sequence)) {
|
|
16846
|
-
return;
|
|
16847
|
-
}
|
|
16848
|
-
}
|
|
16849
|
-
});
|
|
16850
|
-
this._stdinBuffer.on("paste", (data) => {
|
|
16851
|
-
this._keyHandler.processPaste(data);
|
|
16852
|
-
});
|
|
16853
17594
|
}
|
|
16854
17595
|
dispatchMouseEvent(target, attributes) {
|
|
16855
17596
|
const event = new MouseEvent(target, attributes);
|
|
@@ -16866,18 +17607,6 @@ Captured output:
|
|
|
16866
17607
|
}
|
|
16867
17608
|
return event;
|
|
16868
17609
|
}
|
|
16869
|
-
handleMouseData(data) {
|
|
16870
|
-
const mouseEvents = this.mouseParser.parseAllMouseEvents(data);
|
|
16871
|
-
if (mouseEvents.length === 0)
|
|
16872
|
-
return false;
|
|
16873
|
-
let anyHandled = false;
|
|
16874
|
-
for (const mouseEvent of mouseEvents) {
|
|
16875
|
-
if (this.processSingleMouseEvent(mouseEvent)) {
|
|
16876
|
-
anyHandled = true;
|
|
16877
|
-
}
|
|
16878
|
-
}
|
|
16879
|
-
return anyHandled;
|
|
16880
|
-
}
|
|
16881
17610
|
processSingleMouseEvent(mouseEvent) {
|
|
16882
17611
|
if (this._splitHeight > 0) {
|
|
16883
17612
|
if (mouseEvent.y < this.renderOffset) {
|
|
@@ -17052,13 +17781,13 @@ Captured output:
|
|
|
17052
17781
|
}
|
|
17053
17782
|
startMemorySnapshotTimer() {
|
|
17054
17783
|
this.stopMemorySnapshotTimer();
|
|
17055
|
-
this.memorySnapshotTimer = setInterval(() => {
|
|
17784
|
+
this.memorySnapshotTimer = this.clock.setInterval(() => {
|
|
17056
17785
|
this.takeMemorySnapshot();
|
|
17057
17786
|
}, this.memorySnapshotInterval);
|
|
17058
17787
|
}
|
|
17059
17788
|
stopMemorySnapshotTimer() {
|
|
17060
17789
|
if (this.memorySnapshotTimer) {
|
|
17061
|
-
clearInterval(this.memorySnapshotTimer);
|
|
17790
|
+
this.clock.clearInterval(this.memorySnapshotTimer);
|
|
17062
17791
|
this.memorySnapshotTimer = null;
|
|
17063
17792
|
}
|
|
17064
17793
|
}
|
|
@@ -17067,7 +17796,7 @@ Captured output:
|
|
|
17067
17796
|
if (this._isRunning && interval > 0) {
|
|
17068
17797
|
this.startMemorySnapshotTimer();
|
|
17069
17798
|
} else if (interval <= 0 && this.memorySnapshotTimer) {
|
|
17070
|
-
clearInterval(this.memorySnapshotTimer);
|
|
17799
|
+
this.clock.clearInterval(this.memorySnapshotTimer);
|
|
17071
17800
|
this.memorySnapshotTimer = null;
|
|
17072
17801
|
}
|
|
17073
17802
|
}
|
|
@@ -17079,10 +17808,10 @@ Captured output:
|
|
|
17079
17808
|
return;
|
|
17080
17809
|
}
|
|
17081
17810
|
if (this.resizeTimeoutId !== null) {
|
|
17082
|
-
clearTimeout(this.resizeTimeoutId);
|
|
17811
|
+
this.clock.clearTimeout(this.resizeTimeoutId);
|
|
17083
17812
|
this.resizeTimeoutId = null;
|
|
17084
17813
|
}
|
|
17085
|
-
this.resizeTimeoutId = setTimeout(() => {
|
|
17814
|
+
this.resizeTimeoutId = this.clock.setTimeout(() => {
|
|
17086
17815
|
this.resizeTimeoutId = null;
|
|
17087
17816
|
this.processResize(width, height);
|
|
17088
17817
|
}, this.resizeDebounceDelay);
|
|
@@ -17099,7 +17828,7 @@ Captured output:
|
|
|
17099
17828
|
this._terminalHeight = height;
|
|
17100
17829
|
this.queryPixelResolution();
|
|
17101
17830
|
this.setCapturedRenderable(undefined);
|
|
17102
|
-
this.
|
|
17831
|
+
this.stdinParser?.resetMouseState();
|
|
17103
17832
|
if (this._splitHeight > 0) {
|
|
17104
17833
|
if (width < prevWidth) {
|
|
17105
17834
|
const start = this._terminalHeight - this._splitHeight * 2;
|
|
@@ -17262,7 +17991,7 @@ Captured output:
|
|
|
17262
17991
|
this._suspendedMouseEnabled = this._useMouse;
|
|
17263
17992
|
this.disableMouse();
|
|
17264
17993
|
this.removeExitListeners();
|
|
17265
|
-
this.
|
|
17994
|
+
this.stdinParser?.reset();
|
|
17266
17995
|
this.stdin.removeListener("data", this.stdinListener);
|
|
17267
17996
|
this.lib.suspendRenderer(this.rendererPtr);
|
|
17268
17997
|
if (this.stdin.setRawMode) {
|
|
@@ -17295,7 +18024,7 @@ Captured output:
|
|
|
17295
18024
|
internalPause() {
|
|
17296
18025
|
this._isRunning = false;
|
|
17297
18026
|
if (this.renderTimeout) {
|
|
17298
|
-
clearTimeout(this.renderTimeout);
|
|
18027
|
+
this.clock.clearTimeout(this.renderTimeout);
|
|
17299
18028
|
this.renderTimeout = null;
|
|
17300
18029
|
}
|
|
17301
18030
|
if (!this.rendering) {
|
|
@@ -17310,11 +18039,11 @@ Captured output:
|
|
|
17310
18039
|
if (this.isRunning && !this._isDestroyed) {
|
|
17311
18040
|
this._isRunning = false;
|
|
17312
18041
|
if (this.memorySnapshotTimer) {
|
|
17313
|
-
clearInterval(this.memorySnapshotTimer);
|
|
18042
|
+
this.clock.clearInterval(this.memorySnapshotTimer);
|
|
17314
18043
|
this.memorySnapshotTimer = null;
|
|
17315
18044
|
}
|
|
17316
18045
|
if (this.renderTimeout) {
|
|
17317
|
-
clearTimeout(this.renderTimeout);
|
|
18046
|
+
this.clock.clearTimeout(this.renderTimeout);
|
|
17318
18047
|
this.renderTimeout = null;
|
|
17319
18048
|
}
|
|
17320
18049
|
if (!this.rendering) {
|
|
@@ -17345,15 +18074,15 @@ Captured output:
|
|
|
17345
18074
|
capture.removeListener("write", this.captureCallback);
|
|
17346
18075
|
this.removeExitListeners();
|
|
17347
18076
|
if (this.resizeTimeoutId !== null) {
|
|
17348
|
-
clearTimeout(this.resizeTimeoutId);
|
|
18077
|
+
this.clock.clearTimeout(this.resizeTimeoutId);
|
|
17349
18078
|
this.resizeTimeoutId = null;
|
|
17350
18079
|
}
|
|
17351
18080
|
if (this.capabilityTimeoutId !== null) {
|
|
17352
|
-
clearTimeout(this.capabilityTimeoutId);
|
|
18081
|
+
this.clock.clearTimeout(this.capabilityTimeoutId);
|
|
17353
18082
|
this.capabilityTimeoutId = null;
|
|
17354
18083
|
}
|
|
17355
18084
|
if (this.memorySnapshotTimer) {
|
|
17356
|
-
clearInterval(this.memorySnapshotTimer);
|
|
18085
|
+
this.clock.clearInterval(this.memorySnapshotTimer);
|
|
17357
18086
|
}
|
|
17358
18087
|
if (this._paletteDetector) {
|
|
17359
18088
|
this._paletteDetector.cleanup();
|
|
@@ -17363,7 +18092,7 @@ Captured output:
|
|
|
17363
18092
|
this._cachedPalette = null;
|
|
17364
18093
|
this.emit("destroy" /* DESTROY */);
|
|
17365
18094
|
if (this.renderTimeout) {
|
|
17366
|
-
clearTimeout(this.renderTimeout);
|
|
18095
|
+
this.clock.clearTimeout(this.renderTimeout);
|
|
17367
18096
|
this.renderTimeout = null;
|
|
17368
18097
|
}
|
|
17369
18098
|
this._isRunning = false;
|
|
@@ -17374,16 +18103,18 @@ Captured output:
|
|
|
17374
18103
|
} catch (e) {
|
|
17375
18104
|
console.error("Error destroying root renderable:", e instanceof Error ? e.stack : String(e));
|
|
17376
18105
|
}
|
|
17377
|
-
this.
|
|
18106
|
+
this.stdin.removeListener("data", this.stdinListener);
|
|
18107
|
+
if (this.stdin.setRawMode) {
|
|
18108
|
+
this.stdin.setRawMode(false);
|
|
18109
|
+
}
|
|
18110
|
+
this.stdinParser?.destroy();
|
|
18111
|
+
this.stdinParser = null;
|
|
18112
|
+
this.oscSubscribers.clear();
|
|
17378
18113
|
this._console.destroy();
|
|
17379
18114
|
this.disableStdoutInterception();
|
|
17380
18115
|
if (this._splitHeight > 0) {
|
|
17381
18116
|
this.flushStdoutCache(this._splitHeight, true);
|
|
17382
18117
|
}
|
|
17383
|
-
if (this.stdin.setRawMode) {
|
|
17384
|
-
this.stdin.setRawMode(false);
|
|
17385
|
-
}
|
|
17386
|
-
this.stdin.removeListener("data", this.stdinListener);
|
|
17387
18118
|
this.lib.destroyRenderer(this.rendererPtr);
|
|
17388
18119
|
rendererTracker.removeRenderer(this);
|
|
17389
18120
|
if (this._onDestroy) {
|
|
@@ -17398,7 +18129,7 @@ Captured output:
|
|
|
17398
18129
|
startRenderLoop() {
|
|
17399
18130
|
if (!this._isRunning)
|
|
17400
18131
|
return;
|
|
17401
|
-
this.lastTime =
|
|
18132
|
+
this.lastTime = this.clock.now();
|
|
17402
18133
|
this.frameCount = 0;
|
|
17403
18134
|
this.lastFpsTime = this.lastTime;
|
|
17404
18135
|
this.currentFps = 0;
|
|
@@ -17410,11 +18141,11 @@ Captured output:
|
|
|
17410
18141
|
this.renderTimeout = null;
|
|
17411
18142
|
this.rendering = true;
|
|
17412
18143
|
if (this.renderTimeout) {
|
|
17413
|
-
clearTimeout(this.renderTimeout);
|
|
18144
|
+
this.clock.clearTimeout(this.renderTimeout);
|
|
17414
18145
|
this.renderTimeout = null;
|
|
17415
18146
|
}
|
|
17416
18147
|
try {
|
|
17417
|
-
const now =
|
|
18148
|
+
const now = this.clock.now();
|
|
17418
18149
|
const elapsed = now - this.lastTime;
|
|
17419
18150
|
const deltaTime = elapsed;
|
|
17420
18151
|
this.lastTime = now;
|
|
@@ -17465,12 +18196,12 @@ Captured output:
|
|
|
17465
18196
|
const targetFrameTime = this.immediateRerenderRequested ? this.minTargetFrameTime : this.targetFrameTime;
|
|
17466
18197
|
const delay = Math.max(1, targetFrameTime - Math.floor(overallFrameTime));
|
|
17467
18198
|
this.immediateRerenderRequested = false;
|
|
17468
|
-
this.renderTimeout = setTimeout(() => {
|
|
18199
|
+
this.renderTimeout = this.clock.setTimeout(() => {
|
|
17469
18200
|
this.renderTimeout = null;
|
|
17470
18201
|
this.loop();
|
|
17471
18202
|
}, delay);
|
|
17472
18203
|
} else {
|
|
17473
|
-
clearTimeout(this.renderTimeout);
|
|
18204
|
+
this.clock.clearTimeout(this.renderTimeout);
|
|
17474
18205
|
this.renderTimeout = null;
|
|
17475
18206
|
}
|
|
17476
18207
|
}
|
|
@@ -17665,7 +18396,9 @@ Captured output:
|
|
|
17665
18396
|
}
|
|
17666
18397
|
if (!this._paletteDetector) {
|
|
17667
18398
|
const isLegacyTmux = this.capabilities?.terminal?.name?.toLowerCase()?.includes("tmux") && this.capabilities?.terminal?.version?.localeCompare("3.6") < 0;
|
|
17668
|
-
this._paletteDetector = createTerminalPalette(this.stdin, this.stdout, this.writeOut.bind(this), isLegacyTmux
|
|
18399
|
+
this._paletteDetector = createTerminalPalette(this.stdin, this.stdout, this.writeOut.bind(this), isLegacyTmux, {
|
|
18400
|
+
subscribeOsc: this.subscribeOsc.bind(this)
|
|
18401
|
+
}, this.clock);
|
|
17669
18402
|
}
|
|
17670
18403
|
this._paletteDetectionPromise = this._paletteDetector.detect(options).then((result) => {
|
|
17671
18404
|
this._cachedPalette = result;
|
|
@@ -17676,7 +18409,7 @@ Captured output:
|
|
|
17676
18409
|
}
|
|
17677
18410
|
}
|
|
17678
18411
|
|
|
17679
|
-
export { __toESM, __commonJS, __export, __require, Edge, Gutter, MeasureMode, exports_src, isValidBorderStyle, parseBorderStyle, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays,
|
|
18412
|
+
export { __toESM, __commonJS, __export, __require, Edge, Gutter, MeasureMode, exports_src, isValidBorderStyle, parseBorderStyle, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, KeyEvent, PasteEvent, KeyHandler, InternalKeyHandler, RGBA, hexToRgb, rgbToHex, hsvToRgb, parseColor, fonts, measureText, getCharacterPositions, coordinateToCharacterIndex, renderFontToFrameBuffer, TextAttributes, ATTRIBUTE_BASE_BITS, ATTRIBUTE_BASE_MASK, getBaseAttributes, DebugOverlayCorner, createTextAttributes, attributesWithLink, getLinkId, 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, link, t, hastToStyledText, SystemClock, nonAlphanumericKeys, parseKeypress, LinearScrollAccel, MacOSScrollAccel, parseAlign, parseAlignItems, parseBoxSizing, parseDimension, parseDirection, parseDisplay, parseEdge, parseFlexDirection, parseGutter, parseJustify, parseLogLevel, parseMeasureMode, parseOverflow, parsePositionType, parseUnit, parseWrap, MouseParser, Selection, convertGlobalToLocalSelection, ASCIIFontSelectionHelper, envRegistry, registerEnvVar, clearEnvCache, generateEnvMarkdown, generateEnvColored, env, StdinParser, treeSitterToTextChunks, treeSitterToStyledText, addDefaultParsers, TreeSitterClient, DataPathsManager, getDataPaths, extToFiletype, pathToFiletype, main, getTreeSitterClient, ExtmarksController, createExtmarksController, TerminalPalette, createTerminalPalette, decodePasteBytes, stripAnsiSequences, detectLinks, TextBuffer, SpanInfoStruct, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, isValidPercentage, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, ANSI, defaultKeyAliases, mergeKeyAliases, mergeKeyBindings, getKeyBindingKey, buildKeyBindingsMap, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, buildKittyKeyboardFlags, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, RendererControlState, CliRenderer };
|
|
17680
18413
|
|
|
17681
|
-
//# debugId=
|
|
17682
|
-
//# sourceMappingURL=index-
|
|
18414
|
+
//# debugId=CCC74025BA5612C764756E2164756E21
|
|
18415
|
+
//# sourceMappingURL=index-nkrr8a4c.js.map
|