@x-otto/tui 0.1.0-alpha.43 → 0.3.0-beta.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 +92 -137
- package/dist/build-revision.json +4 -0
- package/dist/index.d.ts +14713 -2065
- package/dist/index.js +69199 -113
- package/dist/select-rows-C8rsST7Q.js +975 -0
- package/dist/select-rows-plZKwIeW.d.ts +110 -0
- package/dist/select-rows.d.ts +2 -0
- package/dist/select-rows.js +3 -0
- package/package.json +32 -44
- package/dist/Tabable-BRz398OB.d.ts +0 -4128
- package/dist/WizardDialog-BWGcsBR1.js +0 -14
- package/dist/compat.d.ts +0 -127
- package/dist/compat.js +0 -2
- package/dist/i18n-sGAClHYZ.js +0 -75
- package/dist/standalone.d.ts +0 -323
- package/dist/standalone.js +0 -1
|
@@ -0,0 +1,975 @@
|
|
|
1
|
+
import { charDisplayWidth, stringWidth } from "@x-otto/tui-screen";
|
|
2
|
+
|
|
3
|
+
//#region src/libs/input/cursor.ts
|
|
4
|
+
const segmenter$1 = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
5
|
+
function previousGraphemeBoundary(text, cursor) {
|
|
6
|
+
if (cursor <= 0) return 0;
|
|
7
|
+
let previous = 0;
|
|
8
|
+
let offset = 0;
|
|
9
|
+
for (const { segment } of segmenter$1.segment(text)) {
|
|
10
|
+
offset += segment.length;
|
|
11
|
+
if (offset >= cursor) return previous;
|
|
12
|
+
previous = offset;
|
|
13
|
+
}
|
|
14
|
+
return previous;
|
|
15
|
+
}
|
|
16
|
+
function nextGraphemeBoundary(text, cursor) {
|
|
17
|
+
if (cursor >= text.length) return text.length;
|
|
18
|
+
let offset = 0;
|
|
19
|
+
for (const { segment } of segmenter$1.segment(text)) {
|
|
20
|
+
offset += segment.length;
|
|
21
|
+
if (offset > cursor) return offset;
|
|
22
|
+
}
|
|
23
|
+
return text.length;
|
|
24
|
+
}
|
|
25
|
+
function snapCursorToGrapheme(text, cursor) {
|
|
26
|
+
if (cursor <= 0) return 0;
|
|
27
|
+
if (cursor >= text.length) return text.length;
|
|
28
|
+
let offset = 0;
|
|
29
|
+
for (const { segment } of segmenter$1.segment(text)) {
|
|
30
|
+
offset += segment.length;
|
|
31
|
+
if (offset > cursor) return offset - segment.length;
|
|
32
|
+
if (offset === cursor) return offset;
|
|
33
|
+
}
|
|
34
|
+
return text.length;
|
|
35
|
+
}
|
|
36
|
+
function charDisplayWidth$1(ch) {
|
|
37
|
+
return charDisplayWidth(ch);
|
|
38
|
+
}
|
|
39
|
+
function stringWidth$1(input) {
|
|
40
|
+
return stringWidth(input);
|
|
41
|
+
}
|
|
42
|
+
function padEndWidth(input, target) {
|
|
43
|
+
const padding = Math.max(0, target - stringWidth$1(input));
|
|
44
|
+
return input + " ".repeat(padding);
|
|
45
|
+
}
|
|
46
|
+
function padStartWidth(input, target) {
|
|
47
|
+
const padding = Math.max(0, target - stringWidth$1(input));
|
|
48
|
+
return " ".repeat(padding) + input;
|
|
49
|
+
}
|
|
50
|
+
const ELLIPSIS = "…";
|
|
51
|
+
function truncateByDisplayWidth(text, maxWidth) {
|
|
52
|
+
const ellipsisWidth = stringWidth$1(ELLIPSIS);
|
|
53
|
+
if (maxWidth <= 1) return ELLIPSIS;
|
|
54
|
+
if (stringWidth$1(text) <= maxWidth) return text;
|
|
55
|
+
let budget = maxWidth - ellipsisWidth;
|
|
56
|
+
let out = "";
|
|
57
|
+
for (const { segment } of segmenter$1.segment(text)) {
|
|
58
|
+
const w = charDisplayWidth$1(segment);
|
|
59
|
+
if (w > budget) break;
|
|
60
|
+
out += segment;
|
|
61
|
+
budget -= w;
|
|
62
|
+
}
|
|
63
|
+
return `${out}${ELLIPSIS}`;
|
|
64
|
+
}
|
|
65
|
+
function truncateMiddleByWidth(text, maxWidth) {
|
|
66
|
+
if (maxWidth <= 1) return ELLIPSIS;
|
|
67
|
+
if (stringWidth$1(text) <= maxWidth) return text;
|
|
68
|
+
const budget = maxWidth - stringWidth$1(ELLIPSIS);
|
|
69
|
+
const headBudget = Math.floor(budget / 2);
|
|
70
|
+
const tailBudget = budget - headBudget;
|
|
71
|
+
const segments = graphemeSegmentsOf(text);
|
|
72
|
+
let head = "";
|
|
73
|
+
let headUsed = 0;
|
|
74
|
+
for (const segment of segments) {
|
|
75
|
+
const width = charDisplayWidth$1(segment);
|
|
76
|
+
if (headUsed + width > headBudget) break;
|
|
77
|
+
head += segment;
|
|
78
|
+
headUsed += width;
|
|
79
|
+
}
|
|
80
|
+
let tail = "";
|
|
81
|
+
let tailUsed = 0;
|
|
82
|
+
for (let index = segments.length - 1; index >= 0; index -= 1) {
|
|
83
|
+
const segment = segments[index];
|
|
84
|
+
const width = charDisplayWidth$1(segment);
|
|
85
|
+
if (tailUsed + width > tailBudget) break;
|
|
86
|
+
tail = segment + tail;
|
|
87
|
+
tailUsed += width;
|
|
88
|
+
}
|
|
89
|
+
return `${head}${ELLIPSIS}${tail}`;
|
|
90
|
+
}
|
|
91
|
+
const isPlainAscii = (text) => {
|
|
92
|
+
for (let position = 0; position < text.length; position += 1) {
|
|
93
|
+
const code = text.charCodeAt(position);
|
|
94
|
+
if (code < 32 || code > 126) return false;
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
};
|
|
98
|
+
function indexToCol(text, index) {
|
|
99
|
+
if (isPlainAscii(text)) return Math.min(Math.max(index, 0), text.length);
|
|
100
|
+
let col = 0;
|
|
101
|
+
let i = 0;
|
|
102
|
+
for (const { segment } of segmenter$1.segment(text)) {
|
|
103
|
+
if (i >= index) break;
|
|
104
|
+
col += charDisplayWidth$1(segment);
|
|
105
|
+
i += segment.length;
|
|
106
|
+
}
|
|
107
|
+
return col;
|
|
108
|
+
}
|
|
109
|
+
function colToIndex(text, col, preferForward = true) {
|
|
110
|
+
if (Number.isInteger(col) && col >= 0 && isPlainAscii(text)) return Math.min(col, text.length);
|
|
111
|
+
let currentCol = 0;
|
|
112
|
+
let i = 0;
|
|
113
|
+
for (const { segment } of segmenter$1.segment(text)) {
|
|
114
|
+
const w = charDisplayWidth$1(segment);
|
|
115
|
+
if (currentCol + w > col) {
|
|
116
|
+
if (currentCol === col) return i;
|
|
117
|
+
return preferForward ? i + segment.length : i;
|
|
118
|
+
}
|
|
119
|
+
currentCol += w;
|
|
120
|
+
i += segment.length;
|
|
121
|
+
}
|
|
122
|
+
return i;
|
|
123
|
+
}
|
|
124
|
+
function clampViewportOffset(prevOffset, cursorCol, viewportWidth) {
|
|
125
|
+
if (viewportWidth <= 0) return 0;
|
|
126
|
+
if (cursorCol < prevOffset) return cursorCol;
|
|
127
|
+
if (cursorCol > prevOffset + viewportWidth - 1) return cursorCol - viewportWidth + 1;
|
|
128
|
+
return Math.max(0, prevOffset);
|
|
129
|
+
}
|
|
130
|
+
function alignOffsetToCharBoundary(text, offset) {
|
|
131
|
+
if (offset <= 0) return 0;
|
|
132
|
+
return indexToCol(text, colToIndex(text, offset, false));
|
|
133
|
+
}
|
|
134
|
+
function findAtomAt(atoms, index) {
|
|
135
|
+
for (const a of atoms) if (index > a.start && index < a.end) return a;
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
function snapCursorToAtom(atoms, index, fromLeft) {
|
|
139
|
+
const hit = findAtomAt(atoms, index);
|
|
140
|
+
if (!hit) return index;
|
|
141
|
+
return fromLeft ? hit.start : hit.end;
|
|
142
|
+
}
|
|
143
|
+
function deleteBackwardRange(atoms, cursor, count, text) {
|
|
144
|
+
const atom = atoms.find((a) => a.end === cursor);
|
|
145
|
+
if (atom) return {
|
|
146
|
+
start: atom.start,
|
|
147
|
+
end: atom.end
|
|
148
|
+
};
|
|
149
|
+
let start = cursor;
|
|
150
|
+
for (let step = 0; step < count; step += 1) start = previousGraphemeBoundary(text, start);
|
|
151
|
+
return {
|
|
152
|
+
start,
|
|
153
|
+
end: cursor
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function deleteForwardRange(atoms, cursor, count, textLength, text) {
|
|
157
|
+
const atom = atoms.find((a) => a.start === cursor);
|
|
158
|
+
if (atom) return {
|
|
159
|
+
start: atom.start,
|
|
160
|
+
end: atom.end
|
|
161
|
+
};
|
|
162
|
+
let end = cursor;
|
|
163
|
+
for (let step = 0; step < count; step += 1) end = nextGraphemeBoundary(text, end);
|
|
164
|
+
return {
|
|
165
|
+
start: cursor,
|
|
166
|
+
end: Math.min(textLength, end)
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function graphemeSegmentsOf(text) {
|
|
170
|
+
const segments = [];
|
|
171
|
+
for (const { segment } of segmenter$1.segment(text)) segments.push(segment);
|
|
172
|
+
return segments;
|
|
173
|
+
}
|
|
174
|
+
function colToGraphemeIndex(text, column) {
|
|
175
|
+
if (column <= 0) return 0;
|
|
176
|
+
let col = 0;
|
|
177
|
+
let index = 0;
|
|
178
|
+
for (const { segment } of segmenter$1.segment(text)) {
|
|
179
|
+
const width = charDisplayWidth$1(segment);
|
|
180
|
+
if (col + width > column) return index;
|
|
181
|
+
col += width;
|
|
182
|
+
index += 1;
|
|
183
|
+
if (col === column) return index;
|
|
184
|
+
}
|
|
185
|
+
return index;
|
|
186
|
+
}
|
|
187
|
+
function sliceGraphemesByColumns(text, start, end) {
|
|
188
|
+
const segments = graphemeSegmentsOf(text);
|
|
189
|
+
const from = Math.max(0, Math.min(colToGraphemeIndex(text, start), segments.length));
|
|
190
|
+
const to = Math.max(from, Math.min(colToGraphemeIndex(text, end), segments.length));
|
|
191
|
+
return {
|
|
192
|
+
pre: segments.slice(0, from).join(""),
|
|
193
|
+
selected: segments.slice(from, to).join(""),
|
|
194
|
+
post: segments.slice(to).join("")
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/libs/input/chip-scan.ts
|
|
200
|
+
function scanChipRanges(text) {
|
|
201
|
+
const ranges = [];
|
|
202
|
+
const re = /\[@[a-z][\w.-]*:(?:\\\]|[^\]])*\]/g;
|
|
203
|
+
let m;
|
|
204
|
+
while ((m = re.exec(text)) !== null) ranges.push({
|
|
205
|
+
start: m.index,
|
|
206
|
+
end: m.index + m[0].length
|
|
207
|
+
});
|
|
208
|
+
return ranges;
|
|
209
|
+
}
|
|
210
|
+
function parseChipToken(token) {
|
|
211
|
+
const m = /^\[@([a-z][\w.-]*):((?:\\\]|[^\]])*)\]$/.exec(token);
|
|
212
|
+
return m ? {
|
|
213
|
+
kind: m[1] ?? "",
|
|
214
|
+
raw: m[2] ?? ""
|
|
215
|
+
} : null;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region src/libs/input/normalize.ts
|
|
220
|
+
const INPUT_TAB_STOP = 8;
|
|
221
|
+
function normalizeLineEndings(text) {
|
|
222
|
+
return text.replace(/\r\n?/g, "\n");
|
|
223
|
+
}
|
|
224
|
+
function expandTabsInLine(line, startColumn) {
|
|
225
|
+
if (!line.includes(" ")) return line;
|
|
226
|
+
const parts = line.split(" ");
|
|
227
|
+
let column = startColumn;
|
|
228
|
+
let out = "";
|
|
229
|
+
for (let index = 0; index < parts.length; index += 1) {
|
|
230
|
+
const part = parts[index] ?? "";
|
|
231
|
+
if (index > 0) {
|
|
232
|
+
const spaces = 8 - column % 8;
|
|
233
|
+
out += " ".repeat(spaces);
|
|
234
|
+
column += spaces;
|
|
235
|
+
}
|
|
236
|
+
out += part;
|
|
237
|
+
column += stringWidth$1(part);
|
|
238
|
+
}
|
|
239
|
+
return out;
|
|
240
|
+
}
|
|
241
|
+
function normalizeInputText(text, startColumn = 0) {
|
|
242
|
+
if (text === "") return text;
|
|
243
|
+
const lines = normalizeLineEndings(text).split("\n");
|
|
244
|
+
let out = "";
|
|
245
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
246
|
+
if (index > 0) out += "\n";
|
|
247
|
+
out += expandTabsInLine(lines[index] ?? "", index === 0 ? startColumn : 0);
|
|
248
|
+
}
|
|
249
|
+
return out;
|
|
250
|
+
}
|
|
251
|
+
function normalizeInputPrefix(text, cursor) {
|
|
252
|
+
const clamped = Math.max(0, Math.min(cursor, text.length));
|
|
253
|
+
return normalizeInputText(text.slice(0, clamped)).length;
|
|
254
|
+
}
|
|
255
|
+
function lineColumnAt(text, cursor) {
|
|
256
|
+
const clamped = Math.max(0, Math.min(cursor, text.length));
|
|
257
|
+
const lineStart = text.lastIndexOf("\n", clamped - 1) + 1;
|
|
258
|
+
return stringWidth$1(text.slice(lineStart, clamped));
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
//#endregion
|
|
262
|
+
//#region src/libs/input/input-rows.ts
|
|
263
|
+
const segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
264
|
+
const HARD_LINE_BREAK = /\r\n|\r|\n/g;
|
|
265
|
+
const DEFAULT_CURSOR_GUARD_COLUMNS = 1;
|
|
266
|
+
function inputPrefixWidth(prefix) {
|
|
267
|
+
return prefix === false ? 0 : stringWidth$1(`${prefix} `);
|
|
268
|
+
}
|
|
269
|
+
function normalizedWidth(width, defaultWidth) {
|
|
270
|
+
if (width === "auto") return "auto";
|
|
271
|
+
const numeric = width === void 0 ? defaultWidth : width;
|
|
272
|
+
if (!Number.isFinite(numeric)) return 1;
|
|
273
|
+
return numeric;
|
|
274
|
+
}
|
|
275
|
+
function resolveInputWrap(options) {
|
|
276
|
+
const prefixWidth = inputPrefixWidth(options.prefix);
|
|
277
|
+
const guard = guardColumnsOf(options.cursorGuardColumns);
|
|
278
|
+
const width = normalizedWidth(options.width, options.defaultWidth);
|
|
279
|
+
if (width === "auto") return {
|
|
280
|
+
prefixWidth,
|
|
281
|
+
wrapWidth: Math.max(1, Math.floor(options.defaultWidth) - guard)
|
|
282
|
+
};
|
|
283
|
+
return {
|
|
284
|
+
prefixWidth,
|
|
285
|
+
wrapWidth: Math.max(1, Math.floor(width) - prefixWidth - guard)
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function guardColumnsOf(value) {
|
|
289
|
+
if (value === void 0 || !Number.isFinite(value)) return 1;
|
|
290
|
+
return Math.max(0, Math.floor(value));
|
|
291
|
+
}
|
|
292
|
+
function unitWidth(segment, currentColumn) {
|
|
293
|
+
if (segment === " ") return 8 - currentColumn % 8;
|
|
294
|
+
return stringWidth$1(segment);
|
|
295
|
+
}
|
|
296
|
+
function columnsOf(text) {
|
|
297
|
+
let column = 0;
|
|
298
|
+
for (const { segment } of segmenter.segment(text)) column += unitWidth(segment, column);
|
|
299
|
+
return column;
|
|
300
|
+
}
|
|
301
|
+
function clampCursorOffset(value, cursorOffset) {
|
|
302
|
+
if (!Number.isFinite(cursorOffset)) return 0;
|
|
303
|
+
if (cursorOffset < 0) return 0;
|
|
304
|
+
if (cursorOffset > value.length) return value.length;
|
|
305
|
+
return Math.floor(cursorOffset);
|
|
306
|
+
}
|
|
307
|
+
function mergeAtomRanges(ranges, textLength) {
|
|
308
|
+
const sorted = ranges.filter((range) => range.start >= 0 && range.end > range.start && range.end <= textLength).sort((a, b) => a.start - b.start || a.end - b.end);
|
|
309
|
+
const merged = [];
|
|
310
|
+
for (const range of sorted) {
|
|
311
|
+
const previous = merged[merged.length - 1];
|
|
312
|
+
if (previous && range.start < previous.end) {
|
|
313
|
+
previous.end = Math.max(previous.end, range.end);
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
merged.push({
|
|
317
|
+
start: range.start,
|
|
318
|
+
end: range.end
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
return merged;
|
|
322
|
+
}
|
|
323
|
+
function emptySoftWrapResult() {
|
|
324
|
+
return {
|
|
325
|
+
lines: [{
|
|
326
|
+
row: 0,
|
|
327
|
+
text: "",
|
|
328
|
+
start: 0,
|
|
329
|
+
columns: 0
|
|
330
|
+
}],
|
|
331
|
+
cursorLine: 0,
|
|
332
|
+
cursorColumn: 0
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function hardLinesOf(value) {
|
|
336
|
+
const lines = [];
|
|
337
|
+
let start = 0;
|
|
338
|
+
for (const match of value.matchAll(HARD_LINE_BREAK)) {
|
|
339
|
+
const index = match.index ?? start;
|
|
340
|
+
lines.push({
|
|
341
|
+
text: value.slice(start, index),
|
|
342
|
+
start
|
|
343
|
+
});
|
|
344
|
+
start = index + match[0].length;
|
|
345
|
+
}
|
|
346
|
+
lines.push({
|
|
347
|
+
text: value.slice(start),
|
|
348
|
+
start
|
|
349
|
+
});
|
|
350
|
+
return lines;
|
|
351
|
+
}
|
|
352
|
+
function resolveCursorOf(lines, value, offset) {
|
|
353
|
+
if (lines.length === 0) return {
|
|
354
|
+
cursorLine: 0,
|
|
355
|
+
cursorColumn: 0
|
|
356
|
+
};
|
|
357
|
+
let chosen = 0;
|
|
358
|
+
for (let index = 0; index < lines.length; index += 1) if (lines[index].start <= offset) chosen = index;
|
|
359
|
+
else break;
|
|
360
|
+
const line = lines[chosen];
|
|
361
|
+
const end = Math.min(offset, line.start + line.text.length);
|
|
362
|
+
const column = columnsOf(value.slice(line.start, end));
|
|
363
|
+
return {
|
|
364
|
+
cursorLine: chosen,
|
|
365
|
+
cursorColumn: Math.max(0, Math.min(column, line.columns))
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
function fixedLinesResult(value, cursorOffset) {
|
|
369
|
+
const lines = hardLinesOf(value).map((logical, row) => ({
|
|
370
|
+
row,
|
|
371
|
+
text: logical.text,
|
|
372
|
+
start: logical.start,
|
|
373
|
+
columns: columnsOf(logical.text)
|
|
374
|
+
}));
|
|
375
|
+
return {
|
|
376
|
+
lines,
|
|
377
|
+
...resolveCursorOf(lines, value, cursorOffset)
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
function isWhitespaceSegment(segment) {
|
|
381
|
+
return segment !== "" && /\s/.test(segment);
|
|
382
|
+
}
|
|
383
|
+
function wrapLogicalLine(value, logical, row, width, wrap, atoms, lines) {
|
|
384
|
+
if (logical.text === "") {
|
|
385
|
+
lines.push({
|
|
386
|
+
row,
|
|
387
|
+
text: "",
|
|
388
|
+
start: logical.start,
|
|
389
|
+
columns: 0
|
|
390
|
+
});
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
const logicalEnd = logical.start + logical.text.length;
|
|
394
|
+
let currentText = "";
|
|
395
|
+
let currentWidth = 0;
|
|
396
|
+
let currentStart = logical.start;
|
|
397
|
+
let lastBreakOffset = -1;
|
|
398
|
+
let lastBreakLength = 0;
|
|
399
|
+
let atomIndex = atoms.findIndex((atom) => atom.start >= logical.start);
|
|
400
|
+
if (atomIndex < 0) atomIndex = atoms.length;
|
|
401
|
+
const pushCurrentLine = () => {
|
|
402
|
+
lines.push({
|
|
403
|
+
row,
|
|
404
|
+
text: currentText,
|
|
405
|
+
start: currentStart,
|
|
406
|
+
columns: currentWidth
|
|
407
|
+
});
|
|
408
|
+
currentStart += currentText.length;
|
|
409
|
+
currentText = "";
|
|
410
|
+
currentWidth = 0;
|
|
411
|
+
lastBreakOffset = -1;
|
|
412
|
+
lastBreakLength = 0;
|
|
413
|
+
};
|
|
414
|
+
const breakAtLastWhitespace = () => {
|
|
415
|
+
const head = currentText.slice(0, lastBreakOffset);
|
|
416
|
+
lines.push({
|
|
417
|
+
row,
|
|
418
|
+
text: head,
|
|
419
|
+
start: currentStart,
|
|
420
|
+
columns: columnsOf(head)
|
|
421
|
+
});
|
|
422
|
+
currentStart += lastBreakOffset + lastBreakLength;
|
|
423
|
+
currentText = currentText.slice(lastBreakOffset + lastBreakLength);
|
|
424
|
+
currentWidth = columnsOf(currentText);
|
|
425
|
+
lastBreakOffset = -1;
|
|
426
|
+
lastBreakLength = 0;
|
|
427
|
+
};
|
|
428
|
+
const segments = [...segmenter.segment(logical.text)];
|
|
429
|
+
let segmentIndex = 0;
|
|
430
|
+
while (segmentIndex < segments.length) {
|
|
431
|
+
const entry = segments[segmentIndex];
|
|
432
|
+
const absoluteIndex = logical.start + entry.index;
|
|
433
|
+
const atom = atoms[atomIndex];
|
|
434
|
+
if (atom !== void 0 && atom.start === absoluteIndex) {
|
|
435
|
+
const atomText = value.slice(atom.start, atom.end);
|
|
436
|
+
const atomWidth = columnsOf(atomText);
|
|
437
|
+
if (atom.end <= logicalEnd && atomWidth <= width) {
|
|
438
|
+
if (currentText !== "" && currentWidth + atomWidth > width) pushCurrentLine();
|
|
439
|
+
if (currentText === "") currentStart = absoluteIndex;
|
|
440
|
+
currentText += atomText;
|
|
441
|
+
currentWidth += atomWidth;
|
|
442
|
+
while (segmentIndex < segments.length && logical.start + segments[segmentIndex].index < atom.end) segmentIndex += 1;
|
|
443
|
+
atomIndex += 1;
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
atomIndex += 1;
|
|
447
|
+
}
|
|
448
|
+
let segmentWidth = unitWidth(entry.segment, currentWidth);
|
|
449
|
+
if (wrap === "word" && isWhitespaceSegment(entry.segment)) {
|
|
450
|
+
if (currentText !== "" && currentWidth + segmentWidth > width) {
|
|
451
|
+
pushCurrentLine();
|
|
452
|
+
currentStart = absoluteIndex + entry.segment.length;
|
|
453
|
+
} else {
|
|
454
|
+
if (currentText === "") currentStart = absoluteIndex;
|
|
455
|
+
lastBreakOffset = currentText.length;
|
|
456
|
+
lastBreakLength = entry.segment.length;
|
|
457
|
+
currentText += entry.segment;
|
|
458
|
+
currentWidth += segmentWidth;
|
|
459
|
+
}
|
|
460
|
+
segmentIndex += 1;
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
while (currentText !== "" && currentWidth + segmentWidth > width) {
|
|
464
|
+
if (wrap === "word" && lastBreakOffset > 0) breakAtLastWhitespace();
|
|
465
|
+
else pushCurrentLine();
|
|
466
|
+
segmentWidth = unitWidth(entry.segment, currentWidth);
|
|
467
|
+
}
|
|
468
|
+
if (currentText === "") currentStart = absoluteIndex;
|
|
469
|
+
currentText += entry.segment;
|
|
470
|
+
currentWidth += segmentWidth;
|
|
471
|
+
segmentIndex += 1;
|
|
472
|
+
}
|
|
473
|
+
if (currentText !== "") {
|
|
474
|
+
pushCurrentLine();
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
if (currentStart < logicalEnd) lines.push({
|
|
478
|
+
row,
|
|
479
|
+
text: "",
|
|
480
|
+
start: logicalEnd,
|
|
481
|
+
columns: 0
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
function softWrapOf(value, wrapWidth, wrap, atoms = [], cursorOffset = 0) {
|
|
485
|
+
const width = Number.isFinite(wrapWidth) ? Math.max(0, Math.floor(wrapWidth)) : 0;
|
|
486
|
+
const offset = clampCursorOffset(value, cursorOffset);
|
|
487
|
+
const atomRanges = mergeAtomRanges(atoms, value.length);
|
|
488
|
+
if (value === "") return emptySoftWrapResult();
|
|
489
|
+
if (width <= 0 || wrap === "none") return fixedLinesResult(value, offset);
|
|
490
|
+
const lines = [];
|
|
491
|
+
const logicalLines = hardLinesOf(value);
|
|
492
|
+
for (let row = 0; row < logicalLines.length; row += 1) wrapLogicalLine(value, logicalLines[row], row, width, wrap, atomRanges, lines);
|
|
493
|
+
return {
|
|
494
|
+
lines,
|
|
495
|
+
...resolveCursorOf(lines, value, offset)
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function inputLineVisualRows(line, wrapWidth, wrap = "word") {
|
|
499
|
+
return softWrapOf(line, wrapWidth, wrap, scanChipRanges(line)).lines.length;
|
|
500
|
+
}
|
|
501
|
+
function inputVisualRowsOf(value, wrapWidth, wrap = "word") {
|
|
502
|
+
return softWrapOf(value, wrapWidth, wrap, scanChipRanges(value)).lines.length;
|
|
503
|
+
}
|
|
504
|
+
function lineStartOffsetsOf(value) {
|
|
505
|
+
return hardLinesOf(value).map((logical) => logical.start);
|
|
506
|
+
}
|
|
507
|
+
const columnStopsOf = (text, stops) => {
|
|
508
|
+
const columns = [];
|
|
509
|
+
let column = 0;
|
|
510
|
+
let index = 0;
|
|
511
|
+
let stop = 0;
|
|
512
|
+
if (stops.length === 0) return columns;
|
|
513
|
+
for (const { segment } of segmenter.segment(text)) {
|
|
514
|
+
while (stop < stops.length && index >= (stops[stop] ?? Number.POSITIVE_INFINITY)) {
|
|
515
|
+
columns[stop] = column;
|
|
516
|
+
stop += 1;
|
|
517
|
+
}
|
|
518
|
+
if (stop >= stops.length) return columns;
|
|
519
|
+
column += charDisplayWidth$1(segment);
|
|
520
|
+
index += segment.length;
|
|
521
|
+
}
|
|
522
|
+
while (stop < stops.length) {
|
|
523
|
+
columns[stop] = column;
|
|
524
|
+
stop += 1;
|
|
525
|
+
}
|
|
526
|
+
return columns;
|
|
527
|
+
};
|
|
528
|
+
const startColumnsOf = (logicalLines, rows, localStarts) => {
|
|
529
|
+
const columns = localStarts.map(() => 0);
|
|
530
|
+
const positionsByRow = /* @__PURE__ */ new Map();
|
|
531
|
+
for (let position = 0; position < rows.length; position += 1) {
|
|
532
|
+
const row = rows[position] ?? 0;
|
|
533
|
+
const positions = positionsByRow.get(row) ?? [];
|
|
534
|
+
positions.push(position);
|
|
535
|
+
positionsByRow.set(row, positions);
|
|
536
|
+
}
|
|
537
|
+
for (const [row, positions] of positionsByRow) {
|
|
538
|
+
const ordered = [...positions].sort((left, right) => (localStarts[left] ?? 0) - (localStarts[right] ?? 0));
|
|
539
|
+
const stops = ordered.map((position) => localStarts[position] ?? 0);
|
|
540
|
+
const rowColumns = columnStopsOf(logicalLines[row] ?? "", stops);
|
|
541
|
+
ordered.forEach((position, order) => {
|
|
542
|
+
columns[position] = rowColumns[order] ?? 0;
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
return columns;
|
|
546
|
+
};
|
|
547
|
+
function inputVisualModelOf(value, wrapWidth, wrap, atoms = [], cursorOffset = 0) {
|
|
548
|
+
const wrapped = softWrapOf(value, wrapWidth, wrap, atoms, cursorOffset);
|
|
549
|
+
const lineOffsets = lineStartOffsetsOf(value);
|
|
550
|
+
const startColumns = startColumnsOf(hardLinesOf(value).map((logical) => logical.text), wrapped.lines.map((line) => line.row), wrapped.lines.map((line) => Math.max(0, line.start - (lineOffsets[line.row] ?? 0))));
|
|
551
|
+
return {
|
|
552
|
+
lines: wrapped.lines.map((line, position) => ({
|
|
553
|
+
row: line.row,
|
|
554
|
+
text: line.text,
|
|
555
|
+
startColumn: startColumns[position] ?? 0,
|
|
556
|
+
startOffset: line.start,
|
|
557
|
+
columns: line.columns
|
|
558
|
+
})),
|
|
559
|
+
cursorLine: wrapped.cursorLine,
|
|
560
|
+
cursorColumn: wrapped.cursorColumn
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
//#endregion
|
|
565
|
+
//#region src/libs/input/wrap.ts
|
|
566
|
+
function wrapLine(line, width, mode, atoms) {
|
|
567
|
+
return softWrapOf(line, width, mode, atoms, 0).lines.map((visualLine) => visualLine.text);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
//#endregion
|
|
571
|
+
//#region src/libs/render/text-rows.ts
|
|
572
|
+
function wrapColumns(text, columns) {
|
|
573
|
+
if (columns <= 0) return [];
|
|
574
|
+
const out = [];
|
|
575
|
+
for (const rawLine of text.split("\n")) {
|
|
576
|
+
if (rawLine === "") {
|
|
577
|
+
out.push("");
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
580
|
+
const segments = wrapLine(rawLine, columns, "char");
|
|
581
|
+
if (segments.length === 0) {
|
|
582
|
+
out.push("");
|
|
583
|
+
continue;
|
|
584
|
+
}
|
|
585
|
+
out.push(...segments);
|
|
586
|
+
}
|
|
587
|
+
return out;
|
|
588
|
+
}
|
|
589
|
+
function wrapProse(text, columns) {
|
|
590
|
+
if (columns <= 0) return [];
|
|
591
|
+
const out = [];
|
|
592
|
+
for (const rawLine of text.split("\n")) {
|
|
593
|
+
const words = rawLine.split(" ").filter((word) => word !== "");
|
|
594
|
+
if (words.length === 0) {
|
|
595
|
+
out.push("");
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
let current = "";
|
|
599
|
+
let width = 0;
|
|
600
|
+
for (const word of words) {
|
|
601
|
+
const wordWidth = stringWidth$1(word);
|
|
602
|
+
const required = current === "" ? wordWidth : width + 1 + wordWidth;
|
|
603
|
+
if (required <= columns) {
|
|
604
|
+
current = current === "" ? word : `${current} ${word}`;
|
|
605
|
+
width = required;
|
|
606
|
+
continue;
|
|
607
|
+
}
|
|
608
|
+
if (current !== "") {
|
|
609
|
+
out.push(current);
|
|
610
|
+
current = "";
|
|
611
|
+
width = 0;
|
|
612
|
+
}
|
|
613
|
+
if (wordWidth <= columns) {
|
|
614
|
+
current = word;
|
|
615
|
+
width = wordWidth;
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
const pieces = wrapLine(word, columns, "char");
|
|
619
|
+
for (let i = 0; i < pieces.length - 1; i += 1) {
|
|
620
|
+
const piece = pieces[i];
|
|
621
|
+
if (piece !== void 0) out.push(piece);
|
|
622
|
+
}
|
|
623
|
+
const last = pieces[pieces.length - 1] ?? "";
|
|
624
|
+
current = last;
|
|
625
|
+
width = stringWidth$1(last);
|
|
626
|
+
}
|
|
627
|
+
out.push(current);
|
|
628
|
+
}
|
|
629
|
+
return out;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
//#endregion
|
|
633
|
+
//#region src/libs/render/figures.ts
|
|
634
|
+
const ICON_GLYPHS = {
|
|
635
|
+
user: ">",
|
|
636
|
+
assistant: "●",
|
|
637
|
+
tool: "○",
|
|
638
|
+
error: "✗",
|
|
639
|
+
system: "·",
|
|
640
|
+
tipAbove: "↑",
|
|
641
|
+
tipBelow: "↓",
|
|
642
|
+
separator: "·",
|
|
643
|
+
current: "●",
|
|
644
|
+
pointer: "→",
|
|
645
|
+
arrowUp: "↑",
|
|
646
|
+
arrowDown: "↓",
|
|
647
|
+
requesting: "↑",
|
|
648
|
+
responding: "↓",
|
|
649
|
+
arrowLeft: "←",
|
|
650
|
+
arrowRight: "→",
|
|
651
|
+
triangleLeft: "◀",
|
|
652
|
+
triangleRight: "▶",
|
|
653
|
+
blockFull: "█",
|
|
654
|
+
trackVertical: "│",
|
|
655
|
+
trackHorizontal: "─",
|
|
656
|
+
bullet: "•",
|
|
657
|
+
hr: "─",
|
|
658
|
+
dash: "—",
|
|
659
|
+
radioOn: "◉",
|
|
660
|
+
radioOff: "○",
|
|
661
|
+
radioSquareOn: "▣",
|
|
662
|
+
radioSquareOff: "□",
|
|
663
|
+
radioSquarePartial: "◪",
|
|
664
|
+
todoChecked: "☑",
|
|
665
|
+
todoUnchecked: "☐",
|
|
666
|
+
todoPending: "○",
|
|
667
|
+
todoActive: "◐",
|
|
668
|
+
todoDone: "✓",
|
|
669
|
+
todoFailed: "✗",
|
|
670
|
+
blocked: "⇥",
|
|
671
|
+
replyBullet: "•",
|
|
672
|
+
toolResult: "⎿",
|
|
673
|
+
quoteBar: "▎",
|
|
674
|
+
serviceSignal: "⇢",
|
|
675
|
+
notificationSignal: "✦",
|
|
676
|
+
editedSignal: "~",
|
|
677
|
+
taskSignal: "▸",
|
|
678
|
+
subagentSignal: "◆",
|
|
679
|
+
memorySignal: "⁂",
|
|
680
|
+
sessionSignal: "▤",
|
|
681
|
+
pendingSignal: "⋯",
|
|
682
|
+
clipboardSignal: "✓",
|
|
683
|
+
queueSignal: "☰",
|
|
684
|
+
heldSignal: "⊙",
|
|
685
|
+
historySignal: "↺",
|
|
686
|
+
scheduleSignal: "◷",
|
|
687
|
+
draftSignal: "✍",
|
|
688
|
+
compactSignal: "≡",
|
|
689
|
+
pruneSignal: "✂",
|
|
690
|
+
withdrawSignal: "↩",
|
|
691
|
+
unlimited: "∞",
|
|
692
|
+
restartSignal: "→",
|
|
693
|
+
origin: "◆",
|
|
694
|
+
restartPendingSignal: "↻",
|
|
695
|
+
pinSignal: "★",
|
|
696
|
+
userSafe: ">",
|
|
697
|
+
assistantSafe: "*",
|
|
698
|
+
toolSafe: "-",
|
|
699
|
+
errorSafe: "x",
|
|
700
|
+
systemSafe: ".",
|
|
701
|
+
tipAboveSafe: "^",
|
|
702
|
+
tipBelowSafe: "v",
|
|
703
|
+
separatorSafe: "-",
|
|
704
|
+
currentSafe: "*",
|
|
705
|
+
pointerSafe: ">",
|
|
706
|
+
arrowUpSafe: "^",
|
|
707
|
+
arrowDownSafe: "v",
|
|
708
|
+
requestingSafe: "^",
|
|
709
|
+
respondingSafe: "v",
|
|
710
|
+
arrowLeftSafe: "<",
|
|
711
|
+
arrowRightSafe: ">",
|
|
712
|
+
triangleLeftSafe: "<",
|
|
713
|
+
triangleRightSafe: ">",
|
|
714
|
+
blockFullSafe: "#",
|
|
715
|
+
trackVerticalSafe: "|",
|
|
716
|
+
trackHorizontalSafe: "-",
|
|
717
|
+
bulletSafe: "*",
|
|
718
|
+
hrSafe: "-",
|
|
719
|
+
dashSafe: "-",
|
|
720
|
+
radioOnSafe: "(x)",
|
|
721
|
+
radioOffSafe: "( )",
|
|
722
|
+
radioSquareOnSafe: "[x]",
|
|
723
|
+
radioSquareOffSafe: "[ ]",
|
|
724
|
+
radioSquarePartialSafe: "[-]",
|
|
725
|
+
todoCheckedSafe: "v",
|
|
726
|
+
todoUncheckedSafe: "o",
|
|
727
|
+
todoPendingSafe: "o",
|
|
728
|
+
todoActiveSafe: ">",
|
|
729
|
+
todoDoneSafe: "v",
|
|
730
|
+
todoFailedSafe: "x",
|
|
731
|
+
blockedSafe: "!",
|
|
732
|
+
replyBulletSafe: "*",
|
|
733
|
+
toolResultSafe: "-",
|
|
734
|
+
quoteBarSafe: "|",
|
|
735
|
+
serviceSignalSafe: ">",
|
|
736
|
+
notificationSignalSafe: "*",
|
|
737
|
+
editedSignalSafe: "~",
|
|
738
|
+
taskSignalSafe: ">",
|
|
739
|
+
subagentSignalSafe: "#",
|
|
740
|
+
memorySignalSafe: "m",
|
|
741
|
+
sessionSignalSafe: "=",
|
|
742
|
+
pendingSignalSafe: "+",
|
|
743
|
+
clipboardSignalSafe: "v",
|
|
744
|
+
queueSignalSafe: ":",
|
|
745
|
+
heldSignalSafe: "@",
|
|
746
|
+
historySignalSafe: "h",
|
|
747
|
+
scheduleSignalSafe: "t",
|
|
748
|
+
draftSignalSafe: "w",
|
|
749
|
+
compactSignalSafe: "=",
|
|
750
|
+
pruneSignalSafe: "x",
|
|
751
|
+
withdrawSignalSafe: "<",
|
|
752
|
+
unlimitedSafe: "inf",
|
|
753
|
+
restartSignalSafe: ">",
|
|
754
|
+
originSafe: "#",
|
|
755
|
+
restartPendingSignalSafe: "R",
|
|
756
|
+
pinSignalSafe: "p"
|
|
757
|
+
};
|
|
758
|
+
const STOP_REASON_FIGURE_NAMES = {
|
|
759
|
+
completed: "todoDone",
|
|
760
|
+
partial: "todoActive",
|
|
761
|
+
interrupted: "todoPending",
|
|
762
|
+
error: "todoFailed"
|
|
763
|
+
};
|
|
764
|
+
const SAFE_FIGURES = {
|
|
765
|
+
user: ICON_GLYPHS.userSafe,
|
|
766
|
+
assistant: ICON_GLYPHS.assistantSafe,
|
|
767
|
+
tool: ICON_GLYPHS.toolSafe,
|
|
768
|
+
error: ICON_GLYPHS.errorSafe,
|
|
769
|
+
system: ICON_GLYPHS.systemSafe,
|
|
770
|
+
tipAbove: ICON_GLYPHS.tipAboveSafe,
|
|
771
|
+
tipBelow: ICON_GLYPHS.tipBelowSafe,
|
|
772
|
+
separator: ICON_GLYPHS.separatorSafe,
|
|
773
|
+
current: ICON_GLYPHS.currentSafe,
|
|
774
|
+
pointer: ICON_GLYPHS.pointerSafe,
|
|
775
|
+
arrowUp: ICON_GLYPHS.arrowUpSafe,
|
|
776
|
+
arrowDown: ICON_GLYPHS.arrowDownSafe,
|
|
777
|
+
requesting: ICON_GLYPHS.requestingSafe,
|
|
778
|
+
responding: ICON_GLYPHS.respondingSafe,
|
|
779
|
+
arrowLeft: ICON_GLYPHS.arrowLeftSafe,
|
|
780
|
+
arrowRight: ICON_GLYPHS.arrowRightSafe,
|
|
781
|
+
triangleLeft: ICON_GLYPHS.triangleLeftSafe,
|
|
782
|
+
triangleRight: ICON_GLYPHS.triangleRightSafe,
|
|
783
|
+
blockFull: ICON_GLYPHS.blockFullSafe,
|
|
784
|
+
trackVertical: ICON_GLYPHS.trackVerticalSafe,
|
|
785
|
+
trackHorizontal: ICON_GLYPHS.trackHorizontalSafe,
|
|
786
|
+
bullet: ICON_GLYPHS.bulletSafe,
|
|
787
|
+
hr: ICON_GLYPHS.hrSafe,
|
|
788
|
+
dash: ICON_GLYPHS.dashSafe,
|
|
789
|
+
radioOn: ICON_GLYPHS.radioOnSafe,
|
|
790
|
+
radioOff: ICON_GLYPHS.radioOffSafe,
|
|
791
|
+
radioSquareOn: ICON_GLYPHS.radioSquareOnSafe,
|
|
792
|
+
radioSquareOff: ICON_GLYPHS.radioSquareOffSafe,
|
|
793
|
+
radioSquarePartial: ICON_GLYPHS.radioSquarePartialSafe,
|
|
794
|
+
todoChecked: ICON_GLYPHS.todoCheckedSafe,
|
|
795
|
+
todoUnchecked: ICON_GLYPHS.todoUncheckedSafe,
|
|
796
|
+
todoPending: ICON_GLYPHS.todoPendingSafe,
|
|
797
|
+
todoActive: ICON_GLYPHS.todoActiveSafe,
|
|
798
|
+
todoDone: ICON_GLYPHS.todoDoneSafe,
|
|
799
|
+
todoFailed: ICON_GLYPHS.todoFailedSafe,
|
|
800
|
+
blocked: ICON_GLYPHS.blockedSafe,
|
|
801
|
+
replyBullet: ICON_GLYPHS.replyBulletSafe,
|
|
802
|
+
toolResult: ICON_GLYPHS.toolResultSafe,
|
|
803
|
+
quoteBar: ICON_GLYPHS.quoteBarSafe,
|
|
804
|
+
serviceSignal: ICON_GLYPHS.serviceSignalSafe,
|
|
805
|
+
notificationSignal: ICON_GLYPHS.notificationSignalSafe,
|
|
806
|
+
editedSignal: ICON_GLYPHS.editedSignalSafe,
|
|
807
|
+
taskSignal: ICON_GLYPHS.taskSignalSafe,
|
|
808
|
+
subagentSignal: ICON_GLYPHS.subagentSignalSafe,
|
|
809
|
+
memorySignal: ICON_GLYPHS.memorySignalSafe,
|
|
810
|
+
sessionSignal: ICON_GLYPHS.sessionSignalSafe,
|
|
811
|
+
pendingSignal: ICON_GLYPHS.pendingSignalSafe,
|
|
812
|
+
clipboardSignal: ICON_GLYPHS.clipboardSignalSafe,
|
|
813
|
+
queueSignal: ICON_GLYPHS.queueSignalSafe,
|
|
814
|
+
heldSignal: ICON_GLYPHS.heldSignalSafe,
|
|
815
|
+
historySignal: ICON_GLYPHS.historySignalSafe,
|
|
816
|
+
scheduleSignal: ICON_GLYPHS.scheduleSignalSafe,
|
|
817
|
+
draftSignal: ICON_GLYPHS.draftSignalSafe,
|
|
818
|
+
compactSignal: ICON_GLYPHS.compactSignalSafe,
|
|
819
|
+
pruneSignal: ICON_GLYPHS.pruneSignalSafe,
|
|
820
|
+
withdrawSignal: ICON_GLYPHS.withdrawSignalSafe,
|
|
821
|
+
unlimited: ICON_GLYPHS.unlimitedSafe,
|
|
822
|
+
origin: ICON_GLYPHS.originSafe,
|
|
823
|
+
restartSignal: ICON_GLYPHS.restartSignalSafe,
|
|
824
|
+
restartPendingSignal: ICON_GLYPHS.restartPendingSignalSafe,
|
|
825
|
+
pinSignal: ICON_GLYPHS.pinSignalSafe
|
|
826
|
+
};
|
|
827
|
+
const PRETTY_FIGURES = {
|
|
828
|
+
user: ICON_GLYPHS.user,
|
|
829
|
+
assistant: ICON_GLYPHS.assistant,
|
|
830
|
+
tool: ICON_GLYPHS.tool,
|
|
831
|
+
error: ICON_GLYPHS.error,
|
|
832
|
+
system: ICON_GLYPHS.system,
|
|
833
|
+
tipAbove: ICON_GLYPHS.tipAbove,
|
|
834
|
+
tipBelow: ICON_GLYPHS.tipBelow,
|
|
835
|
+
separator: ICON_GLYPHS.separator,
|
|
836
|
+
current: ICON_GLYPHS.current,
|
|
837
|
+
pointer: ICON_GLYPHS.pointer,
|
|
838
|
+
arrowUp: ICON_GLYPHS.arrowUp,
|
|
839
|
+
arrowDown: ICON_GLYPHS.arrowDown,
|
|
840
|
+
requesting: ICON_GLYPHS.requesting,
|
|
841
|
+
responding: ICON_GLYPHS.responding,
|
|
842
|
+
arrowLeft: ICON_GLYPHS.arrowLeft,
|
|
843
|
+
arrowRight: ICON_GLYPHS.arrowRight,
|
|
844
|
+
triangleLeft: ICON_GLYPHS.triangleLeft,
|
|
845
|
+
triangleRight: ICON_GLYPHS.triangleRight,
|
|
846
|
+
blockFull: ICON_GLYPHS.blockFull,
|
|
847
|
+
trackVertical: ICON_GLYPHS.trackVertical,
|
|
848
|
+
trackHorizontal: ICON_GLYPHS.trackHorizontal,
|
|
849
|
+
bullet: ICON_GLYPHS.bullet,
|
|
850
|
+
hr: ICON_GLYPHS.hr,
|
|
851
|
+
dash: ICON_GLYPHS.dash,
|
|
852
|
+
radioOn: ICON_GLYPHS.radioOn,
|
|
853
|
+
radioOff: ICON_GLYPHS.radioOff,
|
|
854
|
+
radioSquareOn: ICON_GLYPHS.radioSquareOn,
|
|
855
|
+
radioSquareOff: ICON_GLYPHS.radioSquareOff,
|
|
856
|
+
radioSquarePartial: ICON_GLYPHS.radioSquarePartial,
|
|
857
|
+
todoChecked: ICON_GLYPHS.todoChecked,
|
|
858
|
+
todoUnchecked: ICON_GLYPHS.todoUnchecked,
|
|
859
|
+
todoPending: ICON_GLYPHS.todoPending,
|
|
860
|
+
todoActive: ICON_GLYPHS.todoActive,
|
|
861
|
+
todoDone: ICON_GLYPHS.todoDone,
|
|
862
|
+
todoFailed: ICON_GLYPHS.todoFailed,
|
|
863
|
+
blocked: ICON_GLYPHS.blocked,
|
|
864
|
+
replyBullet: ICON_GLYPHS.replyBullet,
|
|
865
|
+
toolResult: ICON_GLYPHS.toolResult,
|
|
866
|
+
quoteBar: ICON_GLYPHS.quoteBar,
|
|
867
|
+
serviceSignal: ICON_GLYPHS.serviceSignal,
|
|
868
|
+
notificationSignal: ICON_GLYPHS.notificationSignal,
|
|
869
|
+
editedSignal: ICON_GLYPHS.editedSignal,
|
|
870
|
+
taskSignal: ICON_GLYPHS.taskSignal,
|
|
871
|
+
subagentSignal: ICON_GLYPHS.subagentSignal,
|
|
872
|
+
memorySignal: ICON_GLYPHS.memorySignal,
|
|
873
|
+
sessionSignal: ICON_GLYPHS.sessionSignal,
|
|
874
|
+
pendingSignal: ICON_GLYPHS.pendingSignal,
|
|
875
|
+
clipboardSignal: ICON_GLYPHS.clipboardSignal,
|
|
876
|
+
queueSignal: ICON_GLYPHS.queueSignal,
|
|
877
|
+
heldSignal: ICON_GLYPHS.heldSignal,
|
|
878
|
+
historySignal: ICON_GLYPHS.historySignal,
|
|
879
|
+
scheduleSignal: ICON_GLYPHS.scheduleSignal,
|
|
880
|
+
draftSignal: ICON_GLYPHS.draftSignal,
|
|
881
|
+
compactSignal: ICON_GLYPHS.compactSignal,
|
|
882
|
+
pruneSignal: ICON_GLYPHS.pruneSignal,
|
|
883
|
+
withdrawSignal: ICON_GLYPHS.withdrawSignal,
|
|
884
|
+
unlimited: ICON_GLYPHS.unlimited,
|
|
885
|
+
origin: ICON_GLYPHS.origin,
|
|
886
|
+
restartSignal: ICON_GLYPHS.restartSignal,
|
|
887
|
+
restartPendingSignal: ICON_GLYPHS.restartPendingSignal,
|
|
888
|
+
pinSignal: ICON_GLYPHS.pinSignal
|
|
889
|
+
};
|
|
890
|
+
function detectCJKCtype(env = process.env) {
|
|
891
|
+
const lower = (env.LC_ALL ?? env.LC_CTYPE ?? env.LANG ?? "").toLowerCase();
|
|
892
|
+
return { isCJK: /(^|_)(zh|ja|ko)(\.|_|$)/.test(lower) };
|
|
893
|
+
}
|
|
894
|
+
function resolveFigures(environment = {}) {
|
|
895
|
+
return environment.cjkAmbiguousWide ?? detectCJKCtype().isCJK ? SAFE_FIGURES : PRETTY_FIGURES;
|
|
896
|
+
}
|
|
897
|
+
function pointerGap(figures = resolveFigures()) {
|
|
898
|
+
return figures.pointer.length + 1;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
//#endregion
|
|
902
|
+
//#region src/libs/render/tag.ts
|
|
903
|
+
function tagText(label) {
|
|
904
|
+
return `#${label}#`;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
//#endregion
|
|
908
|
+
//#region src/components/primitives/Select/select-rows.ts
|
|
909
|
+
function labelText(option, index, numbered) {
|
|
910
|
+
const name = option.segments === void 0 ? option.name : option.segments.map((segment) => segment.text).join("");
|
|
911
|
+
return `${numbered ? `${index + 1}. ` : ""}${name}`;
|
|
912
|
+
}
|
|
913
|
+
function detailHintText() {
|
|
914
|
+
return " [v]";
|
|
915
|
+
}
|
|
916
|
+
function optionTailParts(option) {
|
|
917
|
+
const parts = [];
|
|
918
|
+
if (option.statusTag !== void 0) parts.push(` ${tagText(option.statusTag.label)}`);
|
|
919
|
+
if (option.tags !== void 0) parts.push(...option.tags.map((tag) => ` ${tagText(tag.label)}`));
|
|
920
|
+
if (option.disabled === true) parts.push(" (unavailable)");
|
|
921
|
+
if (option.description !== void 0) parts.push(` ${option.description}`);
|
|
922
|
+
if (option.trailingLabel !== void 0) parts.push(` ${option.trailingLabel}`);
|
|
923
|
+
if (option.detailHint === true) parts.push(detailHintText());
|
|
924
|
+
return parts;
|
|
925
|
+
}
|
|
926
|
+
function optionTail(option) {
|
|
927
|
+
return optionTailParts(option).join("");
|
|
928
|
+
}
|
|
929
|
+
function optionTailWidth(option) {
|
|
930
|
+
return optionTailParts(option).reduce((sum, part) => sum + stringWidth$1(part), 0);
|
|
931
|
+
}
|
|
932
|
+
function selectOptionText(option, index, numbered, labelAlignWidth) {
|
|
933
|
+
const marker = " ".repeat(pointerGap(resolveFigures()));
|
|
934
|
+
const label = labelText(option, index, numbered);
|
|
935
|
+
return `${marker}${labelAlignWidth === void 0 ? label : padEndWidth(label, labelAlignWidth)}${optionTail(option)}`;
|
|
936
|
+
}
|
|
937
|
+
function optionWrapRows(option, index, numbered, innerColumns, labelAlignWidth) {
|
|
938
|
+
const text = selectOptionText(option, index, numbered, labelAlignWidth);
|
|
939
|
+
return Math.max(1, wrapProse(text, Math.max(1, innerColumns)).length);
|
|
940
|
+
}
|
|
941
|
+
function resolveOptionGapRows(optionGapRows) {
|
|
942
|
+
if (optionGapRows === void 0 || !Number.isFinite(optionGapRows)) return 0;
|
|
943
|
+
return Math.max(0, Math.floor(optionGapRows));
|
|
944
|
+
}
|
|
945
|
+
function selectGapRows(itemCount, optionGapRows) {
|
|
946
|
+
return Math.max(0, itemCount - 1) * resolveOptionGapRows(optionGapRows);
|
|
947
|
+
}
|
|
948
|
+
function selectRows(options, innerColumns, { numbered = false, labelAlignWidth, optionGapRows } = {}) {
|
|
949
|
+
return options.reduce((sum, option, index) => sum + optionWrapRows(option, index, numbered, innerColumns, labelAlignWidth) + (option.continuation?.length ?? 0), 0) + selectGapRows(options.length, optionGapRows);
|
|
950
|
+
}
|
|
951
|
+
function resolveLabelAlignWidth(options, numbered, innerColumns) {
|
|
952
|
+
const width = Math.max(1, innerColumns);
|
|
953
|
+
if (options.length < 2) return void 0;
|
|
954
|
+
if (!options.some((option) => option.statusTag !== void 0 || (option.tags?.length ?? 0) > 0 || option.description !== void 0 || option.trailingLabel !== void 0)) return void 0;
|
|
955
|
+
const target = Math.max(...options.map((option, index) => stringWidth$1(labelText(option, index, numbered))));
|
|
956
|
+
return options.every((option, index) => {
|
|
957
|
+
const raw = selectOptionText(option, index, numbered);
|
|
958
|
+
return stringWidth$1(selectOptionText(option, index, numbered, target)) <= width || stringWidth$1(raw) > width;
|
|
959
|
+
}) ? target : void 0;
|
|
960
|
+
}
|
|
961
|
+
function selectBodyRows({ options, height, innerColumns, numbered = false, alignTrailing = false, optionGapRows, groupGapRows = 0 }) {
|
|
962
|
+
if (options.length === 0) return 1;
|
|
963
|
+
const labelAlignWidth = alignTrailing === true ? resolveLabelAlignWidth(options, numbered, innerColumns) : void 0;
|
|
964
|
+
const headerCount = options.some((option) => option.group !== void 0) ? new Set(options.map((option) => option.group ?? "")).size : 0;
|
|
965
|
+
const groupRows = headerCount + (headerCount > 1 ? (headerCount - 1) * groupGapRows : 0);
|
|
966
|
+
const total = selectRows(options, innerColumns, {
|
|
967
|
+
numbered,
|
|
968
|
+
optionGapRows,
|
|
969
|
+
...labelAlignWidth === void 0 ? {} : { labelAlignWidth }
|
|
970
|
+
}) + groupRows;
|
|
971
|
+
return height === void 0 || height <= 0 ? total : Math.min(total, height);
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
//#endregion
|
|
975
|
+
export { deleteForwardRange as A, snapCursorToGrapheme as B, parseChipToken as C, colToGraphemeIndex as D, clampViewportOffset as E, padEndWidth as F, truncateByDisplayWidth as H, padStartWidth as I, previousGraphemeBoundary as L, graphemeSegmentsOf as M, indexToCol as N, colToIndex as O, nextGraphemeBoundary as P, sliceGraphemesByColumns as R, normalizeInputText as S, alignOffsetToCharBoundary as T, truncateMiddleByWidth as U, stringWidth$1 as V, inputVisualModelOf as _, resolveOptionGapRows as a, lineColumnAt as b, tagText as c, pointerGap as d, resolveFigures as f, inputLineVisualRows as g, wrapLine as h, resolveLabelAlignWidth as i, findAtomAt as j, deleteBackwardRange as k, ICON_GLYPHS as l, wrapProse as m, optionTailWidth as n, selectBodyRows as o, wrapColumns as p, optionWrapRows as r, selectRows as s, detailHintText as t, STOP_REASON_FIGURE_NAMES as u, inputVisualRowsOf as v, scanChipRanges as w, normalizeInputPrefix as x, resolveInputWrap as y, snapCursorToAtom as z };
|