@simon_he/vue-tui 1.0.1 → 1.1.0
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/README.md +139 -46
- package/dist/TMermaidText-frVr8Ysb.js +885 -0
- package/dist/{TSelect-HzILuti9.js → TSelect-tJ87rKPM.js} +59 -242
- package/dist/{TTree-ChOot2Bh.js → TTree-CGdE-CYu.js} +138 -102
- package/dist/agent/mermaid.cjs +2 -0
- package/dist/agent/mermaid.d.cts +2 -0
- package/dist/agent/mermaid.d.ts +2 -0
- package/dist/agent/mermaid.js +1 -0
- package/dist/agent.cjs +31188 -24907
- package/dist/agent.d.cts +11 -1
- package/dist/agent.d.ts +11 -1
- package/dist/agent.js +516 -11
- package/dist/{block-source-CKUOnkgT.js → block-source-CrlmaBM5.js} +1039 -66
- package/dist/cli/input.d.ts +8 -0
- package/dist/cli/stdin-buffer.d.ts +1 -1
- package/dist/cli/video/ffmpeg-frame-source.d.ts +10 -0
- package/dist/cli/video/png-frame-parser.d.ts +4 -0
- package/dist/cli/video/raw-frame-parser.d.ts +1 -0
- package/dist/cli/video/yt-dlp-frame-source.d.ts +11 -0
- package/dist/cli.cjs +5470 -6176
- package/dist/cli.d.cts +6 -2
- package/dist/cli.d.ts +6 -2
- package/dist/cli.js +3747 -350
- package/dist/core/buffer/buffer.d.ts +2 -2
- package/dist/core/buffer/eaw-ranges-unicode-17.d.ts +14 -0
- package/dist/core/perf/instrumentation-noop.d.ts +48 -0
- package/dist/core/perf/instrumentation.d.ts +136 -0
- package/dist/core/terminal/create-terminal.d.ts +1 -0
- package/dist/core/types.d.ts +0 -4
- package/dist/core.cjs +851 -1462
- package/dist/core.js +4 -5
- package/dist/create-terminal-app.d.ts +24 -1
- package/dist/debug-logger-CmsGI4of.js +74 -0
- package/dist/{dom-renderer-BqGijQID.js → dom-renderer-DXx8fWzD.js} +2 -3
- package/dist/experimental/3d/bun/contributor-avatar-atlas.d.ts +12 -0
- package/dist/experimental/3d/bun/png.d.ts +1 -0
- package/dist/experimental/3d/bun/terminal-badge-scene.d.ts +11 -0
- package/dist/experimental/3d/bun/terminal-badge.wgsl.d.ts +1 -0
- package/dist/experimental/3d/bun/webgpu-renderer.d.ts +26 -0
- package/dist/experimental/3d/bun.cjs +7271 -0
- package/dist/experimental/3d/bun.d.cts +4 -0
- package/dist/experimental/3d/bun.d.ts +4 -0
- package/dist/experimental/3d/bun.js +7390 -0
- package/dist/experimental/video/node.cjs +497 -0
- package/dist/experimental/video/node.d.cts +4 -0
- package/dist/experimental/video/node.d.ts +4 -0
- package/dist/experimental/video/node.js +610 -0
- package/dist/experimental.cjs +6876 -6192
- package/dist/experimental.d.cts +7 -0
- package/dist/experimental.d.ts +7 -0
- package/dist/experimental.js +3005 -9
- package/dist/frame-perf-CHpWhbC4.js +111 -0
- package/dist/{create-terminal-C2oiWFJU.js → hyperlink-_1FAj7Wq.js} +455 -19
- package/dist/index.cjs +5025 -10332
- package/dist/index.js +14 -13
- package/dist/{linkify-D_gzn9Xq.js → linkify-D68T7rdW.js} +193 -3
- package/dist/markdown.cjs +21295 -12691
- package/dist/markdown.d.cts +1 -1
- package/dist/markdown.d.ts +1 -1
- package/dist/markdown.js +211 -51
- package/dist/mermaid-BNhM1jAZ.js +123 -0
- package/dist/mermaid.cjs +1707 -0
- package/dist/mermaid.d.cts +3 -0
- package/dist/mermaid.d.ts +3 -0
- package/dist/mermaid.js +6 -0
- package/dist/observability/frame-perf-store.d.ts +2 -1
- package/dist/observability/frame-perf.d.ts +33 -0
- package/dist/observability.cjs +106 -107
- package/dist/observability.d.cts +2 -2
- package/dist/observability.d.ts +2 -2
- package/dist/observability.js +3 -3
- package/dist/{wheel-scroll-vBRaQ7p-.js → rect-DUpeDfBg.js} +253 -117
- package/dist/renderer/cli/index.d.ts +1 -1
- package/dist/renderer/cli/stdout-metrics.d.ts +10 -0
- package/dist/renderer/cli/stdout-renderer.d.ts +53 -7
- package/dist/renderer/terminal-graphic-render-queue.d.ts +50 -0
- package/dist/renderer/terminal-graphics-trace.d.ts +53 -0
- package/dist/renderer/terminal-graphics.d.ts +147 -0
- package/dist/renderer-dom.cjs +364 -903
- package/dist/renderer-dom.js +4 -5
- package/dist/runtime/index.d.ts +2 -0
- package/dist/{runtime-rfcZCyJq.js → runtime-Byf8XXOT.js} +28 -15
- package/dist/runtime.cjs +427 -889
- package/dist/runtime.js +2 -2
- package/dist/terminal-graphics-Bbe83wSr.js +597 -0
- package/dist/{terminal-selection-DBinO6p5.js → terminal-selection-4W1SJj4c.js} +4 -1
- package/dist/{tlog-theme-CvLFNMwk.js → tlog-theme-Bul2Na3u.js} +1237 -12
- package/dist/{trace-CjzYeIxN.js → trace-Bh8WnoMo.js} +5 -0
- package/dist/vue/agent/create-png-terminal-graphic-renderer.d.ts +19 -0
- package/dist/vue/components/T3DViewport.d.ts +473 -0
- package/dist/vue/components/TAgentTerminalGraphic.d.ts +494 -0
- package/dist/vue/components/TCharts.d.ts +1121 -0
- package/dist/vue/components/TFeedback.d.ts +1 -1
- package/dist/vue/components/TFlex.d.ts +389 -0
- package/dist/vue/components/TForm.d.ts +4 -4
- package/dist/vue/components/TLogSearchBar.d.ts +3 -3
- package/dist/vue/components/TLogSearchPager.d.ts +2 -2
- package/dist/vue/components/TMarkdownText.d.ts +162 -4
- package/dist/vue/components/TMermaidText.d.ts +900 -0
- package/dist/vue/components/TVideo.d.ts +291 -0
- package/dist/vue/components/TVirtualList.d.ts +9 -0
- package/dist/vue/components/TVirtualMarkdown.d.ts +170 -9
- package/dist/vue/components/TVirtualRows.d.ts +9 -0
- package/dist/vue/components/TerminalProvider.d.ts +2 -0
- package/dist/vue/context.d.ts +24 -0
- package/dist/vue/index.d.ts +5 -0
- package/dist/vue/layout/flex.d.ts +67 -0
- package/dist/vue/markdown/ast.d.ts +5 -2
- package/dist/vue/markdown/document.d.ts +5 -0
- package/dist/vue/markdown/image-actions.d.ts +14 -0
- package/dist/vue/markdown/image.d.ts +11 -0
- package/dist/vue/markdown/link-actions.d.ts +14 -0
- package/dist/vue/markdown/math-actions.d.ts +14 -0
- package/dist/vue/markdown/math.d.ts +6 -0
- package/dist/vue/markdown/render.d.ts +28 -0
- package/dist/vue/markdown/types.d.ts +78 -0
- package/dist/vue/mermaid/beautiful-mermaid.d.ts +1436 -0
- package/dist/vue/render/render-manager.d.ts +7 -0
- package/dist/vue/video/types.d.ts +39 -0
- package/dist/vue.cjs +7215 -12430
- package/dist/vue.js +704 -38
- package/dist/wheel-scroll-DASkEZr-.js +106 -0
- package/dist/{hyperlink-Bn02UXJb.js → width-GqllnV8C.js} +166 -111
- package/package.json +141 -18
- package/dist/frame-perf-C6Xfg85O.js +0 -24
- package/dist/sgr-BmzxEjAO.js +0 -304
- /package/dist/{ansi-palette-CNXqFciC.js → ansi-palette-CH6jc2Z7.js} +0 -0
- /package/dist/{path-suggest-BNqcuE3-.js → path-suggest-Dndu4dTi.js} +0 -0
package/dist/core.cjs
CHANGED
|
@@ -5,17 +5,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __export = (target, all) => {
|
|
7
7
|
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable:
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
12
11
|
for (let key of __getOwnPropNames(from))
|
|
13
|
-
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
13
|
return to;
|
|
17
14
|
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value:
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
19
16
|
|
|
20
17
|
// src/core.ts
|
|
21
18
|
var core_exports = {};
|
|
@@ -65,15 +62,12 @@ var ANSI_PALETTE_HEX = Object.freeze({
|
|
|
65
62
|
whiteBright: "#ffffff"
|
|
66
63
|
});
|
|
67
64
|
function ansiHexToRgb(hex) {
|
|
68
|
-
|
|
65
|
+
let h = hex.startsWith("#") ? hex.slice(1) : hex;
|
|
69
66
|
if (h.length !== 6)
|
|
70
|
-
return
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (!Number.isFinite(r) || !Number.isFinite(g) || !Number.isFinite(b))
|
|
75
|
-
return void 0;
|
|
76
|
-
return { r, g, b };
|
|
67
|
+
return;
|
|
68
|
+
let r = Number.parseInt(h.slice(0, 2), 16), g = Number.parseInt(h.slice(2, 4), 16), b = Number.parseInt(h.slice(4, 6), 16);
|
|
69
|
+
if (!(!Number.isFinite(r) || !Number.isFinite(g) || !Number.isFinite(b)))
|
|
70
|
+
return { r, g, b };
|
|
77
71
|
}
|
|
78
72
|
var ANSI_PALETTE_RGB = Object.freeze(
|
|
79
73
|
Object.fromEntries(
|
|
@@ -81,15 +75,13 @@ var ANSI_PALETTE_RGB = Object.freeze(
|
|
|
81
75
|
)
|
|
82
76
|
);
|
|
83
77
|
function isAnsiColorName(name) {
|
|
84
|
-
return typeof name
|
|
78
|
+
return typeof name == "string" && Object.prototype.hasOwnProperty.call(ANSI_PALETTE_HEX, name);
|
|
85
79
|
}
|
|
86
80
|
function ansiColorRgb(name, palette) {
|
|
87
81
|
if (!isAnsiColorName(name))
|
|
88
|
-
return
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return ansiHexToRgb(custom) ?? ANSI_PALETTE_RGB[name];
|
|
92
|
-
return ANSI_PALETTE_RGB[name];
|
|
82
|
+
return;
|
|
83
|
+
let custom = palette?.[name];
|
|
84
|
+
return custom ? ansiHexToRgb(custom) ?? ANSI_PALETTE_RGB[name] : ANSI_PALETTE_RGB[name];
|
|
93
85
|
}
|
|
94
86
|
|
|
95
87
|
// src/core/ansi/colors.ts
|
|
@@ -102,8 +94,7 @@ var ANSI8_COLOR_NAMES = Object.freeze([
|
|
|
102
94
|
"magenta",
|
|
103
95
|
"cyan",
|
|
104
96
|
"white"
|
|
105
|
-
])
|
|
106
|
-
var ANSI16_COLOR_NAMES = Object.freeze([
|
|
97
|
+
]), ANSI16_COLOR_NAMES = Object.freeze([
|
|
107
98
|
"black",
|
|
108
99
|
"red",
|
|
109
100
|
"green",
|
|
@@ -120,14 +111,7 @@ var ANSI16_COLOR_NAMES = Object.freeze([
|
|
|
120
111
|
"magentaBright",
|
|
121
112
|
"cyanBright",
|
|
122
113
|
"whiteBright"
|
|
123
|
-
])
|
|
124
|
-
var ESC = "\x1B[";
|
|
125
|
-
var SGR_RESET = `${ESC}0m`;
|
|
126
|
-
var SGR_BOLD = `${ESC}1m`;
|
|
127
|
-
var SGR_DIM = `${ESC}2m`;
|
|
128
|
-
var SGR_ITALIC = `${ESC}3m`;
|
|
129
|
-
var SGR_UNDERLINE = `${ESC}4m`;
|
|
130
|
-
var SGR_INVERSE = `${ESC}7m`;
|
|
114
|
+
]), ESC = "\x1B[", SGR_RESET = `${ESC}0m`, SGR_BOLD = `${ESC}1m`, SGR_DIM = `${ESC}2m`, SGR_ITALIC = `${ESC}3m`, SGR_UNDERLINE = `${ESC}4m`, SGR_INVERSE = `${ESC}7m`;
|
|
131
115
|
function toAnsi8ColorName(name) {
|
|
132
116
|
switch (name) {
|
|
133
117
|
case "black":
|
|
@@ -174,8 +158,7 @@ var ANSI16_FG_CODE = Object.freeze({
|
|
|
174
158
|
magentaBright: 95,
|
|
175
159
|
cyanBright: 96,
|
|
176
160
|
whiteBright: 97
|
|
177
|
-
})
|
|
178
|
-
var ANSI16_BG_CODE = Object.freeze({
|
|
161
|
+
}), ANSI16_BG_CODE = Object.freeze({
|
|
179
162
|
black: 40,
|
|
180
163
|
red: 41,
|
|
181
164
|
green: 42,
|
|
@@ -194,13 +177,11 @@ var ANSI16_BG_CODE = Object.freeze({
|
|
|
194
177
|
whiteBright: 107
|
|
195
178
|
});
|
|
196
179
|
function ansi8FgOpen(name) {
|
|
197
|
-
|
|
198
|
-
const idx = ANSI8_COLOR_NAMES.indexOf(base);
|
|
180
|
+
let base = toAnsi8ColorName(name), idx = ANSI8_COLOR_NAMES.indexOf(base);
|
|
199
181
|
return `${ESC}${30 + (idx < 0 ? 7 : idx)}m`;
|
|
200
182
|
}
|
|
201
183
|
function ansi8BgOpen(name) {
|
|
202
|
-
|
|
203
|
-
const idx = ANSI8_COLOR_NAMES.indexOf(base);
|
|
184
|
+
let base = toAnsi8ColorName(name), idx = ANSI8_COLOR_NAMES.indexOf(base);
|
|
204
185
|
return `${ESC}${40 + (idx < 0 ? 0 : idx)}m`;
|
|
205
186
|
}
|
|
206
187
|
function ansi16FgOpen(name) {
|
|
@@ -210,11 +191,11 @@ function ansi16BgOpen(name) {
|
|
|
210
191
|
return `${ESC}${ANSI16_BG_CODE[name]}m`;
|
|
211
192
|
}
|
|
212
193
|
function ansi256FgOpen(index) {
|
|
213
|
-
|
|
194
|
+
let n = clampAnsiIndex(index);
|
|
214
195
|
return `${ESC}38;5;${n}m`;
|
|
215
196
|
}
|
|
216
197
|
function ansi256BgOpen(index) {
|
|
217
|
-
|
|
198
|
+
let n = clampAnsiIndex(index);
|
|
218
199
|
return `${ESC}48;5;${n}m`;
|
|
219
200
|
}
|
|
220
201
|
function truecolorFgOpen(rgb) {
|
|
@@ -224,54 +205,32 @@ function truecolorBgOpen(rgb) {
|
|
|
224
205
|
return `${ESC}48;2;${clampByte(rgb.r)};${clampByte(rgb.g)};${clampByte(rgb.b)}m`;
|
|
225
206
|
}
|
|
226
207
|
function ansi256ToRgb(index) {
|
|
227
|
-
|
|
208
|
+
let n = clampAnsiIndex(index);
|
|
228
209
|
if (n < 16) {
|
|
229
|
-
|
|
210
|
+
let name = ANSI16_COLOR_NAMES[n] ?? "white";
|
|
230
211
|
return ansiColorRgb(name) ?? { r: 255, g: 255, b: 255 };
|
|
231
212
|
}
|
|
232
213
|
if (n >= 232) {
|
|
233
|
-
|
|
214
|
+
let c = 8 + (n - 232) * 10;
|
|
234
215
|
return { r: c, g: c, b: c };
|
|
235
216
|
}
|
|
236
|
-
|
|
237
|
-
const rr = Math.floor(i / 36);
|
|
238
|
-
const gg = Math.floor(i % 36 / 6);
|
|
239
|
-
const bb = i % 6;
|
|
240
|
-
const levels = [0, 95, 135, 175, 215, 255];
|
|
217
|
+
let i = n - 16, rr = Math.floor(i / 36), gg = Math.floor(i % 36 / 6), bb = i % 6, levels = [0, 95, 135, 175, 215, 255];
|
|
241
218
|
return { r: levels[rr], g: levels[gg], b: levels[bb] };
|
|
242
219
|
}
|
|
243
220
|
function rgbToAnsi256(rgb) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const b = clampByte(rgb.b);
|
|
247
|
-
const levels = [0, 95, 135, 175, 215, 255];
|
|
248
|
-
const nearestLevelIndex = (v) => {
|
|
249
|
-
let best = 0;
|
|
250
|
-
let bestDist = Number.POSITIVE_INFINITY;
|
|
221
|
+
let r = clampByte(rgb.r), g = clampByte(rgb.g), b = clampByte(rgb.b), levels = [0, 95, 135, 175, 215, 255], nearestLevelIndex = (v) => {
|
|
222
|
+
let best = 0, bestDist = Number.POSITIVE_INFINITY;
|
|
251
223
|
for (let i = 0; i < levels.length; i++) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
bestDist = d;
|
|
255
|
-
best = i;
|
|
256
|
-
}
|
|
224
|
+
let d = (v - levels[i]) ** 2;
|
|
225
|
+
d < bestDist && (bestDist = d, best = i);
|
|
257
226
|
}
|
|
258
227
|
return best;
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
const gi = nearestLevelIndex(g);
|
|
262
|
-
const bi = nearestLevelIndex(b);
|
|
263
|
-
const cubeIndex = 16 + 36 * ri + 6 * gi + bi;
|
|
264
|
-
const cube = ansi256ToRgb(cubeIndex);
|
|
265
|
-
const cubeDist = (r - cube.r) ** 2 + (g - cube.g) ** 2 + (b - cube.b) ** 2;
|
|
266
|
-
const gray = Math.round((r + g + b) / 3);
|
|
267
|
-
const grayIndex = gray < 8 ? 16 : gray > 248 ? 231 : 232 + Math.round((gray - 8) / 10);
|
|
268
|
-
const grayRgb = ansi256ToRgb(grayIndex);
|
|
269
|
-
const grayDist = (r - grayRgb.r) ** 2 + (g - grayRgb.g) ** 2 + (b - grayRgb.b) ** 2;
|
|
270
|
-
return grayDist < cubeDist ? grayIndex : cubeIndex;
|
|
228
|
+
}, ri = nearestLevelIndex(r), gi = nearestLevelIndex(g), bi = nearestLevelIndex(b), cubeIndex = 16 + 36 * ri + 6 * gi + bi, cube = ansi256ToRgb(cubeIndex), cubeDist = (r - cube.r) ** 2 + (g - cube.g) ** 2 + (b - cube.b) ** 2, gray = Math.round((r + g + b) / 3), grayIndex = gray < 8 ? 16 : gray > 248 ? 231 : 232 + Math.round((gray - 8) / 10), grayRgb = ansi256ToRgb(grayIndex);
|
|
229
|
+
return (r - grayRgb.r) ** 2 + (g - grayRgb.g) ** 2 + (b - grayRgb.b) ** 2 < cubeDist ? grayIndex : cubeIndex;
|
|
271
230
|
}
|
|
272
231
|
function ansi8Palette() {
|
|
273
232
|
return ANSI8_COLOR_NAMES.map((name, index) => {
|
|
274
|
-
|
|
233
|
+
let rgb = ansiColorRgb(name) ?? { r: 255, g: 255, b: 255 };
|
|
275
234
|
return Object.freeze({
|
|
276
235
|
level: 8,
|
|
277
236
|
index,
|
|
@@ -284,7 +243,7 @@ function ansi8Palette() {
|
|
|
284
243
|
}
|
|
285
244
|
function ansi16Palette() {
|
|
286
245
|
return ANSI16_COLOR_NAMES.map((name, index) => {
|
|
287
|
-
|
|
246
|
+
let rgb = ansiColorRgb(name) ?? { r: 255, g: 255, b: 255 };
|
|
288
247
|
return Object.freeze({
|
|
289
248
|
level: 16,
|
|
290
249
|
index,
|
|
@@ -296,8 +255,8 @@ function ansi16Palette() {
|
|
|
296
255
|
});
|
|
297
256
|
}
|
|
298
257
|
function ansi256Palette() {
|
|
299
|
-
|
|
300
|
-
for (let index = 0; index < 256; index++)
|
|
258
|
+
let out = [];
|
|
259
|
+
for (let index = 0; index < 256; index++)
|
|
301
260
|
out.push(
|
|
302
261
|
Object.freeze({
|
|
303
262
|
level: 256,
|
|
@@ -307,18 +266,13 @@ function ansi256Palette() {
|
|
|
307
266
|
bgOpen: ansi256BgOpen(index)
|
|
308
267
|
})
|
|
309
268
|
);
|
|
310
|
-
}
|
|
311
269
|
return Object.freeze(out);
|
|
312
270
|
}
|
|
313
271
|
function clampAnsiIndex(n) {
|
|
314
|
-
|
|
315
|
-
return 0;
|
|
316
|
-
return Math.max(0, Math.min(255, Math.trunc(n)));
|
|
272
|
+
return Number.isFinite(n) ? Math.max(0, Math.min(255, Math.trunc(n))) : 0;
|
|
317
273
|
}
|
|
318
274
|
function clampByte(n) {
|
|
319
|
-
|
|
320
|
-
return 0;
|
|
321
|
-
return Math.max(0, Math.min(255, Math.round(n)));
|
|
275
|
+
return Number.isFinite(n) ? Math.max(0, Math.min(255, Math.round(n))) : 0;
|
|
322
276
|
}
|
|
323
277
|
|
|
324
278
|
// src/ansi-styles.ts
|
|
@@ -374,93 +328,53 @@ var ansiStyles = Object.freeze({
|
|
|
374
328
|
ansi256: (idx) => ansi256BgOpen(idx),
|
|
375
329
|
ansi16m: (r, g, b) => truecolorBgOpen({ r, g, b })
|
|
376
330
|
})
|
|
377
|
-
});
|
|
378
|
-
var ANSI8_COLORS = ansi8Palette();
|
|
379
|
-
var ANSI16_COLORS = ansi16Palette();
|
|
380
|
-
var ANSI256_COLORS = ansi256Palette();
|
|
331
|
+
}), ANSI8_COLORS = ansi8Palette(), ANSI16_COLORS = ansi16Palette(), ANSI256_COLORS = ansi256Palette();
|
|
381
332
|
function ansiColors(level) {
|
|
382
|
-
|
|
383
|
-
return ANSI8_COLORS;
|
|
384
|
-
if (level === 16)
|
|
385
|
-
return ANSI16_COLORS;
|
|
386
|
-
return ANSI256_COLORS;
|
|
333
|
+
return level === 8 ? ANSI8_COLORS : level === 16 ? ANSI16_COLORS : ANSI256_COLORS;
|
|
387
334
|
}
|
|
388
335
|
|
|
389
336
|
// src/utils/env.ts
|
|
390
337
|
function firstNonEmptyEnv(env, primary, legacy) {
|
|
391
|
-
|
|
338
|
+
let primaryValue = env?.[primary];
|
|
392
339
|
if (String(primaryValue ?? "").trim() !== "")
|
|
393
340
|
return primaryValue;
|
|
394
341
|
if (!legacy)
|
|
395
|
-
return
|
|
396
|
-
|
|
342
|
+
return;
|
|
343
|
+
let legacyValue = env?.[legacy];
|
|
397
344
|
if (String(legacyValue ?? "").trim() !== "")
|
|
398
345
|
return legacyValue;
|
|
399
|
-
return void 0;
|
|
400
346
|
}
|
|
401
347
|
|
|
402
348
|
// src/core/ansi/capability.ts
|
|
403
349
|
function parseColorMode(raw) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
return null;
|
|
407
|
-
if (v === "truecolor" || v === "24bit" || v === "rgb")
|
|
408
|
-
return "truecolor";
|
|
409
|
-
if (v === "ansi256" || v === "256" || v === "xterm256" || v === "xterm-256color") {
|
|
410
|
-
return "ansi256";
|
|
411
|
-
}
|
|
412
|
-
if (v === "ansi16" || v === "16")
|
|
413
|
-
return "ansi16";
|
|
414
|
-
if (v === "ansi8" || v === "8")
|
|
415
|
-
return "ansi8";
|
|
416
|
-
return null;
|
|
350
|
+
let v = String(raw ?? "").trim().toLowerCase();
|
|
351
|
+
return v ? v === "truecolor" || v === "24bit" || v === "rgb" ? "truecolor" : v === "ansi256" || v === "256" || v === "xterm256" || v === "xterm-256color" ? "ansi256" : v === "ansi16" || v === "16" ? "ansi16" : v === "ansi8" || v === "8" ? "ansi8" : null : null;
|
|
417
352
|
}
|
|
418
353
|
function levelForMode(mode) {
|
|
419
|
-
|
|
420
|
-
return 8;
|
|
421
|
-
if (mode === "ansi16")
|
|
422
|
-
return 16;
|
|
423
|
-
return 256;
|
|
354
|
+
return mode === "ansi8" ? 8 : mode === "ansi16" ? 16 : 256;
|
|
424
355
|
}
|
|
425
356
|
function detectTerminalColorCapability(opts) {
|
|
426
|
-
|
|
427
|
-
const isTTY = opts?.isTTY ?? false;
|
|
428
|
-
const platform = String(opts?.platform ?? "").trim().toLowerCase();
|
|
429
|
-
const isWindows = platform === "win32" || String(env.OS ?? "").trim().toLowerCase() === "windows_nt";
|
|
430
|
-
const forced = parseColorMode(firstNonEmptyEnv(env, "VUE_TUI_COLOR_MODE", "DIMCODE_COLOR_MODE"));
|
|
357
|
+
let env = opts?.env ?? {}, isTTY = opts?.isTTY ?? !1, isWindows = String(opts?.platform ?? "").trim().toLowerCase() === "win32" || String(env.OS ?? "").trim().toLowerCase() === "windows_nt", forced = parseColorMode(firstNonEmptyEnv(env, "VUE_TUI_COLOR_MODE", "DIMCODE_COLOR_MODE"));
|
|
431
358
|
if (forced)
|
|
432
359
|
return { mode: forced, level: levelForMode(forced) };
|
|
433
360
|
if (!isTTY)
|
|
434
361
|
return { mode: "truecolor", level: 256 };
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
const colorterm = String(env.COLORTERM ?? "").toLowerCase();
|
|
438
|
-
if (!isAppleTerminal && (colorterm.includes("truecolor") || colorterm.includes("24bit"))) {
|
|
362
|
+
let termProgram = String(env.TERM_PROGRAM ?? "").toLowerCase(), isAppleTerminal = termProgram.includes("apple_terminal"), colorterm = String(env.COLORTERM ?? "").toLowerCase();
|
|
363
|
+
if (!isAppleTerminal && (colorterm.includes("truecolor") || colorterm.includes("24bit")))
|
|
439
364
|
return { mode: "truecolor", level: 256 };
|
|
440
|
-
}
|
|
441
365
|
if (termProgram.includes("vscode"))
|
|
442
366
|
return { mode: "truecolor", level: 256 };
|
|
443
|
-
if (termProgram.includes("wezterm") || termProgram.includes("alacritty") || termProgram.includes("ghostty") || termProgram.includes("kitty") || termProgram.includes("iterm") || termProgram.includes("windows terminal") || termProgram.includes("windowsterminal") || termProgram.includes("tabby") || termProgram.includes("hyper") || termProgram.includes("rio") || termProgram.includes("contour"))
|
|
367
|
+
if (termProgram.includes("wezterm") || termProgram.includes("alacritty") || termProgram.includes("ghostty") || termProgram.includes("kitty") || termProgram.includes("iterm") || termProgram.includes("windows terminal") || termProgram.includes("windowsterminal") || termProgram.includes("tabby") || termProgram.includes("hyper") || termProgram.includes("rio") || termProgram.includes("contour"))
|
|
444
368
|
return { mode: "truecolor", level: 256 };
|
|
445
|
-
|
|
446
|
-
const term = String(env.TERM ?? "").toLowerCase();
|
|
369
|
+
let term = String(env.TERM ?? "").toLowerCase();
|
|
447
370
|
if (isWindows) {
|
|
448
|
-
|
|
449
|
-
const hasWezterm = "WEZTERM_EXECUTABLE" in env || "WEZTERM_PANE" in env;
|
|
450
|
-
const hasAlacritty = "ALACRITTY_LOG" in env || "ALACRITTY_WINDOW_ID" in env;
|
|
451
|
-
const hasTabby = "TABBY_CONFIG_DIRECTORY" in env;
|
|
371
|
+
let hasWindowsTerminal = "WT_SESSION" in env || "WT_PROFILE_ID" in env || "WT_ID" in env, hasWezterm = "WEZTERM_EXECUTABLE" in env || "WEZTERM_PANE" in env, hasAlacritty = "ALACRITTY_LOG" in env || "ALACRITTY_WINDOW_ID" in env, hasTabby = "TABBY_CONFIG_DIRECTORY" in env;
|
|
452
372
|
if (hasWindowsTerminal || hasWezterm || hasAlacritty || hasTabby)
|
|
453
373
|
return { mode: "truecolor", level: 256 };
|
|
454
374
|
if (term.includes("xterm") && term.includes("256color"))
|
|
455
375
|
return { mode: "truecolor", level: 256 };
|
|
456
376
|
}
|
|
457
|
-
|
|
458
|
-
return { mode: "ansi256", level: 256 };
|
|
459
|
-
if (term.includes("color"))
|
|
460
|
-
return { mode: "ansi16", level: 16 };
|
|
461
|
-
if (term.includes("dumb"))
|
|
462
|
-
return { mode: "ansi8", level: 8 };
|
|
463
|
-
return { mode: "ansi16", level: 16 };
|
|
377
|
+
return term.includes("256color") ? { mode: "ansi256", level: 256 } : term.includes("color") ? { mode: "ansi16", level: 16 } : term.includes("dumb") ? { mode: "ansi8", level: 8 } : { mode: "ansi16", level: 16 };
|
|
464
378
|
}
|
|
465
379
|
|
|
466
380
|
// src/core/ansi/sgr.ts
|
|
@@ -500,14 +414,13 @@ function ansi16ToColorName(code) {
|
|
|
500
414
|
case 97:
|
|
501
415
|
return "whiteBright";
|
|
502
416
|
default:
|
|
503
|
-
return
|
|
417
|
+
return;
|
|
504
418
|
}
|
|
505
419
|
}
|
|
506
420
|
function ansi16BgToColorName(code) {
|
|
507
|
-
|
|
508
|
-
if (fgCode
|
|
509
|
-
return
|
|
510
|
-
return ansi16ToColorName(fgCode);
|
|
421
|
+
let fgCode = code >= 40 && code <= 47 || code >= 100 && code <= 107 ? code - 10 : null;
|
|
422
|
+
if (fgCode != null)
|
|
423
|
+
return ansi16ToColorName(fgCode);
|
|
511
424
|
}
|
|
512
425
|
var ANSI16_RGB = {
|
|
513
426
|
black: { r: 0, g: 0, b: 0 },
|
|
@@ -528,24 +441,17 @@ var ANSI16_RGB = {
|
|
|
528
441
|
whiteBright: { r: 255, g: 255, b: 255 }
|
|
529
442
|
};
|
|
530
443
|
function nearestAnsi16(r, g, b) {
|
|
531
|
-
let best = "white";
|
|
532
|
-
let
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
const dg = g - rgb.g;
|
|
536
|
-
const db = b - rgb.b;
|
|
537
|
-
const d = dr * dr + dg * dg + db * db;
|
|
538
|
-
if (d < bestDist) {
|
|
539
|
-
bestDist = d;
|
|
540
|
-
best = name;
|
|
541
|
-
}
|
|
444
|
+
let best = "white", bestDist = Number.POSITIVE_INFINITY;
|
|
445
|
+
for (let [name, rgb] of Object.entries(ANSI16_RGB)) {
|
|
446
|
+
let dr = r - rgb.r, dg = g - rgb.g, db = b - rgb.b, d = dr * dr + dg * dg + db * db;
|
|
447
|
+
d < bestDist && (bestDist = d, best = name);
|
|
542
448
|
}
|
|
543
449
|
return best;
|
|
544
450
|
}
|
|
545
451
|
function ansi256ToRgb2(index) {
|
|
546
|
-
|
|
452
|
+
let n = Math.max(0, Math.min(255, Math.trunc(index)));
|
|
547
453
|
if (n < 16) {
|
|
548
|
-
|
|
454
|
+
let name = [
|
|
549
455
|
"black",
|
|
550
456
|
"red",
|
|
551
457
|
"green",
|
|
@@ -562,73 +468,65 @@ function ansi256ToRgb2(index) {
|
|
|
562
468
|
"magentaBright",
|
|
563
469
|
"cyanBright",
|
|
564
470
|
"whiteBright"
|
|
565
|
-
];
|
|
566
|
-
const name = map[n] ?? "white";
|
|
471
|
+
][n] ?? "white";
|
|
567
472
|
return ANSI16_RGB[name];
|
|
568
473
|
}
|
|
569
474
|
if (n >= 232) {
|
|
570
|
-
|
|
475
|
+
let c = 8 + (n - 232) * 10;
|
|
571
476
|
return { r: c, g: c, b: c };
|
|
572
477
|
}
|
|
573
|
-
|
|
574
|
-
const rr = Math.floor(i / 36);
|
|
575
|
-
const gg = Math.floor(i % 36 / 6);
|
|
576
|
-
const bb = i % 6;
|
|
577
|
-
const toComponent = (v) => v === 0 ? 0 : 55 + v * 40;
|
|
478
|
+
let i = n - 16, rr = Math.floor(i / 36), gg = Math.floor(i % 36 / 6), bb = i % 6, toComponent = (v) => v === 0 ? 0 : 55 + v * 40;
|
|
578
479
|
return { r: toComponent(rr), g: toComponent(gg), b: toComponent(bb) };
|
|
579
480
|
}
|
|
580
481
|
function applyAnsiSgrStyle(current, codes) {
|
|
581
482
|
let next = { ...current };
|
|
582
483
|
for (let i = 0; i < codes.length; i++) {
|
|
583
|
-
|
|
484
|
+
let code = codes[i];
|
|
584
485
|
if (code === 0) {
|
|
585
486
|
next = {};
|
|
586
487
|
continue;
|
|
587
488
|
}
|
|
588
|
-
if (code === 1)
|
|
589
|
-
next = { ...next, bold:
|
|
590
|
-
|
|
591
|
-
next = { ...next, dim:
|
|
592
|
-
|
|
593
|
-
next = { ...next, italic:
|
|
594
|
-
|
|
595
|
-
next = { ...next, underline:
|
|
596
|
-
|
|
597
|
-
next = { ...next, inverse:
|
|
598
|
-
|
|
599
|
-
next = { ...next, bold:
|
|
600
|
-
|
|
601
|
-
next = { ...next, italic:
|
|
602
|
-
|
|
603
|
-
next = { ...next, underline:
|
|
604
|
-
|
|
605
|
-
next = { ...next, inverse:
|
|
606
|
-
|
|
489
|
+
if (code === 1)
|
|
490
|
+
next = { ...next, bold: !0 };
|
|
491
|
+
else if (code === 2)
|
|
492
|
+
next = { ...next, dim: !0 };
|
|
493
|
+
else if (code === 3)
|
|
494
|
+
next = { ...next, italic: !0 };
|
|
495
|
+
else if (code === 4)
|
|
496
|
+
next = { ...next, underline: !0 };
|
|
497
|
+
else if (code === 7)
|
|
498
|
+
next = { ...next, inverse: !0 };
|
|
499
|
+
else if (code === 22)
|
|
500
|
+
next = { ...next, bold: !1, dim: !1 };
|
|
501
|
+
else if (code === 23)
|
|
502
|
+
next = { ...next, italic: !1 };
|
|
503
|
+
else if (code === 24)
|
|
504
|
+
next = { ...next, underline: !1 };
|
|
505
|
+
else if (code === 27)
|
|
506
|
+
next = { ...next, inverse: !1 };
|
|
507
|
+
else if (code === 39)
|
|
607
508
|
next = { ...next, fg: void 0 };
|
|
608
|
-
|
|
509
|
+
else if (code === 49)
|
|
609
510
|
next = { ...next, bg: void 0 };
|
|
610
|
-
|
|
611
|
-
|
|
511
|
+
else if (code >= 30 && code <= 37 || code >= 90 && code <= 97) {
|
|
512
|
+
let fg = ansi16ToColorName(code);
|
|
612
513
|
next = { ...next, fg: fg ?? next.fg };
|
|
613
514
|
} else if (code >= 40 && code <= 47 || code >= 100 && code <= 107) {
|
|
614
|
-
|
|
515
|
+
let bg = ansi16BgToColorName(code);
|
|
615
516
|
next = { ...next, bg: bg ?? next.bg };
|
|
616
517
|
} else if (code === 38 || code === 48) {
|
|
617
|
-
|
|
518
|
+
let mode = codes[i + 1];
|
|
618
519
|
if (mode === 5) {
|
|
619
|
-
|
|
520
|
+
let idx = codes[i + 2];
|
|
620
521
|
if (idx != null) {
|
|
621
|
-
|
|
622
|
-
const name = nearestAnsi16(r, g, b);
|
|
522
|
+
let { r, g, b } = ansi256ToRgb2(idx), name = nearestAnsi16(r, g, b);
|
|
623
523
|
next = code === 38 ? { ...next, fg: name } : { ...next, bg: name };
|
|
624
524
|
}
|
|
625
525
|
i += 2;
|
|
626
526
|
} else if (mode === 2) {
|
|
627
|
-
|
|
628
|
-
const g = codes[i + 3];
|
|
629
|
-
const b = codes[i + 4];
|
|
527
|
+
let r = codes[i + 2], g = codes[i + 3], b = codes[i + 4];
|
|
630
528
|
if (r != null && g != null && b != null) {
|
|
631
|
-
|
|
529
|
+
let name = nearestAnsi16(r, g, b);
|
|
632
530
|
next = code === 38 ? { ...next, fg: name } : { ...next, bg: name };
|
|
633
531
|
}
|
|
634
532
|
i += 4;
|
|
@@ -638,15 +536,13 @@ function applyAnsiSgrStyle(current, codes) {
|
|
|
638
536
|
return next;
|
|
639
537
|
}
|
|
640
538
|
function parseAnsiSgr(input, baseStyle = {}) {
|
|
641
|
-
|
|
642
|
-
let style = { ...baseStyle };
|
|
643
|
-
let lastIndex = 0;
|
|
539
|
+
let segments = [], style = { ...baseStyle }, lastIndex = 0;
|
|
644
540
|
for (let i = 0; i < input.length; i++) {
|
|
645
541
|
if (input[i] !== ESC3 || input[i + 1] !== "[")
|
|
646
542
|
continue;
|
|
647
543
|
let j = i + 2;
|
|
648
|
-
|
|
649
|
-
|
|
544
|
+
for (; j < input.length; ) {
|
|
545
|
+
let c = input.charCodeAt(j);
|
|
650
546
|
if (c >= 48 && c <= 57 || c === 59) {
|
|
651
547
|
j++;
|
|
652
548
|
continue;
|
|
@@ -655,32 +551,139 @@ function parseAnsiSgr(input, baseStyle = {}) {
|
|
|
655
551
|
}
|
|
656
552
|
if (j >= input.length || input[j] !== "m")
|
|
657
553
|
continue;
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
lastIndex = j + 1;
|
|
664
|
-
i = j;
|
|
665
|
-
}
|
|
666
|
-
if (lastIndex < input.length)
|
|
667
|
-
segments.push({ text: input.slice(lastIndex), style });
|
|
668
|
-
return segments;
|
|
554
|
+
i > lastIndex && segments.push({ text: input.slice(lastIndex, i), style });
|
|
555
|
+
let codes = input.slice(i + 2, j).split(";").filter(Boolean).map((n) => Number.parseInt(n, 10)).filter((n) => Number.isFinite(n));
|
|
556
|
+
style = applyAnsiSgrStyle(style, codes.length ? codes : [0]), lastIndex = j + 1, i = j;
|
|
557
|
+
}
|
|
558
|
+
return lastIndex < input.length && segments.push({ text: input.slice(lastIndex), style }), segments;
|
|
669
559
|
}
|
|
670
560
|
|
|
671
|
-
// src/core/buffer/
|
|
561
|
+
// src/core/buffer/eaw-ranges-unicode-17.ts
|
|
672
562
|
var fullWidthRanges = [
|
|
673
563
|
[4352, 4447],
|
|
564
|
+
[8986, 8987],
|
|
674
565
|
[9001, 9002],
|
|
675
|
-
[
|
|
566
|
+
[9193, 9196],
|
|
567
|
+
[9200, 9200],
|
|
568
|
+
[9203, 9203],
|
|
569
|
+
[9725, 9726],
|
|
570
|
+
[9748, 9749],
|
|
571
|
+
[9776, 9783],
|
|
572
|
+
[9800, 9811],
|
|
573
|
+
[9855, 9855],
|
|
574
|
+
[9866, 9871],
|
|
575
|
+
[9875, 9875],
|
|
576
|
+
[9889, 9889],
|
|
577
|
+
[9898, 9899],
|
|
578
|
+
[9917, 9918],
|
|
579
|
+
[9924, 9925],
|
|
580
|
+
[9934, 9934],
|
|
581
|
+
[9940, 9940],
|
|
582
|
+
[9962, 9962],
|
|
583
|
+
[9970, 9971],
|
|
584
|
+
[9973, 9973],
|
|
585
|
+
[9978, 9978],
|
|
586
|
+
[9981, 9981],
|
|
587
|
+
[9989, 9989],
|
|
588
|
+
[9994, 9995],
|
|
589
|
+
[10024, 10024],
|
|
590
|
+
[10060, 10060],
|
|
591
|
+
[10062, 10062],
|
|
592
|
+
[10067, 10069],
|
|
593
|
+
[10071, 10071],
|
|
594
|
+
[10133, 10135],
|
|
595
|
+
[10160, 10160],
|
|
596
|
+
[10175, 10175],
|
|
597
|
+
[11035, 11036],
|
|
598
|
+
[11088, 11088],
|
|
599
|
+
[11093, 11093],
|
|
600
|
+
[11904, 11929],
|
|
601
|
+
[11931, 12019],
|
|
602
|
+
[12032, 12245],
|
|
603
|
+
[12272, 12350],
|
|
604
|
+
[12353, 12438],
|
|
605
|
+
[12441, 12543],
|
|
606
|
+
[12549, 12591],
|
|
607
|
+
[12593, 12686],
|
|
608
|
+
[12688, 12773],
|
|
609
|
+
[12783, 12830],
|
|
610
|
+
[12832, 12871],
|
|
611
|
+
[12880, 42124],
|
|
612
|
+
[42128, 42182],
|
|
613
|
+
[43360, 43388],
|
|
676
614
|
[44032, 55203],
|
|
677
615
|
[63744, 64255],
|
|
678
616
|
[65040, 65049],
|
|
679
|
-
[65072,
|
|
680
|
-
[
|
|
681
|
-
[
|
|
682
|
-
]
|
|
683
|
-
|
|
617
|
+
[65072, 65106],
|
|
618
|
+
[65108, 65126],
|
|
619
|
+
[65128, 65131],
|
|
620
|
+
[65281, 65376],
|
|
621
|
+
[65504, 65510],
|
|
622
|
+
[94176, 94180],
|
|
623
|
+
[94192, 94198],
|
|
624
|
+
[94208, 101589],
|
|
625
|
+
[101631, 101662],
|
|
626
|
+
[101760, 101874],
|
|
627
|
+
[110576, 110579],
|
|
628
|
+
[110581, 110587],
|
|
629
|
+
[110589, 110590],
|
|
630
|
+
[110592, 110882],
|
|
631
|
+
[110898, 110898],
|
|
632
|
+
[110928, 110930],
|
|
633
|
+
[110933, 110933],
|
|
634
|
+
[110948, 110951],
|
|
635
|
+
[110960, 111355],
|
|
636
|
+
[119552, 119638],
|
|
637
|
+
[119648, 119670],
|
|
638
|
+
[126980, 126980],
|
|
639
|
+
[127183, 127183],
|
|
640
|
+
[127374, 127374],
|
|
641
|
+
[127377, 127386],
|
|
642
|
+
[127488, 127490],
|
|
643
|
+
[127504, 127547],
|
|
644
|
+
[127552, 127560],
|
|
645
|
+
[127568, 127569],
|
|
646
|
+
[127584, 127589],
|
|
647
|
+
[127744, 127776],
|
|
648
|
+
[127789, 127797],
|
|
649
|
+
[127799, 127868],
|
|
650
|
+
[127870, 127891],
|
|
651
|
+
[127904, 127946],
|
|
652
|
+
[127951, 127955],
|
|
653
|
+
[127968, 127984],
|
|
654
|
+
[127988, 127988],
|
|
655
|
+
[127992, 128062],
|
|
656
|
+
[128064, 128064],
|
|
657
|
+
[128066, 128252],
|
|
658
|
+
[128255, 128317],
|
|
659
|
+
[128331, 128334],
|
|
660
|
+
[128336, 128359],
|
|
661
|
+
[128378, 128378],
|
|
662
|
+
[128405, 128406],
|
|
663
|
+
[128420, 128420],
|
|
664
|
+
[128507, 128591],
|
|
665
|
+
[128640, 128709],
|
|
666
|
+
[128716, 128716],
|
|
667
|
+
[128720, 128722],
|
|
668
|
+
[128725, 128728],
|
|
669
|
+
[128732, 128735],
|
|
670
|
+
[128747, 128748],
|
|
671
|
+
[128756, 128764],
|
|
672
|
+
[128992, 129003],
|
|
673
|
+
[129008, 129008],
|
|
674
|
+
[129292, 129338],
|
|
675
|
+
[129340, 129349],
|
|
676
|
+
[129351, 129535],
|
|
677
|
+
[129648, 129660],
|
|
678
|
+
[129664, 129674],
|
|
679
|
+
[129678, 129734],
|
|
680
|
+
[129736, 129736],
|
|
681
|
+
[129741, 129756],
|
|
682
|
+
[129759, 129770],
|
|
683
|
+
[129775, 129784],
|
|
684
|
+
[131072, 196605],
|
|
685
|
+
[196608, 262141]
|
|
686
|
+
], ambiguousWidthRanges = [
|
|
684
687
|
[161, 161],
|
|
685
688
|
[164, 164],
|
|
686
689
|
[167, 168],
|
|
@@ -734,6 +737,7 @@ var ambiguousWidthRanges = [
|
|
|
734
737
|
[728, 731],
|
|
735
738
|
[733, 733],
|
|
736
739
|
[735, 735],
|
|
740
|
+
[768, 879],
|
|
737
741
|
[913, 929],
|
|
738
742
|
[931, 937],
|
|
739
743
|
[945, 961],
|
|
@@ -741,7 +745,8 @@ var ambiguousWidthRanges = [
|
|
|
741
745
|
[1025, 1025],
|
|
742
746
|
[1040, 1103],
|
|
743
747
|
[1105, 1105],
|
|
744
|
-
[8208,
|
|
748
|
+
[8208, 8208],
|
|
749
|
+
[8211, 8214],
|
|
745
750
|
[8216, 8217],
|
|
746
751
|
[8220, 8221],
|
|
747
752
|
[8224, 8226],
|
|
@@ -803,7 +808,8 @@ var ambiguousWidthRanges = [
|
|
|
803
808
|
[8895, 8895],
|
|
804
809
|
[8978, 8978],
|
|
805
810
|
[9312, 9449],
|
|
806
|
-
[9451,
|
|
811
|
+
[9451, 9547],
|
|
812
|
+
[9552, 9587],
|
|
807
813
|
[9600, 9615],
|
|
808
814
|
[9618, 9621],
|
|
809
815
|
[9632, 9633],
|
|
@@ -829,33 +835,72 @@ var ambiguousWidthRanges = [
|
|
|
829
835
|
[9831, 9834],
|
|
830
836
|
[9836, 9837],
|
|
831
837
|
[9839, 9839],
|
|
838
|
+
[9886, 9887],
|
|
839
|
+
[9919, 9919],
|
|
840
|
+
[9926, 9933],
|
|
841
|
+
[9935, 9939],
|
|
842
|
+
[9941, 9953],
|
|
843
|
+
[9955, 9955],
|
|
844
|
+
[9960, 9961],
|
|
845
|
+
[9963, 9969],
|
|
846
|
+
[9972, 9972],
|
|
847
|
+
[9974, 9977],
|
|
848
|
+
[9979, 9980],
|
|
849
|
+
[9982, 9983],
|
|
832
850
|
[10045, 10045],
|
|
833
851
|
[10102, 10111],
|
|
834
|
-
[11094,
|
|
852
|
+
[11094, 11097],
|
|
853
|
+
[12872, 12879],
|
|
835
854
|
[57344, 63743],
|
|
836
|
-
[
|
|
855
|
+
[65024, 65039],
|
|
856
|
+
[65533, 65533],
|
|
857
|
+
[127232, 127242],
|
|
858
|
+
[127248, 127277],
|
|
859
|
+
[127280, 127337],
|
|
860
|
+
[127344, 127373],
|
|
861
|
+
[127375, 127376],
|
|
862
|
+
[127387, 127404],
|
|
863
|
+
[917760, 917999],
|
|
864
|
+
[983040, 1048573],
|
|
865
|
+
[1048576, 1114109]
|
|
837
866
|
];
|
|
867
|
+
|
|
868
|
+
// src/core/buffer/width.ts
|
|
838
869
|
function isFullWidthCodePoint(codePoint) {
|
|
839
|
-
if (codePoint < 4352
|
|
840
|
-
return
|
|
841
|
-
for (
|
|
870
|
+
if (codePoint < 4352)
|
|
871
|
+
return !1;
|
|
872
|
+
for (let [start, end] of fullWidthRanges) {
|
|
842
873
|
if (codePoint < start)
|
|
843
|
-
return
|
|
874
|
+
return !1;
|
|
844
875
|
if (codePoint <= end)
|
|
845
|
-
return
|
|
876
|
+
return !0;
|
|
846
877
|
}
|
|
847
|
-
return
|
|
878
|
+
return !1;
|
|
848
879
|
}
|
|
849
880
|
function isAmbiguousWidthCodePoint(codePoint) {
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
881
|
+
let first = ambiguousWidthRanges[0], last = ambiguousWidthRanges[ambiguousWidthRanges.length - 1];
|
|
882
|
+
if (!first || !last || codePoint < first[0] || codePoint > last[1])
|
|
883
|
+
return !1;
|
|
884
|
+
for (let [start, end] of ambiguousWidthRanges) {
|
|
853
885
|
if (codePoint < start)
|
|
854
|
-
return
|
|
886
|
+
return !1;
|
|
855
887
|
if (codePoint <= end)
|
|
856
|
-
return
|
|
888
|
+
return !0;
|
|
857
889
|
}
|
|
858
|
-
return
|
|
890
|
+
return !1;
|
|
891
|
+
}
|
|
892
|
+
function isVariationSelectorCodePoint(codePoint) {
|
|
893
|
+
return codePoint >= 65024 && codePoint <= 65039 || codePoint >= 917760 && codePoint <= 917999;
|
|
894
|
+
}
|
|
895
|
+
function isCombiningMarkCodePoint(codePoint) {
|
|
896
|
+
return codePoint >= 768 && codePoint <= 879 || // Combining Diacritical Marks
|
|
897
|
+
codePoint >= 6832 && codePoint <= 6911 || // Combining Diacritical Marks Extended
|
|
898
|
+
codePoint >= 7616 && codePoint <= 7679 || // Combining Diacritical Marks Supplement
|
|
899
|
+
codePoint >= 8400 && codePoint <= 8447 || // Combining Diacritical Marks for Symbols
|
|
900
|
+
codePoint >= 65056 && codePoint <= 65071 || // Combining Half Marks
|
|
901
|
+
codePoint >= 12330 && codePoint <= 12335 || // EAW=W: Ideographic level tone marks
|
|
902
|
+
codePoint >= 12441 && codePoint <= 12442 || // EAW=W: Combining Katakana-Hiragana marks
|
|
903
|
+
codePoint === 94180;
|
|
859
904
|
}
|
|
860
905
|
function isEmojiLike(codePoint) {
|
|
861
906
|
return codePoint >= 127744 && codePoint <= 129791 || codePoint >= 127462 && codePoint <= 127487;
|
|
@@ -884,93 +929,61 @@ function normalizeCustomWidth(width) {
|
|
|
884
929
|
function charCellWidth(text, provider = "default") {
|
|
885
930
|
if (!text)
|
|
886
931
|
return 1;
|
|
887
|
-
if (typeof provider
|
|
932
|
+
if (typeof provider == "function")
|
|
888
933
|
return normalizeCustomWidth(provider(text));
|
|
889
|
-
if (provider !== "cjk" && text.length === 1)
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
return 1;
|
|
893
|
-
}
|
|
894
|
-
const codePoint = text.codePointAt(0);
|
|
934
|
+
if (provider !== "cjk" && text.length === 1 && text.charCodeAt(0) < 4352)
|
|
935
|
+
return 1;
|
|
936
|
+
let codePoint = text.codePointAt(0);
|
|
895
937
|
if (codePoint == null)
|
|
896
938
|
return 1;
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
return 2;
|
|
900
|
-
if (provider === "cjk" && isAmbiguousWidthCodePoint(codePoint))
|
|
901
|
-
return 2;
|
|
902
|
-
if (isEmojiLike(codePoint))
|
|
903
|
-
return 2;
|
|
904
|
-
if (emojiPresentationRe?.test(text))
|
|
905
|
-
return 2;
|
|
906
|
-
if (text.includes("\u20E3"))
|
|
907
|
-
return 2;
|
|
908
|
-
if (hasVs16 && emojiRe?.test(text))
|
|
909
|
-
return 2;
|
|
910
|
-
if (extendedPictographicRe?.test(text)) {
|
|
911
|
-
if (codePoint <= 65535)
|
|
912
|
-
return hasVs16 ? 2 : 1;
|
|
913
|
-
return 2;
|
|
914
|
-
}
|
|
915
|
-
return 1;
|
|
939
|
+
let hasVs16 = text.includes("\uFE0F");
|
|
940
|
+
return isVariationSelectorCodePoint(codePoint) || isCombiningMarkCodePoint(codePoint) || codePoint >= 9472 && codePoint <= 9599 ? 1 : isFullWidthCodePoint(codePoint) || provider === "cjk" && isAmbiguousWidthCodePoint(codePoint) || isEmojiLike(codePoint) || emojiPresentationRe?.test(text) || text.includes("\u20E3") || hasVs16 && emojiRe?.test(text) ? 2 : extendedPictographicRe?.test(text) ? codePoint <= 65535 ? hasVs16 ? 2 : 1 : 2 : 1;
|
|
916
941
|
}
|
|
917
942
|
|
|
918
943
|
// src/utils/url-safety.ts
|
|
919
944
|
var ENCODED_ASCII_CONTROL_RE = /%(?:0[0-9a-f]|1[0-9a-f]|7f)/i;
|
|
920
945
|
function hasControlCodePoint(value) {
|
|
921
946
|
for (let i = 0; i < value.length; i++) {
|
|
922
|
-
|
|
947
|
+
let code = value.charCodeAt(i);
|
|
923
948
|
if (code <= 31 || code >= 127 && code <= 159)
|
|
924
|
-
return
|
|
949
|
+
return !0;
|
|
925
950
|
}
|
|
926
|
-
return
|
|
951
|
+
return !1;
|
|
927
952
|
}
|
|
928
953
|
function hasEncodedControl(value) {
|
|
929
954
|
let current = String(value ?? "");
|
|
930
955
|
for (let depth = 0; depth < 3; depth++) {
|
|
931
956
|
if (ENCODED_ASCII_CONTROL_RE.test(current))
|
|
932
|
-
return
|
|
957
|
+
return !0;
|
|
933
958
|
let decoded;
|
|
934
959
|
try {
|
|
935
960
|
decoded = decodeURIComponent(current);
|
|
936
961
|
} catch {
|
|
937
|
-
return
|
|
962
|
+
return !0;
|
|
938
963
|
}
|
|
939
964
|
if (hasControlCodePoint(decoded))
|
|
940
|
-
return
|
|
965
|
+
return !0;
|
|
941
966
|
if (decoded === current)
|
|
942
|
-
return
|
|
967
|
+
return !1;
|
|
943
968
|
current = decoded;
|
|
944
969
|
}
|
|
945
970
|
return ENCODED_ASCII_CONTROL_RE.test(current) || hasControlCodePoint(current);
|
|
946
971
|
}
|
|
947
972
|
|
|
948
973
|
// src/core/hyperlink.ts
|
|
949
|
-
var SCHEME_RE = /^[a-z][a-z0-9+.-]*:/i;
|
|
950
|
-
var BLOCKED_SCHEME_RE = /^(?:javascript|data|vbscript):/i;
|
|
951
|
-
var SAFE_RELATIVE_HREF_RE = /^(?:[A-Za-z0-9._~!$&()*+,;=:@/?#-]|%[0-9A-Fa-f]{2})+$/u;
|
|
974
|
+
var SCHEME_RE = /^[a-z][a-z0-9+.-]*:/i, BLOCKED_SCHEME_RE = /^(?:javascript|data|vbscript):/i, SAFE_RELATIVE_HREF_RE = /^(?:[A-Za-z0-9._~!$&()*+,;=:@/?#-]|%[0-9A-Fa-f]{2})+$/u;
|
|
952
975
|
function normalizeRawHref(value) {
|
|
953
|
-
if (typeof value
|
|
976
|
+
if (typeof value != "string")
|
|
954
977
|
return null;
|
|
955
|
-
|
|
956
|
-
if (!raw)
|
|
957
|
-
return null;
|
|
958
|
-
if (raw !== value)
|
|
978
|
+
let raw = value.trim();
|
|
979
|
+
if (!raw || raw !== value)
|
|
959
980
|
return null;
|
|
960
981
|
for (let i = 0; i < value.length; i++) {
|
|
961
|
-
|
|
982
|
+
let code = value.charCodeAt(i);
|
|
962
983
|
if (code <= 31 || code >= 127 && code <= 159)
|
|
963
984
|
return null;
|
|
964
985
|
}
|
|
965
|
-
|
|
966
|
-
return null;
|
|
967
|
-
if (raw.startsWith("//"))
|
|
968
|
-
return null;
|
|
969
|
-
if (BLOCKED_SCHEME_RE.test(raw))
|
|
970
|
-
return null;
|
|
971
|
-
if (hasEncodedControl(raw))
|
|
972
|
-
return null;
|
|
973
|
-
return raw;
|
|
986
|
+
return /\s/u.test(raw) || raw.startsWith("//") || BLOCKED_SCHEME_RE.test(raw) || hasEncodedControl(raw) ? null : raw;
|
|
974
987
|
}
|
|
975
988
|
function hrefScheme(raw) {
|
|
976
989
|
return raw.match(SCHEME_RE)?.[0].toLowerCase() ?? null;
|
|
@@ -985,58 +998,33 @@ function parseSafeAbsoluteUrl(raw) {
|
|
|
985
998
|
}
|
|
986
999
|
}
|
|
987
1000
|
function sanitizeAbsoluteHref(raw, options = {}) {
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
return null;
|
|
991
|
-
if (url.protocol === "http:" || url.protocol === "https:") {
|
|
992
|
-
if (!/^https?:\/\//i.test(raw))
|
|
993
|
-
return null;
|
|
994
|
-
return options.preserveHttpHref ? raw : url.toString();
|
|
995
|
-
}
|
|
996
|
-
if (url.protocol === "mailto:")
|
|
997
|
-
return raw;
|
|
998
|
-
return null;
|
|
1001
|
+
let url = parseSafeAbsoluteUrl(raw);
|
|
1002
|
+
return url ? url.protocol === "http:" || url.protocol === "https:" ? /^https?:\/\//i.test(raw) ? options.preserveHttpHref ? raw : url.toString() : null : url.protocol === "mailto:" ? raw : null : null;
|
|
999
1003
|
}
|
|
1000
1004
|
function isSafeNormalizedRelativeHref(raw) {
|
|
1001
|
-
|
|
1002
|
-
return false;
|
|
1003
|
-
if (raw.startsWith("//"))
|
|
1004
|
-
return false;
|
|
1005
|
-
if (SCHEME_RE.test(raw))
|
|
1006
|
-
return false;
|
|
1007
|
-
if (hasEncodedControl(raw))
|
|
1008
|
-
return false;
|
|
1009
|
-
if (!SAFE_RELATIVE_HREF_RE.test(raw))
|
|
1010
|
-
return false;
|
|
1011
|
-
return raw.startsWith("#") || raw.startsWith("?") || raw.startsWith("/") || raw.startsWith("./") || raw.startsWith("../") || /^[A-Za-z0-9._~-]/u.test(raw);
|
|
1005
|
+
return raw.includes("\\") || raw.startsWith("//") || SCHEME_RE.test(raw) || hasEncodedControl(raw) || !SAFE_RELATIVE_HREF_RE.test(raw) ? !1 : raw.startsWith("#") || raw.startsWith("?") || raw.startsWith("/") || raw.startsWith("./") || raw.startsWith("../") || /^[A-Za-z0-9._~-]/u.test(raw);
|
|
1012
1006
|
}
|
|
1013
1007
|
function isSafeRelativeHref(value) {
|
|
1014
|
-
|
|
1008
|
+
let raw = normalizeRawHref(value);
|
|
1015
1009
|
return raw != null && isSafeNormalizedRelativeHref(raw);
|
|
1016
1010
|
}
|
|
1017
1011
|
function sanitizeTerminalHref(value, options = {}) {
|
|
1018
|
-
|
|
1012
|
+
let raw = normalizeRawHref(value);
|
|
1019
1013
|
if (!raw)
|
|
1020
1014
|
return null;
|
|
1021
|
-
|
|
1015
|
+
let sanitized = sanitizeAbsoluteHref(raw, { preserveHttpHref: !0 });
|
|
1022
1016
|
if (sanitized)
|
|
1023
1017
|
return sanitized;
|
|
1024
1018
|
if (options.allowFileUrls) {
|
|
1025
|
-
|
|
1019
|
+
let url = parseSafeAbsoluteUrl(raw);
|
|
1026
1020
|
if (url?.protocol === "file:")
|
|
1027
1021
|
return url.toString();
|
|
1028
1022
|
}
|
|
1029
1023
|
return null;
|
|
1030
1024
|
}
|
|
1031
1025
|
function sanitizeDomHref(value, options = {}) {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
return null;
|
|
1035
|
-
const scheme = hrefScheme(raw);
|
|
1036
|
-
if (!scheme) {
|
|
1037
|
-
return options.allowRelative !== false && isSafeNormalizedRelativeHref(raw) ? raw : null;
|
|
1038
|
-
}
|
|
1039
|
-
return sanitizeAbsoluteHref(raw);
|
|
1026
|
+
let raw = normalizeRawHref(value);
|
|
1027
|
+
return raw ? hrefScheme(raw) ? sanitizeAbsoluteHref(raw) : options.allowRelative !== !1 && isSafeNormalizedRelativeHref(raw) ? raw : null : null;
|
|
1040
1028
|
}
|
|
1041
1029
|
|
|
1042
1030
|
// src/core/render-plane.ts
|
|
@@ -1045,7 +1033,7 @@ var TERMINAL_RENDER_PLANES = ["default", "transcript", "chrome", "overlay"];
|
|
|
1045
1033
|
// src/utils/grapheme.ts
|
|
1046
1034
|
var graphemeSegmenter = null;
|
|
1047
1035
|
try {
|
|
1048
|
-
|
|
1036
|
+
let Segmenter = typeof Intl < "u" ? Intl.Segmenter : void 0;
|
|
1049
1037
|
graphemeSegmenter = Segmenter ? new Segmenter(void 0, { granularity: "grapheme" }) : null;
|
|
1050
1038
|
} catch {
|
|
1051
1039
|
graphemeSegmenter = null;
|
|
@@ -1057,28 +1045,18 @@ try {
|
|
|
1057
1045
|
unicodeMarkRe = null;
|
|
1058
1046
|
}
|
|
1059
1047
|
function needsGraphemeSegmentation(text) {
|
|
1060
|
-
for (
|
|
1061
|
-
|
|
1062
|
-
if (cp === 8205)
|
|
1063
|
-
return
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
if (isCombiningMark(cp))
|
|
1067
|
-
return true;
|
|
1068
|
-
if (cp >= 127995 && cp <= 127999)
|
|
1069
|
-
return true;
|
|
1070
|
-
if (cp >= 127462 && cp <= 127487)
|
|
1071
|
-
return true;
|
|
1072
|
-
if (cp >= 917504 && cp <= 917631)
|
|
1073
|
-
return true;
|
|
1074
|
-
}
|
|
1075
|
-
return false;
|
|
1048
|
+
for (let ch of text) {
|
|
1049
|
+
let cp = ch.codePointAt(0);
|
|
1050
|
+
if (cp === 8205 || cp >= 65024 && cp <= 65039 || cp >= 917760 && cp <= 917999 || isCombiningMark(cp) || cp >= 127995 && cp <= 127999 || cp >= 127462 && cp <= 127487 || cp >= 917504 && cp <= 917631)
|
|
1051
|
+
return !0;
|
|
1052
|
+
}
|
|
1053
|
+
return !1;
|
|
1076
1054
|
}
|
|
1077
1055
|
function isVariationSelector(codePoint) {
|
|
1078
1056
|
return codePoint >= 65024 && codePoint <= 65039 || codePoint >= 917760 && codePoint <= 917999;
|
|
1079
1057
|
}
|
|
1080
1058
|
function isCombiningMark(codePoint) {
|
|
1081
|
-
return codePoint >= 768 && codePoint <= 879 || codePoint >= 6832 && codePoint <= 6911 || codePoint >= 7616 && codePoint <= 7679 || codePoint >= 8400 && codePoint <= 8447 || codePoint >= 65056 && codePoint <= 65071 || isDevanagariMark(codePoint) || unicodeMarkRe?.test(String.fromCodePoint(codePoint)) ===
|
|
1059
|
+
return codePoint >= 768 && codePoint <= 879 || codePoint >= 6832 && codePoint <= 6911 || codePoint >= 7616 && codePoint <= 7679 || codePoint >= 8400 && codePoint <= 8447 || codePoint >= 65056 && codePoint <= 65071 || isDevanagariMark(codePoint) || unicodeMarkRe?.test(String.fromCodePoint(codePoint)) === !0;
|
|
1082
1060
|
}
|
|
1083
1061
|
function isDevanagariMark(codePoint) {
|
|
1084
1062
|
return codePoint >= 2304 && codePoint <= 2307 || codePoint >= 2362 && codePoint <= 2364 || codePoint >= 2366 && codePoint <= 2383 || codePoint >= 2385 && codePoint <= 2391 || codePoint >= 2402 && codePoint <= 2403;
|
|
@@ -1096,125 +1074,73 @@ function isEmojiTag(codePoint) {
|
|
|
1096
1074
|
return codePoint >= 917504 && codePoint <= 917631;
|
|
1097
1075
|
}
|
|
1098
1076
|
function fallbackGraphemeSegments(text) {
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
let segmentStart = 0;
|
|
1102
|
-
let pos = 0;
|
|
1103
|
-
let regionalIndicators = 0;
|
|
1104
|
-
let joinNext = false;
|
|
1105
|
-
const pushSegment = () => {
|
|
1106
|
-
if (segment)
|
|
1107
|
-
out.push({ segment, index: segmentStart });
|
|
1077
|
+
let out = [], segment = "", segmentStart = 0, pos = 0, regionalIndicators = 0, joinNext = !1, pushSegment = () => {
|
|
1078
|
+
segment && out.push({ segment, index: segmentStart });
|
|
1108
1079
|
};
|
|
1109
|
-
for (
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
pos += ch.length;
|
|
1113
|
-
const attach = segment !== "" && (joinNext || codePoint === 8205 || isVariationSelector(codePoint) || isCombiningMark(codePoint) || isEmojiModifier(codePoint) || isEmojiTag(codePoint) || isRegionalIndicator(codePoint) && regionalIndicators === 1);
|
|
1114
|
-
if (!attach) {
|
|
1115
|
-
pushSegment();
|
|
1116
|
-
segment = ch;
|
|
1117
|
-
segmentStart = chStart;
|
|
1118
|
-
regionalIndicators = isRegionalIndicator(codePoint) ? 1 : 0;
|
|
1119
|
-
} else {
|
|
1120
|
-
segment += ch;
|
|
1121
|
-
if (isRegionalIndicator(codePoint))
|
|
1122
|
-
regionalIndicators++;
|
|
1123
|
-
else if (!isVariationSelector(codePoint) && !isCombiningMark(codePoint))
|
|
1124
|
-
regionalIndicators = 0;
|
|
1125
|
-
}
|
|
1126
|
-
if (codePoint === 8205 || isVirama(codePoint))
|
|
1127
|
-
joinNext = true;
|
|
1128
|
-
else if (joinNext && !isVariationSelector(codePoint) && !isCombiningMark(codePoint)) {
|
|
1129
|
-
joinNext = false;
|
|
1130
|
-
}
|
|
1080
|
+
for (let ch of text) {
|
|
1081
|
+
let codePoint = ch.codePointAt(0), chStart = pos;
|
|
1082
|
+
pos += ch.length, segment !== "" && (joinNext || codePoint === 8205 || isVariationSelector(codePoint) || isCombiningMark(codePoint) || isEmojiModifier(codePoint) || isEmojiTag(codePoint) || isRegionalIndicator(codePoint) && regionalIndicators === 1) ? (segment += ch, isRegionalIndicator(codePoint) ? regionalIndicators++ : !isVariationSelector(codePoint) && !isCombiningMark(codePoint) && (regionalIndicators = 0)) : (pushSegment(), segment = ch, segmentStart = chStart, regionalIndicators = isRegionalIndicator(codePoint) ? 1 : 0), codePoint === 8205 || isVirama(codePoint) ? joinNext = !0 : joinNext && !isVariationSelector(codePoint) && !isCombiningMark(codePoint) && (joinNext = !1);
|
|
1131
1083
|
}
|
|
1132
|
-
pushSegment();
|
|
1133
|
-
return out;
|
|
1084
|
+
return pushSegment(), out;
|
|
1134
1085
|
}
|
|
1135
1086
|
function segmentedGraphemes(text) {
|
|
1136
|
-
|
|
1137
|
-
return null;
|
|
1138
|
-
if (graphemeSegmenter)
|
|
1139
|
-
return graphemeSegmenter.segment(text);
|
|
1140
|
-
return fallbackGraphemeSegments(text);
|
|
1087
|
+
return needsGraphemeSegmentation(text) ? graphemeSegmenter ? graphemeSegmenter.segment(text) : fallbackGraphemeSegments(text) : null;
|
|
1141
1088
|
}
|
|
1142
1089
|
|
|
1143
1090
|
// src/core/buffer/buffer.ts
|
|
1144
|
-
var DEFAULT_STYLE = Object.freeze({});
|
|
1145
|
-
var styleCache = /* @__PURE__ */ new WeakMap();
|
|
1146
|
-
var blankCellCache = /* @__PURE__ */ new WeakMap();
|
|
1147
|
-
var continuationCellCache = /* @__PURE__ */ new WeakMap();
|
|
1148
|
-
var cellCacheWidth1 = /* @__PURE__ */ new WeakMap();
|
|
1149
|
-
var cellCacheWidth2 = /* @__PURE__ */ new WeakMap();
|
|
1150
|
-
var MAX_CACHED_CELLS_PER_STYLE = 128;
|
|
1091
|
+
var DEFAULT_STYLE = Object.freeze({}), styleCache = /* @__PURE__ */ new WeakMap(), blankCellCache = /* @__PURE__ */ new WeakMap(), continuationCellCache = /* @__PURE__ */ new WeakMap(), cellCacheWidth1 = /* @__PURE__ */ new WeakMap(), cellCacheWidth2 = /* @__PURE__ */ new WeakMap(), MAX_CACHED_CELLS_PER_STYLE = 128;
|
|
1151
1092
|
function normalizeStyle(style) {
|
|
1152
1093
|
if (!style)
|
|
1153
1094
|
return DEFAULT_STYLE;
|
|
1154
1095
|
if (Object.isFrozen(style))
|
|
1155
1096
|
return style;
|
|
1156
|
-
|
|
1097
|
+
let cached = styleCache.get(style);
|
|
1157
1098
|
if (cached)
|
|
1158
1099
|
return cached;
|
|
1159
|
-
|
|
1160
|
-
styleCache.set(style, frozen);
|
|
1161
|
-
return frozen;
|
|
1100
|
+
let frozen = Object.freeze({ ...style });
|
|
1101
|
+
return styleCache.set(style, frozen), frozen;
|
|
1162
1102
|
}
|
|
1163
1103
|
function getOrCreateCellCache(map, style) {
|
|
1164
|
-
|
|
1104
|
+
let cached = map.get(style);
|
|
1165
1105
|
if (cached)
|
|
1166
1106
|
return cached;
|
|
1167
|
-
|
|
1168
|
-
map.set(style, next);
|
|
1169
|
-
return next;
|
|
1107
|
+
let next = /* @__PURE__ */ new Map();
|
|
1108
|
+
return map.set(style, next), next;
|
|
1170
1109
|
}
|
|
1171
1110
|
function createCell(ch, style, widthProvider) {
|
|
1172
1111
|
if (ch === " ")
|
|
1173
1112
|
return createBlankCell(style);
|
|
1174
|
-
|
|
1175
|
-
const width = charCellWidth(ch, widthProvider);
|
|
1176
|
-
const map = width === 2 ? getOrCreateCellCache(cellCacheWidth2, normalizedStyle) : getOrCreateCellCache(cellCacheWidth1, normalizedStyle);
|
|
1177
|
-
const cached = map.get(ch);
|
|
1113
|
+
let normalizedStyle = normalizeStyle(style), width = charCellWidth(ch, widthProvider), map = getOrCreateCellCache(width === 2 ? cellCacheWidth2 : cellCacheWidth1, normalizedStyle), cached = map.get(ch);
|
|
1178
1114
|
if (cached)
|
|
1179
1115
|
return cached;
|
|
1180
|
-
|
|
1181
|
-
map.set(ch, cell);
|
|
1182
|
-
if (map.size > MAX_CACHED_CELLS_PER_STYLE)
|
|
1183
|
-
map.clear();
|
|
1184
|
-
return cell;
|
|
1116
|
+
let cell = { ch, width, style: normalizedStyle };
|
|
1117
|
+
return map.set(ch, cell), map.size > MAX_CACHED_CELLS_PER_STYLE && map.clear(), cell;
|
|
1185
1118
|
}
|
|
1186
1119
|
function createBlankCell(style) {
|
|
1187
|
-
|
|
1188
|
-
const cached = blankCellCache.get(normalizedStyle);
|
|
1120
|
+
let normalizedStyle = normalizeStyle(style), cached = blankCellCache.get(normalizedStyle);
|
|
1189
1121
|
if (cached)
|
|
1190
1122
|
return cached;
|
|
1191
|
-
|
|
1123
|
+
let cell = Object.freeze({
|
|
1192
1124
|
ch: " ",
|
|
1193
1125
|
width: 1,
|
|
1194
1126
|
style: normalizedStyle
|
|
1195
1127
|
});
|
|
1196
|
-
blankCellCache.set(normalizedStyle, cell);
|
|
1197
|
-
return cell;
|
|
1128
|
+
return blankCellCache.set(normalizedStyle, cell), cell;
|
|
1198
1129
|
}
|
|
1199
1130
|
function createContinuationCell(style) {
|
|
1200
|
-
|
|
1201
|
-
const cached = continuationCellCache.get(normalizedStyle);
|
|
1131
|
+
let normalizedStyle = normalizeStyle(style), cached = continuationCellCache.get(normalizedStyle);
|
|
1202
1132
|
if (cached)
|
|
1203
1133
|
return cached;
|
|
1204
|
-
|
|
1134
|
+
let cell = Object.freeze({
|
|
1205
1135
|
ch: "",
|
|
1206
1136
|
width: 1,
|
|
1207
|
-
continuation:
|
|
1137
|
+
continuation: !0,
|
|
1208
1138
|
style: normalizedStyle
|
|
1209
1139
|
});
|
|
1210
|
-
continuationCellCache.set(normalizedStyle, cell);
|
|
1211
|
-
return cell;
|
|
1140
|
+
return continuationCellCache.set(normalizedStyle, cell), cell;
|
|
1212
1141
|
}
|
|
1213
1142
|
function createGridBuffer(cols, rows, options = {}) {
|
|
1214
|
-
|
|
1215
|
-
const safeRows = Math.max(0, Math.floor(rows));
|
|
1216
|
-
const blank = createBlankCell();
|
|
1217
|
-
const grid = Array.from(
|
|
1143
|
+
let safeCols = Math.max(0, Math.floor(cols)), safeRows = Math.max(0, Math.floor(rows)), blank = createBlankCell(), grid = Array.from(
|
|
1218
1144
|
{ length: safeRows },
|
|
1219
1145
|
() => Array.from({ length: safeCols }, () => blank)
|
|
1220
1146
|
);
|
|
@@ -1230,7 +1156,7 @@ function createGridBuffer(cols, rows, options = {}) {
|
|
|
1230
1156
|
dirtyAll: safeRows > 0,
|
|
1231
1157
|
cursorX: 0,
|
|
1232
1158
|
cursorY: 0,
|
|
1233
|
-
cursorVisible:
|
|
1159
|
+
cursorVisible: !0,
|
|
1234
1160
|
cursorStyle: DEFAULT_STYLE,
|
|
1235
1161
|
scrollback: [],
|
|
1236
1162
|
scrollbackLimit: 1e3,
|
|
@@ -1245,42 +1171,38 @@ function clamp(n, min, max) {
|
|
|
1245
1171
|
}
|
|
1246
1172
|
function setFingerprintFn(buffer, fn) {
|
|
1247
1173
|
buffer.fingerprintFn = fn;
|
|
1248
|
-
|
|
1249
|
-
if (!len) {
|
|
1174
|
+
let len = buffer.rows * buffer.cols;
|
|
1175
|
+
if (!fn || !len) {
|
|
1250
1176
|
buffer.soaFingerprints = null;
|
|
1251
1177
|
return;
|
|
1252
1178
|
}
|
|
1253
1179
|
buffer.soaFingerprints = new Uint32Array(len);
|
|
1254
1180
|
for (let y = 0; y < buffer.rows; y++) {
|
|
1255
|
-
|
|
1256
|
-
const physY = physicalRowIndex(buffer, y);
|
|
1257
|
-
const base = physY * buffer.cols;
|
|
1181
|
+
let row = getBufferRow(buffer, y), base = physicalRowIndex(buffer, y) * buffer.cols;
|
|
1258
1182
|
for (let x = 0; x < buffer.cols; x++) {
|
|
1259
|
-
|
|
1183
|
+
let cell = row[x];
|
|
1260
1184
|
buffer.soaFingerprints[base + x] = fn(cell.ch, cell.style);
|
|
1261
1185
|
}
|
|
1262
1186
|
}
|
|
1263
1187
|
}
|
|
1264
1188
|
function getRowFingerprints(buffer, y) {
|
|
1265
|
-
if (!buffer.soaFingerprints)
|
|
1189
|
+
if (!buffer.soaFingerprints || buffer.rows <= 0 || buffer.cols <= 0)
|
|
1190
|
+
return null;
|
|
1191
|
+
let yy = Math.floor(y);
|
|
1192
|
+
if (!Number.isFinite(yy) || yy < 0 || yy >= buffer.rows)
|
|
1266
1193
|
return null;
|
|
1267
|
-
|
|
1268
|
-
const base = physY * buffer.cols;
|
|
1194
|
+
let base = physicalRowIndex(buffer, yy) * buffer.cols;
|
|
1269
1195
|
return buffer.soaFingerprints.subarray(base, base + buffer.cols);
|
|
1270
1196
|
}
|
|
1271
1197
|
function updateCellFingerprint(buffer, physY, x, ch, style) {
|
|
1272
|
-
|
|
1273
|
-
return;
|
|
1274
|
-
buffer.soaFingerprints[physY * buffer.cols + x] = buffer.fingerprintFn(ch, style);
|
|
1198
|
+
!buffer.soaFingerprints || !buffer.fingerprintFn || (buffer.soaFingerprints[physY * buffer.cols + x] = buffer.fingerprintFn(ch, style));
|
|
1275
1199
|
}
|
|
1276
1200
|
function updateRangeFingerprint(buffer, physY, x0, x1, ch, style) {
|
|
1277
1201
|
if (!buffer.soaFingerprints || !buffer.fingerprintFn)
|
|
1278
1202
|
return;
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
for (let x = x0; x < x1; x++) {
|
|
1203
|
+
let fp = buffer.fingerprintFn(ch, style), base = physY * buffer.cols;
|
|
1204
|
+
for (let x = x0; x < x1; x++)
|
|
1282
1205
|
buffer.soaFingerprints[base + x] = fp;
|
|
1283
|
-
}
|
|
1284
1206
|
}
|
|
1285
1207
|
function physicalRowIndex(buffer, y) {
|
|
1286
1208
|
return (buffer.gridStart + y) % buffer.rows;
|
|
@@ -1292,400 +1214,264 @@ function getBufferCell(buffer, x, y) {
|
|
|
1292
1214
|
return getBufferRow(buffer, y)[x];
|
|
1293
1215
|
}
|
|
1294
1216
|
function markAllDirty(buffer) {
|
|
1295
|
-
|
|
1296
|
-
return;
|
|
1297
|
-
buffer.dirtyAll = true;
|
|
1298
|
-
buffer.dirtyCount = buffer.rows;
|
|
1299
|
-
buffer.dirtyMin = 0;
|
|
1300
|
-
buffer.dirtyMax = buffer.rows - 1;
|
|
1217
|
+
buffer.rows <= 0 || (buffer.dirtyAll = !0, buffer.dirtyCount = buffer.rows, buffer.dirtyMin = 0, buffer.dirtyMax = buffer.rows - 1);
|
|
1301
1218
|
}
|
|
1302
1219
|
function markDirty(buffer, y) {
|
|
1303
|
-
|
|
1304
|
-
return;
|
|
1305
|
-
if (y < 0 || y >= buffer.rows)
|
|
1306
|
-
return;
|
|
1307
|
-
if (buffer.dirtyBits[y]) {
|
|
1308
|
-
return;
|
|
1309
|
-
}
|
|
1310
|
-
buffer.dirtyBits[y] = 1;
|
|
1311
|
-
buffer.dirtyCount++;
|
|
1312
|
-
if (y < buffer.dirtyMin)
|
|
1313
|
-
buffer.dirtyMin = y;
|
|
1314
|
-
if (y > buffer.dirtyMax)
|
|
1315
|
-
buffer.dirtyMax = y;
|
|
1220
|
+
buffer.dirtyAll || y < 0 || y >= buffer.rows || buffer.dirtyBits[y] || (buffer.dirtyBits[y] = 1, buffer.dirtyCount++, y < buffer.dirtyMin && (buffer.dirtyMin = y), y > buffer.dirtyMax && (buffer.dirtyMax = y));
|
|
1316
1221
|
}
|
|
1317
1222
|
function clearCellRange(row, startX, endXExclusive) {
|
|
1318
|
-
|
|
1223
|
+
let blank = createBlankCell();
|
|
1319
1224
|
for (let x = startX; x < endXExclusive; x++)
|
|
1320
1225
|
row[x] = blank;
|
|
1321
1226
|
}
|
|
1322
1227
|
function clearWideIfOverwriting(row, x) {
|
|
1323
|
-
|
|
1324
|
-
if (
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
row[x] = createBlankCell();
|
|
1330
|
-
return;
|
|
1331
|
-
}
|
|
1332
|
-
if (cell.width === 2) {
|
|
1333
|
-
row[x] = createBlankCell();
|
|
1334
|
-
if (x + 1 < row.length)
|
|
1335
|
-
row[x + 1] = createBlankCell();
|
|
1228
|
+
let cell = row[x];
|
|
1229
|
+
if (cell) {
|
|
1230
|
+
if (cell.continuation) {
|
|
1231
|
+
x - 1 >= 0 && (row[x - 1] = createBlankCell()), row[x] = createBlankCell();
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1234
|
+
cell.width === 2 && (row[x] = createBlankCell(), x + 1 < row.length && (row[x + 1] = createBlankCell()));
|
|
1336
1235
|
}
|
|
1337
1236
|
}
|
|
1338
1237
|
function putCell(buffer, x, y, ch, style) {
|
|
1339
|
-
if (y < 0 || y >= buffer.rows)
|
|
1238
|
+
if (y < 0 || y >= buffer.rows || x < 0 || x >= buffer.cols)
|
|
1340
1239
|
return;
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
const next = width === 2 && x + 1 < buffer.cols ? row[x + 1] : void 0;
|
|
1347
|
-
const previousWideOverlap = Boolean(
|
|
1348
|
-
previous?.continuation || previous?.width === 2 || next?.continuation || next?.width === 2
|
|
1349
|
-
);
|
|
1350
|
-
clearWideIfOverwriting(row, x);
|
|
1351
|
-
if (width === 2 && x + 1 < buffer.cols)
|
|
1352
|
-
clearWideIfOverwriting(row, x + 1);
|
|
1353
|
-
if (width === 2 && x + 1 >= buffer.cols) {
|
|
1354
|
-
const blank = createBlankCell();
|
|
1355
|
-
row[x] = blank;
|
|
1356
|
-
if (buffer.soaFingerprints) {
|
|
1357
|
-
if (previousWideOverlap) {
|
|
1240
|
+
let row = getBufferRow(buffer, y), width = charCellWidth(ch, buffer.widthProvider), previous = row[x], next = width === 2 && x + 1 < buffer.cols ? row[x + 1] : void 0, previousWideOverlap = !!(previous?.continuation || previous?.width === 2 || next?.continuation || next?.width === 2);
|
|
1241
|
+
if (clearWideIfOverwriting(row, x), width === 2 && x + 1 < buffer.cols && clearWideIfOverwriting(row, x + 1), width === 2 && x + 1 >= buffer.cols) {
|
|
1242
|
+
let blank = createBlankCell();
|
|
1243
|
+
if (row[x] = blank, buffer.soaFingerprints)
|
|
1244
|
+
if (previousWideOverlap)
|
|
1358
1245
|
recomputeFingerprintsForRows(buffer, y, y + 1);
|
|
1359
|
-
|
|
1360
|
-
|
|
1246
|
+
else {
|
|
1247
|
+
let physY = physicalRowIndex(buffer, y);
|
|
1361
1248
|
updateCellFingerprint(buffer, physY, x, blank.ch, blank.style);
|
|
1362
1249
|
}
|
|
1363
|
-
}
|
|
1364
1250
|
markDirty(buffer, y);
|
|
1365
1251
|
return;
|
|
1366
1252
|
}
|
|
1367
|
-
|
|
1368
|
-
row[x] = cell
|
|
1369
|
-
|
|
1370
|
-
row[x + 1] = createContinuationCell(style);
|
|
1371
|
-
if (buffer.soaFingerprints) {
|
|
1372
|
-
if (previousWideOverlap) {
|
|
1253
|
+
let cell = createCell(ch, style, buffer.widthProvider);
|
|
1254
|
+
if (row[x] = cell, width === 2 && x + 1 < buffer.cols && (row[x + 1] = createContinuationCell(style)), buffer.soaFingerprints)
|
|
1255
|
+
if (previousWideOverlap)
|
|
1373
1256
|
recomputeFingerprintsForRows(buffer, y, y + 1);
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
updateCellFingerprint(buffer, physY, x, cell.ch, cell.style);
|
|
1377
|
-
if (width === 2 && x + 1 < buffer.cols) {
|
|
1378
|
-
updateCellFingerprint(buffer, physY, x + 1, "", cell.style);
|
|
1379
|
-
}
|
|
1257
|
+
else {
|
|
1258
|
+
let physY = physicalRowIndex(buffer, y);
|
|
1259
|
+
updateCellFingerprint(buffer, physY, x, cell.ch, cell.style), width === 2 && x + 1 < buffer.cols && updateCellFingerprint(buffer, physY, x + 1, "", cell.style);
|
|
1380
1260
|
}
|
|
1381
|
-
}
|
|
1382
1261
|
markDirty(buffer, y);
|
|
1383
1262
|
}
|
|
1384
1263
|
function fillRect(buffer, x, y, w, h, ch = " ", style) {
|
|
1385
1264
|
if (w <= 0 || h <= 0 || buffer.cols === 0 || buffer.rows === 0)
|
|
1386
1265
|
return;
|
|
1387
|
-
|
|
1388
|
-
const y0 = clamp(Math.floor(y), 0, buffer.rows);
|
|
1389
|
-
const x1 = clamp(Math.floor(x + w), 0, buffer.cols);
|
|
1390
|
-
const y1 = clamp(Math.floor(y + h), 0, buffer.rows);
|
|
1266
|
+
let x0 = clamp(Math.floor(x), 0, buffer.cols), y0 = clamp(Math.floor(y), 0, buffer.rows), x1 = clamp(Math.floor(x + w), 0, buffer.cols), y1 = clamp(Math.floor(y + h), 0, buffer.rows);
|
|
1391
1267
|
if (x1 <= x0 || y1 <= y0)
|
|
1392
1268
|
return;
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
const fillCell2 = createCell(ch, style, buffer.widthProvider);
|
|
1396
|
-
const blank2 = createBlankCell();
|
|
1269
|
+
if (charCellWidth(ch, buffer.widthProvider) === 1) {
|
|
1270
|
+
let fillCell2 = createCell(ch, style, buffer.widthProvider), blank2 = createBlankCell();
|
|
1397
1271
|
for (let yy = y0; yy < y1; yy++) {
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
if (clearsLeftWideBase)
|
|
1402
|
-
clearWideIfOverwriting(row, x0);
|
|
1403
|
-
row.fill(fillCell2, x0, x1);
|
|
1404
|
-
if (clearsRightContinuation)
|
|
1405
|
-
row[x1] = blank2;
|
|
1406
|
-
if (buffer.soaFingerprints) {
|
|
1407
|
-
if (clearsLeftWideBase || clearsRightContinuation) {
|
|
1272
|
+
let row = getBufferRow(buffer, yy), clearsLeftWideBase = !!row[x0]?.continuation, clearsRightContinuation = !!(x1 < buffer.cols && row[x1]?.continuation);
|
|
1273
|
+
if (clearsLeftWideBase && clearWideIfOverwriting(row, x0), row.fill(fillCell2, x0, x1), clearsRightContinuation && (row[x1] = blank2), buffer.soaFingerprints)
|
|
1274
|
+
if (clearsLeftWideBase || clearsRightContinuation)
|
|
1408
1275
|
recomputeFingerprintsForRows(buffer, yy, yy + 1);
|
|
1409
|
-
|
|
1410
|
-
|
|
1276
|
+
else {
|
|
1277
|
+
let physY = physicalRowIndex(buffer, yy);
|
|
1411
1278
|
updateRangeFingerprint(buffer, physY, x0, x1, fillCell2.ch, fillCell2.style);
|
|
1412
1279
|
}
|
|
1413
|
-
}
|
|
1414
1280
|
markDirty(buffer, yy);
|
|
1415
1281
|
}
|
|
1416
1282
|
return;
|
|
1417
1283
|
}
|
|
1418
|
-
|
|
1419
|
-
const continuationCell = createContinuationCell(style);
|
|
1420
|
-
const blank = createBlankCell();
|
|
1284
|
+
let fillCell = createCell(ch, style, buffer.widthProvider), continuationCell = createContinuationCell(style), blank = createBlankCell();
|
|
1421
1285
|
for (let yy = y0; yy < y1; yy++) {
|
|
1422
|
-
|
|
1286
|
+
let row = getBufferRow(buffer, yy);
|
|
1423
1287
|
for (let xx = x0; xx < x1; ) {
|
|
1424
|
-
clearWideIfOverwriting(row, xx)
|
|
1425
|
-
|
|
1426
|
-
row[xx] = blank;
|
|
1427
|
-
xx += 1;
|
|
1288
|
+
if (clearWideIfOverwriting(row, xx), xx + 1 >= x1 || xx + 1 >= buffer.cols) {
|
|
1289
|
+
row[xx] = blank, xx += 1;
|
|
1428
1290
|
continue;
|
|
1429
1291
|
}
|
|
1430
|
-
clearWideIfOverwriting(row, xx + 1);
|
|
1431
|
-
row[xx] = fillCell;
|
|
1432
|
-
row[xx + 1] = continuationCell;
|
|
1433
|
-
xx += 2;
|
|
1292
|
+
clearWideIfOverwriting(row, xx + 1), row[xx] = fillCell, row[xx + 1] = continuationCell, xx += 2;
|
|
1434
1293
|
}
|
|
1435
|
-
recomputeFingerprintsForRows(buffer, yy, yy + 1);
|
|
1436
|
-
markDirty(buffer, yy);
|
|
1294
|
+
recomputeFingerprintsForRows(buffer, yy, yy + 1), markDirty(buffer, yy);
|
|
1437
1295
|
}
|
|
1438
1296
|
}
|
|
1439
1297
|
function clearRect(buffer, x, y, w, h) {
|
|
1440
1298
|
if (buffer.cols === 0 || buffer.rows === 0)
|
|
1441
1299
|
return;
|
|
1442
1300
|
if (x == null || y == null || w == null || h == null) {
|
|
1443
|
-
|
|
1301
|
+
let blank = createBlankCell();
|
|
1444
1302
|
for (let yy = 0; yy < buffer.rows; yy++) {
|
|
1445
|
-
|
|
1303
|
+
let row = getBufferRow(buffer, yy);
|
|
1446
1304
|
row.length = buffer.cols;
|
|
1447
1305
|
for (let xx = 0; xx < buffer.cols; xx++)
|
|
1448
1306
|
row[xx] = blank;
|
|
1449
1307
|
}
|
|
1450
|
-
recomputeFingerprintsForRows(buffer, 0, buffer.rows);
|
|
1451
|
-
markAllDirty(buffer);
|
|
1452
|
-
buffer.cursorX = 0;
|
|
1453
|
-
buffer.cursorY = 0;
|
|
1308
|
+
recomputeFingerprintsForRows(buffer, 0, buffer.rows), markAllDirty(buffer), buffer.cursorX = 0, buffer.cursorY = 0;
|
|
1454
1309
|
return;
|
|
1455
1310
|
}
|
|
1456
1311
|
if (w <= 0 || h <= 0)
|
|
1457
1312
|
return;
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
for (let yy = y0; yy < y1; yy++) {
|
|
1465
|
-
const row = getBufferRow(buffer, yy);
|
|
1466
|
-
if (row[x0]?.continuation)
|
|
1467
|
-
clearWideIfOverwriting(row, x0);
|
|
1468
|
-
clearCellRange(row, x0, x1);
|
|
1469
|
-
if (x1 < buffer.cols && row[x1]?.continuation)
|
|
1470
|
-
row[x1] = createBlankCell();
|
|
1471
|
-
recomputeFingerprintsForRows(buffer, yy, yy + 1);
|
|
1472
|
-
markDirty(buffer, yy);
|
|
1473
|
-
}
|
|
1313
|
+
let x0 = clamp(Math.floor(x), 0, buffer.cols), y0 = clamp(Math.floor(y), 0, buffer.rows), x1 = clamp(Math.floor(x + w), 0, buffer.cols), y1 = clamp(Math.floor(y + h), 0, buffer.rows);
|
|
1314
|
+
if (!(x1 <= x0 || y1 <= y0))
|
|
1315
|
+
for (let yy = y0; yy < y1; yy++) {
|
|
1316
|
+
let row = getBufferRow(buffer, yy);
|
|
1317
|
+
row[x0]?.continuation && clearWideIfOverwriting(row, x0), clearCellRange(row, x0, x1), x1 < buffer.cols && row[x1]?.continuation && (row[x1] = createBlankCell()), recomputeFingerprintsForRows(buffer, yy, yy + 1), markDirty(buffer, yy);
|
|
1318
|
+
}
|
|
1474
1319
|
}
|
|
1475
1320
|
function takePooledRow(buffer) {
|
|
1476
|
-
|
|
1477
|
-
return row ?? null;
|
|
1321
|
+
return buffer.rowPool.pop() ?? null;
|
|
1478
1322
|
}
|
|
1479
1323
|
function blankRow(buffer) {
|
|
1480
|
-
|
|
1324
|
+
let pooled = takePooledRow(buffer);
|
|
1481
1325
|
if (!pooled)
|
|
1482
1326
|
return Array.from({ length: buffer.cols }, () => createBlankCell());
|
|
1483
1327
|
pooled.length = buffer.cols;
|
|
1484
|
-
|
|
1328
|
+
let blank = createBlankCell();
|
|
1485
1329
|
for (let x = 0; x < buffer.cols; x++)
|
|
1486
1330
|
pooled[x] = blank;
|
|
1487
1331
|
return pooled;
|
|
1488
1332
|
}
|
|
1489
1333
|
function recomputeFingerprintsForRows(buffer, startY, endY) {
|
|
1490
|
-
if (!buffer.soaFingerprints || !buffer.fingerprintFn)
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
const cell = row[x];
|
|
1498
|
-
buffer.soaFingerprints[base + x] = buffer.fingerprintFn(cell.ch, cell.style);
|
|
1334
|
+
if (!(!buffer.soaFingerprints || !buffer.fingerprintFn))
|
|
1335
|
+
for (let y = startY; y < endY; y++) {
|
|
1336
|
+
let row = getBufferRow(buffer, y), base = physicalRowIndex(buffer, y) * buffer.cols;
|
|
1337
|
+
for (let x = 0; x < buffer.cols; x++) {
|
|
1338
|
+
let cell = row[x];
|
|
1339
|
+
buffer.soaFingerprints[base + x] = buffer.fingerprintFn(cell.ch, cell.style);
|
|
1340
|
+
}
|
|
1499
1341
|
}
|
|
1500
|
-
}
|
|
1501
1342
|
}
|
|
1502
1343
|
function recomputeAllVisibleFingerprints(buffer) {
|
|
1503
1344
|
recomputeFingerprintsForRows(buffer, 0, buffer.rows);
|
|
1504
1345
|
}
|
|
1505
1346
|
function scrollBuffer(buffer, lines) {
|
|
1506
|
-
|
|
1347
|
+
let raw = Math.trunc(lines);
|
|
1507
1348
|
if (raw === 0 || buffer.rows === 0)
|
|
1508
1349
|
return;
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
if (n > 0) {
|
|
1350
|
+
let abs = Math.min(Math.abs(raw), buffer.rows), n = raw > 0 ? abs : -abs;
|
|
1351
|
+
if (n > 0)
|
|
1512
1352
|
for (let i = 0; i < n; i++) {
|
|
1513
|
-
|
|
1514
|
-
const removed = buffer.grid[removedIdx];
|
|
1353
|
+
let removedIdx = buffer.gridStart, removed = buffer.grid[removedIdx];
|
|
1515
1354
|
if (buffer.scrollbackLimit > 0) {
|
|
1516
|
-
buffer.scrollback.push(removed)
|
|
1517
|
-
|
|
1518
|
-
const excess = buffer.scrollback.length - buffer.scrollbackLimit;
|
|
1519
|
-
const dropped = buffer.scrollback.splice(0, excess);
|
|
1355
|
+
if (buffer.scrollback.push(removed), buffer.scrollback.length > buffer.scrollbackLimit) {
|
|
1356
|
+
let excess = buffer.scrollback.length - buffer.scrollbackLimit, dropped = buffer.scrollback.splice(0, excess);
|
|
1520
1357
|
buffer.rowPool.push(...dropped);
|
|
1521
1358
|
}
|
|
1522
|
-
} else
|
|
1359
|
+
} else
|
|
1523
1360
|
buffer.rowPool.push(removed);
|
|
1524
|
-
}
|
|
1525
1361
|
buffer.gridStart = (buffer.gridStart + 1) % buffer.rows;
|
|
1526
|
-
|
|
1362
|
+
let bottomIdx = (buffer.gridStart + buffer.rows - 1) % buffer.rows;
|
|
1527
1363
|
buffer.grid[bottomIdx] = blankRow(buffer);
|
|
1528
1364
|
}
|
|
1529
|
-
|
|
1365
|
+
else
|
|
1530
1366
|
for (let i = 0; i < -n; i++) {
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
buffer.rowPool.push(removed);
|
|
1534
|
-
buffer.gridStart = (buffer.gridStart - 1 + buffer.rows) % buffer.rows;
|
|
1535
|
-
buffer.grid[buffer.gridStart] = blankRow(buffer);
|
|
1367
|
+
let bottomIdx = (buffer.gridStart + buffer.rows - 1) % buffer.rows, removed = buffer.grid[bottomIdx];
|
|
1368
|
+
buffer.rowPool.push(removed), buffer.gridStart = (buffer.gridStart - 1 + buffer.rows) % buffer.rows, buffer.grid[buffer.gridStart] = blankRow(buffer);
|
|
1536
1369
|
}
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
if (inserted >= buffer.rows) {
|
|
1540
|
-
recomputeAllVisibleFingerprints(buffer);
|
|
1541
|
-
} else if (n > 0) {
|
|
1542
|
-
recomputeFingerprintsForRows(buffer, buffer.rows - inserted, buffer.rows);
|
|
1543
|
-
} else {
|
|
1544
|
-
recomputeFingerprintsForRows(buffer, 0, inserted);
|
|
1545
|
-
}
|
|
1546
|
-
markAllDirty(buffer);
|
|
1547
|
-
buffer.cursorY = clamp(buffer.cursorY - n, 0, Math.max(0, buffer.rows - 1));
|
|
1370
|
+
let inserted = Math.abs(n);
|
|
1371
|
+
inserted >= buffer.rows ? recomputeAllVisibleFingerprints(buffer) : n > 0 ? recomputeFingerprintsForRows(buffer, buffer.rows - inserted, buffer.rows) : recomputeFingerprintsForRows(buffer, 0, inserted), markAllDirty(buffer), buffer.cursorY = clamp(buffer.cursorY - n, 0, Math.max(0, buffer.rows - 1));
|
|
1548
1372
|
}
|
|
1549
1373
|
function scrollBufferRegion(buffer, startY, endY, lines) {
|
|
1550
|
-
|
|
1374
|
+
let n = Math.trunc(lines);
|
|
1551
1375
|
if (n === 0 || buffer.rows === 0)
|
|
1552
1376
|
return [];
|
|
1553
|
-
|
|
1554
|
-
const end = clamp(Math.floor(endY), 0, buffer.rows);
|
|
1555
|
-
const height = end - start;
|
|
1377
|
+
let start = clamp(Math.floor(startY), 0, buffer.rows), end = clamp(Math.floor(endY), 0, buffer.rows), height = end - start;
|
|
1556
1378
|
if (height <= 0)
|
|
1557
1379
|
return [];
|
|
1558
|
-
|
|
1559
|
-
const insertedRows = [];
|
|
1560
|
-
const replaceRegionWithBlankRows = () => {
|
|
1380
|
+
let absDelta = Math.abs(n), insertedRows = [], replaceRegionWithBlankRows = () => {
|
|
1561
1381
|
for (let y = start; y < end; y++) {
|
|
1562
|
-
|
|
1563
|
-
buffer.rowPool.push(buffer.grid[physY]);
|
|
1564
|
-
buffer.grid[physY] = blankRow(buffer);
|
|
1565
|
-
markDirty(buffer, y);
|
|
1566
|
-
insertedRows.push(y);
|
|
1382
|
+
let physY = physicalRowIndex(buffer, y);
|
|
1383
|
+
buffer.rowPool.push(buffer.grid[physY]), buffer.grid[physY] = blankRow(buffer), markDirty(buffer, y), insertedRows.push(y);
|
|
1567
1384
|
}
|
|
1568
1385
|
};
|
|
1569
|
-
if (absDelta >= height)
|
|
1570
|
-
replaceRegionWithBlankRows();
|
|
1571
|
-
|
|
1572
|
-
if (buffer.cursorY >= start && buffer.cursorY < end)
|
|
1573
|
-
buffer.cursorY = clamp(buffer.cursorY - n, start, Math.max(start, end - 1));
|
|
1574
|
-
return insertedRows;
|
|
1575
|
-
}
|
|
1576
|
-
const regionRows = [];
|
|
1386
|
+
if (absDelta >= height)
|
|
1387
|
+
return replaceRegionWithBlankRows(), recomputeFingerprintsForRows(buffer, start, end), buffer.cursorY >= start && buffer.cursorY < end && (buffer.cursorY = clamp(buffer.cursorY - n, start, Math.max(start, end - 1))), insertedRows;
|
|
1388
|
+
let regionRows = [];
|
|
1577
1389
|
for (let y = start; y < end; y++)
|
|
1578
1390
|
regionRows.push(getBufferRow(buffer, y));
|
|
1579
|
-
|
|
1391
|
+
let nextRows = Array.from({ length: height }, () => []);
|
|
1580
1392
|
if (n > 0) {
|
|
1581
|
-
|
|
1393
|
+
let movedCount = height - n;
|
|
1582
1394
|
for (let i = 0; i < movedCount; i++)
|
|
1583
1395
|
nextRows[i] = regionRows[i + n];
|
|
1584
1396
|
for (let i = 0; i < n; i++) {
|
|
1585
1397
|
buffer.rowPool.push(regionRows[i]);
|
|
1586
|
-
|
|
1587
|
-
nextRows[movedCount + i] = blankRow(buffer);
|
|
1588
|
-
markDirty(buffer, y);
|
|
1589
|
-
insertedRows.push(y);
|
|
1398
|
+
let y = end - n + i;
|
|
1399
|
+
nextRows[movedCount + i] = blankRow(buffer), markDirty(buffer, y), insertedRows.push(y);
|
|
1590
1400
|
}
|
|
1591
1401
|
} else {
|
|
1592
|
-
|
|
1593
|
-
const movedCount = height - insertedCount;
|
|
1402
|
+
let insertedCount = -n, movedCount = height - insertedCount;
|
|
1594
1403
|
for (let i = 0; i < insertedCount; i++) {
|
|
1595
1404
|
buffer.rowPool.push(regionRows[height - insertedCount + i]);
|
|
1596
|
-
|
|
1597
|
-
nextRows[i] = blankRow(buffer);
|
|
1598
|
-
markDirty(buffer, y);
|
|
1599
|
-
insertedRows.push(y);
|
|
1405
|
+
let y = start + i;
|
|
1406
|
+
nextRows[i] = blankRow(buffer), markDirty(buffer, y), insertedRows.push(y);
|
|
1600
1407
|
}
|
|
1601
1408
|
for (let i = 0; i < movedCount; i++)
|
|
1602
1409
|
nextRows[insertedCount + i] = regionRows[i];
|
|
1603
1410
|
}
|
|
1604
1411
|
for (let i = 0; i < height; i++) {
|
|
1605
|
-
|
|
1412
|
+
let physY = physicalRowIndex(buffer, start + i);
|
|
1606
1413
|
buffer.grid[physY] = nextRows[i];
|
|
1607
1414
|
}
|
|
1608
|
-
recomputeFingerprintsForRows(buffer, start, end);
|
|
1609
|
-
if (buffer.cursorY >= start && buffer.cursorY < end)
|
|
1610
|
-
buffer.cursorY = clamp(buffer.cursorY - n, start, Math.max(start, end - 1));
|
|
1611
|
-
return insertedRows;
|
|
1415
|
+
return recomputeFingerprintsForRows(buffer, start, end), buffer.cursorY >= start && buffer.cursorY < end && (buffer.cursorY = clamp(buffer.cursorY - n, start, Math.max(start, end - 1))), insertedRows;
|
|
1612
1416
|
}
|
|
1613
1417
|
function resizeBuffer(buffer, cols, rows) {
|
|
1614
|
-
|
|
1615
|
-
const nextRows = Math.max(0, Math.floor(rows));
|
|
1418
|
+
let nextCols = Math.max(0, Math.floor(cols)), nextRows = Math.max(0, Math.floor(rows));
|
|
1616
1419
|
if (nextCols === buffer.cols && nextRows === buffer.rows)
|
|
1617
1420
|
return;
|
|
1618
|
-
|
|
1619
|
-
const nextGrid = Array.from(
|
|
1421
|
+
let prevRows = buffer.rows, prevDirtyAll = buffer.dirtyAll, prevDirtyBits = buffer.dirtyBits, blank = createBlankCell(), nextGrid = Array.from(
|
|
1620
1422
|
{ length: nextRows },
|
|
1621
1423
|
() => Array.from({ length: nextCols }, () => blank)
|
|
1622
|
-
);
|
|
1623
|
-
const copyRows = Math.min(buffer.rows, nextRows);
|
|
1624
|
-
const copyCols = Math.min(buffer.cols, nextCols);
|
|
1424
|
+
), copyRows = Math.min(prevRows, nextRows), copyCols = Math.min(buffer.cols, nextCols);
|
|
1625
1425
|
for (let y = 0; y < copyRows; y++) {
|
|
1626
|
-
|
|
1627
|
-
const dst = nextGrid[y];
|
|
1426
|
+
let src = getBufferRow(buffer, y), dst = nextGrid[y];
|
|
1628
1427
|
for (let x = 0; x < copyCols; x++)
|
|
1629
1428
|
dst[x] = src[x];
|
|
1630
1429
|
}
|
|
1631
|
-
if (nextCols > 0)
|
|
1430
|
+
if (nextCols > 0)
|
|
1632
1431
|
for (let y = 0; y < nextGrid.length; y++) {
|
|
1633
|
-
|
|
1432
|
+
let row = nextGrid[y];
|
|
1634
1433
|
for (let x = 0; x < nextCols; x++) {
|
|
1635
|
-
|
|
1434
|
+
let cell = row[x];
|
|
1636
1435
|
if (cell.continuation) {
|
|
1637
|
-
|
|
1638
|
-
row[x] = blank;
|
|
1436
|
+
(x === 0 || row[x - 1]?.width !== 2 || row[x - 1]?.continuation) && (row[x] = blank);
|
|
1639
1437
|
continue;
|
|
1640
1438
|
}
|
|
1641
|
-
|
|
1642
|
-
row[x] = blank;
|
|
1643
|
-
}
|
|
1439
|
+
cell.width === 2 && (x + 1 >= nextCols || !row[x + 1]?.continuation) && (row[x] = blank);
|
|
1644
1440
|
}
|
|
1645
1441
|
}
|
|
1646
|
-
}
|
|
1647
1442
|
for (let y = 0; y < buffer.rows; y++)
|
|
1648
1443
|
buffer.rowPool.push(getBufferRow(buffer, y));
|
|
1649
|
-
buffer.grid = nextGrid
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
buffer.
|
|
1655
|
-
|
|
1656
|
-
buffer.dirtyMax = nextRows ? nextRows - 1 : -1;
|
|
1657
|
-
buffer.dirtyAll = nextRows > 0;
|
|
1658
|
-
buffer.cursorX = clamp(buffer.cursorX, 0, Math.max(0, nextCols));
|
|
1659
|
-
buffer.cursorY = clamp(buffer.cursorY, 0, Math.max(0, nextRows - 1));
|
|
1660
|
-
if (buffer.fingerprintFn) {
|
|
1661
|
-
const len = nextRows * nextCols;
|
|
1444
|
+
if (buffer.grid = nextGrid, buffer.gridStart = 0, buffer.cols = nextCols, buffer.rows = nextRows, buffer.dirtyBits = new Uint8Array(nextRows), buffer.dirtyCount = 0, buffer.dirtyMin = Number.POSITIVE_INFINITY, buffer.dirtyMax = -1, buffer.dirtyAll = prevDirtyAll && nextRows > 0, buffer.dirtyAll)
|
|
1445
|
+
buffer.dirtyCount = nextRows, buffer.dirtyMin = 0, buffer.dirtyMax = nextRows - 1;
|
|
1446
|
+
else
|
|
1447
|
+
for (let y = 0; y < copyRows; y++)
|
|
1448
|
+
prevDirtyBits[y] === 1 && (buffer.dirtyBits[y] = 1, buffer.dirtyCount++, y < buffer.dirtyMin && (buffer.dirtyMin = y), y > buffer.dirtyMax && (buffer.dirtyMax = y));
|
|
1449
|
+
if (buffer.cursorX = clamp(buffer.cursorX, 0, Math.max(0, nextCols)), buffer.cursorY = clamp(buffer.cursorY, 0, Math.max(0, nextRows - 1)), buffer.fingerprintFn) {
|
|
1450
|
+
let len = nextRows * nextCols;
|
|
1662
1451
|
if (len > 0) {
|
|
1663
1452
|
buffer.soaFingerprints = new Uint32Array(len);
|
|
1664
1453
|
for (let y = 0; y < nextRows; y++) {
|
|
1665
|
-
|
|
1666
|
-
const base = y * nextCols;
|
|
1454
|
+
let row = nextGrid[y], base = y * nextCols;
|
|
1667
1455
|
for (let x = 0; x < nextCols; x++) {
|
|
1668
|
-
|
|
1456
|
+
let cell = row[x];
|
|
1669
1457
|
buffer.soaFingerprints[base + x] = buffer.fingerprintFn(cell.ch, cell.style);
|
|
1670
1458
|
}
|
|
1671
1459
|
}
|
|
1672
|
-
} else
|
|
1460
|
+
} else
|
|
1673
1461
|
buffer.soaFingerprints = null;
|
|
1674
|
-
}
|
|
1675
1462
|
}
|
|
1676
1463
|
}
|
|
1677
1464
|
function snapshotText(buffer) {
|
|
1678
|
-
|
|
1465
|
+
let out = [];
|
|
1679
1466
|
for (let y = 0; y < buffer.rows; y++) {
|
|
1680
|
-
|
|
1467
|
+
let row = getBufferRow(buffer, y);
|
|
1681
1468
|
out.push(row.map((cell) => cell.continuation ? " " : cell.ch || " ").join(""));
|
|
1682
1469
|
}
|
|
1683
1470
|
return out;
|
|
1684
1471
|
}
|
|
1685
1472
|
|
|
1686
1473
|
// src/core/terminal/emitter.ts
|
|
1687
|
-
var emitterListeners = /* @__PURE__ */ new WeakMap()
|
|
1688
|
-
var Emitter = class {
|
|
1474
|
+
var emitterListeners = /* @__PURE__ */ new WeakMap(), Emitter = class {
|
|
1689
1475
|
constructor() {
|
|
1690
1476
|
emitterListeners.set(this, /* @__PURE__ */ new Map());
|
|
1691
1477
|
}
|
|
@@ -1693,25 +1479,16 @@ var Emitter = class {
|
|
|
1693
1479
|
return emitterListeners.get(this);
|
|
1694
1480
|
}
|
|
1695
1481
|
on(event, cb) {
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
set = /* @__PURE__ */ new Set();
|
|
1700
|
-
listeners.set(event, set);
|
|
1701
|
-
}
|
|
1702
|
-
set.add(cb);
|
|
1703
|
-
return () => {
|
|
1704
|
-
set.delete(cb);
|
|
1705
|
-
if (set.size === 0)
|
|
1706
|
-
listeners.delete(event);
|
|
1482
|
+
let listeners = this.getListeners(), set = listeners.get(event);
|
|
1483
|
+
return set || (set = /* @__PURE__ */ new Set(), listeners.set(event, set)), set.add(cb), () => {
|
|
1484
|
+
set.delete(cb), set.size === 0 && listeners.delete(event);
|
|
1707
1485
|
};
|
|
1708
1486
|
}
|
|
1709
1487
|
emit(event, payload) {
|
|
1710
|
-
|
|
1711
|
-
if (
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
cb(payload);
|
|
1488
|
+
let set = this.getListeners().get(event);
|
|
1489
|
+
if (set)
|
|
1490
|
+
for (let cb of set)
|
|
1491
|
+
cb(payload);
|
|
1715
1492
|
}
|
|
1716
1493
|
clear() {
|
|
1717
1494
|
this.getListeners().clear();
|
|
@@ -1720,44 +1497,37 @@ var Emitter = class {
|
|
|
1720
1497
|
|
|
1721
1498
|
// src/core/terminal/create-terminal.ts
|
|
1722
1499
|
function isControlChar(ch) {
|
|
1723
|
-
return ch ===
|
|
1500
|
+
return ch === `
|
|
1501
|
+
` || ch === "\r" || ch === " ";
|
|
1724
1502
|
}
|
|
1725
1503
|
function mergePlanes(prev, next) {
|
|
1726
1504
|
if (!prev?.length)
|
|
1727
1505
|
return next?.length ? [...next] : null;
|
|
1728
1506
|
if (!next?.length)
|
|
1729
1507
|
return prev;
|
|
1730
|
-
|
|
1731
|
-
for (
|
|
1508
|
+
let merged = new Set(prev);
|
|
1509
|
+
for (let plane of next)
|
|
1732
1510
|
merged.add(plane);
|
|
1733
1511
|
return Array.from(merged);
|
|
1734
1512
|
}
|
|
1735
|
-
var TERMINAL_PLANE_INTERNALS = Symbol.for("@simon_he/vue-tui:v1:terminal-plane-internals");
|
|
1513
|
+
var TERMINAL_PLANE_INTERNALS = Symbol.for("@simon_he/vue-tui:v1:terminal-plane-internals"), TERMINAL_ROOT = Symbol.for("@simon_he/vue-tui:v1:terminal-root");
|
|
1736
1514
|
function createCoverage(cols, rows) {
|
|
1737
1515
|
return Array.from({ length: rows }, () => new Uint8Array(cols));
|
|
1738
1516
|
}
|
|
1739
1517
|
function resizeCoverage(prev, cols, rows) {
|
|
1740
|
-
|
|
1741
|
-
const copyRows = Math.min(prev.length, rows);
|
|
1518
|
+
let next = createCoverage(cols, rows), copyRows = Math.min(prev.length, rows);
|
|
1742
1519
|
for (let y = 0; y < copyRows; y++) {
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
dst.set(src.subarray(0, Math.min(src.length, cols)));
|
|
1520
|
+
let src = prev[y];
|
|
1521
|
+
next[y].set(src.subarray(0, Math.min(src.length, cols)));
|
|
1746
1522
|
}
|
|
1747
1523
|
return next;
|
|
1748
1524
|
}
|
|
1749
1525
|
function setBufferClean(buffer) {
|
|
1750
|
-
buffer.dirtyBits.fill(0);
|
|
1751
|
-
buffer.dirtyCount = 0;
|
|
1752
|
-
buffer.dirtyMin = Number.POSITIVE_INFINITY;
|
|
1753
|
-
buffer.dirtyMax = -1;
|
|
1754
|
-
buffer.dirtyAll = false;
|
|
1526
|
+
buffer.dirtyBits.fill(0), buffer.dirtyCount = 0, buffer.dirtyMin = Number.POSITIVE_INFINITY, buffer.dirtyMax = -1, buffer.dirtyAll = !1;
|
|
1755
1527
|
}
|
|
1756
1528
|
function createPlaneState(cols, rows, widthProvider) {
|
|
1757
|
-
|
|
1758
|
-
setBufferClean(buffer)
|
|
1759
|
-
buffer.cursorVisible = false;
|
|
1760
|
-
return {
|
|
1529
|
+
let buffer = createGridBuffer(cols, rows, { widthProvider });
|
|
1530
|
+
return setBufferClean(buffer), buffer.cursorVisible = !1, {
|
|
1761
1531
|
buffer,
|
|
1762
1532
|
coverage: createCoverage(cols, rows)
|
|
1763
1533
|
};
|
|
@@ -1765,31 +1535,14 @@ function createPlaneState(cols, rows, widthProvider) {
|
|
|
1765
1535
|
function collectAndClearDirtyRows(buffer) {
|
|
1766
1536
|
if (buffer.rows === 0)
|
|
1767
1537
|
return [];
|
|
1768
|
-
if (buffer.dirtyAll)
|
|
1769
|
-
buffer.dirtyAll =
|
|
1770
|
-
buffer.dirtyBits.fill(0);
|
|
1771
|
-
buffer.dirtyCount = 0;
|
|
1772
|
-
buffer.dirtyMin = Number.POSITIVE_INFINITY;
|
|
1773
|
-
buffer.dirtyMax = -1;
|
|
1774
|
-
return null;
|
|
1775
|
-
}
|
|
1538
|
+
if (buffer.dirtyAll)
|
|
1539
|
+
return buffer.dirtyAll = !1, buffer.dirtyBits.fill(0), buffer.dirtyCount = 0, buffer.dirtyMin = Number.POSITIVE_INFINITY, buffer.dirtyMax = -1, null;
|
|
1776
1540
|
if (buffer.dirtyCount === 0)
|
|
1777
1541
|
return [];
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
if (buffer.dirtyBits[y]) {
|
|
1783
|
-
buffer.dirtyBits[y] = 0;
|
|
1784
|
-
out.push(y);
|
|
1785
|
-
if (out.length === buffer.dirtyCount)
|
|
1786
|
-
break;
|
|
1787
|
-
}
|
|
1788
|
-
}
|
|
1789
|
-
buffer.dirtyCount = 0;
|
|
1790
|
-
buffer.dirtyMin = Number.POSITIVE_INFINITY;
|
|
1791
|
-
buffer.dirtyMax = -1;
|
|
1792
|
-
return out;
|
|
1542
|
+
let out = [], start = Math.max(0, buffer.dirtyMin), end = Math.min(buffer.rows - 1, buffer.dirtyMax);
|
|
1543
|
+
for (let y = start; y <= end && !(buffer.dirtyBits[y] && (buffer.dirtyBits[y] = 0, out.push(y), out.length === buffer.dirtyCount)); y++)
|
|
1544
|
+
;
|
|
1545
|
+
return buffer.dirtyCount = 0, buffer.dirtyMin = Number.POSITIVE_INFINITY, buffer.dirtyMax = -1, out;
|
|
1793
1546
|
}
|
|
1794
1547
|
function peekDirtyRows(buffer) {
|
|
1795
1548
|
if (buffer.rows === 0)
|
|
@@ -1798,60 +1551,39 @@ function peekDirtyRows(buffer) {
|
|
|
1798
1551
|
return null;
|
|
1799
1552
|
if (buffer.dirtyCount === 0)
|
|
1800
1553
|
return [];
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
for (let y = start; y <= end; y++) {
|
|
1805
|
-
if (buffer.dirtyBits[y]) {
|
|
1806
|
-
out.push(y);
|
|
1807
|
-
if (out.length === buffer.dirtyCount)
|
|
1808
|
-
break;
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1554
|
+
let out = [], start = Math.max(0, buffer.dirtyMin), end = Math.min(buffer.rows - 1, buffer.dirtyMax);
|
|
1555
|
+
for (let y = start; y <= end && !(buffer.dirtyBits[y] && (out.push(y), out.length === buffer.dirtyCount)); y++)
|
|
1556
|
+
;
|
|
1811
1557
|
return out;
|
|
1812
1558
|
}
|
|
1813
1559
|
function clearPlaneCoverageRow(state, y) {
|
|
1814
1560
|
if (y < 0 || y >= state.buffer.rows)
|
|
1815
1561
|
return;
|
|
1816
|
-
|
|
1817
|
-
const blank = createBlankCell();
|
|
1562
|
+
let row = getBufferRow(state.buffer, y), blank = createBlankCell();
|
|
1818
1563
|
row.length = state.buffer.cols;
|
|
1819
1564
|
for (let x = 0; x < state.buffer.cols; x++)
|
|
1820
1565
|
row[x] = blank;
|
|
1821
|
-
state.coverage[y]?.fill(0);
|
|
1822
|
-
markDirty(state.buffer, y);
|
|
1566
|
+
state.coverage[y]?.fill(0), markDirty(state.buffer, y);
|
|
1823
1567
|
}
|
|
1824
1568
|
function markPlaneCoverageRange(state, x0, y0, x1, y1, value) {
|
|
1825
1569
|
for (let y = y0; y < y1; y++) {
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
continue;
|
|
1829
|
-
row.fill(value, x0, x1);
|
|
1570
|
+
let row = state.coverage[y];
|
|
1571
|
+
row && row.fill(value, x0, x1);
|
|
1830
1572
|
}
|
|
1831
1573
|
}
|
|
1832
1574
|
function markPlaneCoverageForPut(state, x, y, ch, prevCell) {
|
|
1833
|
-
|
|
1834
|
-
if (!row)
|
|
1575
|
+
if (!Number.isSafeInteger(x) || !Number.isSafeInteger(y) || x < 0 || x >= state.buffer.cols || y < 0 || y >= state.buffer.rows)
|
|
1835
1576
|
return;
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
if (prevCell?.width === 2 && x + 1 < row.length)
|
|
1839
|
-
row[x + 1] = 1;
|
|
1840
|
-
row[x] = 1;
|
|
1841
|
-
if (ch !== " " && x + 1 < row.length) {
|
|
1842
|
-
const next = getBufferCell(state.buffer, x, y);
|
|
1843
|
-
if (next.width === 2)
|
|
1844
|
-
row[x + 1] = 1;
|
|
1845
|
-
}
|
|
1577
|
+
let row = state.coverage[y];
|
|
1578
|
+
row && (prevCell?.continuation && x > 0 && (row[x - 1] = 1), prevCell?.width === 2 && x + 1 < row.length && (row[x + 1] = 1), row[x] = 1, ch !== " " && x + 1 < row.length && getBufferCell(state.buffer, x, y).width === 2 && (row[x + 1] = 1));
|
|
1846
1579
|
}
|
|
1847
1580
|
function scrollPlaneCoverage(state, lines) {
|
|
1848
|
-
|
|
1581
|
+
let n = Math.trunc(lines);
|
|
1849
1582
|
if (n === 0 || state.coverage.length === 0)
|
|
1850
1583
|
return;
|
|
1851
|
-
|
|
1852
|
-
const cols = state.buffer.cols;
|
|
1584
|
+
let rows = state.coverage.length, cols = state.buffer.cols;
|
|
1853
1585
|
if (Math.abs(n) >= rows) {
|
|
1854
|
-
for (
|
|
1586
|
+
for (let row of state.coverage)
|
|
1855
1587
|
row.fill(0);
|
|
1856
1588
|
return;
|
|
1857
1589
|
}
|
|
@@ -1866,31 +1598,27 @@ function scrollPlaneCoverage(state, lines) {
|
|
|
1866
1598
|
state.coverage.unshift(new Uint8Array(cols));
|
|
1867
1599
|
}
|
|
1868
1600
|
function scrollPlaneCoverageRegion(state, startY, endY, lines) {
|
|
1869
|
-
|
|
1601
|
+
let n = Math.trunc(lines);
|
|
1870
1602
|
if (n === 0 || state.coverage.length === 0)
|
|
1871
1603
|
return;
|
|
1872
|
-
|
|
1873
|
-
const end = Math.max(0, Math.min(state.coverage.length, Math.floor(endY)));
|
|
1874
|
-
const height = end - start;
|
|
1604
|
+
let start = Math.max(0, Math.min(state.coverage.length, Math.floor(startY))), end = Math.max(0, Math.min(state.coverage.length, Math.floor(endY))), height = end - start;
|
|
1875
1605
|
if (height <= 0)
|
|
1876
1606
|
return;
|
|
1877
|
-
|
|
1607
|
+
let cols = state.buffer.cols;
|
|
1878
1608
|
if (Math.abs(n) >= height) {
|
|
1879
1609
|
for (let y = start; y < end; y++)
|
|
1880
1610
|
state.coverage[y] = new Uint8Array(cols);
|
|
1881
1611
|
return;
|
|
1882
1612
|
}
|
|
1883
|
-
|
|
1884
|
-
const next = Array.from({ length: height }, () => new Uint8Array(0));
|
|
1613
|
+
let region = state.coverage.slice(start, end), next = Array.from({ length: height }, () => new Uint8Array(0));
|
|
1885
1614
|
if (n > 0) {
|
|
1886
|
-
|
|
1615
|
+
let movedCount = height - n;
|
|
1887
1616
|
for (let i = 0; i < movedCount; i++)
|
|
1888
1617
|
next[i] = region[i + n];
|
|
1889
1618
|
for (let i = 0; i < n; i++)
|
|
1890
1619
|
next[movedCount + i] = new Uint8Array(cols);
|
|
1891
1620
|
} else {
|
|
1892
|
-
|
|
1893
|
-
const movedCount = height - insertedCount;
|
|
1621
|
+
let insertedCount = -n, movedCount = height - insertedCount;
|
|
1894
1622
|
for (let i = 0; i < insertedCount; i++)
|
|
1895
1623
|
next[i] = new Uint8Array(cols);
|
|
1896
1624
|
for (let i = 0; i < movedCount; i++)
|
|
@@ -1900,303 +1628,211 @@ function scrollPlaneCoverageRegion(state, startY, endY, lines) {
|
|
|
1900
1628
|
state.coverage[start + i] = next[i];
|
|
1901
1629
|
}
|
|
1902
1630
|
function resizePlaneState(state, cols, rows) {
|
|
1903
|
-
resizeBuffer(state.buffer, cols, rows);
|
|
1904
|
-
state.coverage = resizeCoverage(state.coverage, state.buffer.cols, state.buffer.rows);
|
|
1631
|
+
resizeBuffer(state.buffer, cols, rows), state.coverage = resizeCoverage(state.coverage, state.buffer.cols, state.buffer.rows);
|
|
1905
1632
|
}
|
|
1906
1633
|
function normalizeDirtyRows(rows, totalRows) {
|
|
1907
1634
|
if (rows === null)
|
|
1908
1635
|
return null;
|
|
1909
1636
|
if (rows.length === 0)
|
|
1910
1637
|
return rows;
|
|
1911
|
-
|
|
1912
|
-
for (
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
continue;
|
|
1916
|
-
if (out[out.length - 1] === yy)
|
|
1917
|
-
continue;
|
|
1918
|
-
out.push(yy);
|
|
1638
|
+
let out = [];
|
|
1639
|
+
for (let y of rows) {
|
|
1640
|
+
let yy = Math.floor(y);
|
|
1641
|
+
yy < 0 || yy >= totalRows || out[out.length - 1] !== yy && out.push(yy);
|
|
1919
1642
|
}
|
|
1920
1643
|
return out;
|
|
1921
1644
|
}
|
|
1922
1645
|
function createTerminal(opts) {
|
|
1923
|
-
|
|
1924
|
-
const emitter = new Emitter();
|
|
1925
|
-
const compositeBuffer = createGridBuffer(opts.cols, opts.rows, {
|
|
1646
|
+
let widthProvider = opts.widthProvider ?? "default", emitter = new Emitter(), compositeBuffer = createGridBuffer(opts.cols, opts.rows, {
|
|
1926
1647
|
widthProvider
|
|
1927
|
-
});
|
|
1928
|
-
|
|
1929
|
-
let disposed = false;
|
|
1930
|
-
let batchingDepth = 0;
|
|
1931
|
-
let pendingCommit = false;
|
|
1932
|
-
let pendingCommitAllPlanes = false;
|
|
1933
|
-
let pendingCommitPlanes = null;
|
|
1934
|
-
const pendingPlaneScrollOps = /* @__PURE__ */ new Map();
|
|
1935
|
-
const planeTerminals = /* @__PURE__ */ new Map();
|
|
1936
|
-
let base;
|
|
1937
|
-
compositeBuffer.cursorVisible = false;
|
|
1648
|
+
}), planeStates = /* @__PURE__ */ new Map(), disposed = !1, batchingDepth = 0, pendingCommit = !1, pendingCommitAllPlanes = !1, pendingCommitPlanes = null, pendingPlaneScrollOps = /* @__PURE__ */ new Map(), planeTerminals = /* @__PURE__ */ new Map(), base;
|
|
1649
|
+
compositeBuffer.cursorVisible = !1;
|
|
1938
1650
|
function assertNotDisposed() {
|
|
1939
1651
|
if (disposed)
|
|
1940
1652
|
throw new Error("Terminal is disposed");
|
|
1941
1653
|
}
|
|
1942
1654
|
function getPlaneState(plane) {
|
|
1943
1655
|
let state = planeStates.get(plane);
|
|
1944
|
-
|
|
1945
|
-
state = createPlaneState(compositeBuffer.cols, compositeBuffer.rows, widthProvider);
|
|
1946
|
-
planeStates.set(plane, state);
|
|
1947
|
-
}
|
|
1948
|
-
return state;
|
|
1656
|
+
return state || (state = createPlaneState(compositeBuffer.cols, compositeBuffer.rows, widthProvider), planeStates.set(plane, state)), state;
|
|
1949
1657
|
}
|
|
1950
|
-
function setCursorForPlane(plane, x, y, visible =
|
|
1951
|
-
|
|
1952
|
-
state.buffer.cursorX = Math.max(0, Math.min(state.buffer.cols, Math.floor(x)))
|
|
1953
|
-
state.buffer.cursorY = Math.max(
|
|
1658
|
+
function setCursorForPlane(plane, x, y, visible = !0) {
|
|
1659
|
+
let state = getPlaneState(plane);
|
|
1660
|
+
state.buffer.cursorX = Math.max(0, Math.min(state.buffer.cols, Math.floor(x))), state.buffer.cursorY = Math.max(
|
|
1954
1661
|
0,
|
|
1955
1662
|
Math.min(state.buffer.rows ? state.buffer.rows - 1 : 0, Math.floor(y))
|
|
1956
|
-
);
|
|
1957
|
-
state.buffer.cursorVisible = visible;
|
|
1958
|
-
markDirty(state.buffer, state.buffer.cursorY);
|
|
1663
|
+
), state.buffer.cursorVisible = visible, markDirty(state.buffer, state.buffer.cursorY);
|
|
1959
1664
|
}
|
|
1960
1665
|
function putForPlane(plane, x, y, ch, style) {
|
|
1961
|
-
|
|
1962
|
-
if (
|
|
1666
|
+
let state = getPlaneState(plane);
|
|
1667
|
+
if (typeof x != "number" || typeof y != "number")
|
|
1668
|
+
return;
|
|
1669
|
+
let cellX = Math.floor(x), cellY = Math.floor(y);
|
|
1670
|
+
if (!Number.isFinite(cellX) || !Number.isFinite(cellY) || cellY < 0 || cellY >= state.buffer.rows || cellX < 0 || cellX >= state.buffer.cols)
|
|
1963
1671
|
return;
|
|
1964
|
-
|
|
1965
|
-
putCell(state.buffer,
|
|
1966
|
-
markPlaneCoverageForPut(state, x, y, ch, prevCell);
|
|
1672
|
+
let prevCell = getBufferCell(state.buffer, cellX, cellY);
|
|
1673
|
+
putCell(state.buffer, cellX, cellY, ch, style), markPlaneCoverageForPut(state, cellX, cellY, ch, prevCell);
|
|
1967
1674
|
}
|
|
1968
1675
|
function writeAtForPlane(plane, text, x, y, style) {
|
|
1969
|
-
|
|
1970
|
-
let cx = x;
|
|
1971
|
-
let cy = y;
|
|
1676
|
+
let state = getPlaneState(plane), cx = x, cy = y;
|
|
1972
1677
|
if (state.buffer.cols === 0 || state.buffer.rows === 0)
|
|
1973
1678
|
return { x: cx, y: cy };
|
|
1974
|
-
|
|
1679
|
+
let writeChar = (ch) => {
|
|
1975
1680
|
if (isControlChar(ch)) {
|
|
1976
|
-
if (ch ===
|
|
1681
|
+
if (ch === `
|
|
1682
|
+
`)
|
|
1683
|
+
cx = 0, cy += 1, cy >= state.buffer.rows && (scrollBuffer(state.buffer, 1), scrollPlaneCoverage(state, 1), cy = state.buffer.rows - 1);
|
|
1684
|
+
else if (ch === "\r")
|
|
1977
1685
|
cx = 0;
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
scrollBuffer(state.buffer, 1);
|
|
1981
|
-
scrollPlaneCoverage(state, 1);
|
|
1982
|
-
cy = state.buffer.rows - 1;
|
|
1983
|
-
}
|
|
1984
|
-
} else if (ch === "\r") {
|
|
1985
|
-
cx = 0;
|
|
1986
|
-
} else if (ch === " ") {
|
|
1987
|
-
const tabSize = 4;
|
|
1988
|
-
const next = Math.min(state.buffer.cols, cx + (tabSize - cx % tabSize));
|
|
1686
|
+
else if (ch === " ") {
|
|
1687
|
+
let next = Math.min(state.buffer.cols, cx + (4 - cx % 4));
|
|
1989
1688
|
for (; cx < next; cx++)
|
|
1990
1689
|
putForPlane(plane, cx, cy, " ", style);
|
|
1991
1690
|
}
|
|
1992
|
-
return
|
|
1691
|
+
return !0;
|
|
1993
1692
|
}
|
|
1994
1693
|
if (cy < 0 || cy >= state.buffer.rows)
|
|
1995
|
-
return
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
if (cy >= state.buffer.rows) {
|
|
2001
|
-
scrollBuffer(state.buffer, 1);
|
|
2002
|
-
scrollPlaneCoverage(state, 1);
|
|
2003
|
-
cy = state.buffer.rows - 1;
|
|
2004
|
-
}
|
|
2005
|
-
putForPlane(plane, cx, cy, ch, style);
|
|
2006
|
-
const width = ch === " " ? 1 : getBufferCell(state.buffer, cx, cy).width || 1;
|
|
2007
|
-
cx += width;
|
|
2008
|
-
return true;
|
|
2009
|
-
};
|
|
2010
|
-
const segments = segmentedGraphemes(text);
|
|
1694
|
+
return !1;
|
|
1695
|
+
cx >= state.buffer.cols && (cx = 0, cy += 1), cy >= state.buffer.rows && (scrollBuffer(state.buffer, 1), scrollPlaneCoverage(state, 1), cy = state.buffer.rows - 1), putForPlane(plane, cx, cy, ch, style);
|
|
1696
|
+
let width = ch === " " ? 1 : getBufferCell(state.buffer, cx, cy).width || 1;
|
|
1697
|
+
return cx += width, !0;
|
|
1698
|
+
}, segments = segmentedGraphemes(text);
|
|
2011
1699
|
if (segments) {
|
|
2012
|
-
for (
|
|
1700
|
+
for (let seg of segments)
|
|
2013
1701
|
if (!writeChar(seg.segment))
|
|
2014
1702
|
break;
|
|
2015
|
-
}
|
|
2016
1703
|
return { x: cx, y: cy };
|
|
2017
1704
|
}
|
|
2018
1705
|
let i = 0;
|
|
2019
|
-
for (; i < text.length; i++)
|
|
2020
|
-
const code = text.charCodeAt(i);
|
|
2021
|
-
if (code > 127)
|
|
2022
|
-
break;
|
|
1706
|
+
for (; i < text.length && !(text.charCodeAt(i) > 127); i++)
|
|
2023
1707
|
if (!writeChar(text[i]))
|
|
2024
1708
|
return { x: cx, y: cy };
|
|
2025
|
-
}
|
|
2026
1709
|
if (i < text.length) {
|
|
2027
|
-
|
|
2028
|
-
const restSegments = segmentedGraphemes(rest);
|
|
1710
|
+
let rest = text.slice(i), restSegments = segmentedGraphemes(rest);
|
|
2029
1711
|
if (restSegments) {
|
|
2030
|
-
for (
|
|
1712
|
+
for (let seg of restSegments)
|
|
2031
1713
|
if (!writeChar(seg.segment))
|
|
2032
1714
|
break;
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
for (const ch of rest) {
|
|
1715
|
+
} else
|
|
1716
|
+
for (let ch of rest)
|
|
2036
1717
|
if (!writeChar(ch))
|
|
2037
1718
|
break;
|
|
2038
|
-
}
|
|
2039
|
-
}
|
|
2040
1719
|
}
|
|
2041
1720
|
return { x: cx, y: cy };
|
|
2042
1721
|
}
|
|
2043
1722
|
function clearForPlane(plane, x, y, w, h) {
|
|
2044
|
-
|
|
2045
|
-
clearRect(state.buffer, x, y, w, h)
|
|
2046
|
-
|
|
2047
|
-
for (const row of state.coverage)
|
|
1723
|
+
let state = getPlaneState(plane);
|
|
1724
|
+
if (clearRect(state.buffer, x, y, w, h), x == null || y == null || w == null || h == null) {
|
|
1725
|
+
for (let row of state.coverage)
|
|
2048
1726
|
row.fill(1);
|
|
2049
1727
|
return;
|
|
2050
1728
|
}
|
|
2051
1729
|
if (w <= 0 || h <= 0)
|
|
2052
1730
|
return;
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
const x1 = Math.max(0, Math.min(state.buffer.cols, Math.floor(x + w)));
|
|
2056
|
-
const y1 = Math.max(0, Math.min(state.buffer.rows, Math.floor(y + h)));
|
|
2057
|
-
if (x1 <= x0 || y1 <= y0)
|
|
2058
|
-
return;
|
|
2059
|
-
markPlaneCoverageRange(state, x0, y0, x1, y1, 1);
|
|
1731
|
+
let x0 = Math.max(0, Math.min(state.buffer.cols, Math.floor(x))), y0 = Math.max(0, Math.min(state.buffer.rows, Math.floor(y))), x1 = Math.max(0, Math.min(state.buffer.cols, Math.floor(x + w))), y1 = Math.max(0, Math.min(state.buffer.rows, Math.floor(y + h)));
|
|
1732
|
+
x1 <= x0 || y1 <= y0 || markPlaneCoverageRange(state, x0, y0, x1, y1, 1);
|
|
2060
1733
|
}
|
|
2061
1734
|
function fillForPlane(plane, x, y, w, h, ch, style) {
|
|
2062
|
-
|
|
2063
|
-
fillRect(state.buffer, x, y, w, h, ch ?? " ", style)
|
|
2064
|
-
if (w <= 0 || h <= 0 || state.buffer.cols === 0 || state.buffer.rows === 0)
|
|
1735
|
+
let state = getPlaneState(plane);
|
|
1736
|
+
if (fillRect(state.buffer, x, y, w, h, ch ?? " ", style), w <= 0 || h <= 0 || state.buffer.cols === 0 || state.buffer.rows === 0)
|
|
2065
1737
|
return;
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
const x1 = Math.max(0, Math.min(state.buffer.cols, Math.floor(x + w)));
|
|
2069
|
-
const y1 = Math.max(0, Math.min(state.buffer.rows, Math.floor(y + h)));
|
|
2070
|
-
if (x1 <= x0 || y1 <= y0)
|
|
2071
|
-
return;
|
|
2072
|
-
markPlaneCoverageRange(state, x0, y0, x1, y1, 1);
|
|
1738
|
+
let x0 = Math.max(0, Math.min(state.buffer.cols, Math.floor(x))), y0 = Math.max(0, Math.min(state.buffer.rows, Math.floor(y))), x1 = Math.max(0, Math.min(state.buffer.cols, Math.floor(x + w))), y1 = Math.max(0, Math.min(state.buffer.rows, Math.floor(y + h)));
|
|
1739
|
+
x1 <= x0 || y1 <= y0 || markPlaneCoverageRange(state, x0, y0, x1, y1, 1);
|
|
2073
1740
|
}
|
|
2074
1741
|
function scrollForPlane(plane, lines) {
|
|
2075
|
-
|
|
2076
|
-
scrollBuffer(state.buffer, lines);
|
|
2077
|
-
scrollPlaneCoverage(state, lines);
|
|
1742
|
+
let state = getPlaneState(plane);
|
|
1743
|
+
scrollBuffer(state.buffer, lines), scrollPlaneCoverage(state, lines);
|
|
2078
1744
|
}
|
|
2079
1745
|
function normalizeScrollOperation(startY, endY, delta, totalRows) {
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
const height = end - start;
|
|
2083
|
-
const lines = Math.trunc(delta);
|
|
2084
|
-
if (height <= 0 || lines === 0 || Math.abs(lines) >= height)
|
|
2085
|
-
return null;
|
|
2086
|
-
return { startY: start, endY: end, delta: lines };
|
|
1746
|
+
let start = Math.max(0, Math.min(totalRows, Math.floor(startY))), end = Math.max(0, Math.min(totalRows, Math.floor(endY))), height = end - start, lines = Math.trunc(delta);
|
|
1747
|
+
return height <= 0 || lines === 0 || Math.abs(lines) >= height ? null : { startY: start, endY: end, delta: lines };
|
|
2087
1748
|
}
|
|
2088
1749
|
function recordPendingScrollOp(plane, op) {
|
|
2089
|
-
|
|
2090
|
-
const last = list[list.length - 1];
|
|
1750
|
+
let list = pendingPlaneScrollOps.get(plane) ?? [], last = list[list.length - 1];
|
|
2091
1751
|
if (last && last.startY === op.startY && last.endY === op.endY && Math.sign(last.delta) === Math.sign(op.delta)) {
|
|
2092
|
-
|
|
1752
|
+
let next = normalizeScrollOperation(
|
|
2093
1753
|
op.startY,
|
|
2094
1754
|
op.endY,
|
|
2095
1755
|
last.delta + op.delta,
|
|
2096
1756
|
compositeBuffer.rows
|
|
2097
1757
|
);
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
else
|
|
2101
|
-
list.push(op);
|
|
2102
|
-
} else {
|
|
1758
|
+
next ? list[list.length - 1] = next : list.push(op);
|
|
1759
|
+
} else
|
|
2103
1760
|
list.push(op);
|
|
2104
|
-
}
|
|
2105
1761
|
pendingPlaneScrollOps.set(plane, list);
|
|
2106
1762
|
}
|
|
2107
1763
|
function takePendingScrollOps(planes) {
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
out.push({ plane, ...op });
|
|
1764
|
+
let planesToTake = planes?.length ? planes : TERMINAL_RENDER_PLANES, out = [];
|
|
1765
|
+
for (let plane of planesToTake) {
|
|
1766
|
+
let ops = pendingPlaneScrollOps.get(plane);
|
|
1767
|
+
if (ops?.length) {
|
|
1768
|
+
pendingPlaneScrollOps.delete(plane);
|
|
1769
|
+
for (let op of ops)
|
|
1770
|
+
out.push({ plane, ...op });
|
|
1771
|
+
}
|
|
2117
1772
|
}
|
|
2118
1773
|
return out.length ? out : null;
|
|
2119
1774
|
}
|
|
2120
1775
|
function higherPlanesFor(plane) {
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
return [];
|
|
2124
|
-
return TERMINAL_RENDER_PLANES.slice(planeIndex + 1);
|
|
1776
|
+
let planeIndex = TERMINAL_RENDER_PLANES.indexOf(plane);
|
|
1777
|
+
return planeIndex < 0 ? [] : TERMINAL_RENDER_PLANES.slice(planeIndex + 1);
|
|
2125
1778
|
}
|
|
2126
1779
|
function higherPlaneCoverageKind(plane, y) {
|
|
2127
|
-
|
|
1780
|
+
let higherPlanes = higherPlanesFor(plane);
|
|
2128
1781
|
if (!higherPlanes.length || y < 0 || y >= compositeBuffer.rows)
|
|
2129
1782
|
return 0;
|
|
2130
1783
|
let covered = 0;
|
|
2131
1784
|
for (let x = 0; x < compositeBuffer.cols; x++) {
|
|
2132
|
-
let cellCovered =
|
|
2133
|
-
for (
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
cellCovered = true;
|
|
1785
|
+
let cellCovered = !1;
|
|
1786
|
+
for (let higherPlane of higherPlanes)
|
|
1787
|
+
if (planeStates.get(higherPlane)?.coverage[y]?.[x]) {
|
|
1788
|
+
cellCovered = !0;
|
|
2137
1789
|
break;
|
|
2138
1790
|
}
|
|
2139
|
-
|
|
2140
|
-
if (cellCovered)
|
|
2141
|
-
covered++;
|
|
1791
|
+
cellCovered && covered++;
|
|
2142
1792
|
}
|
|
2143
|
-
|
|
2144
|
-
return 0;
|
|
2145
|
-
if (covered >= compositeBuffer.cols)
|
|
2146
|
-
return 2;
|
|
2147
|
-
return 1;
|
|
1793
|
+
return covered === 0 ? 0 : covered >= compositeBuffer.cols ? 2 : 1;
|
|
2148
1794
|
}
|
|
2149
1795
|
function addAffectedRows(out, op) {
|
|
2150
1796
|
for (let y = op.startY; y < op.endY; y++)
|
|
2151
1797
|
out.add(y);
|
|
2152
1798
|
}
|
|
2153
1799
|
function areDisjointSorted(ops) {
|
|
2154
|
-
for (let i = 1; i < ops.length; i++)
|
|
1800
|
+
for (let i = 1; i < ops.length; i++)
|
|
2155
1801
|
if (ops[i - 1].endY > ops[i].startY)
|
|
2156
|
-
return
|
|
2157
|
-
|
|
2158
|
-
return true;
|
|
1802
|
+
return !1;
|
|
1803
|
+
return !0;
|
|
2159
1804
|
}
|
|
2160
1805
|
function groupedPendingScrollOps(pendingOps) {
|
|
2161
|
-
|
|
2162
|
-
for (
|
|
2163
|
-
|
|
1806
|
+
let grouped = /* @__PURE__ */ new Map();
|
|
1807
|
+
for (let pending of pendingOps) {
|
|
1808
|
+
let list = grouped.get(pending.plane) ?? [];
|
|
2164
1809
|
list.push({
|
|
2165
1810
|
startY: pending.startY,
|
|
2166
1811
|
endY: pending.endY,
|
|
2167
1812
|
delta: pending.delta
|
|
2168
|
-
});
|
|
2169
|
-
grouped.set(pending.plane, list);
|
|
1813
|
+
}), grouped.set(pending.plane, list);
|
|
2170
1814
|
}
|
|
2171
1815
|
return grouped;
|
|
2172
1816
|
}
|
|
2173
1817
|
function prepareCompositeScrollOps(pendingOps) {
|
|
2174
|
-
if (!pendingOps?.length)
|
|
1818
|
+
if (!pendingOps?.length)
|
|
2175
1819
|
return {
|
|
2176
1820
|
scrollOperations: null,
|
|
2177
1821
|
extraDirtyRows: []
|
|
2178
1822
|
};
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
const grouped = groupedPendingScrollOps(pendingOps);
|
|
2183
|
-
for (const [plane, ops] of grouped) {
|
|
2184
|
-
const sorted = [...ops].sort((a, b) => a.startY - b.startY || a.endY - b.endY);
|
|
1823
|
+
let scrollOperations = [], extraDirtyRows = /* @__PURE__ */ new Set(), grouped = groupedPendingScrollOps(pendingOps);
|
|
1824
|
+
for (let [plane, ops] of grouped) {
|
|
1825
|
+
let sorted = [...ops].sort((a, b) => a.startY - b.startY || a.endY - b.endY);
|
|
2185
1826
|
if (!areDisjointSorted(sorted)) {
|
|
2186
|
-
for (
|
|
1827
|
+
for (let op of ops)
|
|
2187
1828
|
addAffectedRows(extraDirtyRows, op);
|
|
2188
1829
|
continue;
|
|
2189
1830
|
}
|
|
2190
|
-
for (
|
|
2191
|
-
|
|
2192
|
-
const partiallyBlockedRows = /* @__PURE__ */ new Set();
|
|
1831
|
+
for (let op of sorted) {
|
|
1832
|
+
let blockedRows = /* @__PURE__ */ new Set(), partiallyBlockedRows = /* @__PURE__ */ new Set();
|
|
2193
1833
|
for (let y = op.startY; y < op.endY; y++) {
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
continue;
|
|
2197
|
-
blockedRows.add(y);
|
|
2198
|
-
if (coverageKind === 1)
|
|
2199
|
-
partiallyBlockedRows.add(y);
|
|
1834
|
+
let coverageKind = higherPlaneCoverageKind(plane, y);
|
|
1835
|
+
coverageKind !== 0 && (blockedRows.add(y), coverageKind === 1 && partiallyBlockedRows.add(y));
|
|
2200
1836
|
}
|
|
2201
1837
|
if (!blockedRows.size) {
|
|
2202
1838
|
scrollOperations.push({
|
|
@@ -2206,34 +1842,29 @@ function createTerminal(opts) {
|
|
|
2206
1842
|
});
|
|
2207
1843
|
continue;
|
|
2208
1844
|
}
|
|
2209
|
-
|
|
2210
|
-
for (let y = op.startY; y < op.endY; y++)
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
}
|
|
2214
|
-
let bandStart = -1;
|
|
2215
|
-
const flushBand = (bandEnd) => {
|
|
1845
|
+
let absDelta = Math.abs(op.delta);
|
|
1846
|
+
for (let y = op.startY; y < op.endY; y++)
|
|
1847
|
+
partiallyBlockedRows.has(y) && extraDirtyRows.add(y);
|
|
1848
|
+
let bandStart = -1, flushBand = (bandEnd) => {
|
|
2216
1849
|
if (bandStart < 0 || bandEnd <= bandStart)
|
|
2217
1850
|
return;
|
|
2218
|
-
|
|
1851
|
+
let bandHeight = bandEnd - bandStart;
|
|
2219
1852
|
if (absDelta >= bandHeight) {
|
|
2220
1853
|
for (let y = bandStart; y < bandEnd; y++)
|
|
2221
1854
|
extraDirtyRows.add(y);
|
|
2222
1855
|
bandStart = -1;
|
|
2223
1856
|
return;
|
|
2224
1857
|
}
|
|
2225
|
-
scrollOperations.push({
|
|
1858
|
+
if (scrollOperations.push({
|
|
2226
1859
|
startY: bandStart,
|
|
2227
1860
|
endY: bandEnd,
|
|
2228
1861
|
delta: op.delta
|
|
2229
|
-
})
|
|
2230
|
-
if (op.delta > 0) {
|
|
1862
|
+
}), op.delta > 0)
|
|
2231
1863
|
for (let y = bandEnd - absDelta; y < bandEnd; y++)
|
|
2232
1864
|
extraDirtyRows.add(y);
|
|
2233
|
-
|
|
1865
|
+
else
|
|
2234
1866
|
for (let y = bandStart; y < bandStart + absDelta; y++)
|
|
2235
1867
|
extraDirtyRows.add(y);
|
|
2236
|
-
}
|
|
2237
1868
|
bandStart = -1;
|
|
2238
1869
|
};
|
|
2239
1870
|
for (let y = op.startY; y < op.endY; y++) {
|
|
@@ -2241,8 +1872,7 @@ function createTerminal(opts) {
|
|
|
2241
1872
|
flushBand(y);
|
|
2242
1873
|
continue;
|
|
2243
1874
|
}
|
|
2244
|
-
|
|
2245
|
-
bandStart = y;
|
|
1875
|
+
bandStart < 0 && (bandStart = y);
|
|
2246
1876
|
}
|
|
2247
1877
|
flushBand(op.endY);
|
|
2248
1878
|
}
|
|
@@ -2254,77 +1884,56 @@ function createTerminal(opts) {
|
|
|
2254
1884
|
}
|
|
2255
1885
|
function dirtyRowsCoverRange(rows, startY, endY) {
|
|
2256
1886
|
if (rows === null)
|
|
2257
|
-
return
|
|
1887
|
+
return !0;
|
|
2258
1888
|
if (!rows.length)
|
|
2259
|
-
return
|
|
1889
|
+
return !1;
|
|
2260
1890
|
let idx = 0;
|
|
2261
|
-
|
|
1891
|
+
for (; idx < rows.length && (rows[idx] ?? -1) < startY; )
|
|
2262
1892
|
idx++;
|
|
2263
1893
|
for (let y = startY; y < endY; y++) {
|
|
2264
1894
|
if (rows[idx] !== y)
|
|
2265
|
-
return
|
|
1895
|
+
return !1;
|
|
2266
1896
|
idx++;
|
|
2267
1897
|
}
|
|
2268
|
-
return
|
|
1898
|
+
return !0;
|
|
2269
1899
|
}
|
|
2270
1900
|
function dropScrollOpsCoveredByDirtyRows(ops, dirtyRows) {
|
|
2271
1901
|
if (!ops?.length)
|
|
2272
1902
|
return null;
|
|
2273
|
-
|
|
1903
|
+
let next = ops.filter((op) => !dirtyRowsCoverRange(dirtyRows, op.startY, op.endY));
|
|
2274
1904
|
return next.length ? next : null;
|
|
2275
1905
|
}
|
|
2276
1906
|
function scrollRowsForPlane(plane, startY, endY, lines) {
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
if (!op)
|
|
2280
|
-
return;
|
|
2281
|
-
scrollBufferRegion(state.buffer, op.startY, op.endY, op.delta);
|
|
2282
|
-
scrollPlaneCoverageRegion(state, op.startY, op.endY, op.delta);
|
|
2283
|
-
recordPendingScrollOp(plane, op);
|
|
1907
|
+
let state = getPlaneState(plane), op = normalizeScrollOperation(startY, endY, lines, state.buffer.rows);
|
|
1908
|
+
op && (scrollBufferRegion(state.buffer, op.startY, op.endY, op.delta), scrollPlaneCoverageRegion(state, op.startY, op.endY, op.delta), recordPendingScrollOp(plane, op));
|
|
2284
1909
|
}
|
|
2285
1910
|
function composeRows(rows, planes = TERMINAL_RENDER_PLANES) {
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
const fpArr = compositeBuffer.soaFingerprints;
|
|
2289
|
-
const rowList = rows ?? Array.from({ length: compositeBuffer.rows }, (_, index) => index);
|
|
2290
|
-
for (const y of rowList) {
|
|
1911
|
+
let blank = createBlankCell(), fpFn = compositeBuffer.fingerprintFn, fpArr = compositeBuffer.soaFingerprints, rowList = rows ?? Array.from({ length: compositeBuffer.rows }, (_, index) => index);
|
|
1912
|
+
for (let y of rowList) {
|
|
2291
1913
|
if (y < 0 || y >= compositeBuffer.rows)
|
|
2292
1914
|
continue;
|
|
2293
|
-
|
|
1915
|
+
let dst = getBufferRow(compositeBuffer, y);
|
|
2294
1916
|
dst.length = compositeBuffer.cols;
|
|
2295
1917
|
for (let x = 0; x < compositeBuffer.cols; x++)
|
|
2296
1918
|
dst[x] = blank;
|
|
2297
|
-
for (
|
|
2298
|
-
|
|
1919
|
+
for (let plane of planes) {
|
|
1920
|
+
let state = planeStates.get(plane);
|
|
2299
1921
|
if (!state)
|
|
2300
1922
|
continue;
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
for (let x = 0; x < compositeBuffer.cols; x++) {
|
|
2306
|
-
if (coverage[x])
|
|
2307
|
-
dst[x] = src[x];
|
|
2308
|
-
}
|
|
1923
|
+
let src = getBufferRow(state.buffer, y), coverage = state.coverage[y];
|
|
1924
|
+
if (coverage)
|
|
1925
|
+
for (let x = 0; x < compositeBuffer.cols; x++)
|
|
1926
|
+
coverage[x] && (dst[x] = src[x]);
|
|
2309
1927
|
}
|
|
2310
|
-
|
|
1928
|
+
let cols = compositeBuffer.cols;
|
|
2311
1929
|
for (let x = 0; x < cols; x++) {
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
if (x + 1 >= cols || !dst[x + 1].continuation) {
|
|
2315
|
-
dst[x] = blank;
|
|
2316
|
-
}
|
|
2317
|
-
} else if (cell.continuation) {
|
|
2318
|
-
if (x === 0 || dst[x - 1].width !== 2 || dst[x - 1].continuation) {
|
|
2319
|
-
dst[x] = blank;
|
|
2320
|
-
}
|
|
2321
|
-
}
|
|
1930
|
+
let cell = dst[x];
|
|
1931
|
+
cell.width === 2 && !cell.continuation ? (x + 1 >= cols || !dst[x + 1].continuation) && (dst[x] = blank) : cell.continuation && (x === 0 || dst[x - 1].width !== 2 || dst[x - 1].continuation) && (dst[x] = blank);
|
|
2322
1932
|
}
|
|
2323
1933
|
if (fpFn && fpArr) {
|
|
2324
|
-
|
|
2325
|
-
const base2 = physY * cols;
|
|
1934
|
+
let base2 = (compositeBuffer.gridStart + y) % compositeBuffer.rows * cols;
|
|
2326
1935
|
for (let x = 0; x < cols; x++) {
|
|
2327
|
-
|
|
1936
|
+
let cell = dst[x];
|
|
2328
1937
|
fpArr[base2 + x] = fpFn(cell.ch, cell.style);
|
|
2329
1938
|
}
|
|
2330
1939
|
}
|
|
@@ -2332,166 +1941,121 @@ function createTerminal(opts) {
|
|
|
2332
1941
|
}
|
|
2333
1942
|
}
|
|
2334
1943
|
function syncCompositeCursor() {
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
for (const plane of ["overlay", "chrome", "transcript", "default"]) {
|
|
2339
|
-
const state = planeStates.get(plane);
|
|
1944
|
+
let prevVisible = compositeBuffer.cursorVisible, prevY = compositeBuffer.cursorY, nextPlane = null;
|
|
1945
|
+
for (let plane of ["overlay", "chrome", "transcript", "default"]) {
|
|
1946
|
+
let state = planeStates.get(plane);
|
|
2340
1947
|
if (state?.buffer.cursorVisible) {
|
|
2341
1948
|
nextPlane = state;
|
|
2342
1949
|
break;
|
|
2343
1950
|
}
|
|
2344
1951
|
}
|
|
2345
|
-
compositeBuffer.cursorVisible =
|
|
2346
|
-
compositeBuffer.cursorX = nextPlane?.buffer.cursorX ?? 0;
|
|
2347
|
-
compositeBuffer.cursorY = nextPlane?.buffer.cursorY ?? 0;
|
|
2348
|
-
if (prevVisible)
|
|
2349
|
-
markDirty(compositeBuffer, prevY);
|
|
2350
|
-
if (compositeBuffer.cursorVisible)
|
|
2351
|
-
markDirty(compositeBuffer, compositeBuffer.cursorY);
|
|
1952
|
+
compositeBuffer.cursorVisible = !!nextPlane, compositeBuffer.cursorX = nextPlane?.buffer.cursorX ?? 0, compositeBuffer.cursorY = nextPlane?.buffer.cursorY ?? 0, prevVisible && markDirty(compositeBuffer, prevY), compositeBuffer.cursorVisible && markDirty(compositeBuffer, compositeBuffer.cursorY);
|
|
2352
1953
|
}
|
|
2353
1954
|
function syncCompositeForRead(planes) {
|
|
2354
|
-
|
|
2355
|
-
let
|
|
2356
|
-
|
|
2357
|
-
for (const plane of planesToCompose) {
|
|
2358
|
-
const state = planeStates.get(plane);
|
|
1955
|
+
let planesToCompose = planes?.length ? planes : TERMINAL_RENDER_PLANES, composeAllRows = !1, dirtyRows = /* @__PURE__ */ new Set();
|
|
1956
|
+
for (let plane of planesToCompose) {
|
|
1957
|
+
let state = planeStates.get(plane);
|
|
2359
1958
|
if (!state)
|
|
2360
1959
|
continue;
|
|
2361
|
-
|
|
1960
|
+
let rows = peekDirtyRows(state.buffer);
|
|
2362
1961
|
if (rows === null) {
|
|
2363
|
-
composeAllRows =
|
|
1962
|
+
composeAllRows = !0;
|
|
2364
1963
|
break;
|
|
2365
1964
|
}
|
|
2366
|
-
for (
|
|
1965
|
+
for (let y of rows)
|
|
2367
1966
|
dirtyRows.add(y);
|
|
2368
1967
|
}
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
);
|
|
2374
|
-
syncCompositeCursor();
|
|
1968
|
+
(composeAllRows || dirtyRows.size > 0) && composeRows(
|
|
1969
|
+
composeAllRows ? null : Array.from(dirtyRows).sort((a, b) => a - b),
|
|
1970
|
+
planesToCompose
|
|
1971
|
+
), syncCompositeCursor();
|
|
2375
1972
|
}
|
|
2376
1973
|
function readRowForPlanes(y, planes) {
|
|
2377
|
-
assertNotDisposed()
|
|
2378
|
-
if (y < 0 || y >= compositeBuffer.rows)
|
|
1974
|
+
if (assertNotDisposed(), y < 0 || y >= compositeBuffer.rows)
|
|
2379
1975
|
throw new RangeError("Row out of bounds");
|
|
2380
|
-
composeRows([y], planes?.length ? planes : TERMINAL_RENDER_PLANES);
|
|
2381
|
-
return getBufferRow(compositeBuffer, y);
|
|
1976
|
+
return composeRows([y], planes?.length ? planes : TERMINAL_RENDER_PLANES), getBufferRow(compositeBuffer, y);
|
|
2382
1977
|
}
|
|
2383
1978
|
function pendingDirtyRowsForPlanes(planes) {
|
|
2384
|
-
|
|
2385
|
-
let
|
|
2386
|
-
|
|
2387
|
-
for (const plane of planesToCheck) {
|
|
2388
|
-
const state = planeStates.get(plane);
|
|
1979
|
+
let planesToCheck = planes?.length ? planes : TERMINAL_RENDER_PLANES, full = !1, rows = /* @__PURE__ */ new Set();
|
|
1980
|
+
for (let plane of planesToCheck) {
|
|
1981
|
+
let state = planeStates.get(plane);
|
|
2389
1982
|
if (!state)
|
|
2390
1983
|
continue;
|
|
2391
|
-
|
|
1984
|
+
let dirty = peekDirtyRows(state.buffer);
|
|
2392
1985
|
if (dirty === null) {
|
|
2393
|
-
full =
|
|
1986
|
+
full = !0;
|
|
2394
1987
|
break;
|
|
2395
1988
|
}
|
|
2396
|
-
for (
|
|
1989
|
+
for (let y of dirty)
|
|
2397
1990
|
rows.add(y);
|
|
2398
1991
|
}
|
|
2399
|
-
|
|
2400
|
-
return null;
|
|
2401
|
-
return Array.from(rows).sort((a, b) => a - b);
|
|
1992
|
+
return full ? null : Array.from(rows).sort((a, b) => a - b);
|
|
2402
1993
|
}
|
|
2403
1994
|
function createPlaneTerminalApi(plane) {
|
|
2404
|
-
|
|
1995
|
+
let existing = planeTerminals.get(plane);
|
|
2405
1996
|
if (existing)
|
|
2406
1997
|
return existing;
|
|
2407
|
-
|
|
1998
|
+
let api = {
|
|
2408
1999
|
resize(cols, rows) {
|
|
2409
|
-
assertNotDisposed();
|
|
2410
|
-
base.resize(cols, rows);
|
|
2000
|
+
assertNotDisposed(), base.resize(cols, rows);
|
|
2411
2001
|
},
|
|
2412
2002
|
clear(x, y, w, h) {
|
|
2413
|
-
assertNotDisposed();
|
|
2414
|
-
clearForPlane(plane, x, y, w, h);
|
|
2003
|
+
assertNotDisposed(), clearForPlane(plane, x, y, w, h);
|
|
2415
2004
|
},
|
|
2416
2005
|
write(text, opts2) {
|
|
2417
2006
|
assertNotDisposed();
|
|
2418
|
-
|
|
2419
|
-
const x = opts2?.x;
|
|
2420
|
-
const y = opts2?.y;
|
|
2421
|
-
const style = opts2?.style;
|
|
2007
|
+
let state = getPlaneState(plane), x = opts2?.x, y = opts2?.y, style = opts2?.style;
|
|
2422
2008
|
if (x == null || y == null) {
|
|
2423
|
-
|
|
2009
|
+
let next = writeAtForPlane(
|
|
2424
2010
|
plane,
|
|
2425
2011
|
text,
|
|
2426
2012
|
state.buffer.cursorX,
|
|
2427
2013
|
state.buffer.cursorY,
|
|
2428
2014
|
style ?? state.buffer.cursorStyle
|
|
2429
2015
|
);
|
|
2430
|
-
state.buffer.cursorX = next.x;
|
|
2431
|
-
|
|
2432
|
-
} else {
|
|
2016
|
+
state.buffer.cursorX = next.x, state.buffer.cursorY = next.y;
|
|
2017
|
+
} else
|
|
2433
2018
|
writeAtForPlane(plane, text, x, y, style);
|
|
2434
|
-
}
|
|
2435
2019
|
},
|
|
2436
2020
|
writeAnsi(text, opts2) {
|
|
2437
2021
|
assertNotDisposed();
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
let cx = positionedWrite ? x : state.buffer.cursorX;
|
|
2443
|
-
let cy = positionedWrite ? y : state.buffer.cursorY;
|
|
2444
|
-
let style = positionedWrite ? {} : state.buffer.cursorStyle;
|
|
2445
|
-
for (const seg of parseAnsiSgr(text, style)) {
|
|
2446
|
-
const next = writeAtForPlane(plane, seg.text, cx, cy, seg.style);
|
|
2447
|
-
cx = next.x;
|
|
2448
|
-
cy = next.y;
|
|
2449
|
-
style = seg.style;
|
|
2450
|
-
}
|
|
2451
|
-
if (!positionedWrite) {
|
|
2452
|
-
state.buffer.cursorX = cx;
|
|
2453
|
-
state.buffer.cursorY = cy;
|
|
2454
|
-
state.buffer.cursorStyle = style;
|
|
2022
|
+
let state = getPlaneState(plane), x = opts2?.x, y = opts2?.y, positionedWrite = x != null && y != null, cx = positionedWrite ? x : state.buffer.cursorX, cy = positionedWrite ? y : state.buffer.cursorY, style = positionedWrite ? {} : state.buffer.cursorStyle;
|
|
2023
|
+
for (let seg of parseAnsiSgr(text, style)) {
|
|
2024
|
+
let next = writeAtForPlane(plane, seg.text, cx, cy, seg.style);
|
|
2025
|
+
cx = next.x, cy = next.y, style = seg.style;
|
|
2455
2026
|
}
|
|
2027
|
+
positionedWrite || (state.buffer.cursorX = cx, state.buffer.cursorY = cy, state.buffer.cursorStyle = style);
|
|
2456
2028
|
},
|
|
2457
2029
|
put(x, y, ch, style) {
|
|
2458
|
-
assertNotDisposed();
|
|
2459
|
-
putForPlane(plane, x, y, ch, style);
|
|
2030
|
+
assertNotDisposed(), putForPlane(plane, x, y, ch, style);
|
|
2460
2031
|
},
|
|
2461
2032
|
fill(x, y, w, h, ch, style) {
|
|
2462
|
-
assertNotDisposed();
|
|
2463
|
-
fillForPlane(plane, x, y, w, h, ch, style);
|
|
2033
|
+
assertNotDisposed(), fillForPlane(plane, x, y, w, h, ch, style);
|
|
2464
2034
|
},
|
|
2465
2035
|
scroll(lines) {
|
|
2466
|
-
assertNotDisposed();
|
|
2467
|
-
scrollForPlane(plane, lines);
|
|
2036
|
+
assertNotDisposed(), scrollForPlane(plane, lines);
|
|
2468
2037
|
},
|
|
2469
2038
|
setCursor(x, y, visible) {
|
|
2470
|
-
assertNotDisposed();
|
|
2471
|
-
setCursorForPlane(plane, x, y, visible);
|
|
2039
|
+
assertNotDisposed(), setCursorForPlane(plane, x, y, visible);
|
|
2472
2040
|
},
|
|
2473
2041
|
batch(fn) {
|
|
2474
|
-
assertNotDisposed();
|
|
2475
|
-
return base.batch(fn);
|
|
2042
|
+
return assertNotDisposed(), base.batch(fn);
|
|
2476
2043
|
},
|
|
2477
2044
|
commit(meta) {
|
|
2478
|
-
assertNotDisposed();
|
|
2479
|
-
return base.commit({ planes: meta?.planes ?? [plane], sync: meta?.sync });
|
|
2045
|
+
return assertNotDisposed(), base.commit({ planes: meta?.planes ?? [plane], sync: meta?.sync });
|
|
2480
2046
|
},
|
|
2481
2047
|
on(event, cb) {
|
|
2482
|
-
assertNotDisposed();
|
|
2483
|
-
return base.on(event, cb);
|
|
2048
|
+
return assertNotDisposed(), base.on(event, cb);
|
|
2484
2049
|
},
|
|
2485
2050
|
dispose() {
|
|
2486
2051
|
base.dispose();
|
|
2487
2052
|
},
|
|
2488
2053
|
size() {
|
|
2489
|
-
assertNotDisposed();
|
|
2490
|
-
return base.size();
|
|
2054
|
+
return assertNotDisposed(), base.size();
|
|
2491
2055
|
},
|
|
2492
2056
|
snapshot() {
|
|
2493
2057
|
assertNotDisposed();
|
|
2494
|
-
|
|
2058
|
+
let state = getPlaneState(plane);
|
|
2495
2059
|
return {
|
|
2496
2060
|
cols: state.buffer.cols,
|
|
2497
2061
|
rows: state.buffer.rows,
|
|
@@ -2500,188 +2064,142 @@ function createTerminal(opts) {
|
|
|
2500
2064
|
},
|
|
2501
2065
|
getCell(x, y) {
|
|
2502
2066
|
assertNotDisposed();
|
|
2503
|
-
|
|
2067
|
+
let state = getPlaneState(plane);
|
|
2504
2068
|
if (y < 0 || y >= state.buffer.rows || x < 0 || x >= state.buffer.cols)
|
|
2505
2069
|
throw new RangeError("Cell out of bounds");
|
|
2506
2070
|
return getBufferCell(state.buffer, x, y);
|
|
2507
2071
|
},
|
|
2508
2072
|
getRow(y) {
|
|
2509
2073
|
assertNotDisposed();
|
|
2510
|
-
|
|
2074
|
+
let state = getPlaneState(plane);
|
|
2511
2075
|
if (y < 0 || y >= state.buffer.rows)
|
|
2512
2076
|
throw new RangeError("Row out of bounds");
|
|
2513
2077
|
return getBufferRow(state.buffer, y);
|
|
2514
2078
|
},
|
|
2515
2079
|
setScrollbackLimit(limit) {
|
|
2516
2080
|
assertNotDisposed();
|
|
2517
|
-
|
|
2518
|
-
state.buffer.scrollbackLimit = Math.max(0, Math.floor(limit))
|
|
2519
|
-
|
|
2520
|
-
state.buffer.scrollback.
|
|
2521
|
-
|
|
2522
|
-
state.buffer.scrollback.length - state.buffer.scrollbackLimit
|
|
2523
|
-
);
|
|
2524
|
-
}
|
|
2081
|
+
let state = getPlaneState(plane);
|
|
2082
|
+
state.buffer.scrollbackLimit = Math.max(0, Math.floor(limit)), state.buffer.scrollback.length > state.buffer.scrollbackLimit && state.buffer.scrollback.splice(
|
|
2083
|
+
0,
|
|
2084
|
+
state.buffer.scrollback.length - state.buffer.scrollbackLimit
|
|
2085
|
+
);
|
|
2525
2086
|
},
|
|
2526
2087
|
getScrollbackLines(count) {
|
|
2527
2088
|
assertNotDisposed();
|
|
2528
|
-
|
|
2529
|
-
const all = state.buffer.scrollback.map(
|
|
2089
|
+
let all = getPlaneState(plane).buffer.scrollback.map(
|
|
2530
2090
|
(row) => row.map((cell) => cell.continuation ? " " : cell.ch || " ").join("")
|
|
2531
2091
|
);
|
|
2532
|
-
|
|
2533
|
-
return all;
|
|
2534
|
-
return all.slice(Math.max(0, all.length - Math.max(0, Math.floor(count))));
|
|
2092
|
+
return count == null ? all : all.slice(Math.max(0, all.length - Math.max(0, Math.floor(count))));
|
|
2535
2093
|
},
|
|
2536
2094
|
setFingerprintFn(fn) {
|
|
2537
2095
|
assertNotDisposed();
|
|
2538
|
-
|
|
2096
|
+
let state = getPlaneState(plane);
|
|
2097
|
+
setFingerprintFn(state.buffer, fn);
|
|
2539
2098
|
},
|
|
2540
2099
|
getRowFingerprints(y) {
|
|
2541
2100
|
assertNotDisposed();
|
|
2542
|
-
|
|
2101
|
+
let yy = Math.floor(y), state = getPlaneState(plane);
|
|
2102
|
+
if (!Number.isFinite(yy) || yy < 0 || yy >= state.buffer.rows)
|
|
2103
|
+
throw new RangeError("Row out of bounds");
|
|
2104
|
+
return getRowFingerprints(state.buffer, yy);
|
|
2543
2105
|
}
|
|
2544
2106
|
};
|
|
2545
|
-
planeTerminals.set(plane, api);
|
|
2546
|
-
return api;
|
|
2107
|
+
return api[TERMINAL_ROOT] = base, planeTerminals.set(plane, api), api;
|
|
2547
2108
|
}
|
|
2548
|
-
base = {
|
|
2109
|
+
return base = {
|
|
2549
2110
|
resize(cols, rows) {
|
|
2550
2111
|
assertNotDisposed();
|
|
2551
|
-
|
|
2552
|
-
const prevRows = compositeBuffer.rows;
|
|
2112
|
+
let prevCols = compositeBuffer.cols, prevRows = compositeBuffer.rows;
|
|
2553
2113
|
resizeBuffer(compositeBuffer, cols, rows);
|
|
2554
|
-
for (
|
|
2114
|
+
for (let state of planeStates.values())
|
|
2555
2115
|
resizePlaneState(state, cols, rows);
|
|
2556
|
-
|
|
2557
|
-
emitter.emit("resize", { cols: compositeBuffer.cols, rows: compositeBuffer.rows });
|
|
2116
|
+
(compositeBuffer.cols !== prevCols || compositeBuffer.rows !== prevRows) && emitter.emit("resize", { cols: compositeBuffer.cols, rows: compositeBuffer.rows });
|
|
2558
2117
|
},
|
|
2559
2118
|
clear(x, y, w, h) {
|
|
2560
|
-
assertNotDisposed();
|
|
2561
|
-
clearForPlane("default", x, y, w, h);
|
|
2119
|
+
assertNotDisposed(), clearForPlane("default", x, y, w, h);
|
|
2562
2120
|
},
|
|
2563
2121
|
write(text, opts2) {
|
|
2564
|
-
assertNotDisposed();
|
|
2565
|
-
createPlaneTerminalApi("default").write(text, opts2);
|
|
2122
|
+
assertNotDisposed(), createPlaneTerminalApi("default").write(text, opts2);
|
|
2566
2123
|
},
|
|
2567
2124
|
writeAnsi(text, opts2) {
|
|
2568
|
-
assertNotDisposed();
|
|
2569
|
-
createPlaneTerminalApi("default").writeAnsi(text, opts2);
|
|
2125
|
+
assertNotDisposed(), createPlaneTerminalApi("default").writeAnsi(text, opts2);
|
|
2570
2126
|
},
|
|
2571
2127
|
put(x, y, ch, style) {
|
|
2572
|
-
assertNotDisposed();
|
|
2573
|
-
putForPlane("default", x, y, ch, style);
|
|
2128
|
+
assertNotDisposed(), putForPlane("default", x, y, ch, style);
|
|
2574
2129
|
},
|
|
2575
2130
|
fill(x, y, w, h, ch, style) {
|
|
2576
|
-
assertNotDisposed();
|
|
2577
|
-
fillForPlane("default", x, y, w, h, ch, style);
|
|
2131
|
+
assertNotDisposed(), fillForPlane("default", x, y, w, h, ch, style);
|
|
2578
2132
|
},
|
|
2579
2133
|
scroll(lines) {
|
|
2580
|
-
assertNotDisposed();
|
|
2581
|
-
scrollForPlane("default", lines);
|
|
2134
|
+
assertNotDisposed(), scrollForPlane("default", lines);
|
|
2582
2135
|
},
|
|
2583
|
-
setCursor(x, y, visible =
|
|
2584
|
-
assertNotDisposed();
|
|
2585
|
-
setCursorForPlane("default", x, y, visible);
|
|
2136
|
+
setCursor(x, y, visible = !0) {
|
|
2137
|
+
assertNotDisposed(), setCursorForPlane("default", x, y, visible);
|
|
2586
2138
|
},
|
|
2587
2139
|
batch(fn) {
|
|
2588
|
-
assertNotDisposed()
|
|
2589
|
-
batchingDepth++;
|
|
2140
|
+
assertNotDisposed(), batchingDepth++;
|
|
2590
2141
|
try {
|
|
2591
2142
|
return fn();
|
|
2592
2143
|
} finally {
|
|
2593
|
-
batchingDepth
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
pendingCommitAllPlanes = false;
|
|
2598
|
-
pendingCommitPlanes = null;
|
|
2599
|
-
base.commit({ planes });
|
|
2144
|
+
if (batchingDepth--, batchingDepth === 0 && pendingCommit) {
|
|
2145
|
+
pendingCommit = !1;
|
|
2146
|
+
let planes = pendingCommitAllPlanes ? null : pendingCommitPlanes;
|
|
2147
|
+
pendingCommitAllPlanes = !1, pendingCommitPlanes = null, base.commit({ planes });
|
|
2600
2148
|
}
|
|
2601
2149
|
}
|
|
2602
2150
|
},
|
|
2603
2151
|
commit(meta) {
|
|
2604
|
-
assertNotDisposed()
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
pendingCommitPlanes = null;
|
|
2610
|
-
} else if (!pendingCommitAllPlanes) {
|
|
2611
|
-
pendingCommitPlanes = mergePlanes(pendingCommitPlanes, meta.planes);
|
|
2612
|
-
}
|
|
2613
|
-
return pendingDirtyRowsForPlanes(meta?.planes ?? null);
|
|
2614
|
-
}
|
|
2615
|
-
const planesToCompose = meta?.planes?.length ? meta.planes : TERMINAL_RENDER_PLANES;
|
|
2616
|
-
const pendingScrollOps = takePendingScrollOps(planesToCompose);
|
|
2617
|
-
const preparedScroll = prepareCompositeScrollOps(pendingScrollOps);
|
|
2618
|
-
let scrollOperations = preparedScroll.scrollOperations;
|
|
2619
|
-
let composeAllRows = false;
|
|
2620
|
-
const dirtyRows = /* @__PURE__ */ new Set();
|
|
2621
|
-
for (const plane of planesToCompose) {
|
|
2622
|
-
const state = planeStates.get(plane);
|
|
2152
|
+
if (assertNotDisposed(), batchingDepth > 0)
|
|
2153
|
+
return pendingCommit = !0, meta?.planes?.length ? pendingCommitAllPlanes || (pendingCommitPlanes = mergePlanes(pendingCommitPlanes, meta.planes)) : (pendingCommitAllPlanes = !0, pendingCommitPlanes = null), pendingDirtyRowsForPlanes(meta?.planes ?? null);
|
|
2154
|
+
let planesToCompose = meta?.planes?.length ? meta.planes : TERMINAL_RENDER_PLANES, pendingScrollOps = takePendingScrollOps(planesToCompose), preparedScroll = prepareCompositeScrollOps(pendingScrollOps), scrollOperations = preparedScroll.scrollOperations, composeAllRows = !1, dirtyRows = /* @__PURE__ */ new Set();
|
|
2155
|
+
for (let plane of planesToCompose) {
|
|
2156
|
+
let state = planeStates.get(plane);
|
|
2623
2157
|
if (!state)
|
|
2624
2158
|
continue;
|
|
2625
|
-
|
|
2159
|
+
let rows = collectAndClearDirtyRows(state.buffer);
|
|
2626
2160
|
if (rows === null) {
|
|
2627
|
-
composeAllRows =
|
|
2628
|
-
|
|
2161
|
+
composeAllRows = !0;
|
|
2162
|
+
continue;
|
|
2629
2163
|
}
|
|
2630
|
-
for (
|
|
2164
|
+
for (let y of rows)
|
|
2631
2165
|
dirtyRows.add(y);
|
|
2632
2166
|
}
|
|
2633
|
-
for (
|
|
2167
|
+
for (let y of preparedScroll.extraDirtyRows)
|
|
2634
2168
|
dirtyRows.add(y);
|
|
2635
|
-
|
|
2636
|
-
scrollOperations = dropScrollOpsCoveredByDirtyRows(scrollOperations, normalizedDirtyRows)
|
|
2637
|
-
|
|
2638
|
-
for (const op of scrollOperations)
|
|
2169
|
+
let normalizedDirtyRows = composeAllRows ? null : Array.from(dirtyRows).sort((a, b) => a - b);
|
|
2170
|
+
if (scrollOperations = dropScrollOpsCoveredByDirtyRows(scrollOperations, normalizedDirtyRows), scrollOperations)
|
|
2171
|
+
for (let op of scrollOperations)
|
|
2639
2172
|
scrollBufferRegion(compositeBuffer, op.startY, op.endY, op.delta);
|
|
2640
|
-
}
|
|
2641
2173
|
if (normalizedDirtyRows !== null && normalizedDirtyRows.length === 0) {
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
return pendingCompositeRows;
|
|
2645
|
-
emitter.emit("commit", {
|
|
2174
|
+
let pendingCompositeRows = collectAndClearDirtyRows(compositeBuffer);
|
|
2175
|
+
return pendingCompositeRows !== null && pendingCompositeRows.length === 0 || emitter.emit("commit", {
|
|
2646
2176
|
dirtyRows: pendingCompositeRows,
|
|
2647
2177
|
planes: meta?.planes ?? null,
|
|
2648
2178
|
sync: meta?.sync,
|
|
2649
2179
|
scrollOperations
|
|
2650
|
-
});
|
|
2651
|
-
return pendingCompositeRows;
|
|
2180
|
+
}), pendingCompositeRows;
|
|
2652
2181
|
}
|
|
2653
|
-
composeRows(normalizedDirtyRows);
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
syncCompositeCursor();
|
|
2657
|
-
const committedRows = collectAndClearDirtyRows(compositeBuffer);
|
|
2658
|
-
if (committedRows !== null && committedRows.length === 0)
|
|
2659
|
-
return committedRows;
|
|
2660
|
-
emitter.emit("commit", {
|
|
2182
|
+
composeRows(normalizedDirtyRows), normalizedDirtyRows === null && markAllDirty(compositeBuffer), syncCompositeCursor();
|
|
2183
|
+
let committedRows = collectAndClearDirtyRows(compositeBuffer);
|
|
2184
|
+
return committedRows !== null && committedRows.length === 0 || emitter.emit("commit", {
|
|
2661
2185
|
dirtyRows: committedRows,
|
|
2662
2186
|
planes: meta?.planes ?? null,
|
|
2663
2187
|
sync: meta?.sync,
|
|
2664
2188
|
scrollOperations
|
|
2665
|
-
});
|
|
2666
|
-
return committedRows;
|
|
2189
|
+
}), committedRows;
|
|
2667
2190
|
},
|
|
2668
2191
|
on(event, cb) {
|
|
2669
|
-
assertNotDisposed();
|
|
2670
|
-
return emitter.on(event, cb);
|
|
2192
|
+
return assertNotDisposed(), emitter.on(event, cb);
|
|
2671
2193
|
},
|
|
2672
2194
|
dispose() {
|
|
2673
|
-
disposed =
|
|
2674
|
-
emitter.clear();
|
|
2195
|
+
disposed = !0, emitter.clear();
|
|
2675
2196
|
},
|
|
2676
2197
|
size() {
|
|
2677
|
-
assertNotDisposed();
|
|
2678
|
-
return { cols: compositeBuffer.cols, rows: compositeBuffer.rows };
|
|
2198
|
+
return assertNotDisposed(), { cols: compositeBuffer.cols, rows: compositeBuffer.rows };
|
|
2679
2199
|
},
|
|
2680
2200
|
snapshot() {
|
|
2681
|
-
assertNotDisposed();
|
|
2682
|
-
|
|
2683
|
-
syncCompositeForRead();
|
|
2684
|
-
const source = batchingDepth > 0 ? getPlaneState("default").buffer : compositeBuffer;
|
|
2201
|
+
assertNotDisposed(), batchingDepth === 0 && syncCompositeForRead();
|
|
2202
|
+
let source = batchingDepth > 0 ? getPlaneState("default").buffer : compositeBuffer;
|
|
2685
2203
|
return {
|
|
2686
2204
|
cols: source.cols,
|
|
2687
2205
|
rows: source.rows,
|
|
@@ -2689,176 +2207,131 @@ function createTerminal(opts) {
|
|
|
2689
2207
|
};
|
|
2690
2208
|
},
|
|
2691
2209
|
getCell(x, y) {
|
|
2692
|
-
assertNotDisposed();
|
|
2693
|
-
|
|
2694
|
-
syncCompositeForRead();
|
|
2695
|
-
const source = batchingDepth > 0 ? getPlaneState("default").buffer : compositeBuffer;
|
|
2210
|
+
assertNotDisposed(), batchingDepth === 0 && syncCompositeForRead();
|
|
2211
|
+
let source = batchingDepth > 0 ? getPlaneState("default").buffer : compositeBuffer;
|
|
2696
2212
|
if (y < 0 || y >= source.rows || x < 0 || x >= source.cols)
|
|
2697
2213
|
throw new RangeError("Cell out of bounds");
|
|
2698
2214
|
return getBufferCell(source, x, y);
|
|
2699
2215
|
},
|
|
2700
2216
|
getRow(y) {
|
|
2701
|
-
assertNotDisposed();
|
|
2702
|
-
|
|
2703
|
-
syncCompositeForRead();
|
|
2704
|
-
const source = batchingDepth > 0 ? getPlaneState("default").buffer : compositeBuffer;
|
|
2217
|
+
assertNotDisposed(), batchingDepth === 0 && syncCompositeForRead();
|
|
2218
|
+
let source = batchingDepth > 0 ? getPlaneState("default").buffer : compositeBuffer;
|
|
2705
2219
|
if (y < 0 || y >= source.rows)
|
|
2706
2220
|
throw new RangeError("Row out of bounds");
|
|
2707
2221
|
return getBufferRow(source, y);
|
|
2708
2222
|
},
|
|
2709
2223
|
setScrollbackLimit(limit) {
|
|
2710
2224
|
assertNotDisposed();
|
|
2711
|
-
|
|
2712
|
-
state.buffer.scrollbackLimit = Math.max(0, Math.floor(limit))
|
|
2713
|
-
|
|
2714
|
-
state.buffer.scrollback.
|
|
2715
|
-
|
|
2716
|
-
state.buffer.scrollback.length - state.buffer.scrollbackLimit
|
|
2717
|
-
);
|
|
2718
|
-
}
|
|
2225
|
+
let state = getPlaneState("default");
|
|
2226
|
+
state.buffer.scrollbackLimit = Math.max(0, Math.floor(limit)), state.buffer.scrollback.length > state.buffer.scrollbackLimit && state.buffer.scrollback.splice(
|
|
2227
|
+
0,
|
|
2228
|
+
state.buffer.scrollback.length - state.buffer.scrollbackLimit
|
|
2229
|
+
);
|
|
2719
2230
|
},
|
|
2720
2231
|
getScrollbackLines(count) {
|
|
2721
2232
|
assertNotDisposed();
|
|
2722
|
-
|
|
2723
|
-
const all = state.buffer.scrollback.map(
|
|
2233
|
+
let all = getPlaneState("default").buffer.scrollback.map(
|
|
2724
2234
|
(row) => row.map((cell) => cell.continuation ? " " : cell.ch || " ").join("")
|
|
2725
2235
|
);
|
|
2726
|
-
|
|
2727
|
-
return all;
|
|
2728
|
-
return all.slice(Math.max(0, all.length - Math.max(0, Math.floor(count))));
|
|
2236
|
+
return count == null ? all : all.slice(Math.max(0, all.length - Math.max(0, Math.floor(count))));
|
|
2729
2237
|
},
|
|
2730
2238
|
setFingerprintFn(fn) {
|
|
2731
|
-
assertNotDisposed();
|
|
2732
|
-
setFingerprintFn(compositeBuffer, fn);
|
|
2239
|
+
assertNotDisposed(), setFingerprintFn(compositeBuffer, fn);
|
|
2733
2240
|
},
|
|
2734
2241
|
getRowFingerprints(y) {
|
|
2735
2242
|
assertNotDisposed();
|
|
2736
|
-
|
|
2243
|
+
let yy = Math.floor(y);
|
|
2244
|
+
if (!Number.isFinite(yy) || yy < 0 || yy >= compositeBuffer.rows)
|
|
2245
|
+
throw new RangeError("Row out of bounds");
|
|
2246
|
+
return getRowFingerprints(compositeBuffer, yy);
|
|
2737
2247
|
}
|
|
2738
|
-
}
|
|
2739
|
-
base[TERMINAL_PLANE_INTERNALS] = {
|
|
2248
|
+
}, base[TERMINAL_PLANE_INTERNALS] = {
|
|
2740
2249
|
getPlaneTerminal: createPlaneTerminalApi,
|
|
2741
2250
|
readRowForPlanes,
|
|
2742
2251
|
resetRowsForRender(plane, dirtyRows) {
|
|
2743
|
-
|
|
2744
|
-
const rows = normalizeDirtyRows(dirtyRows, state.buffer.rows);
|
|
2252
|
+
let state = getPlaneState(plane), rows = normalizeDirtyRows(dirtyRows, state.buffer.rows);
|
|
2745
2253
|
if (rows === null) {
|
|
2746
2254
|
for (let y = 0; y < state.buffer.rows; y++)
|
|
2747
2255
|
clearPlaneCoverageRow(state, y);
|
|
2748
2256
|
return;
|
|
2749
2257
|
}
|
|
2750
|
-
for (
|
|
2258
|
+
for (let y of rows)
|
|
2751
2259
|
clearPlaneCoverageRow(state, y);
|
|
2752
2260
|
},
|
|
2753
2261
|
getRowCoverageKind(plane, y) {
|
|
2754
|
-
|
|
2262
|
+
let state = getPlaneState(plane);
|
|
2755
2263
|
if (y < 0 || y >= state.coverage.length)
|
|
2756
2264
|
return 0;
|
|
2757
|
-
|
|
2265
|
+
let row = state.coverage[y];
|
|
2758
2266
|
if (!row?.length)
|
|
2759
2267
|
return 0;
|
|
2760
2268
|
let covered = 0;
|
|
2761
|
-
for (let x = 0; x < row.length; x++)
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
}
|
|
2765
|
-
if (covered === 0)
|
|
2766
|
-
return 0;
|
|
2767
|
-
if (covered >= row.length)
|
|
2768
|
-
return 2;
|
|
2769
|
-
return 1;
|
|
2269
|
+
for (let x = 0; x < row.length; x++)
|
|
2270
|
+
row[x] && covered++;
|
|
2271
|
+
return covered === 0 ? 0 : covered >= row.length ? 2 : 1;
|
|
2770
2272
|
},
|
|
2771
2273
|
scrollRows(plane, startY, endY, lines) {
|
|
2772
2274
|
scrollRowsForPlane(plane, startY, endY, lines);
|
|
2773
2275
|
}
|
|
2774
|
-
};
|
|
2775
|
-
return base;
|
|
2276
|
+
}, base[TERMINAL_ROOT] = base, base;
|
|
2776
2277
|
}
|
|
2777
2278
|
|
|
2778
2279
|
// src/utils/path.ts
|
|
2779
2280
|
function normalizeSeparators(input) {
|
|
2780
2281
|
let out = "";
|
|
2781
2282
|
for (let i = 0; i < input.length; i++) {
|
|
2782
|
-
|
|
2283
|
+
let ch = input[i];
|
|
2783
2284
|
out += ch === "\\" ? "/" : ch;
|
|
2784
2285
|
}
|
|
2785
2286
|
return out;
|
|
2786
2287
|
}
|
|
2787
2288
|
function isAbsolutePath(path) {
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
return true;
|
|
2791
|
-
return /^[A-Z]:\//i.test(p);
|
|
2289
|
+
let p = normalizeSeparators(path);
|
|
2290
|
+
return p.startsWith("/") ? !0 : /^[A-Z]:\//i.test(p);
|
|
2792
2291
|
}
|
|
2793
2292
|
function stripTrailingSlash(path) {
|
|
2794
|
-
|
|
2293
|
+
let p = normalizeSeparators(path);
|
|
2795
2294
|
if (p === "/")
|
|
2796
2295
|
return p;
|
|
2797
2296
|
let end = p.length;
|
|
2798
|
-
|
|
2297
|
+
for (; end > 0 && p.charCodeAt(end - 1) === 47; )
|
|
2799
2298
|
end--;
|
|
2800
2299
|
return end === p.length ? p : p.slice(0, end);
|
|
2801
2300
|
}
|
|
2802
2301
|
function joinPath(base, next) {
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
if (!a)
|
|
2806
|
-
return b;
|
|
2807
|
-
if (!b)
|
|
2808
|
-
return a;
|
|
2809
|
-
if (a.endsWith("/"))
|
|
2810
|
-
return `${a}${b.startsWith("/") ? b.slice(1) : b}`;
|
|
2811
|
-
return `${a}/${b.startsWith("/") ? b.slice(1) : b}`;
|
|
2302
|
+
let a = normalizeSeparators(base), b = normalizeSeparators(next);
|
|
2303
|
+
return a ? b ? a.endsWith("/") ? `${a}${b.startsWith("/") ? b.slice(1) : b}` : `${a}/${b.startsWith("/") ? b.slice(1) : b}` : a : b;
|
|
2812
2304
|
}
|
|
2813
2305
|
function dirname(path) {
|
|
2814
|
-
|
|
2815
|
-
const normalized = normalizeSeparators(p);
|
|
2306
|
+
let p = stripTrailingSlash(path), normalized = normalizeSeparators(p);
|
|
2816
2307
|
if (normalized === "/")
|
|
2817
2308
|
return "/";
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
const idx = normalized.lastIndexOf("/");
|
|
2821
|
-
if (idx < start)
|
|
2822
|
-
return drive ? `${drive}/` : "";
|
|
2823
|
-
const out = normalized.slice(0, idx) || (drive ? `${drive}/` : "/");
|
|
2824
|
-
return out;
|
|
2309
|
+
let drive = normalized.match(/^([A-Z]:)\//i)?.[1] ?? null, start = drive ? drive.length + 1 : 0, idx = normalized.lastIndexOf("/");
|
|
2310
|
+
return idx < start ? drive ? `${drive}/` : "" : normalized.slice(0, idx) || (drive ? `${drive}/` : "/");
|
|
2825
2311
|
}
|
|
2826
2312
|
function normalizePath(path) {
|
|
2827
|
-
|
|
2313
|
+
let raw = normalizeSeparators(path);
|
|
2828
2314
|
if (!raw)
|
|
2829
2315
|
return "";
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
if (stack.length > 0 && stack[stack.length - 1] !== "..") {
|
|
2840
|
-
stack.pop();
|
|
2316
|
+
let drive = raw.match(/^([A-Z]:)(\/|$)/i)?.[1] ?? null, rest = drive ? raw.slice(drive.length) : raw, absolute = rest.startsWith("/"), parts = rest.split("/").filter(Boolean), stack = [];
|
|
2317
|
+
for (let part of parts)
|
|
2318
|
+
if (part !== ".") {
|
|
2319
|
+
if (part === "..") {
|
|
2320
|
+
if (stack.length > 0 && stack[stack.length - 1] !== "..") {
|
|
2321
|
+
stack.pop();
|
|
2322
|
+
continue;
|
|
2323
|
+
}
|
|
2324
|
+
absolute || stack.push("..");
|
|
2841
2325
|
continue;
|
|
2842
2326
|
}
|
|
2843
|
-
|
|
2844
|
-
stack.push("..");
|
|
2845
|
-
continue;
|
|
2327
|
+
stack.push(part);
|
|
2846
2328
|
}
|
|
2847
|
-
|
|
2848
|
-
}
|
|
2849
|
-
const prefix = drive ? `${drive}${absolute ? "/" : ""}` : absolute ? "/" : "";
|
|
2850
|
-
const joined = stack.join("/");
|
|
2851
|
-
const out = `${prefix}${joined}`;
|
|
2852
|
-
return out || (absolute ? drive ? `${drive}/` : "/" : "");
|
|
2329
|
+
let prefix = drive ? `${drive}${absolute ? "/" : ""}` : absolute ? "/" : "", joined = stack.join("/");
|
|
2330
|
+
return `${prefix}${joined}` || (absolute ? drive ? `${drive}/` : "/" : "");
|
|
2853
2331
|
}
|
|
2854
2332
|
function resolvePath(baseAbs, input) {
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
if (!b)
|
|
2858
|
-
return i;
|
|
2859
|
-
if (isAbsolutePath(i))
|
|
2860
|
-
return i;
|
|
2861
|
-
return normalizePath(joinPath(b, i));
|
|
2333
|
+
let b = normalizePath(baseAbs), i = normalizePath(input);
|
|
2334
|
+
return !b || isAbsolutePath(i) ? i : normalizePath(joinPath(b, i));
|
|
2862
2335
|
}
|
|
2863
2336
|
|
|
2864
2337
|
// src/core/path-suggest.ts
|
|
@@ -2868,55 +2341,46 @@ function lower(s) {
|
|
|
2868
2341
|
function normalizePathInputSeparators(input) {
|
|
2869
2342
|
let out = "";
|
|
2870
2343
|
for (let i = 0; i < input.length; i++) {
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
continue;
|
|
2874
|
-
out += ch === "\\" ? "/" : ch;
|
|
2344
|
+
let ch = input[i];
|
|
2345
|
+
ch !== "\r" && (out += ch === "\\" ? "/" : ch);
|
|
2875
2346
|
}
|
|
2876
2347
|
return out;
|
|
2877
2348
|
}
|
|
2878
2349
|
function stripCarriageReturns(input) {
|
|
2879
2350
|
let out = "";
|
|
2880
2351
|
for (let i = 0; i < input.length; i++) {
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
out += ch;
|
|
2352
|
+
let ch = input[i];
|
|
2353
|
+
ch !== "\r" && (out += ch);
|
|
2884
2354
|
}
|
|
2885
2355
|
return out;
|
|
2886
2356
|
}
|
|
2887
2357
|
function stripLeadingDotSlash(input) {
|
|
2888
2358
|
let i = 0;
|
|
2889
|
-
|
|
2359
|
+
for (; i + 1 < input.length && input.charCodeAt(i) === 46 && input.charCodeAt(i + 1) === 47; )
|
|
2890
2360
|
i += 2;
|
|
2891
|
-
}
|
|
2892
2361
|
return i === 0 ? input : input.slice(i);
|
|
2893
2362
|
}
|
|
2894
2363
|
function stripLeadingSlashes(input) {
|
|
2895
2364
|
let i = 0;
|
|
2896
|
-
|
|
2365
|
+
for (; i < input.length && input.charCodeAt(i) === 47; )
|
|
2897
2366
|
i++;
|
|
2898
2367
|
return i === 0 ? input : input.slice(i);
|
|
2899
2368
|
}
|
|
2900
2369
|
function stripTrailingSlashes(input) {
|
|
2901
2370
|
let end = input.length;
|
|
2902
|
-
|
|
2371
|
+
for (; end > 0 && input.charCodeAt(end - 1) === 47; )
|
|
2903
2372
|
end--;
|
|
2904
2373
|
return end === input.length ? input : input.slice(0, end);
|
|
2905
2374
|
}
|
|
2906
2375
|
function collapseSlashes(input) {
|
|
2907
|
-
let out = "";
|
|
2908
|
-
let previousWasSlash = false;
|
|
2376
|
+
let out = "", previousWasSlash = !1;
|
|
2909
2377
|
for (let i = 0; i < input.length; i++) {
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
if (!previousWasSlash)
|
|
2914
|
-
out += "/";
|
|
2915
|
-
previousWasSlash = true;
|
|
2378
|
+
let ch = input[i];
|
|
2379
|
+
if (ch === "/") {
|
|
2380
|
+
previousWasSlash || (out += "/"), previousWasSlash = !0;
|
|
2916
2381
|
continue;
|
|
2917
2382
|
}
|
|
2918
|
-
out += ch;
|
|
2919
|
-
previousWasSlash = false;
|
|
2383
|
+
out += ch, previousWasSlash = !1;
|
|
2920
2384
|
}
|
|
2921
2385
|
return out;
|
|
2922
2386
|
}
|
|
@@ -2926,52 +2390,35 @@ function normalizeRelativePathForIgnore(input) {
|
|
|
2926
2390
|
);
|
|
2927
2391
|
}
|
|
2928
2392
|
function fuzzyScore(name, query) {
|
|
2929
|
-
|
|
2930
|
-
const q = lower(query);
|
|
2393
|
+
let n = lower(name), q = lower(query);
|
|
2931
2394
|
if (!q)
|
|
2932
2395
|
return 0;
|
|
2933
2396
|
if (n === q)
|
|
2934
2397
|
return 2e3;
|
|
2935
2398
|
if (n.startsWith(q))
|
|
2936
2399
|
return 1500 - (n.length - q.length);
|
|
2937
|
-
|
|
2400
|
+
let idx = n.indexOf(q);
|
|
2938
2401
|
if (idx >= 0)
|
|
2939
2402
|
return 1200 - idx;
|
|
2940
|
-
let ni = 0;
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
let lastMatch = -1;
|
|
2944
|
-
while (ni < n.length && qi < q.length) {
|
|
2945
|
-
if (n[ni] === q[qi]) {
|
|
2946
|
-
if (lastMatch >= 0)
|
|
2947
|
-
gaps += ni - lastMatch - 1;
|
|
2948
|
-
lastMatch = ni;
|
|
2949
|
-
qi++;
|
|
2950
|
-
}
|
|
2951
|
-
ni++;
|
|
2952
|
-
}
|
|
2403
|
+
let ni = 0, qi = 0, gaps = 0, lastMatch = -1;
|
|
2404
|
+
for (; ni < n.length && qi < q.length; )
|
|
2405
|
+
n[ni] === q[qi] && (lastMatch >= 0 && (gaps += ni - lastMatch - 1), lastMatch = ni, qi++), ni++;
|
|
2953
2406
|
if (qi !== q.length)
|
|
2954
2407
|
return null;
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
return null;
|
|
2958
|
-
return 800 - gaps;
|
|
2408
|
+
let maxGaps = Math.max(4, q.length * 2);
|
|
2409
|
+
return gaps > maxGaps ? null : 800 - gaps;
|
|
2959
2410
|
}
|
|
2960
2411
|
function parsePathQuery(rawInput) {
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
if (lastSlash < 0)
|
|
2964
|
-
return { dirPrefix: "", query: input };
|
|
2965
|
-
return {
|
|
2412
|
+
let input = normalizePathInputSeparators(rawInput), lastSlash = input.lastIndexOf("/");
|
|
2413
|
+
return lastSlash < 0 ? { dirPrefix: "", query: input } : {
|
|
2966
2414
|
dirPrefix: input.slice(0, lastSlash + 1),
|
|
2967
2415
|
query: input.slice(lastSlash + 1)
|
|
2968
2416
|
};
|
|
2969
2417
|
}
|
|
2970
2418
|
async function suggestPaths(options) {
|
|
2971
|
-
|
|
2972
|
-
const rawInput = String(options.input ?? "");
|
|
2419
|
+
let rawWorkspace = String(options.workspaceAbs ?? ""), rawInput = String(options.input ?? "");
|
|
2973
2420
|
if (!rawWorkspace || rawWorkspace.includes("\0") || rawInput.includes("\0")) {
|
|
2974
|
-
|
|
2421
|
+
let safeWorkspaceAbs = normalizePath(rawWorkspace || ".");
|
|
2975
2422
|
return {
|
|
2976
2423
|
baseDirAbs: resolvePath(safeWorkspaceAbs, "."),
|
|
2977
2424
|
dirPrefix: "",
|
|
@@ -2979,64 +2426,31 @@ async function suggestPaths(options) {
|
|
|
2979
2426
|
suggestions: []
|
|
2980
2427
|
};
|
|
2981
2428
|
}
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
let query = parsed.query;
|
|
2987
|
-
let baseDirAbs = resolvePath(workspaceAbs, dirPrefix || ".");
|
|
2988
|
-
let maxDepth = options.maxDepth ?? 0;
|
|
2989
|
-
if (!query)
|
|
2990
|
-
maxDepth = 0;
|
|
2991
|
-
const allowHidden = Boolean(options.showHidden);
|
|
2992
|
-
const allowDir = options.mode === "directory" || options.mode === "any" || options.mode === "file";
|
|
2993
|
-
const allowFile = options.mode === "file" || options.mode === "any";
|
|
2994
|
-
const max = Math.max(0, Math.floor(options.max));
|
|
2995
|
-
if (max <= 0) {
|
|
2429
|
+
let workspaceAbs = normalizePath(rawWorkspace), input = normalizePathInputSeparators(rawInput), parsed = parsePathQuery(input), dirPrefix = parsed.dirPrefix, query = parsed.query, baseDirAbs = resolvePath(workspaceAbs, dirPrefix || "."), maxDepth = options.maxDepth ?? 0;
|
|
2430
|
+
query || (maxDepth = 0);
|
|
2431
|
+
let allowHidden = !!options.showHidden, allowDir = options.mode === "directory" || options.mode === "any" || options.mode === "file", allowFile = options.mode === "file" || options.mode === "any", max = Math.max(0, Math.floor(options.max));
|
|
2432
|
+
if (max <= 0)
|
|
2996
2433
|
return { baseDirAbs, dirPrefix, query, suggestions: [] };
|
|
2997
|
-
|
|
2998
|
-
const maxDepthClamped = Math.max(0, Math.floor(maxDepth || 0));
|
|
2999
|
-
const keepCapacity = Math.max(500, Math.min(8e3, max * 40));
|
|
3000
|
-
const maxScannedDirs = Math.max(200, Math.min(6e3, 800 + maxDepthClamped * 600));
|
|
3001
|
-
const maxScannedEntries = Math.max(2e3, Math.min(8e4, max * 2e3));
|
|
3002
|
-
const scored = [];
|
|
3003
|
-
let scannedDirs = 0;
|
|
3004
|
-
let scannedEntries = 0;
|
|
3005
|
-
let scanAborted = false;
|
|
2434
|
+
let maxDepthClamped = Math.max(0, Math.floor(maxDepth || 0)), keepCapacity = Math.max(500, Math.min(8e3, max * 40)), maxScannedDirs = Math.max(200, Math.min(6e3, 800 + maxDepthClamped * 600)), maxScannedEntries = Math.max(2e3, Math.min(8e4, max * 2e3)), scored = [], scannedDirs = 0, scannedEntries = 0, scanAborted = !1;
|
|
3006
2435
|
function cmpScored(a, b) {
|
|
3007
|
-
|
|
3008
|
-
return b.score - a.score;
|
|
3009
|
-
if (a.depth !== b.depth)
|
|
3010
|
-
return a.depth - b.depth;
|
|
3011
|
-
return a.name.localeCompare(b.name);
|
|
2436
|
+
return a.score !== b.score ? b.score - a.score : a.depth !== b.depth ? a.depth - b.depth : a.name.localeCompare(b.name);
|
|
3012
2437
|
}
|
|
3013
2438
|
function pruneScored() {
|
|
3014
|
-
|
|
3015
|
-
return;
|
|
3016
|
-
scored.sort(cmpScored);
|
|
3017
|
-
scored.length = keepCapacity;
|
|
2439
|
+
scored.length <= keepCapacity || (scored.sort(cmpScored), scored.length = keepCapacity);
|
|
3018
2440
|
}
|
|
3019
2441
|
function scoreItem(name, relPath, q) {
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
if (byName == null && byPath == null)
|
|
3023
|
-
return null;
|
|
3024
|
-
if (byName != null && byPath != null)
|
|
3025
|
-
return Math.max(byName + 50, byPath);
|
|
3026
|
-
return byName ?? byPath;
|
|
2442
|
+
let byName = fuzzyScore(name, q), byPath = fuzzyScore(relPath, q);
|
|
2443
|
+
return byName == null && byPath == null ? null : byName != null && byPath != null ? Math.max(byName + 50, byPath) : byName ?? byPath;
|
|
3027
2444
|
}
|
|
3028
2445
|
async function searchDir(dirAbs, currentDepth, currentRelPath, preloadedEntries) {
|
|
3029
|
-
if (scanAborted)
|
|
3030
|
-
return;
|
|
3031
|
-
if (currentDepth > maxDepth)
|
|
2446
|
+
if (scanAborted || currentDepth > maxDepth)
|
|
3032
2447
|
return;
|
|
3033
2448
|
if (dirAbs.includes("\0")) {
|
|
3034
|
-
scanAborted =
|
|
2449
|
+
scanAborted = !0;
|
|
3035
2450
|
return;
|
|
3036
2451
|
}
|
|
3037
|
-
scannedDirs
|
|
3038
|
-
|
|
3039
|
-
scanAborted = true;
|
|
2452
|
+
if (scannedDirs++, scannedDirs > maxScannedDirs) {
|
|
2453
|
+
scanAborted = !0;
|
|
3040
2454
|
return;
|
|
3041
2455
|
}
|
|
3042
2456
|
let entries = [];
|
|
@@ -3045,109 +2459,84 @@ async function suggestPaths(options) {
|
|
|
3045
2459
|
} catch {
|
|
3046
2460
|
return;
|
|
3047
2461
|
}
|
|
3048
|
-
for (
|
|
2462
|
+
for (let e of entries) {
|
|
3049
2463
|
if (scanAborted)
|
|
3050
2464
|
return;
|
|
3051
|
-
scannedEntries
|
|
3052
|
-
|
|
3053
|
-
scanAborted = true;
|
|
2465
|
+
if (scannedEntries++, scannedEntries > maxScannedEntries) {
|
|
2466
|
+
scanAborted = !0;
|
|
3054
2467
|
return;
|
|
3055
2468
|
}
|
|
3056
2469
|
if (!allowHidden && !query && e.name.startsWith("."))
|
|
3057
2470
|
continue;
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
continue;
|
|
3066
|
-
const score = scoreItem(e.name, itemRelPath, query);
|
|
3067
|
-
if (score != null) {
|
|
3068
|
-
scored.push({
|
|
2471
|
+
let itemRelPath = currentRelPath ? `${currentRelPath}/${e.name}` : e.name, normalizedRelPath = normalizeRelativePathForIgnore(`${dirPrefix}${itemRelPath}`), isDir = e.kind === "directory";
|
|
2472
|
+
if (!options.shouldIgnore?.({ normalizedRelPath, isDir })) {
|
|
2473
|
+
if (e.kind === "directory") {
|
|
2474
|
+
if (!allowDir)
|
|
2475
|
+
continue;
|
|
2476
|
+
let score = scoreItem(e.name, itemRelPath, query);
|
|
2477
|
+
score != null && (scored.push({
|
|
3069
2478
|
score,
|
|
3070
2479
|
name: e.name,
|
|
3071
2480
|
kind: "directory",
|
|
3072
2481
|
depth: currentDepth,
|
|
3073
2482
|
relPath: itemRelPath
|
|
3074
|
-
});
|
|
3075
|
-
if (scored.length > keepCapacity * 2)
|
|
3076
|
-
pruneScored();
|
|
3077
|
-
}
|
|
3078
|
-
await searchDir(`${dirAbs}/${e.name}`, currentDepth + 1, itemRelPath);
|
|
3079
|
-
continue;
|
|
3080
|
-
}
|
|
3081
|
-
if (e.kind === "file") {
|
|
3082
|
-
if (!allowFile)
|
|
2483
|
+
}), scored.length > keepCapacity * 2 && pruneScored()), await searchDir(`${dirAbs}/${e.name}`, currentDepth + 1, itemRelPath);
|
|
3083
2484
|
continue;
|
|
3084
|
-
|
|
3085
|
-
if (
|
|
3086
|
-
|
|
2485
|
+
}
|
|
2486
|
+
if (e.kind === "file") {
|
|
2487
|
+
if (!allowFile)
|
|
2488
|
+
continue;
|
|
2489
|
+
let score = scoreItem(e.name, itemRelPath, query);
|
|
2490
|
+
score != null && (scored.push({
|
|
3087
2491
|
score,
|
|
3088
2492
|
name: e.name,
|
|
3089
2493
|
kind: "file",
|
|
3090
2494
|
depth: currentDepth,
|
|
3091
2495
|
relPath: itemRelPath
|
|
3092
|
-
});
|
|
3093
|
-
if (scored.length > keepCapacity * 2)
|
|
3094
|
-
pruneScored();
|
|
2496
|
+
}), scored.length > keepCapacity * 2 && pruneScored());
|
|
3095
2497
|
}
|
|
3096
2498
|
}
|
|
3097
2499
|
}
|
|
3098
2500
|
}
|
|
3099
|
-
let ok =
|
|
3100
|
-
let baseEntries = null;
|
|
2501
|
+
let ok = !0, baseEntries = null;
|
|
3101
2502
|
try {
|
|
3102
2503
|
baseEntries = await options.listDir(baseDirAbs);
|
|
3103
2504
|
} catch {
|
|
3104
|
-
ok =
|
|
2505
|
+
ok = !1;
|
|
3105
2506
|
}
|
|
3106
2507
|
if (!ok && dirPrefix) {
|
|
3107
|
-
|
|
3108
|
-
dirPrefix = "";
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
maxDepth = 0;
|
|
3114
|
-
baseEntries = null;
|
|
3115
|
-
}
|
|
3116
|
-
await searchDir(baseDirAbs, 0, "", baseEntries ?? void 0);
|
|
3117
|
-
pruneScored();
|
|
3118
|
-
scored.sort(cmpScored);
|
|
3119
|
-
const list = max ? scored.slice(0, max) : [];
|
|
3120
|
-
const suggestions = list.map((s) => {
|
|
3121
|
-
const suffix = s.kind === "directory" ? "/" : "";
|
|
3122
|
-
const completion = `${dirPrefix}${s.relPath}${suffix}`;
|
|
3123
|
-
const absPath = resolvePath(workspaceAbs, `${dirPrefix}${s.relPath}`);
|
|
2508
|
+
let fallbackQuery = stripTrailingSlashes(input);
|
|
2509
|
+
dirPrefix = "", query = fallbackQuery, baseDirAbs = workspaceAbs, maxDepth = options.maxDepth ?? 0, query || (maxDepth = 0), baseEntries = null;
|
|
2510
|
+
}
|
|
2511
|
+
await searchDir(baseDirAbs, 0, "", baseEntries ?? void 0), pruneScored(), scored.sort(cmpScored);
|
|
2512
|
+
let suggestions = (max ? scored.slice(0, max) : []).map((s) => {
|
|
2513
|
+
let suffix = s.kind === "directory" ? "/" : "", completion = `${dirPrefix}${s.relPath}${suffix}`, absPath = resolvePath(workspaceAbs, `${dirPrefix}${s.relPath}`);
|
|
3124
2514
|
return { kind: s.kind, display: completion, completion, absPath };
|
|
3125
2515
|
});
|
|
3126
2516
|
return { baseDirAbs, dirPrefix, query, suggestions };
|
|
3127
2517
|
}
|
|
3128
2518
|
function resolveUserPath(workspaceAbs, input, options) {
|
|
3129
|
-
|
|
2519
|
+
let raw = stripCarriageReturns(input ?? "").trim();
|
|
3130
2520
|
if (!raw)
|
|
3131
2521
|
return resolvePath(normalizePath(workspaceAbs), ".");
|
|
3132
2522
|
if (raw === "~" || raw.startsWith("~/")) {
|
|
3133
|
-
|
|
2523
|
+
let home = String(options?.homeDir ?? "").trim();
|
|
3134
2524
|
if (home) {
|
|
3135
|
-
|
|
2525
|
+
let rest = raw === "~" ? "" : raw.slice(2);
|
|
3136
2526
|
return resolvePath(normalizePath(home), rest);
|
|
3137
2527
|
}
|
|
3138
2528
|
}
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
return normalizePath(normalized);
|
|
3142
|
-
return resolvePath(normalizePath(workspaceAbs), normalized);
|
|
2529
|
+
let normalized = normalizePathInputSeparators(raw);
|
|
2530
|
+
return isAbsolutePath(normalized) ? normalizePath(normalized) : resolvePath(normalizePath(workspaceAbs), normalized);
|
|
3143
2531
|
}
|
|
3144
2532
|
function suggestParentHint(path) {
|
|
3145
|
-
|
|
3146
|
-
const d = dirname(p);
|
|
2533
|
+
let p = normalizePath(path), d = dirname(p);
|
|
3147
2534
|
return d ? joinPath(d, "..") : "..";
|
|
3148
2535
|
}
|
|
3149
2536
|
|
|
3150
2537
|
// src/utils/newlines.ts
|
|
3151
2538
|
function normalizeNewlines(text) {
|
|
3152
|
-
return text.replace(/\r\n/g,
|
|
2539
|
+
return text.replace(/\r\n/g, `
|
|
2540
|
+
`).replace(/\r/g, `
|
|
2541
|
+
`);
|
|
3153
2542
|
}
|