@simon_he/vue-tui 1.0.2 → 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 +84 -26
- package/dist/TMermaidText-frVr8Ysb.js +885 -0
- package/dist/{TSelect-DR0FomSu.js → TSelect-tJ87rKPM.js} +59 -242
- package/dist/{TTree-kzhlB5P0.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 +5146 -6767
- package/dist/cli.d.cts +5 -1
- package/dist/cli.d.ts +5 -1
- package/dist/cli.js +2869 -154
- 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.cjs +843 -1469
- 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-BniJSQyX.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-DBFNYr8f.js → hyperlink-_1FAj7Wq.js} +440 -13
- package/dist/index.cjs +5017 -10339
- 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/stdout-metrics.d.ts +10 -0
- package/dist/renderer/cli/stdout-renderer.d.ts +3 -0
- 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 +7207 -12437
- 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 +119 -14
- 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,47 +1171,38 @@ function clamp(n, min, max) {
|
|
|
1245
1171
|
}
|
|
1246
1172
|
function setFingerprintFn(buffer, fn) {
|
|
1247
1173
|
buffer.fingerprintFn = fn;
|
|
1248
|
-
|
|
1174
|
+
let len = buffer.rows * buffer.cols;
|
|
1249
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)
|
|
1266
|
-
return null;
|
|
1267
|
-
if (buffer.rows <= 0 || buffer.cols <= 0)
|
|
1189
|
+
if (!buffer.soaFingerprints || buffer.rows <= 0 || buffer.cols <= 0)
|
|
1268
1190
|
return null;
|
|
1269
|
-
|
|
1191
|
+
let yy = Math.floor(y);
|
|
1270
1192
|
if (!Number.isFinite(yy) || yy < 0 || yy >= buffer.rows)
|
|
1271
1193
|
return null;
|
|
1272
|
-
|
|
1273
|
-
const base = physY * buffer.cols;
|
|
1194
|
+
let base = physicalRowIndex(buffer, yy) * buffer.cols;
|
|
1274
1195
|
return buffer.soaFingerprints.subarray(base, base + buffer.cols);
|
|
1275
1196
|
}
|
|
1276
1197
|
function updateCellFingerprint(buffer, physY, x, ch, style) {
|
|
1277
|
-
|
|
1278
|
-
return;
|
|
1279
|
-
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));
|
|
1280
1199
|
}
|
|
1281
1200
|
function updateRangeFingerprint(buffer, physY, x0, x1, ch, style) {
|
|
1282
1201
|
if (!buffer.soaFingerprints || !buffer.fingerprintFn)
|
|
1283
1202
|
return;
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
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++)
|
|
1287
1205
|
buffer.soaFingerprints[base + x] = fp;
|
|
1288
|
-
}
|
|
1289
1206
|
}
|
|
1290
1207
|
function physicalRowIndex(buffer, y) {
|
|
1291
1208
|
return (buffer.gridStart + y) % buffer.rows;
|
|
@@ -1297,400 +1214,264 @@ function getBufferCell(buffer, x, y) {
|
|
|
1297
1214
|
return getBufferRow(buffer, y)[x];
|
|
1298
1215
|
}
|
|
1299
1216
|
function markAllDirty(buffer) {
|
|
1300
|
-
|
|
1301
|
-
return;
|
|
1302
|
-
buffer.dirtyAll = true;
|
|
1303
|
-
buffer.dirtyCount = buffer.rows;
|
|
1304
|
-
buffer.dirtyMin = 0;
|
|
1305
|
-
buffer.dirtyMax = buffer.rows - 1;
|
|
1217
|
+
buffer.rows <= 0 || (buffer.dirtyAll = !0, buffer.dirtyCount = buffer.rows, buffer.dirtyMin = 0, buffer.dirtyMax = buffer.rows - 1);
|
|
1306
1218
|
}
|
|
1307
1219
|
function markDirty(buffer, y) {
|
|
1308
|
-
|
|
1309
|
-
return;
|
|
1310
|
-
if (y < 0 || y >= buffer.rows)
|
|
1311
|
-
return;
|
|
1312
|
-
if (buffer.dirtyBits[y]) {
|
|
1313
|
-
return;
|
|
1314
|
-
}
|
|
1315
|
-
buffer.dirtyBits[y] = 1;
|
|
1316
|
-
buffer.dirtyCount++;
|
|
1317
|
-
if (y < buffer.dirtyMin)
|
|
1318
|
-
buffer.dirtyMin = y;
|
|
1319
|
-
if (y > buffer.dirtyMax)
|
|
1320
|
-
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));
|
|
1321
1221
|
}
|
|
1322
1222
|
function clearCellRange(row, startX, endXExclusive) {
|
|
1323
|
-
|
|
1223
|
+
let blank = createBlankCell();
|
|
1324
1224
|
for (let x = startX; x < endXExclusive; x++)
|
|
1325
1225
|
row[x] = blank;
|
|
1326
1226
|
}
|
|
1327
1227
|
function clearWideIfOverwriting(row, x) {
|
|
1328
|
-
|
|
1329
|
-
if (
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
row[x] = createBlankCell();
|
|
1335
|
-
return;
|
|
1336
|
-
}
|
|
1337
|
-
if (cell.width === 2) {
|
|
1338
|
-
row[x] = createBlankCell();
|
|
1339
|
-
if (x + 1 < row.length)
|
|
1340
|
-
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()));
|
|
1341
1235
|
}
|
|
1342
1236
|
}
|
|
1343
1237
|
function putCell(buffer, x, y, ch, style) {
|
|
1344
|
-
if (y < 0 || y >= buffer.rows)
|
|
1238
|
+
if (y < 0 || y >= buffer.rows || x < 0 || x >= buffer.cols)
|
|
1345
1239
|
return;
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
const next = width === 2 && x + 1 < buffer.cols ? row[x + 1] : void 0;
|
|
1352
|
-
const previousWideOverlap = Boolean(
|
|
1353
|
-
previous?.continuation || previous?.width === 2 || next?.continuation || next?.width === 2
|
|
1354
|
-
);
|
|
1355
|
-
clearWideIfOverwriting(row, x);
|
|
1356
|
-
if (width === 2 && x + 1 < buffer.cols)
|
|
1357
|
-
clearWideIfOverwriting(row, x + 1);
|
|
1358
|
-
if (width === 2 && x + 1 >= buffer.cols) {
|
|
1359
|
-
const blank = createBlankCell();
|
|
1360
|
-
row[x] = blank;
|
|
1361
|
-
if (buffer.soaFingerprints) {
|
|
1362
|
-
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)
|
|
1363
1245
|
recomputeFingerprintsForRows(buffer, y, y + 1);
|
|
1364
|
-
|
|
1365
|
-
|
|
1246
|
+
else {
|
|
1247
|
+
let physY = physicalRowIndex(buffer, y);
|
|
1366
1248
|
updateCellFingerprint(buffer, physY, x, blank.ch, blank.style);
|
|
1367
1249
|
}
|
|
1368
|
-
}
|
|
1369
1250
|
markDirty(buffer, y);
|
|
1370
1251
|
return;
|
|
1371
1252
|
}
|
|
1372
|
-
|
|
1373
|
-
row[x] = cell
|
|
1374
|
-
|
|
1375
|
-
row[x + 1] = createContinuationCell(style);
|
|
1376
|
-
if (buffer.soaFingerprints) {
|
|
1377
|
-
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)
|
|
1378
1256
|
recomputeFingerprintsForRows(buffer, y, y + 1);
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
updateCellFingerprint(buffer, physY, x, cell.ch, cell.style);
|
|
1382
|
-
if (width === 2 && x + 1 < buffer.cols) {
|
|
1383
|
-
updateCellFingerprint(buffer, physY, x + 1, "", cell.style);
|
|
1384
|
-
}
|
|
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);
|
|
1385
1260
|
}
|
|
1386
|
-
}
|
|
1387
1261
|
markDirty(buffer, y);
|
|
1388
1262
|
}
|
|
1389
1263
|
function fillRect(buffer, x, y, w, h, ch = " ", style) {
|
|
1390
1264
|
if (w <= 0 || h <= 0 || buffer.cols === 0 || buffer.rows === 0)
|
|
1391
1265
|
return;
|
|
1392
|
-
|
|
1393
|
-
const y0 = clamp(Math.floor(y), 0, buffer.rows);
|
|
1394
|
-
const x1 = clamp(Math.floor(x + w), 0, buffer.cols);
|
|
1395
|
-
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);
|
|
1396
1267
|
if (x1 <= x0 || y1 <= y0)
|
|
1397
1268
|
return;
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
const fillCell2 = createCell(ch, style, buffer.widthProvider);
|
|
1401
|
-
const blank2 = createBlankCell();
|
|
1269
|
+
if (charCellWidth(ch, buffer.widthProvider) === 1) {
|
|
1270
|
+
let fillCell2 = createCell(ch, style, buffer.widthProvider), blank2 = createBlankCell();
|
|
1402
1271
|
for (let yy = y0; yy < y1; yy++) {
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
if (clearsLeftWideBase)
|
|
1407
|
-
clearWideIfOverwriting(row, x0);
|
|
1408
|
-
row.fill(fillCell2, x0, x1);
|
|
1409
|
-
if (clearsRightContinuation)
|
|
1410
|
-
row[x1] = blank2;
|
|
1411
|
-
if (buffer.soaFingerprints) {
|
|
1412
|
-
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)
|
|
1413
1275
|
recomputeFingerprintsForRows(buffer, yy, yy + 1);
|
|
1414
|
-
|
|
1415
|
-
|
|
1276
|
+
else {
|
|
1277
|
+
let physY = physicalRowIndex(buffer, yy);
|
|
1416
1278
|
updateRangeFingerprint(buffer, physY, x0, x1, fillCell2.ch, fillCell2.style);
|
|
1417
1279
|
}
|
|
1418
|
-
}
|
|
1419
1280
|
markDirty(buffer, yy);
|
|
1420
1281
|
}
|
|
1421
1282
|
return;
|
|
1422
1283
|
}
|
|
1423
|
-
|
|
1424
|
-
const continuationCell = createContinuationCell(style);
|
|
1425
|
-
const blank = createBlankCell();
|
|
1284
|
+
let fillCell = createCell(ch, style, buffer.widthProvider), continuationCell = createContinuationCell(style), blank = createBlankCell();
|
|
1426
1285
|
for (let yy = y0; yy < y1; yy++) {
|
|
1427
|
-
|
|
1286
|
+
let row = getBufferRow(buffer, yy);
|
|
1428
1287
|
for (let xx = x0; xx < x1; ) {
|
|
1429
|
-
clearWideIfOverwriting(row, xx)
|
|
1430
|
-
|
|
1431
|
-
row[xx] = blank;
|
|
1432
|
-
xx += 1;
|
|
1288
|
+
if (clearWideIfOverwriting(row, xx), xx + 1 >= x1 || xx + 1 >= buffer.cols) {
|
|
1289
|
+
row[xx] = blank, xx += 1;
|
|
1433
1290
|
continue;
|
|
1434
1291
|
}
|
|
1435
|
-
clearWideIfOverwriting(row, xx + 1);
|
|
1436
|
-
row[xx] = fillCell;
|
|
1437
|
-
row[xx + 1] = continuationCell;
|
|
1438
|
-
xx += 2;
|
|
1292
|
+
clearWideIfOverwriting(row, xx + 1), row[xx] = fillCell, row[xx + 1] = continuationCell, xx += 2;
|
|
1439
1293
|
}
|
|
1440
|
-
recomputeFingerprintsForRows(buffer, yy, yy + 1);
|
|
1441
|
-
markDirty(buffer, yy);
|
|
1294
|
+
recomputeFingerprintsForRows(buffer, yy, yy + 1), markDirty(buffer, yy);
|
|
1442
1295
|
}
|
|
1443
1296
|
}
|
|
1444
1297
|
function clearRect(buffer, x, y, w, h) {
|
|
1445
1298
|
if (buffer.cols === 0 || buffer.rows === 0)
|
|
1446
1299
|
return;
|
|
1447
1300
|
if (x == null || y == null || w == null || h == null) {
|
|
1448
|
-
|
|
1301
|
+
let blank = createBlankCell();
|
|
1449
1302
|
for (let yy = 0; yy < buffer.rows; yy++) {
|
|
1450
|
-
|
|
1303
|
+
let row = getBufferRow(buffer, yy);
|
|
1451
1304
|
row.length = buffer.cols;
|
|
1452
1305
|
for (let xx = 0; xx < buffer.cols; xx++)
|
|
1453
1306
|
row[xx] = blank;
|
|
1454
1307
|
}
|
|
1455
|
-
recomputeFingerprintsForRows(buffer, 0, buffer.rows);
|
|
1456
|
-
markAllDirty(buffer);
|
|
1457
|
-
buffer.cursorX = 0;
|
|
1458
|
-
buffer.cursorY = 0;
|
|
1308
|
+
recomputeFingerprintsForRows(buffer, 0, buffer.rows), markAllDirty(buffer), buffer.cursorX = 0, buffer.cursorY = 0;
|
|
1459
1309
|
return;
|
|
1460
1310
|
}
|
|
1461
1311
|
if (w <= 0 || h <= 0)
|
|
1462
1312
|
return;
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
for (let yy = y0; yy < y1; yy++) {
|
|
1470
|
-
const row = getBufferRow(buffer, yy);
|
|
1471
|
-
if (row[x0]?.continuation)
|
|
1472
|
-
clearWideIfOverwriting(row, x0);
|
|
1473
|
-
clearCellRange(row, x0, x1);
|
|
1474
|
-
if (x1 < buffer.cols && row[x1]?.continuation)
|
|
1475
|
-
row[x1] = createBlankCell();
|
|
1476
|
-
recomputeFingerprintsForRows(buffer, yy, yy + 1);
|
|
1477
|
-
markDirty(buffer, yy);
|
|
1478
|
-
}
|
|
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
|
+
}
|
|
1479
1319
|
}
|
|
1480
1320
|
function takePooledRow(buffer) {
|
|
1481
|
-
|
|
1482
|
-
return row ?? null;
|
|
1321
|
+
return buffer.rowPool.pop() ?? null;
|
|
1483
1322
|
}
|
|
1484
1323
|
function blankRow(buffer) {
|
|
1485
|
-
|
|
1324
|
+
let pooled = takePooledRow(buffer);
|
|
1486
1325
|
if (!pooled)
|
|
1487
1326
|
return Array.from({ length: buffer.cols }, () => createBlankCell());
|
|
1488
1327
|
pooled.length = buffer.cols;
|
|
1489
|
-
|
|
1328
|
+
let blank = createBlankCell();
|
|
1490
1329
|
for (let x = 0; x < buffer.cols; x++)
|
|
1491
1330
|
pooled[x] = blank;
|
|
1492
1331
|
return pooled;
|
|
1493
1332
|
}
|
|
1494
1333
|
function recomputeFingerprintsForRows(buffer, startY, endY) {
|
|
1495
|
-
if (!buffer.soaFingerprints || !buffer.fingerprintFn)
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
const cell = row[x];
|
|
1503
|
-
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
|
+
}
|
|
1504
1341
|
}
|
|
1505
|
-
}
|
|
1506
1342
|
}
|
|
1507
1343
|
function recomputeAllVisibleFingerprints(buffer) {
|
|
1508
1344
|
recomputeFingerprintsForRows(buffer, 0, buffer.rows);
|
|
1509
1345
|
}
|
|
1510
1346
|
function scrollBuffer(buffer, lines) {
|
|
1511
|
-
|
|
1347
|
+
let raw = Math.trunc(lines);
|
|
1512
1348
|
if (raw === 0 || buffer.rows === 0)
|
|
1513
1349
|
return;
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
if (n > 0) {
|
|
1350
|
+
let abs = Math.min(Math.abs(raw), buffer.rows), n = raw > 0 ? abs : -abs;
|
|
1351
|
+
if (n > 0)
|
|
1517
1352
|
for (let i = 0; i < n; i++) {
|
|
1518
|
-
|
|
1519
|
-
const removed = buffer.grid[removedIdx];
|
|
1353
|
+
let removedIdx = buffer.gridStart, removed = buffer.grid[removedIdx];
|
|
1520
1354
|
if (buffer.scrollbackLimit > 0) {
|
|
1521
|
-
buffer.scrollback.push(removed)
|
|
1522
|
-
|
|
1523
|
-
const excess = buffer.scrollback.length - buffer.scrollbackLimit;
|
|
1524
|
-
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);
|
|
1525
1357
|
buffer.rowPool.push(...dropped);
|
|
1526
1358
|
}
|
|
1527
|
-
} else
|
|
1359
|
+
} else
|
|
1528
1360
|
buffer.rowPool.push(removed);
|
|
1529
|
-
}
|
|
1530
1361
|
buffer.gridStart = (buffer.gridStart + 1) % buffer.rows;
|
|
1531
|
-
|
|
1362
|
+
let bottomIdx = (buffer.gridStart + buffer.rows - 1) % buffer.rows;
|
|
1532
1363
|
buffer.grid[bottomIdx] = blankRow(buffer);
|
|
1533
1364
|
}
|
|
1534
|
-
|
|
1365
|
+
else
|
|
1535
1366
|
for (let i = 0; i < -n; i++) {
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
buffer.rowPool.push(removed);
|
|
1539
|
-
buffer.gridStart = (buffer.gridStart - 1 + buffer.rows) % buffer.rows;
|
|
1540
|
-
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);
|
|
1541
1369
|
}
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
if (inserted >= buffer.rows) {
|
|
1545
|
-
recomputeAllVisibleFingerprints(buffer);
|
|
1546
|
-
} else if (n > 0) {
|
|
1547
|
-
recomputeFingerprintsForRows(buffer, buffer.rows - inserted, buffer.rows);
|
|
1548
|
-
} else {
|
|
1549
|
-
recomputeFingerprintsForRows(buffer, 0, inserted);
|
|
1550
|
-
}
|
|
1551
|
-
markAllDirty(buffer);
|
|
1552
|
-
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));
|
|
1553
1372
|
}
|
|
1554
1373
|
function scrollBufferRegion(buffer, startY, endY, lines) {
|
|
1555
|
-
|
|
1374
|
+
let n = Math.trunc(lines);
|
|
1556
1375
|
if (n === 0 || buffer.rows === 0)
|
|
1557
1376
|
return [];
|
|
1558
|
-
|
|
1559
|
-
const end = clamp(Math.floor(endY), 0, buffer.rows);
|
|
1560
|
-
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;
|
|
1561
1378
|
if (height <= 0)
|
|
1562
1379
|
return [];
|
|
1563
|
-
|
|
1564
|
-
const insertedRows = [];
|
|
1565
|
-
const replaceRegionWithBlankRows = () => {
|
|
1380
|
+
let absDelta = Math.abs(n), insertedRows = [], replaceRegionWithBlankRows = () => {
|
|
1566
1381
|
for (let y = start; y < end; y++) {
|
|
1567
|
-
|
|
1568
|
-
buffer.rowPool.push(buffer.grid[physY]);
|
|
1569
|
-
buffer.grid[physY] = blankRow(buffer);
|
|
1570
|
-
markDirty(buffer, y);
|
|
1571
|
-
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);
|
|
1572
1384
|
}
|
|
1573
1385
|
};
|
|
1574
|
-
if (absDelta >= height)
|
|
1575
|
-
replaceRegionWithBlankRows();
|
|
1576
|
-
|
|
1577
|
-
if (buffer.cursorY >= start && buffer.cursorY < end)
|
|
1578
|
-
buffer.cursorY = clamp(buffer.cursorY - n, start, Math.max(start, end - 1));
|
|
1579
|
-
return insertedRows;
|
|
1580
|
-
}
|
|
1581
|
-
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 = [];
|
|
1582
1389
|
for (let y = start; y < end; y++)
|
|
1583
1390
|
regionRows.push(getBufferRow(buffer, y));
|
|
1584
|
-
|
|
1391
|
+
let nextRows = Array.from({ length: height }, () => []);
|
|
1585
1392
|
if (n > 0) {
|
|
1586
|
-
|
|
1393
|
+
let movedCount = height - n;
|
|
1587
1394
|
for (let i = 0; i < movedCount; i++)
|
|
1588
1395
|
nextRows[i] = regionRows[i + n];
|
|
1589
1396
|
for (let i = 0; i < n; i++) {
|
|
1590
1397
|
buffer.rowPool.push(regionRows[i]);
|
|
1591
|
-
|
|
1592
|
-
nextRows[movedCount + i] = blankRow(buffer);
|
|
1593
|
-
markDirty(buffer, y);
|
|
1594
|
-
insertedRows.push(y);
|
|
1398
|
+
let y = end - n + i;
|
|
1399
|
+
nextRows[movedCount + i] = blankRow(buffer), markDirty(buffer, y), insertedRows.push(y);
|
|
1595
1400
|
}
|
|
1596
1401
|
} else {
|
|
1597
|
-
|
|
1598
|
-
const movedCount = height - insertedCount;
|
|
1402
|
+
let insertedCount = -n, movedCount = height - insertedCount;
|
|
1599
1403
|
for (let i = 0; i < insertedCount; i++) {
|
|
1600
1404
|
buffer.rowPool.push(regionRows[height - insertedCount + i]);
|
|
1601
|
-
|
|
1602
|
-
nextRows[i] = blankRow(buffer);
|
|
1603
|
-
markDirty(buffer, y);
|
|
1604
|
-
insertedRows.push(y);
|
|
1405
|
+
let y = start + i;
|
|
1406
|
+
nextRows[i] = blankRow(buffer), markDirty(buffer, y), insertedRows.push(y);
|
|
1605
1407
|
}
|
|
1606
1408
|
for (let i = 0; i < movedCount; i++)
|
|
1607
1409
|
nextRows[insertedCount + i] = regionRows[i];
|
|
1608
1410
|
}
|
|
1609
1411
|
for (let i = 0; i < height; i++) {
|
|
1610
|
-
|
|
1412
|
+
let physY = physicalRowIndex(buffer, start + i);
|
|
1611
1413
|
buffer.grid[physY] = nextRows[i];
|
|
1612
1414
|
}
|
|
1613
|
-
recomputeFingerprintsForRows(buffer, start, end);
|
|
1614
|
-
if (buffer.cursorY >= start && buffer.cursorY < end)
|
|
1615
|
-
buffer.cursorY = clamp(buffer.cursorY - n, start, Math.max(start, end - 1));
|
|
1616
|
-
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;
|
|
1617
1416
|
}
|
|
1618
1417
|
function resizeBuffer(buffer, cols, rows) {
|
|
1619
|
-
|
|
1620
|
-
const nextRows = Math.max(0, Math.floor(rows));
|
|
1418
|
+
let nextCols = Math.max(0, Math.floor(cols)), nextRows = Math.max(0, Math.floor(rows));
|
|
1621
1419
|
if (nextCols === buffer.cols && nextRows === buffer.rows)
|
|
1622
1420
|
return;
|
|
1623
|
-
|
|
1624
|
-
const nextGrid = Array.from(
|
|
1421
|
+
let prevRows = buffer.rows, prevDirtyAll = buffer.dirtyAll, prevDirtyBits = buffer.dirtyBits, blank = createBlankCell(), nextGrid = Array.from(
|
|
1625
1422
|
{ length: nextRows },
|
|
1626
1423
|
() => Array.from({ length: nextCols }, () => blank)
|
|
1627
|
-
);
|
|
1628
|
-
const copyRows = Math.min(buffer.rows, nextRows);
|
|
1629
|
-
const copyCols = Math.min(buffer.cols, nextCols);
|
|
1424
|
+
), copyRows = Math.min(prevRows, nextRows), copyCols = Math.min(buffer.cols, nextCols);
|
|
1630
1425
|
for (let y = 0; y < copyRows; y++) {
|
|
1631
|
-
|
|
1632
|
-
const dst = nextGrid[y];
|
|
1426
|
+
let src = getBufferRow(buffer, y), dst = nextGrid[y];
|
|
1633
1427
|
for (let x = 0; x < copyCols; x++)
|
|
1634
1428
|
dst[x] = src[x];
|
|
1635
1429
|
}
|
|
1636
|
-
if (nextCols > 0)
|
|
1430
|
+
if (nextCols > 0)
|
|
1637
1431
|
for (let y = 0; y < nextGrid.length; y++) {
|
|
1638
|
-
|
|
1432
|
+
let row = nextGrid[y];
|
|
1639
1433
|
for (let x = 0; x < nextCols; x++) {
|
|
1640
|
-
|
|
1434
|
+
let cell = row[x];
|
|
1641
1435
|
if (cell.continuation) {
|
|
1642
|
-
|
|
1643
|
-
row[x] = blank;
|
|
1436
|
+
(x === 0 || row[x - 1]?.width !== 2 || row[x - 1]?.continuation) && (row[x] = blank);
|
|
1644
1437
|
continue;
|
|
1645
1438
|
}
|
|
1646
|
-
|
|
1647
|
-
row[x] = blank;
|
|
1648
|
-
}
|
|
1439
|
+
cell.width === 2 && (x + 1 >= nextCols || !row[x + 1]?.continuation) && (row[x] = blank);
|
|
1649
1440
|
}
|
|
1650
1441
|
}
|
|
1651
|
-
}
|
|
1652
1442
|
for (let y = 0; y < buffer.rows; y++)
|
|
1653
1443
|
buffer.rowPool.push(getBufferRow(buffer, y));
|
|
1654
|
-
buffer.grid = nextGrid
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
buffer.
|
|
1660
|
-
|
|
1661
|
-
buffer.dirtyMax = nextRows ? nextRows - 1 : -1;
|
|
1662
|
-
buffer.dirtyAll = nextRows > 0;
|
|
1663
|
-
buffer.cursorX = clamp(buffer.cursorX, 0, Math.max(0, nextCols));
|
|
1664
|
-
buffer.cursorY = clamp(buffer.cursorY, 0, Math.max(0, nextRows - 1));
|
|
1665
|
-
if (buffer.fingerprintFn) {
|
|
1666
|
-
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;
|
|
1667
1451
|
if (len > 0) {
|
|
1668
1452
|
buffer.soaFingerprints = new Uint32Array(len);
|
|
1669
1453
|
for (let y = 0; y < nextRows; y++) {
|
|
1670
|
-
|
|
1671
|
-
const base = y * nextCols;
|
|
1454
|
+
let row = nextGrid[y], base = y * nextCols;
|
|
1672
1455
|
for (let x = 0; x < nextCols; x++) {
|
|
1673
|
-
|
|
1456
|
+
let cell = row[x];
|
|
1674
1457
|
buffer.soaFingerprints[base + x] = buffer.fingerprintFn(cell.ch, cell.style);
|
|
1675
1458
|
}
|
|
1676
1459
|
}
|
|
1677
|
-
} else
|
|
1460
|
+
} else
|
|
1678
1461
|
buffer.soaFingerprints = null;
|
|
1679
|
-
}
|
|
1680
1462
|
}
|
|
1681
1463
|
}
|
|
1682
1464
|
function snapshotText(buffer) {
|
|
1683
|
-
|
|
1465
|
+
let out = [];
|
|
1684
1466
|
for (let y = 0; y < buffer.rows; y++) {
|
|
1685
|
-
|
|
1467
|
+
let row = getBufferRow(buffer, y);
|
|
1686
1468
|
out.push(row.map((cell) => cell.continuation ? " " : cell.ch || " ").join(""));
|
|
1687
1469
|
}
|
|
1688
1470
|
return out;
|
|
1689
1471
|
}
|
|
1690
1472
|
|
|
1691
1473
|
// src/core/terminal/emitter.ts
|
|
1692
|
-
var emitterListeners = /* @__PURE__ */ new WeakMap()
|
|
1693
|
-
var Emitter = class {
|
|
1474
|
+
var emitterListeners = /* @__PURE__ */ new WeakMap(), Emitter = class {
|
|
1694
1475
|
constructor() {
|
|
1695
1476
|
emitterListeners.set(this, /* @__PURE__ */ new Map());
|
|
1696
1477
|
}
|
|
@@ -1698,25 +1479,16 @@ var Emitter = class {
|
|
|
1698
1479
|
return emitterListeners.get(this);
|
|
1699
1480
|
}
|
|
1700
1481
|
on(event, cb) {
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
set = /* @__PURE__ */ new Set();
|
|
1705
|
-
listeners.set(event, set);
|
|
1706
|
-
}
|
|
1707
|
-
set.add(cb);
|
|
1708
|
-
return () => {
|
|
1709
|
-
set.delete(cb);
|
|
1710
|
-
if (set.size === 0)
|
|
1711
|
-
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);
|
|
1712
1485
|
};
|
|
1713
1486
|
}
|
|
1714
1487
|
emit(event, payload) {
|
|
1715
|
-
|
|
1716
|
-
if (
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
cb(payload);
|
|
1488
|
+
let set = this.getListeners().get(event);
|
|
1489
|
+
if (set)
|
|
1490
|
+
for (let cb of set)
|
|
1491
|
+
cb(payload);
|
|
1720
1492
|
}
|
|
1721
1493
|
clear() {
|
|
1722
1494
|
this.getListeners().clear();
|
|
@@ -1725,44 +1497,37 @@ var Emitter = class {
|
|
|
1725
1497
|
|
|
1726
1498
|
// src/core/terminal/create-terminal.ts
|
|
1727
1499
|
function isControlChar(ch) {
|
|
1728
|
-
return ch ===
|
|
1500
|
+
return ch === `
|
|
1501
|
+
` || ch === "\r" || ch === " ";
|
|
1729
1502
|
}
|
|
1730
1503
|
function mergePlanes(prev, next) {
|
|
1731
1504
|
if (!prev?.length)
|
|
1732
1505
|
return next?.length ? [...next] : null;
|
|
1733
1506
|
if (!next?.length)
|
|
1734
1507
|
return prev;
|
|
1735
|
-
|
|
1736
|
-
for (
|
|
1508
|
+
let merged = new Set(prev);
|
|
1509
|
+
for (let plane of next)
|
|
1737
1510
|
merged.add(plane);
|
|
1738
1511
|
return Array.from(merged);
|
|
1739
1512
|
}
|
|
1740
|
-
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");
|
|
1741
1514
|
function createCoverage(cols, rows) {
|
|
1742
1515
|
return Array.from({ length: rows }, () => new Uint8Array(cols));
|
|
1743
1516
|
}
|
|
1744
1517
|
function resizeCoverage(prev, cols, rows) {
|
|
1745
|
-
|
|
1746
|
-
const copyRows = Math.min(prev.length, rows);
|
|
1518
|
+
let next = createCoverage(cols, rows), copyRows = Math.min(prev.length, rows);
|
|
1747
1519
|
for (let y = 0; y < copyRows; y++) {
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
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)));
|
|
1751
1522
|
}
|
|
1752
1523
|
return next;
|
|
1753
1524
|
}
|
|
1754
1525
|
function setBufferClean(buffer) {
|
|
1755
|
-
buffer.dirtyBits.fill(0);
|
|
1756
|
-
buffer.dirtyCount = 0;
|
|
1757
|
-
buffer.dirtyMin = Number.POSITIVE_INFINITY;
|
|
1758
|
-
buffer.dirtyMax = -1;
|
|
1759
|
-
buffer.dirtyAll = false;
|
|
1526
|
+
buffer.dirtyBits.fill(0), buffer.dirtyCount = 0, buffer.dirtyMin = Number.POSITIVE_INFINITY, buffer.dirtyMax = -1, buffer.dirtyAll = !1;
|
|
1760
1527
|
}
|
|
1761
1528
|
function createPlaneState(cols, rows, widthProvider) {
|
|
1762
|
-
|
|
1763
|
-
setBufferClean(buffer)
|
|
1764
|
-
buffer.cursorVisible = false;
|
|
1765
|
-
return {
|
|
1529
|
+
let buffer = createGridBuffer(cols, rows, { widthProvider });
|
|
1530
|
+
return setBufferClean(buffer), buffer.cursorVisible = !1, {
|
|
1766
1531
|
buffer,
|
|
1767
1532
|
coverage: createCoverage(cols, rows)
|
|
1768
1533
|
};
|
|
@@ -1770,31 +1535,14 @@ function createPlaneState(cols, rows, widthProvider) {
|
|
|
1770
1535
|
function collectAndClearDirtyRows(buffer) {
|
|
1771
1536
|
if (buffer.rows === 0)
|
|
1772
1537
|
return [];
|
|
1773
|
-
if (buffer.dirtyAll)
|
|
1774
|
-
buffer.dirtyAll =
|
|
1775
|
-
buffer.dirtyBits.fill(0);
|
|
1776
|
-
buffer.dirtyCount = 0;
|
|
1777
|
-
buffer.dirtyMin = Number.POSITIVE_INFINITY;
|
|
1778
|
-
buffer.dirtyMax = -1;
|
|
1779
|
-
return null;
|
|
1780
|
-
}
|
|
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;
|
|
1781
1540
|
if (buffer.dirtyCount === 0)
|
|
1782
1541
|
return [];
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
if (buffer.dirtyBits[y]) {
|
|
1788
|
-
buffer.dirtyBits[y] = 0;
|
|
1789
|
-
out.push(y);
|
|
1790
|
-
if (out.length === buffer.dirtyCount)
|
|
1791
|
-
break;
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
buffer.dirtyCount = 0;
|
|
1795
|
-
buffer.dirtyMin = Number.POSITIVE_INFINITY;
|
|
1796
|
-
buffer.dirtyMax = -1;
|
|
1797
|
-
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;
|
|
1798
1546
|
}
|
|
1799
1547
|
function peekDirtyRows(buffer) {
|
|
1800
1548
|
if (buffer.rows === 0)
|
|
@@ -1803,60 +1551,39 @@ function peekDirtyRows(buffer) {
|
|
|
1803
1551
|
return null;
|
|
1804
1552
|
if (buffer.dirtyCount === 0)
|
|
1805
1553
|
return [];
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
for (let y = start; y <= end; y++) {
|
|
1810
|
-
if (buffer.dirtyBits[y]) {
|
|
1811
|
-
out.push(y);
|
|
1812
|
-
if (out.length === buffer.dirtyCount)
|
|
1813
|
-
break;
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
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
|
+
;
|
|
1816
1557
|
return out;
|
|
1817
1558
|
}
|
|
1818
1559
|
function clearPlaneCoverageRow(state, y) {
|
|
1819
1560
|
if (y < 0 || y >= state.buffer.rows)
|
|
1820
1561
|
return;
|
|
1821
|
-
|
|
1822
|
-
const blank = createBlankCell();
|
|
1562
|
+
let row = getBufferRow(state.buffer, y), blank = createBlankCell();
|
|
1823
1563
|
row.length = state.buffer.cols;
|
|
1824
1564
|
for (let x = 0; x < state.buffer.cols; x++)
|
|
1825
1565
|
row[x] = blank;
|
|
1826
|
-
state.coverage[y]?.fill(0);
|
|
1827
|
-
markDirty(state.buffer, y);
|
|
1566
|
+
state.coverage[y]?.fill(0), markDirty(state.buffer, y);
|
|
1828
1567
|
}
|
|
1829
1568
|
function markPlaneCoverageRange(state, x0, y0, x1, y1, value) {
|
|
1830
1569
|
for (let y = y0; y < y1; y++) {
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
continue;
|
|
1834
|
-
row.fill(value, x0, x1);
|
|
1570
|
+
let row = state.coverage[y];
|
|
1571
|
+
row && row.fill(value, x0, x1);
|
|
1835
1572
|
}
|
|
1836
1573
|
}
|
|
1837
1574
|
function markPlaneCoverageForPut(state, x, y, ch, prevCell) {
|
|
1838
|
-
|
|
1839
|
-
if (!row)
|
|
1575
|
+
if (!Number.isSafeInteger(x) || !Number.isSafeInteger(y) || x < 0 || x >= state.buffer.cols || y < 0 || y >= state.buffer.rows)
|
|
1840
1576
|
return;
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
if (prevCell?.width === 2 && x + 1 < row.length)
|
|
1844
|
-
row[x + 1] = 1;
|
|
1845
|
-
row[x] = 1;
|
|
1846
|
-
if (ch !== " " && x + 1 < row.length) {
|
|
1847
|
-
const next = getBufferCell(state.buffer, x, y);
|
|
1848
|
-
if (next.width === 2)
|
|
1849
|
-
row[x + 1] = 1;
|
|
1850
|
-
}
|
|
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));
|
|
1851
1579
|
}
|
|
1852
1580
|
function scrollPlaneCoverage(state, lines) {
|
|
1853
|
-
|
|
1581
|
+
let n = Math.trunc(lines);
|
|
1854
1582
|
if (n === 0 || state.coverage.length === 0)
|
|
1855
1583
|
return;
|
|
1856
|
-
|
|
1857
|
-
const cols = state.buffer.cols;
|
|
1584
|
+
let rows = state.coverage.length, cols = state.buffer.cols;
|
|
1858
1585
|
if (Math.abs(n) >= rows) {
|
|
1859
|
-
for (
|
|
1586
|
+
for (let row of state.coverage)
|
|
1860
1587
|
row.fill(0);
|
|
1861
1588
|
return;
|
|
1862
1589
|
}
|
|
@@ -1871,31 +1598,27 @@ function scrollPlaneCoverage(state, lines) {
|
|
|
1871
1598
|
state.coverage.unshift(new Uint8Array(cols));
|
|
1872
1599
|
}
|
|
1873
1600
|
function scrollPlaneCoverageRegion(state, startY, endY, lines) {
|
|
1874
|
-
|
|
1601
|
+
let n = Math.trunc(lines);
|
|
1875
1602
|
if (n === 0 || state.coverage.length === 0)
|
|
1876
1603
|
return;
|
|
1877
|
-
|
|
1878
|
-
const end = Math.max(0, Math.min(state.coverage.length, Math.floor(endY)));
|
|
1879
|
-
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;
|
|
1880
1605
|
if (height <= 0)
|
|
1881
1606
|
return;
|
|
1882
|
-
|
|
1607
|
+
let cols = state.buffer.cols;
|
|
1883
1608
|
if (Math.abs(n) >= height) {
|
|
1884
1609
|
for (let y = start; y < end; y++)
|
|
1885
1610
|
state.coverage[y] = new Uint8Array(cols);
|
|
1886
1611
|
return;
|
|
1887
1612
|
}
|
|
1888
|
-
|
|
1889
|
-
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));
|
|
1890
1614
|
if (n > 0) {
|
|
1891
|
-
|
|
1615
|
+
let movedCount = height - n;
|
|
1892
1616
|
for (let i = 0; i < movedCount; i++)
|
|
1893
1617
|
next[i] = region[i + n];
|
|
1894
1618
|
for (let i = 0; i < n; i++)
|
|
1895
1619
|
next[movedCount + i] = new Uint8Array(cols);
|
|
1896
1620
|
} else {
|
|
1897
|
-
|
|
1898
|
-
const movedCount = height - insertedCount;
|
|
1621
|
+
let insertedCount = -n, movedCount = height - insertedCount;
|
|
1899
1622
|
for (let i = 0; i < insertedCount; i++)
|
|
1900
1623
|
next[i] = new Uint8Array(cols);
|
|
1901
1624
|
for (let i = 0; i < movedCount; i++)
|
|
@@ -1905,303 +1628,211 @@ function scrollPlaneCoverageRegion(state, startY, endY, lines) {
|
|
|
1905
1628
|
state.coverage[start + i] = next[i];
|
|
1906
1629
|
}
|
|
1907
1630
|
function resizePlaneState(state, cols, rows) {
|
|
1908
|
-
resizeBuffer(state.buffer, cols, rows);
|
|
1909
|
-
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);
|
|
1910
1632
|
}
|
|
1911
1633
|
function normalizeDirtyRows(rows, totalRows) {
|
|
1912
1634
|
if (rows === null)
|
|
1913
1635
|
return null;
|
|
1914
1636
|
if (rows.length === 0)
|
|
1915
1637
|
return rows;
|
|
1916
|
-
|
|
1917
|
-
for (
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
continue;
|
|
1921
|
-
if (out[out.length - 1] === yy)
|
|
1922
|
-
continue;
|
|
1923
|
-
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);
|
|
1924
1642
|
}
|
|
1925
1643
|
return out;
|
|
1926
1644
|
}
|
|
1927
1645
|
function createTerminal(opts) {
|
|
1928
|
-
|
|
1929
|
-
const emitter = new Emitter();
|
|
1930
|
-
const compositeBuffer = createGridBuffer(opts.cols, opts.rows, {
|
|
1646
|
+
let widthProvider = opts.widthProvider ?? "default", emitter = new Emitter(), compositeBuffer = createGridBuffer(opts.cols, opts.rows, {
|
|
1931
1647
|
widthProvider
|
|
1932
|
-
});
|
|
1933
|
-
|
|
1934
|
-
let disposed = false;
|
|
1935
|
-
let batchingDepth = 0;
|
|
1936
|
-
let pendingCommit = false;
|
|
1937
|
-
let pendingCommitAllPlanes = false;
|
|
1938
|
-
let pendingCommitPlanes = null;
|
|
1939
|
-
const pendingPlaneScrollOps = /* @__PURE__ */ new Map();
|
|
1940
|
-
const planeTerminals = /* @__PURE__ */ new Map();
|
|
1941
|
-
let base;
|
|
1942
|
-
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;
|
|
1943
1650
|
function assertNotDisposed() {
|
|
1944
1651
|
if (disposed)
|
|
1945
1652
|
throw new Error("Terminal is disposed");
|
|
1946
1653
|
}
|
|
1947
1654
|
function getPlaneState(plane) {
|
|
1948
1655
|
let state = planeStates.get(plane);
|
|
1949
|
-
|
|
1950
|
-
state = createPlaneState(compositeBuffer.cols, compositeBuffer.rows, widthProvider);
|
|
1951
|
-
planeStates.set(plane, state);
|
|
1952
|
-
}
|
|
1953
|
-
return state;
|
|
1656
|
+
return state || (state = createPlaneState(compositeBuffer.cols, compositeBuffer.rows, widthProvider), planeStates.set(plane, state)), state;
|
|
1954
1657
|
}
|
|
1955
|
-
function setCursorForPlane(plane, x, y, visible =
|
|
1956
|
-
|
|
1957
|
-
state.buffer.cursorX = Math.max(0, Math.min(state.buffer.cols, Math.floor(x)))
|
|
1958
|
-
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(
|
|
1959
1661
|
0,
|
|
1960
1662
|
Math.min(state.buffer.rows ? state.buffer.rows - 1 : 0, Math.floor(y))
|
|
1961
|
-
);
|
|
1962
|
-
state.buffer.cursorVisible = visible;
|
|
1963
|
-
markDirty(state.buffer, state.buffer.cursorY);
|
|
1663
|
+
), state.buffer.cursorVisible = visible, markDirty(state.buffer, state.buffer.cursorY);
|
|
1964
1664
|
}
|
|
1965
1665
|
function putForPlane(plane, x, y, ch, style) {
|
|
1966
|
-
|
|
1967
|
-
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)
|
|
1968
1671
|
return;
|
|
1969
|
-
|
|
1970
|
-
putCell(state.buffer,
|
|
1971
|
-
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);
|
|
1972
1674
|
}
|
|
1973
1675
|
function writeAtForPlane(plane, text, x, y, style) {
|
|
1974
|
-
|
|
1975
|
-
let cx = x;
|
|
1976
|
-
let cy = y;
|
|
1676
|
+
let state = getPlaneState(plane), cx = x, cy = y;
|
|
1977
1677
|
if (state.buffer.cols === 0 || state.buffer.rows === 0)
|
|
1978
1678
|
return { x: cx, y: cy };
|
|
1979
|
-
|
|
1679
|
+
let writeChar = (ch) => {
|
|
1980
1680
|
if (isControlChar(ch)) {
|
|
1981
|
-
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")
|
|
1982
1685
|
cx = 0;
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
scrollBuffer(state.buffer, 1);
|
|
1986
|
-
scrollPlaneCoverage(state, 1);
|
|
1987
|
-
cy = state.buffer.rows - 1;
|
|
1988
|
-
}
|
|
1989
|
-
} else if (ch === "\r") {
|
|
1990
|
-
cx = 0;
|
|
1991
|
-
} else if (ch === " ") {
|
|
1992
|
-
const tabSize = 4;
|
|
1993
|
-
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));
|
|
1994
1688
|
for (; cx < next; cx++)
|
|
1995
1689
|
putForPlane(plane, cx, cy, " ", style);
|
|
1996
1690
|
}
|
|
1997
|
-
return
|
|
1691
|
+
return !0;
|
|
1998
1692
|
}
|
|
1999
1693
|
if (cy < 0 || cy >= state.buffer.rows)
|
|
2000
|
-
return
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
if (cy >= state.buffer.rows) {
|
|
2006
|
-
scrollBuffer(state.buffer, 1);
|
|
2007
|
-
scrollPlaneCoverage(state, 1);
|
|
2008
|
-
cy = state.buffer.rows - 1;
|
|
2009
|
-
}
|
|
2010
|
-
putForPlane(plane, cx, cy, ch, style);
|
|
2011
|
-
const width = ch === " " ? 1 : getBufferCell(state.buffer, cx, cy).width || 1;
|
|
2012
|
-
cx += width;
|
|
2013
|
-
return true;
|
|
2014
|
-
};
|
|
2015
|
-
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);
|
|
2016
1699
|
if (segments) {
|
|
2017
|
-
for (
|
|
1700
|
+
for (let seg of segments)
|
|
2018
1701
|
if (!writeChar(seg.segment))
|
|
2019
1702
|
break;
|
|
2020
|
-
}
|
|
2021
1703
|
return { x: cx, y: cy };
|
|
2022
1704
|
}
|
|
2023
1705
|
let i = 0;
|
|
2024
|
-
for (; i < text.length; i++)
|
|
2025
|
-
const code = text.charCodeAt(i);
|
|
2026
|
-
if (code > 127)
|
|
2027
|
-
break;
|
|
1706
|
+
for (; i < text.length && !(text.charCodeAt(i) > 127); i++)
|
|
2028
1707
|
if (!writeChar(text[i]))
|
|
2029
1708
|
return { x: cx, y: cy };
|
|
2030
|
-
}
|
|
2031
1709
|
if (i < text.length) {
|
|
2032
|
-
|
|
2033
|
-
const restSegments = segmentedGraphemes(rest);
|
|
1710
|
+
let rest = text.slice(i), restSegments = segmentedGraphemes(rest);
|
|
2034
1711
|
if (restSegments) {
|
|
2035
|
-
for (
|
|
1712
|
+
for (let seg of restSegments)
|
|
2036
1713
|
if (!writeChar(seg.segment))
|
|
2037
1714
|
break;
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
for (const ch of rest) {
|
|
1715
|
+
} else
|
|
1716
|
+
for (let ch of rest)
|
|
2041
1717
|
if (!writeChar(ch))
|
|
2042
1718
|
break;
|
|
2043
|
-
}
|
|
2044
|
-
}
|
|
2045
1719
|
}
|
|
2046
1720
|
return { x: cx, y: cy };
|
|
2047
1721
|
}
|
|
2048
1722
|
function clearForPlane(plane, x, y, w, h) {
|
|
2049
|
-
|
|
2050
|
-
clearRect(state.buffer, x, y, w, h)
|
|
2051
|
-
|
|
2052
|
-
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)
|
|
2053
1726
|
row.fill(1);
|
|
2054
1727
|
return;
|
|
2055
1728
|
}
|
|
2056
1729
|
if (w <= 0 || h <= 0)
|
|
2057
1730
|
return;
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
const x1 = Math.max(0, Math.min(state.buffer.cols, Math.floor(x + w)));
|
|
2061
|
-
const y1 = Math.max(0, Math.min(state.buffer.rows, Math.floor(y + h)));
|
|
2062
|
-
if (x1 <= x0 || y1 <= y0)
|
|
2063
|
-
return;
|
|
2064
|
-
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);
|
|
2065
1733
|
}
|
|
2066
1734
|
function fillForPlane(plane, x, y, w, h, ch, style) {
|
|
2067
|
-
|
|
2068
|
-
fillRect(state.buffer, x, y, w, h, ch ?? " ", style)
|
|
2069
|
-
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)
|
|
2070
1737
|
return;
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
const x1 = Math.max(0, Math.min(state.buffer.cols, Math.floor(x + w)));
|
|
2074
|
-
const y1 = Math.max(0, Math.min(state.buffer.rows, Math.floor(y + h)));
|
|
2075
|
-
if (x1 <= x0 || y1 <= y0)
|
|
2076
|
-
return;
|
|
2077
|
-
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);
|
|
2078
1740
|
}
|
|
2079
1741
|
function scrollForPlane(plane, lines) {
|
|
2080
|
-
|
|
2081
|
-
scrollBuffer(state.buffer, lines);
|
|
2082
|
-
scrollPlaneCoverage(state, lines);
|
|
1742
|
+
let state = getPlaneState(plane);
|
|
1743
|
+
scrollBuffer(state.buffer, lines), scrollPlaneCoverage(state, lines);
|
|
2083
1744
|
}
|
|
2084
1745
|
function normalizeScrollOperation(startY, endY, delta, totalRows) {
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
const height = end - start;
|
|
2088
|
-
const lines = Math.trunc(delta);
|
|
2089
|
-
if (height <= 0 || lines === 0 || Math.abs(lines) >= height)
|
|
2090
|
-
return null;
|
|
2091
|
-
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 };
|
|
2092
1748
|
}
|
|
2093
1749
|
function recordPendingScrollOp(plane, op) {
|
|
2094
|
-
|
|
2095
|
-
const last = list[list.length - 1];
|
|
1750
|
+
let list = pendingPlaneScrollOps.get(plane) ?? [], last = list[list.length - 1];
|
|
2096
1751
|
if (last && last.startY === op.startY && last.endY === op.endY && Math.sign(last.delta) === Math.sign(op.delta)) {
|
|
2097
|
-
|
|
1752
|
+
let next = normalizeScrollOperation(
|
|
2098
1753
|
op.startY,
|
|
2099
1754
|
op.endY,
|
|
2100
1755
|
last.delta + op.delta,
|
|
2101
1756
|
compositeBuffer.rows
|
|
2102
1757
|
);
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
else
|
|
2106
|
-
list.push(op);
|
|
2107
|
-
} else {
|
|
1758
|
+
next ? list[list.length - 1] = next : list.push(op);
|
|
1759
|
+
} else
|
|
2108
1760
|
list.push(op);
|
|
2109
|
-
}
|
|
2110
1761
|
pendingPlaneScrollOps.set(plane, list);
|
|
2111
1762
|
}
|
|
2112
1763
|
function takePendingScrollOps(planes) {
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
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
|
+
}
|
|
2122
1772
|
}
|
|
2123
1773
|
return out.length ? out : null;
|
|
2124
1774
|
}
|
|
2125
1775
|
function higherPlanesFor(plane) {
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
return [];
|
|
2129
|
-
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);
|
|
2130
1778
|
}
|
|
2131
1779
|
function higherPlaneCoverageKind(plane, y) {
|
|
2132
|
-
|
|
1780
|
+
let higherPlanes = higherPlanesFor(plane);
|
|
2133
1781
|
if (!higherPlanes.length || y < 0 || y >= compositeBuffer.rows)
|
|
2134
1782
|
return 0;
|
|
2135
1783
|
let covered = 0;
|
|
2136
1784
|
for (let x = 0; x < compositeBuffer.cols; x++) {
|
|
2137
|
-
let cellCovered =
|
|
2138
|
-
for (
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
cellCovered = true;
|
|
1785
|
+
let cellCovered = !1;
|
|
1786
|
+
for (let higherPlane of higherPlanes)
|
|
1787
|
+
if (planeStates.get(higherPlane)?.coverage[y]?.[x]) {
|
|
1788
|
+
cellCovered = !0;
|
|
2142
1789
|
break;
|
|
2143
1790
|
}
|
|
2144
|
-
|
|
2145
|
-
if (cellCovered)
|
|
2146
|
-
covered++;
|
|
1791
|
+
cellCovered && covered++;
|
|
2147
1792
|
}
|
|
2148
|
-
|
|
2149
|
-
return 0;
|
|
2150
|
-
if (covered >= compositeBuffer.cols)
|
|
2151
|
-
return 2;
|
|
2152
|
-
return 1;
|
|
1793
|
+
return covered === 0 ? 0 : covered >= compositeBuffer.cols ? 2 : 1;
|
|
2153
1794
|
}
|
|
2154
1795
|
function addAffectedRows(out, op) {
|
|
2155
1796
|
for (let y = op.startY; y < op.endY; y++)
|
|
2156
1797
|
out.add(y);
|
|
2157
1798
|
}
|
|
2158
1799
|
function areDisjointSorted(ops) {
|
|
2159
|
-
for (let i = 1; i < ops.length; i++)
|
|
1800
|
+
for (let i = 1; i < ops.length; i++)
|
|
2160
1801
|
if (ops[i - 1].endY > ops[i].startY)
|
|
2161
|
-
return
|
|
2162
|
-
|
|
2163
|
-
return true;
|
|
1802
|
+
return !1;
|
|
1803
|
+
return !0;
|
|
2164
1804
|
}
|
|
2165
1805
|
function groupedPendingScrollOps(pendingOps) {
|
|
2166
|
-
|
|
2167
|
-
for (
|
|
2168
|
-
|
|
1806
|
+
let grouped = /* @__PURE__ */ new Map();
|
|
1807
|
+
for (let pending of pendingOps) {
|
|
1808
|
+
let list = grouped.get(pending.plane) ?? [];
|
|
2169
1809
|
list.push({
|
|
2170
1810
|
startY: pending.startY,
|
|
2171
1811
|
endY: pending.endY,
|
|
2172
1812
|
delta: pending.delta
|
|
2173
|
-
});
|
|
2174
|
-
grouped.set(pending.plane, list);
|
|
1813
|
+
}), grouped.set(pending.plane, list);
|
|
2175
1814
|
}
|
|
2176
1815
|
return grouped;
|
|
2177
1816
|
}
|
|
2178
1817
|
function prepareCompositeScrollOps(pendingOps) {
|
|
2179
|
-
if (!pendingOps?.length)
|
|
1818
|
+
if (!pendingOps?.length)
|
|
2180
1819
|
return {
|
|
2181
1820
|
scrollOperations: null,
|
|
2182
1821
|
extraDirtyRows: []
|
|
2183
1822
|
};
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
const grouped = groupedPendingScrollOps(pendingOps);
|
|
2188
|
-
for (const [plane, ops] of grouped) {
|
|
2189
|
-
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);
|
|
2190
1826
|
if (!areDisjointSorted(sorted)) {
|
|
2191
|
-
for (
|
|
1827
|
+
for (let op of ops)
|
|
2192
1828
|
addAffectedRows(extraDirtyRows, op);
|
|
2193
1829
|
continue;
|
|
2194
1830
|
}
|
|
2195
|
-
for (
|
|
2196
|
-
|
|
2197
|
-
const partiallyBlockedRows = /* @__PURE__ */ new Set();
|
|
1831
|
+
for (let op of sorted) {
|
|
1832
|
+
let blockedRows = /* @__PURE__ */ new Set(), partiallyBlockedRows = /* @__PURE__ */ new Set();
|
|
2198
1833
|
for (let y = op.startY; y < op.endY; y++) {
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
continue;
|
|
2202
|
-
blockedRows.add(y);
|
|
2203
|
-
if (coverageKind === 1)
|
|
2204
|
-
partiallyBlockedRows.add(y);
|
|
1834
|
+
let coverageKind = higherPlaneCoverageKind(plane, y);
|
|
1835
|
+
coverageKind !== 0 && (blockedRows.add(y), coverageKind === 1 && partiallyBlockedRows.add(y));
|
|
2205
1836
|
}
|
|
2206
1837
|
if (!blockedRows.size) {
|
|
2207
1838
|
scrollOperations.push({
|
|
@@ -2211,34 +1842,29 @@ function createTerminal(opts) {
|
|
|
2211
1842
|
});
|
|
2212
1843
|
continue;
|
|
2213
1844
|
}
|
|
2214
|
-
|
|
2215
|
-
for (let y = op.startY; y < op.endY; y++)
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
}
|
|
2219
|
-
let bandStart = -1;
|
|
2220
|
-
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) => {
|
|
2221
1849
|
if (bandStart < 0 || bandEnd <= bandStart)
|
|
2222
1850
|
return;
|
|
2223
|
-
|
|
1851
|
+
let bandHeight = bandEnd - bandStart;
|
|
2224
1852
|
if (absDelta >= bandHeight) {
|
|
2225
1853
|
for (let y = bandStart; y < bandEnd; y++)
|
|
2226
1854
|
extraDirtyRows.add(y);
|
|
2227
1855
|
bandStart = -1;
|
|
2228
1856
|
return;
|
|
2229
1857
|
}
|
|
2230
|
-
scrollOperations.push({
|
|
1858
|
+
if (scrollOperations.push({
|
|
2231
1859
|
startY: bandStart,
|
|
2232
1860
|
endY: bandEnd,
|
|
2233
1861
|
delta: op.delta
|
|
2234
|
-
})
|
|
2235
|
-
if (op.delta > 0) {
|
|
1862
|
+
}), op.delta > 0)
|
|
2236
1863
|
for (let y = bandEnd - absDelta; y < bandEnd; y++)
|
|
2237
1864
|
extraDirtyRows.add(y);
|
|
2238
|
-
|
|
1865
|
+
else
|
|
2239
1866
|
for (let y = bandStart; y < bandStart + absDelta; y++)
|
|
2240
1867
|
extraDirtyRows.add(y);
|
|
2241
|
-
}
|
|
2242
1868
|
bandStart = -1;
|
|
2243
1869
|
};
|
|
2244
1870
|
for (let y = op.startY; y < op.endY; y++) {
|
|
@@ -2246,8 +1872,7 @@ function createTerminal(opts) {
|
|
|
2246
1872
|
flushBand(y);
|
|
2247
1873
|
continue;
|
|
2248
1874
|
}
|
|
2249
|
-
|
|
2250
|
-
bandStart = y;
|
|
1875
|
+
bandStart < 0 && (bandStart = y);
|
|
2251
1876
|
}
|
|
2252
1877
|
flushBand(op.endY);
|
|
2253
1878
|
}
|
|
@@ -2259,77 +1884,56 @@ function createTerminal(opts) {
|
|
|
2259
1884
|
}
|
|
2260
1885
|
function dirtyRowsCoverRange(rows, startY, endY) {
|
|
2261
1886
|
if (rows === null)
|
|
2262
|
-
return
|
|
1887
|
+
return !0;
|
|
2263
1888
|
if (!rows.length)
|
|
2264
|
-
return
|
|
1889
|
+
return !1;
|
|
2265
1890
|
let idx = 0;
|
|
2266
|
-
|
|
1891
|
+
for (; idx < rows.length && (rows[idx] ?? -1) < startY; )
|
|
2267
1892
|
idx++;
|
|
2268
1893
|
for (let y = startY; y < endY; y++) {
|
|
2269
1894
|
if (rows[idx] !== y)
|
|
2270
|
-
return
|
|
1895
|
+
return !1;
|
|
2271
1896
|
idx++;
|
|
2272
1897
|
}
|
|
2273
|
-
return
|
|
1898
|
+
return !0;
|
|
2274
1899
|
}
|
|
2275
1900
|
function dropScrollOpsCoveredByDirtyRows(ops, dirtyRows) {
|
|
2276
1901
|
if (!ops?.length)
|
|
2277
1902
|
return null;
|
|
2278
|
-
|
|
1903
|
+
let next = ops.filter((op) => !dirtyRowsCoverRange(dirtyRows, op.startY, op.endY));
|
|
2279
1904
|
return next.length ? next : null;
|
|
2280
1905
|
}
|
|
2281
1906
|
function scrollRowsForPlane(plane, startY, endY, lines) {
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
if (!op)
|
|
2285
|
-
return;
|
|
2286
|
-
scrollBufferRegion(state.buffer, op.startY, op.endY, op.delta);
|
|
2287
|
-
scrollPlaneCoverageRegion(state, op.startY, op.endY, op.delta);
|
|
2288
|
-
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));
|
|
2289
1909
|
}
|
|
2290
1910
|
function composeRows(rows, planes = TERMINAL_RENDER_PLANES) {
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
const fpArr = compositeBuffer.soaFingerprints;
|
|
2294
|
-
const rowList = rows ?? Array.from({ length: compositeBuffer.rows }, (_, index) => index);
|
|
2295
|
-
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) {
|
|
2296
1913
|
if (y < 0 || y >= compositeBuffer.rows)
|
|
2297
1914
|
continue;
|
|
2298
|
-
|
|
1915
|
+
let dst = getBufferRow(compositeBuffer, y);
|
|
2299
1916
|
dst.length = compositeBuffer.cols;
|
|
2300
1917
|
for (let x = 0; x < compositeBuffer.cols; x++)
|
|
2301
1918
|
dst[x] = blank;
|
|
2302
|
-
for (
|
|
2303
|
-
|
|
1919
|
+
for (let plane of planes) {
|
|
1920
|
+
let state = planeStates.get(plane);
|
|
2304
1921
|
if (!state)
|
|
2305
1922
|
continue;
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
for (let x = 0; x < compositeBuffer.cols; x++) {
|
|
2311
|
-
if (coverage[x])
|
|
2312
|
-
dst[x] = src[x];
|
|
2313
|
-
}
|
|
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]);
|
|
2314
1927
|
}
|
|
2315
|
-
|
|
1928
|
+
let cols = compositeBuffer.cols;
|
|
2316
1929
|
for (let x = 0; x < cols; x++) {
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
if (x + 1 >= cols || !dst[x + 1].continuation) {
|
|
2320
|
-
dst[x] = blank;
|
|
2321
|
-
}
|
|
2322
|
-
} else if (cell.continuation) {
|
|
2323
|
-
if (x === 0 || dst[x - 1].width !== 2 || dst[x - 1].continuation) {
|
|
2324
|
-
dst[x] = blank;
|
|
2325
|
-
}
|
|
2326
|
-
}
|
|
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);
|
|
2327
1932
|
}
|
|
2328
1933
|
if (fpFn && fpArr) {
|
|
2329
|
-
|
|
2330
|
-
const base2 = physY * cols;
|
|
1934
|
+
let base2 = (compositeBuffer.gridStart + y) % compositeBuffer.rows * cols;
|
|
2331
1935
|
for (let x = 0; x < cols; x++) {
|
|
2332
|
-
|
|
1936
|
+
let cell = dst[x];
|
|
2333
1937
|
fpArr[base2 + x] = fpFn(cell.ch, cell.style);
|
|
2334
1938
|
}
|
|
2335
1939
|
}
|
|
@@ -2337,166 +1941,121 @@ function createTerminal(opts) {
|
|
|
2337
1941
|
}
|
|
2338
1942
|
}
|
|
2339
1943
|
function syncCompositeCursor() {
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
for (const plane of ["overlay", "chrome", "transcript", "default"]) {
|
|
2344
|
-
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);
|
|
2345
1947
|
if (state?.buffer.cursorVisible) {
|
|
2346
1948
|
nextPlane = state;
|
|
2347
1949
|
break;
|
|
2348
1950
|
}
|
|
2349
1951
|
}
|
|
2350
|
-
compositeBuffer.cursorVisible =
|
|
2351
|
-
compositeBuffer.cursorX = nextPlane?.buffer.cursorX ?? 0;
|
|
2352
|
-
compositeBuffer.cursorY = nextPlane?.buffer.cursorY ?? 0;
|
|
2353
|
-
if (prevVisible)
|
|
2354
|
-
markDirty(compositeBuffer, prevY);
|
|
2355
|
-
if (compositeBuffer.cursorVisible)
|
|
2356
|
-
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);
|
|
2357
1953
|
}
|
|
2358
1954
|
function syncCompositeForRead(planes) {
|
|
2359
|
-
|
|
2360
|
-
let
|
|
2361
|
-
|
|
2362
|
-
for (const plane of planesToCompose) {
|
|
2363
|
-
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);
|
|
2364
1958
|
if (!state)
|
|
2365
1959
|
continue;
|
|
2366
|
-
|
|
1960
|
+
let rows = peekDirtyRows(state.buffer);
|
|
2367
1961
|
if (rows === null) {
|
|
2368
|
-
composeAllRows =
|
|
1962
|
+
composeAllRows = !0;
|
|
2369
1963
|
break;
|
|
2370
1964
|
}
|
|
2371
|
-
for (
|
|
1965
|
+
for (let y of rows)
|
|
2372
1966
|
dirtyRows.add(y);
|
|
2373
1967
|
}
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
);
|
|
2379
|
-
syncCompositeCursor();
|
|
1968
|
+
(composeAllRows || dirtyRows.size > 0) && composeRows(
|
|
1969
|
+
composeAllRows ? null : Array.from(dirtyRows).sort((a, b) => a - b),
|
|
1970
|
+
planesToCompose
|
|
1971
|
+
), syncCompositeCursor();
|
|
2380
1972
|
}
|
|
2381
1973
|
function readRowForPlanes(y, planes) {
|
|
2382
|
-
assertNotDisposed()
|
|
2383
|
-
if (y < 0 || y >= compositeBuffer.rows)
|
|
1974
|
+
if (assertNotDisposed(), y < 0 || y >= compositeBuffer.rows)
|
|
2384
1975
|
throw new RangeError("Row out of bounds");
|
|
2385
|
-
composeRows([y], planes?.length ? planes : TERMINAL_RENDER_PLANES);
|
|
2386
|
-
return getBufferRow(compositeBuffer, y);
|
|
1976
|
+
return composeRows([y], planes?.length ? planes : TERMINAL_RENDER_PLANES), getBufferRow(compositeBuffer, y);
|
|
2387
1977
|
}
|
|
2388
1978
|
function pendingDirtyRowsForPlanes(planes) {
|
|
2389
|
-
|
|
2390
|
-
let
|
|
2391
|
-
|
|
2392
|
-
for (const plane of planesToCheck) {
|
|
2393
|
-
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);
|
|
2394
1982
|
if (!state)
|
|
2395
1983
|
continue;
|
|
2396
|
-
|
|
1984
|
+
let dirty = peekDirtyRows(state.buffer);
|
|
2397
1985
|
if (dirty === null) {
|
|
2398
|
-
full =
|
|
1986
|
+
full = !0;
|
|
2399
1987
|
break;
|
|
2400
1988
|
}
|
|
2401
|
-
for (
|
|
1989
|
+
for (let y of dirty)
|
|
2402
1990
|
rows.add(y);
|
|
2403
1991
|
}
|
|
2404
|
-
|
|
2405
|
-
return null;
|
|
2406
|
-
return Array.from(rows).sort((a, b) => a - b);
|
|
1992
|
+
return full ? null : Array.from(rows).sort((a, b) => a - b);
|
|
2407
1993
|
}
|
|
2408
1994
|
function createPlaneTerminalApi(plane) {
|
|
2409
|
-
|
|
1995
|
+
let existing = planeTerminals.get(plane);
|
|
2410
1996
|
if (existing)
|
|
2411
1997
|
return existing;
|
|
2412
|
-
|
|
1998
|
+
let api = {
|
|
2413
1999
|
resize(cols, rows) {
|
|
2414
|
-
assertNotDisposed();
|
|
2415
|
-
base.resize(cols, rows);
|
|
2000
|
+
assertNotDisposed(), base.resize(cols, rows);
|
|
2416
2001
|
},
|
|
2417
2002
|
clear(x, y, w, h) {
|
|
2418
|
-
assertNotDisposed();
|
|
2419
|
-
clearForPlane(plane, x, y, w, h);
|
|
2003
|
+
assertNotDisposed(), clearForPlane(plane, x, y, w, h);
|
|
2420
2004
|
},
|
|
2421
2005
|
write(text, opts2) {
|
|
2422
2006
|
assertNotDisposed();
|
|
2423
|
-
|
|
2424
|
-
const x = opts2?.x;
|
|
2425
|
-
const y = opts2?.y;
|
|
2426
|
-
const style = opts2?.style;
|
|
2007
|
+
let state = getPlaneState(plane), x = opts2?.x, y = opts2?.y, style = opts2?.style;
|
|
2427
2008
|
if (x == null || y == null) {
|
|
2428
|
-
|
|
2009
|
+
let next = writeAtForPlane(
|
|
2429
2010
|
plane,
|
|
2430
2011
|
text,
|
|
2431
2012
|
state.buffer.cursorX,
|
|
2432
2013
|
state.buffer.cursorY,
|
|
2433
2014
|
style ?? state.buffer.cursorStyle
|
|
2434
2015
|
);
|
|
2435
|
-
state.buffer.cursorX = next.x;
|
|
2436
|
-
|
|
2437
|
-
} else {
|
|
2016
|
+
state.buffer.cursorX = next.x, state.buffer.cursorY = next.y;
|
|
2017
|
+
} else
|
|
2438
2018
|
writeAtForPlane(plane, text, x, y, style);
|
|
2439
|
-
}
|
|
2440
2019
|
},
|
|
2441
2020
|
writeAnsi(text, opts2) {
|
|
2442
2021
|
assertNotDisposed();
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
let cx = positionedWrite ? x : state.buffer.cursorX;
|
|
2448
|
-
let cy = positionedWrite ? y : state.buffer.cursorY;
|
|
2449
|
-
let style = positionedWrite ? {} : state.buffer.cursorStyle;
|
|
2450
|
-
for (const seg of parseAnsiSgr(text, style)) {
|
|
2451
|
-
const next = writeAtForPlane(plane, seg.text, cx, cy, seg.style);
|
|
2452
|
-
cx = next.x;
|
|
2453
|
-
cy = next.y;
|
|
2454
|
-
style = seg.style;
|
|
2455
|
-
}
|
|
2456
|
-
if (!positionedWrite) {
|
|
2457
|
-
state.buffer.cursorX = cx;
|
|
2458
|
-
state.buffer.cursorY = cy;
|
|
2459
|
-
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;
|
|
2460
2026
|
}
|
|
2027
|
+
positionedWrite || (state.buffer.cursorX = cx, state.buffer.cursorY = cy, state.buffer.cursorStyle = style);
|
|
2461
2028
|
},
|
|
2462
2029
|
put(x, y, ch, style) {
|
|
2463
|
-
assertNotDisposed();
|
|
2464
|
-
putForPlane(plane, x, y, ch, style);
|
|
2030
|
+
assertNotDisposed(), putForPlane(plane, x, y, ch, style);
|
|
2465
2031
|
},
|
|
2466
2032
|
fill(x, y, w, h, ch, style) {
|
|
2467
|
-
assertNotDisposed();
|
|
2468
|
-
fillForPlane(plane, x, y, w, h, ch, style);
|
|
2033
|
+
assertNotDisposed(), fillForPlane(plane, x, y, w, h, ch, style);
|
|
2469
2034
|
},
|
|
2470
2035
|
scroll(lines) {
|
|
2471
|
-
assertNotDisposed();
|
|
2472
|
-
scrollForPlane(plane, lines);
|
|
2036
|
+
assertNotDisposed(), scrollForPlane(plane, lines);
|
|
2473
2037
|
},
|
|
2474
2038
|
setCursor(x, y, visible) {
|
|
2475
|
-
assertNotDisposed();
|
|
2476
|
-
setCursorForPlane(plane, x, y, visible);
|
|
2039
|
+
assertNotDisposed(), setCursorForPlane(plane, x, y, visible);
|
|
2477
2040
|
},
|
|
2478
2041
|
batch(fn) {
|
|
2479
|
-
assertNotDisposed();
|
|
2480
|
-
return base.batch(fn);
|
|
2042
|
+
return assertNotDisposed(), base.batch(fn);
|
|
2481
2043
|
},
|
|
2482
2044
|
commit(meta) {
|
|
2483
|
-
assertNotDisposed();
|
|
2484
|
-
return base.commit({ planes: meta?.planes ?? [plane], sync: meta?.sync });
|
|
2045
|
+
return assertNotDisposed(), base.commit({ planes: meta?.planes ?? [plane], sync: meta?.sync });
|
|
2485
2046
|
},
|
|
2486
2047
|
on(event, cb) {
|
|
2487
|
-
assertNotDisposed();
|
|
2488
|
-
return base.on(event, cb);
|
|
2048
|
+
return assertNotDisposed(), base.on(event, cb);
|
|
2489
2049
|
},
|
|
2490
2050
|
dispose() {
|
|
2491
2051
|
base.dispose();
|
|
2492
2052
|
},
|
|
2493
2053
|
size() {
|
|
2494
|
-
assertNotDisposed();
|
|
2495
|
-
return base.size();
|
|
2054
|
+
return assertNotDisposed(), base.size();
|
|
2496
2055
|
},
|
|
2497
2056
|
snapshot() {
|
|
2498
2057
|
assertNotDisposed();
|
|
2499
|
-
|
|
2058
|
+
let state = getPlaneState(plane);
|
|
2500
2059
|
return {
|
|
2501
2060
|
cols: state.buffer.cols,
|
|
2502
2061
|
rows: state.buffer.rows,
|
|
@@ -2505,194 +2064,142 @@ function createTerminal(opts) {
|
|
|
2505
2064
|
},
|
|
2506
2065
|
getCell(x, y) {
|
|
2507
2066
|
assertNotDisposed();
|
|
2508
|
-
|
|
2067
|
+
let state = getPlaneState(plane);
|
|
2509
2068
|
if (y < 0 || y >= state.buffer.rows || x < 0 || x >= state.buffer.cols)
|
|
2510
2069
|
throw new RangeError("Cell out of bounds");
|
|
2511
2070
|
return getBufferCell(state.buffer, x, y);
|
|
2512
2071
|
},
|
|
2513
2072
|
getRow(y) {
|
|
2514
2073
|
assertNotDisposed();
|
|
2515
|
-
|
|
2074
|
+
let state = getPlaneState(plane);
|
|
2516
2075
|
if (y < 0 || y >= state.buffer.rows)
|
|
2517
2076
|
throw new RangeError("Row out of bounds");
|
|
2518
2077
|
return getBufferRow(state.buffer, y);
|
|
2519
2078
|
},
|
|
2520
2079
|
setScrollbackLimit(limit) {
|
|
2521
2080
|
assertNotDisposed();
|
|
2522
|
-
|
|
2523
|
-
state.buffer.scrollbackLimit = Math.max(0, Math.floor(limit))
|
|
2524
|
-
|
|
2525
|
-
state.buffer.scrollback.
|
|
2526
|
-
|
|
2527
|
-
state.buffer.scrollback.length - state.buffer.scrollbackLimit
|
|
2528
|
-
);
|
|
2529
|
-
}
|
|
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
|
+
);
|
|
2530
2086
|
},
|
|
2531
2087
|
getScrollbackLines(count) {
|
|
2532
2088
|
assertNotDisposed();
|
|
2533
|
-
|
|
2534
|
-
const all = state.buffer.scrollback.map(
|
|
2089
|
+
let all = getPlaneState(plane).buffer.scrollback.map(
|
|
2535
2090
|
(row) => row.map((cell) => cell.continuation ? " " : cell.ch || " ").join("")
|
|
2536
2091
|
);
|
|
2537
|
-
|
|
2538
|
-
return all;
|
|
2539
|
-
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))));
|
|
2540
2093
|
},
|
|
2541
2094
|
setFingerprintFn(fn) {
|
|
2542
2095
|
assertNotDisposed();
|
|
2543
|
-
|
|
2096
|
+
let state = getPlaneState(plane);
|
|
2544
2097
|
setFingerprintFn(state.buffer, fn);
|
|
2545
2098
|
},
|
|
2546
2099
|
getRowFingerprints(y) {
|
|
2547
2100
|
assertNotDisposed();
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
if (!Number.isFinite(yy) || yy < 0 || yy >= state.buffer.rows) {
|
|
2101
|
+
let yy = Math.floor(y), state = getPlaneState(plane);
|
|
2102
|
+
if (!Number.isFinite(yy) || yy < 0 || yy >= state.buffer.rows)
|
|
2551
2103
|
throw new RangeError("Row out of bounds");
|
|
2552
|
-
}
|
|
2553
2104
|
return getRowFingerprints(state.buffer, yy);
|
|
2554
2105
|
}
|
|
2555
2106
|
};
|
|
2556
|
-
planeTerminals.set(plane, api);
|
|
2557
|
-
return api;
|
|
2107
|
+
return api[TERMINAL_ROOT] = base, planeTerminals.set(plane, api), api;
|
|
2558
2108
|
}
|
|
2559
|
-
base = {
|
|
2109
|
+
return base = {
|
|
2560
2110
|
resize(cols, rows) {
|
|
2561
2111
|
assertNotDisposed();
|
|
2562
|
-
|
|
2563
|
-
const prevRows = compositeBuffer.rows;
|
|
2112
|
+
let prevCols = compositeBuffer.cols, prevRows = compositeBuffer.rows;
|
|
2564
2113
|
resizeBuffer(compositeBuffer, cols, rows);
|
|
2565
|
-
for (
|
|
2114
|
+
for (let state of planeStates.values())
|
|
2566
2115
|
resizePlaneState(state, cols, rows);
|
|
2567
|
-
|
|
2568
|
-
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 });
|
|
2569
2117
|
},
|
|
2570
2118
|
clear(x, y, w, h) {
|
|
2571
|
-
assertNotDisposed();
|
|
2572
|
-
clearForPlane("default", x, y, w, h);
|
|
2119
|
+
assertNotDisposed(), clearForPlane("default", x, y, w, h);
|
|
2573
2120
|
},
|
|
2574
2121
|
write(text, opts2) {
|
|
2575
|
-
assertNotDisposed();
|
|
2576
|
-
createPlaneTerminalApi("default").write(text, opts2);
|
|
2122
|
+
assertNotDisposed(), createPlaneTerminalApi("default").write(text, opts2);
|
|
2577
2123
|
},
|
|
2578
2124
|
writeAnsi(text, opts2) {
|
|
2579
|
-
assertNotDisposed();
|
|
2580
|
-
createPlaneTerminalApi("default").writeAnsi(text, opts2);
|
|
2125
|
+
assertNotDisposed(), createPlaneTerminalApi("default").writeAnsi(text, opts2);
|
|
2581
2126
|
},
|
|
2582
2127
|
put(x, y, ch, style) {
|
|
2583
|
-
assertNotDisposed();
|
|
2584
|
-
putForPlane("default", x, y, ch, style);
|
|
2128
|
+
assertNotDisposed(), putForPlane("default", x, y, ch, style);
|
|
2585
2129
|
},
|
|
2586
2130
|
fill(x, y, w, h, ch, style) {
|
|
2587
|
-
assertNotDisposed();
|
|
2588
|
-
fillForPlane("default", x, y, w, h, ch, style);
|
|
2131
|
+
assertNotDisposed(), fillForPlane("default", x, y, w, h, ch, style);
|
|
2589
2132
|
},
|
|
2590
2133
|
scroll(lines) {
|
|
2591
|
-
assertNotDisposed();
|
|
2592
|
-
scrollForPlane("default", lines);
|
|
2134
|
+
assertNotDisposed(), scrollForPlane("default", lines);
|
|
2593
2135
|
},
|
|
2594
|
-
setCursor(x, y, visible =
|
|
2595
|
-
assertNotDisposed();
|
|
2596
|
-
setCursorForPlane("default", x, y, visible);
|
|
2136
|
+
setCursor(x, y, visible = !0) {
|
|
2137
|
+
assertNotDisposed(), setCursorForPlane("default", x, y, visible);
|
|
2597
2138
|
},
|
|
2598
2139
|
batch(fn) {
|
|
2599
|
-
assertNotDisposed()
|
|
2600
|
-
batchingDepth++;
|
|
2140
|
+
assertNotDisposed(), batchingDepth++;
|
|
2601
2141
|
try {
|
|
2602
2142
|
return fn();
|
|
2603
2143
|
} finally {
|
|
2604
|
-
batchingDepth
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
pendingCommitAllPlanes = false;
|
|
2609
|
-
pendingCommitPlanes = null;
|
|
2610
|
-
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 });
|
|
2611
2148
|
}
|
|
2612
2149
|
}
|
|
2613
2150
|
},
|
|
2614
2151
|
commit(meta) {
|
|
2615
|
-
assertNotDisposed()
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
pendingCommitPlanes = null;
|
|
2621
|
-
} else if (!pendingCommitAllPlanes) {
|
|
2622
|
-
pendingCommitPlanes = mergePlanes(pendingCommitPlanes, meta.planes);
|
|
2623
|
-
}
|
|
2624
|
-
return pendingDirtyRowsForPlanes(meta?.planes ?? null);
|
|
2625
|
-
}
|
|
2626
|
-
const planesToCompose = meta?.planes?.length ? meta.planes : TERMINAL_RENDER_PLANES;
|
|
2627
|
-
const pendingScrollOps = takePendingScrollOps(planesToCompose);
|
|
2628
|
-
const preparedScroll = prepareCompositeScrollOps(pendingScrollOps);
|
|
2629
|
-
let scrollOperations = preparedScroll.scrollOperations;
|
|
2630
|
-
let composeAllRows = false;
|
|
2631
|
-
const dirtyRows = /* @__PURE__ */ new Set();
|
|
2632
|
-
for (const plane of planesToCompose) {
|
|
2633
|
-
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);
|
|
2634
2157
|
if (!state)
|
|
2635
2158
|
continue;
|
|
2636
|
-
|
|
2159
|
+
let rows = collectAndClearDirtyRows(state.buffer);
|
|
2637
2160
|
if (rows === null) {
|
|
2638
|
-
composeAllRows =
|
|
2639
|
-
|
|
2161
|
+
composeAllRows = !0;
|
|
2162
|
+
continue;
|
|
2640
2163
|
}
|
|
2641
|
-
for (
|
|
2164
|
+
for (let y of rows)
|
|
2642
2165
|
dirtyRows.add(y);
|
|
2643
2166
|
}
|
|
2644
|
-
for (
|
|
2167
|
+
for (let y of preparedScroll.extraDirtyRows)
|
|
2645
2168
|
dirtyRows.add(y);
|
|
2646
|
-
|
|
2647
|
-
scrollOperations = dropScrollOpsCoveredByDirtyRows(scrollOperations, normalizedDirtyRows)
|
|
2648
|
-
|
|
2649
|
-
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)
|
|
2650
2172
|
scrollBufferRegion(compositeBuffer, op.startY, op.endY, op.delta);
|
|
2651
|
-
}
|
|
2652
2173
|
if (normalizedDirtyRows !== null && normalizedDirtyRows.length === 0) {
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
return pendingCompositeRows;
|
|
2656
|
-
emitter.emit("commit", {
|
|
2174
|
+
let pendingCompositeRows = collectAndClearDirtyRows(compositeBuffer);
|
|
2175
|
+
return pendingCompositeRows !== null && pendingCompositeRows.length === 0 || emitter.emit("commit", {
|
|
2657
2176
|
dirtyRows: pendingCompositeRows,
|
|
2658
2177
|
planes: meta?.planes ?? null,
|
|
2659
2178
|
sync: meta?.sync,
|
|
2660
2179
|
scrollOperations
|
|
2661
|
-
});
|
|
2662
|
-
return pendingCompositeRows;
|
|
2180
|
+
}), pendingCompositeRows;
|
|
2663
2181
|
}
|
|
2664
|
-
composeRows(normalizedDirtyRows);
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
syncCompositeCursor();
|
|
2668
|
-
const committedRows = collectAndClearDirtyRows(compositeBuffer);
|
|
2669
|
-
if (committedRows !== null && committedRows.length === 0)
|
|
2670
|
-
return committedRows;
|
|
2671
|
-
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", {
|
|
2672
2185
|
dirtyRows: committedRows,
|
|
2673
2186
|
planes: meta?.planes ?? null,
|
|
2674
2187
|
sync: meta?.sync,
|
|
2675
2188
|
scrollOperations
|
|
2676
|
-
});
|
|
2677
|
-
return committedRows;
|
|
2189
|
+
}), committedRows;
|
|
2678
2190
|
},
|
|
2679
2191
|
on(event, cb) {
|
|
2680
|
-
assertNotDisposed();
|
|
2681
|
-
return emitter.on(event, cb);
|
|
2192
|
+
return assertNotDisposed(), emitter.on(event, cb);
|
|
2682
2193
|
},
|
|
2683
2194
|
dispose() {
|
|
2684
|
-
disposed =
|
|
2685
|
-
emitter.clear();
|
|
2195
|
+
disposed = !0, emitter.clear();
|
|
2686
2196
|
},
|
|
2687
2197
|
size() {
|
|
2688
|
-
assertNotDisposed();
|
|
2689
|
-
return { cols: compositeBuffer.cols, rows: compositeBuffer.rows };
|
|
2198
|
+
return assertNotDisposed(), { cols: compositeBuffer.cols, rows: compositeBuffer.rows };
|
|
2690
2199
|
},
|
|
2691
2200
|
snapshot() {
|
|
2692
|
-
assertNotDisposed();
|
|
2693
|
-
|
|
2694
|
-
syncCompositeForRead();
|
|
2695
|
-
const source = batchingDepth > 0 ? getPlaneState("default").buffer : compositeBuffer;
|
|
2201
|
+
assertNotDisposed(), batchingDepth === 0 && syncCompositeForRead();
|
|
2202
|
+
let source = batchingDepth > 0 ? getPlaneState("default").buffer : compositeBuffer;
|
|
2696
2203
|
return {
|
|
2697
2204
|
cols: source.cols,
|
|
2698
2205
|
rows: source.rows,
|
|
@@ -2700,180 +2207,131 @@ function createTerminal(opts) {
|
|
|
2700
2207
|
};
|
|
2701
2208
|
},
|
|
2702
2209
|
getCell(x, y) {
|
|
2703
|
-
assertNotDisposed();
|
|
2704
|
-
|
|
2705
|
-
syncCompositeForRead();
|
|
2706
|
-
const source = batchingDepth > 0 ? getPlaneState("default").buffer : compositeBuffer;
|
|
2210
|
+
assertNotDisposed(), batchingDepth === 0 && syncCompositeForRead();
|
|
2211
|
+
let source = batchingDepth > 0 ? getPlaneState("default").buffer : compositeBuffer;
|
|
2707
2212
|
if (y < 0 || y >= source.rows || x < 0 || x >= source.cols)
|
|
2708
2213
|
throw new RangeError("Cell out of bounds");
|
|
2709
2214
|
return getBufferCell(source, x, y);
|
|
2710
2215
|
},
|
|
2711
2216
|
getRow(y) {
|
|
2712
|
-
assertNotDisposed();
|
|
2713
|
-
|
|
2714
|
-
syncCompositeForRead();
|
|
2715
|
-
const source = batchingDepth > 0 ? getPlaneState("default").buffer : compositeBuffer;
|
|
2217
|
+
assertNotDisposed(), batchingDepth === 0 && syncCompositeForRead();
|
|
2218
|
+
let source = batchingDepth > 0 ? getPlaneState("default").buffer : compositeBuffer;
|
|
2716
2219
|
if (y < 0 || y >= source.rows)
|
|
2717
2220
|
throw new RangeError("Row out of bounds");
|
|
2718
2221
|
return getBufferRow(source, y);
|
|
2719
2222
|
},
|
|
2720
2223
|
setScrollbackLimit(limit) {
|
|
2721
2224
|
assertNotDisposed();
|
|
2722
|
-
|
|
2723
|
-
state.buffer.scrollbackLimit = Math.max(0, Math.floor(limit))
|
|
2724
|
-
|
|
2725
|
-
state.buffer.scrollback.
|
|
2726
|
-
|
|
2727
|
-
state.buffer.scrollback.length - state.buffer.scrollbackLimit
|
|
2728
|
-
);
|
|
2729
|
-
}
|
|
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
|
+
);
|
|
2730
2230
|
},
|
|
2731
2231
|
getScrollbackLines(count) {
|
|
2732
2232
|
assertNotDisposed();
|
|
2733
|
-
|
|
2734
|
-
const all = state.buffer.scrollback.map(
|
|
2233
|
+
let all = getPlaneState("default").buffer.scrollback.map(
|
|
2735
2234
|
(row) => row.map((cell) => cell.continuation ? " " : cell.ch || " ").join("")
|
|
2736
2235
|
);
|
|
2737
|
-
|
|
2738
|
-
return all;
|
|
2739
|
-
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))));
|
|
2740
2237
|
},
|
|
2741
2238
|
setFingerprintFn(fn) {
|
|
2742
|
-
assertNotDisposed();
|
|
2743
|
-
setFingerprintFn(compositeBuffer, fn);
|
|
2239
|
+
assertNotDisposed(), setFingerprintFn(compositeBuffer, fn);
|
|
2744
2240
|
},
|
|
2745
2241
|
getRowFingerprints(y) {
|
|
2746
2242
|
assertNotDisposed();
|
|
2747
|
-
|
|
2748
|
-
if (!Number.isFinite(yy) || yy < 0 || yy >= compositeBuffer.rows)
|
|
2243
|
+
let yy = Math.floor(y);
|
|
2244
|
+
if (!Number.isFinite(yy) || yy < 0 || yy >= compositeBuffer.rows)
|
|
2749
2245
|
throw new RangeError("Row out of bounds");
|
|
2750
|
-
}
|
|
2751
2246
|
return getRowFingerprints(compositeBuffer, yy);
|
|
2752
2247
|
}
|
|
2753
|
-
}
|
|
2754
|
-
base[TERMINAL_PLANE_INTERNALS] = {
|
|
2248
|
+
}, base[TERMINAL_PLANE_INTERNALS] = {
|
|
2755
2249
|
getPlaneTerminal: createPlaneTerminalApi,
|
|
2756
2250
|
readRowForPlanes,
|
|
2757
2251
|
resetRowsForRender(plane, dirtyRows) {
|
|
2758
|
-
|
|
2759
|
-
const rows = normalizeDirtyRows(dirtyRows, state.buffer.rows);
|
|
2252
|
+
let state = getPlaneState(plane), rows = normalizeDirtyRows(dirtyRows, state.buffer.rows);
|
|
2760
2253
|
if (rows === null) {
|
|
2761
2254
|
for (let y = 0; y < state.buffer.rows; y++)
|
|
2762
2255
|
clearPlaneCoverageRow(state, y);
|
|
2763
2256
|
return;
|
|
2764
2257
|
}
|
|
2765
|
-
for (
|
|
2258
|
+
for (let y of rows)
|
|
2766
2259
|
clearPlaneCoverageRow(state, y);
|
|
2767
2260
|
},
|
|
2768
2261
|
getRowCoverageKind(plane, y) {
|
|
2769
|
-
|
|
2262
|
+
let state = getPlaneState(plane);
|
|
2770
2263
|
if (y < 0 || y >= state.coverage.length)
|
|
2771
2264
|
return 0;
|
|
2772
|
-
|
|
2265
|
+
let row = state.coverage[y];
|
|
2773
2266
|
if (!row?.length)
|
|
2774
2267
|
return 0;
|
|
2775
2268
|
let covered = 0;
|
|
2776
|
-
for (let x = 0; x < row.length; x++)
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
}
|
|
2780
|
-
if (covered === 0)
|
|
2781
|
-
return 0;
|
|
2782
|
-
if (covered >= row.length)
|
|
2783
|
-
return 2;
|
|
2784
|
-
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;
|
|
2785
2272
|
},
|
|
2786
2273
|
scrollRows(plane, startY, endY, lines) {
|
|
2787
2274
|
scrollRowsForPlane(plane, startY, endY, lines);
|
|
2788
2275
|
}
|
|
2789
|
-
};
|
|
2790
|
-
return base;
|
|
2276
|
+
}, base[TERMINAL_ROOT] = base, base;
|
|
2791
2277
|
}
|
|
2792
2278
|
|
|
2793
2279
|
// src/utils/path.ts
|
|
2794
2280
|
function normalizeSeparators(input) {
|
|
2795
2281
|
let out = "";
|
|
2796
2282
|
for (let i = 0; i < input.length; i++) {
|
|
2797
|
-
|
|
2283
|
+
let ch = input[i];
|
|
2798
2284
|
out += ch === "\\" ? "/" : ch;
|
|
2799
2285
|
}
|
|
2800
2286
|
return out;
|
|
2801
2287
|
}
|
|
2802
2288
|
function isAbsolutePath(path) {
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
return true;
|
|
2806
|
-
return /^[A-Z]:\//i.test(p);
|
|
2289
|
+
let p = normalizeSeparators(path);
|
|
2290
|
+
return p.startsWith("/") ? !0 : /^[A-Z]:\//i.test(p);
|
|
2807
2291
|
}
|
|
2808
2292
|
function stripTrailingSlash(path) {
|
|
2809
|
-
|
|
2293
|
+
let p = normalizeSeparators(path);
|
|
2810
2294
|
if (p === "/")
|
|
2811
2295
|
return p;
|
|
2812
2296
|
let end = p.length;
|
|
2813
|
-
|
|
2297
|
+
for (; end > 0 && p.charCodeAt(end - 1) === 47; )
|
|
2814
2298
|
end--;
|
|
2815
2299
|
return end === p.length ? p : p.slice(0, end);
|
|
2816
2300
|
}
|
|
2817
2301
|
function joinPath(base, next) {
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
if (!a)
|
|
2821
|
-
return b;
|
|
2822
|
-
if (!b)
|
|
2823
|
-
return a;
|
|
2824
|
-
if (a.endsWith("/"))
|
|
2825
|
-
return `${a}${b.startsWith("/") ? b.slice(1) : b}`;
|
|
2826
|
-
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;
|
|
2827
2304
|
}
|
|
2828
2305
|
function dirname(path) {
|
|
2829
|
-
|
|
2830
|
-
const normalized = normalizeSeparators(p);
|
|
2306
|
+
let p = stripTrailingSlash(path), normalized = normalizeSeparators(p);
|
|
2831
2307
|
if (normalized === "/")
|
|
2832
2308
|
return "/";
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
const idx = normalized.lastIndexOf("/");
|
|
2836
|
-
if (idx < start)
|
|
2837
|
-
return drive ? `${drive}/` : "";
|
|
2838
|
-
const out = normalized.slice(0, idx) || (drive ? `${drive}/` : "/");
|
|
2839
|
-
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}/` : "/");
|
|
2840
2311
|
}
|
|
2841
2312
|
function normalizePath(path) {
|
|
2842
|
-
|
|
2313
|
+
let raw = normalizeSeparators(path);
|
|
2843
2314
|
if (!raw)
|
|
2844
2315
|
return "";
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
if (stack.length > 0 && stack[stack.length - 1] !== "..") {
|
|
2855
|
-
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("..");
|
|
2856
2325
|
continue;
|
|
2857
2326
|
}
|
|
2858
|
-
|
|
2859
|
-
stack.push("..");
|
|
2860
|
-
continue;
|
|
2327
|
+
stack.push(part);
|
|
2861
2328
|
}
|
|
2862
|
-
|
|
2863
|
-
}
|
|
2864
|
-
const prefix = drive ? `${drive}${absolute ? "/" : ""}` : absolute ? "/" : "";
|
|
2865
|
-
const joined = stack.join("/");
|
|
2866
|
-
const out = `${prefix}${joined}`;
|
|
2867
|
-
return out || (absolute ? drive ? `${drive}/` : "/" : "");
|
|
2329
|
+
let prefix = drive ? `${drive}${absolute ? "/" : ""}` : absolute ? "/" : "", joined = stack.join("/");
|
|
2330
|
+
return `${prefix}${joined}` || (absolute ? drive ? `${drive}/` : "/" : "");
|
|
2868
2331
|
}
|
|
2869
2332
|
function resolvePath(baseAbs, input) {
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
if (!b)
|
|
2873
|
-
return i;
|
|
2874
|
-
if (isAbsolutePath(i))
|
|
2875
|
-
return i;
|
|
2876
|
-
return normalizePath(joinPath(b, i));
|
|
2333
|
+
let b = normalizePath(baseAbs), i = normalizePath(input);
|
|
2334
|
+
return !b || isAbsolutePath(i) ? i : normalizePath(joinPath(b, i));
|
|
2877
2335
|
}
|
|
2878
2336
|
|
|
2879
2337
|
// src/core/path-suggest.ts
|
|
@@ -2883,55 +2341,46 @@ function lower(s) {
|
|
|
2883
2341
|
function normalizePathInputSeparators(input) {
|
|
2884
2342
|
let out = "";
|
|
2885
2343
|
for (let i = 0; i < input.length; i++) {
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
continue;
|
|
2889
|
-
out += ch === "\\" ? "/" : ch;
|
|
2344
|
+
let ch = input[i];
|
|
2345
|
+
ch !== "\r" && (out += ch === "\\" ? "/" : ch);
|
|
2890
2346
|
}
|
|
2891
2347
|
return out;
|
|
2892
2348
|
}
|
|
2893
2349
|
function stripCarriageReturns(input) {
|
|
2894
2350
|
let out = "";
|
|
2895
2351
|
for (let i = 0; i < input.length; i++) {
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
out += ch;
|
|
2352
|
+
let ch = input[i];
|
|
2353
|
+
ch !== "\r" && (out += ch);
|
|
2899
2354
|
}
|
|
2900
2355
|
return out;
|
|
2901
2356
|
}
|
|
2902
2357
|
function stripLeadingDotSlash(input) {
|
|
2903
2358
|
let i = 0;
|
|
2904
|
-
|
|
2359
|
+
for (; i + 1 < input.length && input.charCodeAt(i) === 46 && input.charCodeAt(i + 1) === 47; )
|
|
2905
2360
|
i += 2;
|
|
2906
|
-
}
|
|
2907
2361
|
return i === 0 ? input : input.slice(i);
|
|
2908
2362
|
}
|
|
2909
2363
|
function stripLeadingSlashes(input) {
|
|
2910
2364
|
let i = 0;
|
|
2911
|
-
|
|
2365
|
+
for (; i < input.length && input.charCodeAt(i) === 47; )
|
|
2912
2366
|
i++;
|
|
2913
2367
|
return i === 0 ? input : input.slice(i);
|
|
2914
2368
|
}
|
|
2915
2369
|
function stripTrailingSlashes(input) {
|
|
2916
2370
|
let end = input.length;
|
|
2917
|
-
|
|
2371
|
+
for (; end > 0 && input.charCodeAt(end - 1) === 47; )
|
|
2918
2372
|
end--;
|
|
2919
2373
|
return end === input.length ? input : input.slice(0, end);
|
|
2920
2374
|
}
|
|
2921
2375
|
function collapseSlashes(input) {
|
|
2922
|
-
let out = "";
|
|
2923
|
-
let previousWasSlash = false;
|
|
2376
|
+
let out = "", previousWasSlash = !1;
|
|
2924
2377
|
for (let i = 0; i < input.length; i++) {
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
if (!previousWasSlash)
|
|
2929
|
-
out += "/";
|
|
2930
|
-
previousWasSlash = true;
|
|
2378
|
+
let ch = input[i];
|
|
2379
|
+
if (ch === "/") {
|
|
2380
|
+
previousWasSlash || (out += "/"), previousWasSlash = !0;
|
|
2931
2381
|
continue;
|
|
2932
2382
|
}
|
|
2933
|
-
out += ch;
|
|
2934
|
-
previousWasSlash = false;
|
|
2383
|
+
out += ch, previousWasSlash = !1;
|
|
2935
2384
|
}
|
|
2936
2385
|
return out;
|
|
2937
2386
|
}
|
|
@@ -2941,52 +2390,35 @@ function normalizeRelativePathForIgnore(input) {
|
|
|
2941
2390
|
);
|
|
2942
2391
|
}
|
|
2943
2392
|
function fuzzyScore(name, query) {
|
|
2944
|
-
|
|
2945
|
-
const q = lower(query);
|
|
2393
|
+
let n = lower(name), q = lower(query);
|
|
2946
2394
|
if (!q)
|
|
2947
2395
|
return 0;
|
|
2948
2396
|
if (n === q)
|
|
2949
2397
|
return 2e3;
|
|
2950
2398
|
if (n.startsWith(q))
|
|
2951
2399
|
return 1500 - (n.length - q.length);
|
|
2952
|
-
|
|
2400
|
+
let idx = n.indexOf(q);
|
|
2953
2401
|
if (idx >= 0)
|
|
2954
2402
|
return 1200 - idx;
|
|
2955
|
-
let ni = 0;
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
let lastMatch = -1;
|
|
2959
|
-
while (ni < n.length && qi < q.length) {
|
|
2960
|
-
if (n[ni] === q[qi]) {
|
|
2961
|
-
if (lastMatch >= 0)
|
|
2962
|
-
gaps += ni - lastMatch - 1;
|
|
2963
|
-
lastMatch = ni;
|
|
2964
|
-
qi++;
|
|
2965
|
-
}
|
|
2966
|
-
ni++;
|
|
2967
|
-
}
|
|
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++;
|
|
2968
2406
|
if (qi !== q.length)
|
|
2969
2407
|
return null;
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
return null;
|
|
2973
|
-
return 800 - gaps;
|
|
2408
|
+
let maxGaps = Math.max(4, q.length * 2);
|
|
2409
|
+
return gaps > maxGaps ? null : 800 - gaps;
|
|
2974
2410
|
}
|
|
2975
2411
|
function parsePathQuery(rawInput) {
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
if (lastSlash < 0)
|
|
2979
|
-
return { dirPrefix: "", query: input };
|
|
2980
|
-
return {
|
|
2412
|
+
let input = normalizePathInputSeparators(rawInput), lastSlash = input.lastIndexOf("/");
|
|
2413
|
+
return lastSlash < 0 ? { dirPrefix: "", query: input } : {
|
|
2981
2414
|
dirPrefix: input.slice(0, lastSlash + 1),
|
|
2982
2415
|
query: input.slice(lastSlash + 1)
|
|
2983
2416
|
};
|
|
2984
2417
|
}
|
|
2985
2418
|
async function suggestPaths(options) {
|
|
2986
|
-
|
|
2987
|
-
const rawInput = String(options.input ?? "");
|
|
2419
|
+
let rawWorkspace = String(options.workspaceAbs ?? ""), rawInput = String(options.input ?? "");
|
|
2988
2420
|
if (!rawWorkspace || rawWorkspace.includes("\0") || rawInput.includes("\0")) {
|
|
2989
|
-
|
|
2421
|
+
let safeWorkspaceAbs = normalizePath(rawWorkspace || ".");
|
|
2990
2422
|
return {
|
|
2991
2423
|
baseDirAbs: resolvePath(safeWorkspaceAbs, "."),
|
|
2992
2424
|
dirPrefix: "",
|
|
@@ -2994,64 +2426,31 @@ async function suggestPaths(options) {
|
|
|
2994
2426
|
suggestions: []
|
|
2995
2427
|
};
|
|
2996
2428
|
}
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
let query = parsed.query;
|
|
3002
|
-
let baseDirAbs = resolvePath(workspaceAbs, dirPrefix || ".");
|
|
3003
|
-
let maxDepth = options.maxDepth ?? 0;
|
|
3004
|
-
if (!query)
|
|
3005
|
-
maxDepth = 0;
|
|
3006
|
-
const allowHidden = Boolean(options.showHidden);
|
|
3007
|
-
const allowDir = options.mode === "directory" || options.mode === "any" || options.mode === "file";
|
|
3008
|
-
const allowFile = options.mode === "file" || options.mode === "any";
|
|
3009
|
-
const max = Math.max(0, Math.floor(options.max));
|
|
3010
|
-
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)
|
|
3011
2433
|
return { baseDirAbs, dirPrefix, query, suggestions: [] };
|
|
3012
|
-
|
|
3013
|
-
const maxDepthClamped = Math.max(0, Math.floor(maxDepth || 0));
|
|
3014
|
-
const keepCapacity = Math.max(500, Math.min(8e3, max * 40));
|
|
3015
|
-
const maxScannedDirs = Math.max(200, Math.min(6e3, 800 + maxDepthClamped * 600));
|
|
3016
|
-
const maxScannedEntries = Math.max(2e3, Math.min(8e4, max * 2e3));
|
|
3017
|
-
const scored = [];
|
|
3018
|
-
let scannedDirs = 0;
|
|
3019
|
-
let scannedEntries = 0;
|
|
3020
|
-
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;
|
|
3021
2435
|
function cmpScored(a, b) {
|
|
3022
|
-
|
|
3023
|
-
return b.score - a.score;
|
|
3024
|
-
if (a.depth !== b.depth)
|
|
3025
|
-
return a.depth - b.depth;
|
|
3026
|
-
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);
|
|
3027
2437
|
}
|
|
3028
2438
|
function pruneScored() {
|
|
3029
|
-
|
|
3030
|
-
return;
|
|
3031
|
-
scored.sort(cmpScored);
|
|
3032
|
-
scored.length = keepCapacity;
|
|
2439
|
+
scored.length <= keepCapacity || (scored.sort(cmpScored), scored.length = keepCapacity);
|
|
3033
2440
|
}
|
|
3034
2441
|
function scoreItem(name, relPath, q) {
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
if (byName == null && byPath == null)
|
|
3038
|
-
return null;
|
|
3039
|
-
if (byName != null && byPath != null)
|
|
3040
|
-
return Math.max(byName + 50, byPath);
|
|
3041
|
-
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;
|
|
3042
2444
|
}
|
|
3043
2445
|
async function searchDir(dirAbs, currentDepth, currentRelPath, preloadedEntries) {
|
|
3044
|
-
if (scanAborted)
|
|
3045
|
-
return;
|
|
3046
|
-
if (currentDepth > maxDepth)
|
|
2446
|
+
if (scanAborted || currentDepth > maxDepth)
|
|
3047
2447
|
return;
|
|
3048
2448
|
if (dirAbs.includes("\0")) {
|
|
3049
|
-
scanAborted =
|
|
2449
|
+
scanAborted = !0;
|
|
3050
2450
|
return;
|
|
3051
2451
|
}
|
|
3052
|
-
scannedDirs
|
|
3053
|
-
|
|
3054
|
-
scanAborted = true;
|
|
2452
|
+
if (scannedDirs++, scannedDirs > maxScannedDirs) {
|
|
2453
|
+
scanAborted = !0;
|
|
3055
2454
|
return;
|
|
3056
2455
|
}
|
|
3057
2456
|
let entries = [];
|
|
@@ -3060,109 +2459,84 @@ async function suggestPaths(options) {
|
|
|
3060
2459
|
} catch {
|
|
3061
2460
|
return;
|
|
3062
2461
|
}
|
|
3063
|
-
for (
|
|
2462
|
+
for (let e of entries) {
|
|
3064
2463
|
if (scanAborted)
|
|
3065
2464
|
return;
|
|
3066
|
-
scannedEntries
|
|
3067
|
-
|
|
3068
|
-
scanAborted = true;
|
|
2465
|
+
if (scannedEntries++, scannedEntries > maxScannedEntries) {
|
|
2466
|
+
scanAborted = !0;
|
|
3069
2467
|
return;
|
|
3070
2468
|
}
|
|
3071
2469
|
if (!allowHidden && !query && e.name.startsWith("."))
|
|
3072
2470
|
continue;
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
continue;
|
|
3081
|
-
const score = scoreItem(e.name, itemRelPath, query);
|
|
3082
|
-
if (score != null) {
|
|
3083
|
-
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({
|
|
3084
2478
|
score,
|
|
3085
2479
|
name: e.name,
|
|
3086
2480
|
kind: "directory",
|
|
3087
2481
|
depth: currentDepth,
|
|
3088
2482
|
relPath: itemRelPath
|
|
3089
|
-
});
|
|
3090
|
-
if (scored.length > keepCapacity * 2)
|
|
3091
|
-
pruneScored();
|
|
3092
|
-
}
|
|
3093
|
-
await searchDir(`${dirAbs}/${e.name}`, currentDepth + 1, itemRelPath);
|
|
3094
|
-
continue;
|
|
3095
|
-
}
|
|
3096
|
-
if (e.kind === "file") {
|
|
3097
|
-
if (!allowFile)
|
|
2483
|
+
}), scored.length > keepCapacity * 2 && pruneScored()), await searchDir(`${dirAbs}/${e.name}`, currentDepth + 1, itemRelPath);
|
|
3098
2484
|
continue;
|
|
3099
|
-
|
|
3100
|
-
if (
|
|
3101
|
-
|
|
2485
|
+
}
|
|
2486
|
+
if (e.kind === "file") {
|
|
2487
|
+
if (!allowFile)
|
|
2488
|
+
continue;
|
|
2489
|
+
let score = scoreItem(e.name, itemRelPath, query);
|
|
2490
|
+
score != null && (scored.push({
|
|
3102
2491
|
score,
|
|
3103
2492
|
name: e.name,
|
|
3104
2493
|
kind: "file",
|
|
3105
2494
|
depth: currentDepth,
|
|
3106
2495
|
relPath: itemRelPath
|
|
3107
|
-
});
|
|
3108
|
-
if (scored.length > keepCapacity * 2)
|
|
3109
|
-
pruneScored();
|
|
2496
|
+
}), scored.length > keepCapacity * 2 && pruneScored());
|
|
3110
2497
|
}
|
|
3111
2498
|
}
|
|
3112
2499
|
}
|
|
3113
2500
|
}
|
|
3114
|
-
let ok =
|
|
3115
|
-
let baseEntries = null;
|
|
2501
|
+
let ok = !0, baseEntries = null;
|
|
3116
2502
|
try {
|
|
3117
2503
|
baseEntries = await options.listDir(baseDirAbs);
|
|
3118
2504
|
} catch {
|
|
3119
|
-
ok =
|
|
2505
|
+
ok = !1;
|
|
3120
2506
|
}
|
|
3121
2507
|
if (!ok && dirPrefix) {
|
|
3122
|
-
|
|
3123
|
-
dirPrefix = "";
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
maxDepth = 0;
|
|
3129
|
-
baseEntries = null;
|
|
3130
|
-
}
|
|
3131
|
-
await searchDir(baseDirAbs, 0, "", baseEntries ?? void 0);
|
|
3132
|
-
pruneScored();
|
|
3133
|
-
scored.sort(cmpScored);
|
|
3134
|
-
const list = max ? scored.slice(0, max) : [];
|
|
3135
|
-
const suggestions = list.map((s) => {
|
|
3136
|
-
const suffix = s.kind === "directory" ? "/" : "";
|
|
3137
|
-
const completion = `${dirPrefix}${s.relPath}${suffix}`;
|
|
3138
|
-
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}`);
|
|
3139
2514
|
return { kind: s.kind, display: completion, completion, absPath };
|
|
3140
2515
|
});
|
|
3141
2516
|
return { baseDirAbs, dirPrefix, query, suggestions };
|
|
3142
2517
|
}
|
|
3143
2518
|
function resolveUserPath(workspaceAbs, input, options) {
|
|
3144
|
-
|
|
2519
|
+
let raw = stripCarriageReturns(input ?? "").trim();
|
|
3145
2520
|
if (!raw)
|
|
3146
2521
|
return resolvePath(normalizePath(workspaceAbs), ".");
|
|
3147
2522
|
if (raw === "~" || raw.startsWith("~/")) {
|
|
3148
|
-
|
|
2523
|
+
let home = String(options?.homeDir ?? "").trim();
|
|
3149
2524
|
if (home) {
|
|
3150
|
-
|
|
2525
|
+
let rest = raw === "~" ? "" : raw.slice(2);
|
|
3151
2526
|
return resolvePath(normalizePath(home), rest);
|
|
3152
2527
|
}
|
|
3153
2528
|
}
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
return normalizePath(normalized);
|
|
3157
|
-
return resolvePath(normalizePath(workspaceAbs), normalized);
|
|
2529
|
+
let normalized = normalizePathInputSeparators(raw);
|
|
2530
|
+
return isAbsolutePath(normalized) ? normalizePath(normalized) : resolvePath(normalizePath(workspaceAbs), normalized);
|
|
3158
2531
|
}
|
|
3159
2532
|
function suggestParentHint(path) {
|
|
3160
|
-
|
|
3161
|
-
const d = dirname(p);
|
|
2533
|
+
let p = normalizePath(path), d = dirname(p);
|
|
3162
2534
|
return d ? joinPath(d, "..") : "..";
|
|
3163
2535
|
}
|
|
3164
2536
|
|
|
3165
2537
|
// src/utils/newlines.ts
|
|
3166
2538
|
function normalizeNewlines(text) {
|
|
3167
|
-
return text.replace(/\r\n/g,
|
|
2539
|
+
return text.replace(/\r\n/g, `
|
|
2540
|
+
`).replace(/\r/g, `
|
|
2541
|
+
`);
|
|
3168
2542
|
}
|