@hit-sudomaker/ccw 0.4.0 → 0.4.1
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 +1 -1
- package/dist/ccline.js +31 -30
- package/dist/ccw.js +37 -33
- package/dist/claude-config.js +3 -1
- package/dist/cleanup.js +21 -5
- package/dist/collect.js +147 -0
- package/dist/errors.js +3 -2
- package/dist/legacy-amirc.js +3 -3
- package/dist/machine.js +4 -2
- package/dist/main.js +18 -7
- package/dist/management-catalog.js +7 -1
- package/dist/mcp.js +124 -106
- package/dist/model.js +13 -0
- package/dist/npm-registry.js +4 -0
- package/dist/officecli.js +23 -16
- package/dist/plugins.js +47 -22
- package/dist/program-channels.js +55 -46
- package/dist/programs.js +164 -145
- package/dist/read-machine.js +5 -10
- package/dist/render.js +96 -41
- package/dist/run-presentation.js +9 -7
- package/dist/skill-files.js +31 -10
- package/dist/skills.js +53 -31
- package/dist/storage.js +44 -0
- package/dist/terminal-view.js +97 -36
- package/dist/terminal.js +86 -45
- package/dist/titles.js +10 -7
- package/package.json +1 -1
package/dist/terminal-view.js
CHANGED
|
@@ -4,15 +4,50 @@ import { Box, Text, render, useAnimation, useApp, useInput, usePaste, useWindowS
|
|
|
4
4
|
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import stringWidth from 'string-width';
|
|
6
6
|
import wrapAnsi from 'wrap-ansi';
|
|
7
|
-
import { BRAND, HOME_TITLE, safeText } from './render.js';
|
|
7
|
+
import { BACK_TO_HOME, BANNER_WIDTH, BRAND, GROUP_MARK, HOME_TITLE, platformSummary, PROBLEM_MARK, safeText, } from './render.js';
|
|
8
|
+
import { statusLine } from './run-presentation.js';
|
|
8
9
|
const ACCENT = '#D97757';
|
|
10
|
+
/** 选中行与未选中行的前缀对(等宽) */
|
|
11
|
+
const CURSOR_PREFIX = '› ';
|
|
12
|
+
const BLANK_PREFIX = ' ';
|
|
13
|
+
/** 滚动窗口夹取:请求起点不越出 [0, total - visible] */
|
|
14
|
+
const clampWindow = (requested, visible, total) => Math.min(Math.max(0, total - visible), Math.max(0, requested));
|
|
15
|
+
/** 居中滚动窗口起点:活动行居中后夹取 */
|
|
16
|
+
const windowStart = (active, height, total) => clampWindow(active - Math.floor(height / 2), height, total);
|
|
17
|
+
/** 窗口指示器:显示范围内的行区间 */
|
|
18
|
+
const windowIndicator = (start, visible, total) => `${start + 1}–${Math.min(start + visible, total)}/${total}`;
|
|
19
|
+
/** 窄屏回退时详情行的缩进:wrap 宽度与 marginLeft 必须取同一值 */
|
|
20
|
+
const detailIndent = (width) => (width < 24 ? 2 : 12);
|
|
9
21
|
function isExit({ input, key }) {
|
|
10
22
|
return key.ctrl && input === 'c';
|
|
11
23
|
}
|
|
24
|
+
/** 输入法组合/提交的自由文本:不匹配任何快捷键,也非命名控制键 */
|
|
25
|
+
export function isIgnoredText(input, key) {
|
|
26
|
+
return (input.length > 0 &&
|
|
27
|
+
!key.escape &&
|
|
28
|
+
!key.return &&
|
|
29
|
+
!key.tab &&
|
|
30
|
+
!key.backspace &&
|
|
31
|
+
!key.delete &&
|
|
32
|
+
!key.upArrow &&
|
|
33
|
+
!key.downArrow &&
|
|
34
|
+
!key.leftArrow &&
|
|
35
|
+
!key.rightArrow &&
|
|
36
|
+
!key.pageUp &&
|
|
37
|
+
!key.pageDown &&
|
|
38
|
+
!key.home &&
|
|
39
|
+
!key.end &&
|
|
40
|
+
!key.ctrl &&
|
|
41
|
+
!key.meta);
|
|
42
|
+
}
|
|
43
|
+
/** 归一化捕获的未知异常:保留原 Error 实例,其余包裹为携带 cause 的 Error */
|
|
44
|
+
function asError(error, code) {
|
|
45
|
+
return error instanceof Error ? error : new Error(code, { cause: error });
|
|
46
|
+
}
|
|
12
47
|
function HomeHeader({ size }) {
|
|
13
48
|
const platform = process.platform === 'win32' ? 'Windows' : process.platform === 'darwin' ? 'macOS' : 'Linux';
|
|
14
|
-
const system =
|
|
15
|
-
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: ACCENT, children: '═'.repeat(Math.min(
|
|
49
|
+
const system = platformSummary(platform, os.arch());
|
|
50
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: ACCENT, children: '═'.repeat(Math.min(BANNER_WIDTH, size.columns)) }), size.rows >= 28 && _jsx(Text, { children: " " }), size.rows >= 20 && size.columns >= 30 ? (BRAND.logo.map((line, index) => _jsx(Text, { color: ACCENT, bold: true, children: ` ${line}` }, index))) : (_jsxs(Text, { color: ACCENT, bold: true, children: [' ', "CCW"] })), size.rows >= 28 && _jsx(Text, { children: " " }), _jsxs(Text, { bold: true, wrap: "truncate-end", children: [' ', BRAND.title, " ", _jsx(Text, { dimColor: true, children: BRAND.version })] }), _jsxs(Text, { dimColor: true, children: [" ", BRAND.credit] }), size.rows >= 24 ? (_jsxs(_Fragment, { children: [_jsx(Text, { color: ACCENT, children: '─'.repeat(Math.min(BANNER_WIDTH, size.columns)) }), _jsx(Text, { bold: true, children: " \u5F53\u524D\u73AF\u5883\u72B6\u6001" }), _jsxs(Text, { children: [" 1. \u7CFB\u7EDF ", system] }), _jsxs(Text, { children: [" 2. Node ", process.version] }), _jsxs(Text, { wrap: "truncate-end", children: [" 3. \u4E3B\u76EE\u5F55 ", safeText(os.homedir())] })] })) : (_jsxs(_Fragment, { children: [_jsx(Text, { dimColor: true, children: ` ${system} · Node ${process.version}` }), _jsxs(Text, { dimColor: true, wrap: "truncate-end", children: [' ', safeText(os.homedir())] })] })), _jsx(Text, { color: ACCENT, children: '═'.repeat(Math.min(BANNER_WIDTH, size.columns)) }), _jsx(Text, { bold: true, children: "\u8BF7\u9009\u62E9\uFF1A" })] }));
|
|
16
51
|
}
|
|
17
52
|
function Frame({ title, footer, page = 0, children }) {
|
|
18
53
|
const terminalSize = useWindowSize();
|
|
@@ -27,9 +62,9 @@ function Frame({ title, footer, page = 0, children }) {
|
|
|
27
62
|
? 5 + (size.rows >= 28 ? 2 : 0) + (size.rows >= 20 && size.columns >= 30 ? 6 : 1) + (size.rows >= 24 ? 5 : 2)
|
|
28
63
|
: 3 + detailHeight + (hasPages ? 1 : 0);
|
|
29
64
|
const height = Math.max(1, size.rows - headerHeight - 4);
|
|
30
|
-
return (_jsxs(Box, { flexDirection: "column", width: size.columns, height: size.rows - 1, children: [isHome ? (_jsx(HomeHeader, { size: size })) : (_jsxs(_Fragment, { children: [_jsx(Box, { borderStyle: "double", borderColor: ACCENT, width: Math.min(
|
|
65
|
+
return (_jsxs(Box, { flexDirection: "column", width: size.columns, height: size.rows - 1, children: [isHome ? (_jsx(HomeHeader, { size: size })) : (_jsxs(_Fragment, { children: [_jsx(Box, { borderStyle: "double", borderColor: ACCENT, width: Math.min(BANNER_WIDTH, size.columns), paddingX: 1, flexShrink: 0, children: _jsxs(Text, { bold: true, color: ACCENT, wrap: "truncate-end", children: ["CCW \u00B7 ", name] }) }), details.slice(offset, offset + detailHeight).map((line, index) => (_jsx(Text, { children: line }, index))), hasPages && _jsxs(Text, { dimColor: true, children: ["PgUp/PgDn \u00B7 ", windowIndicator(offset, detailHeight, details.length)] })] })), _jsx(Box, { flexDirection: "column", height: height, marginTop: 1, flexShrink: 0, children: children(height, size.columns) }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, wrap: "truncate-end", children: footer }) })] }));
|
|
31
66
|
}
|
|
32
|
-
function Menu({ title, choices, focus, selection, change, interrupt, done }) {
|
|
67
|
+
function Menu({ title, choices, focus, selection, change, interrupt, done, invalidate }) {
|
|
33
68
|
const initialCount = selection ? selection.rows.length + 2 : choices.length;
|
|
34
69
|
const live = useRef({
|
|
35
70
|
index: Math.max(0, Math.min(focus, initialCount - 1)),
|
|
@@ -47,9 +82,10 @@ function Menu({ title, choices, focus, selection, change, interrupt, done }) {
|
|
|
47
82
|
const row = current?.rows[prior.index];
|
|
48
83
|
const count = current ? current.rows.length + 2 : choices.length;
|
|
49
84
|
const toggle = () => (change ? { ...prior, selection: change({ kind: 'toggle', index: prior.index }) } : prior);
|
|
50
|
-
|
|
85
|
+
const exit = isExit(event);
|
|
86
|
+
if (exit)
|
|
51
87
|
interrupt();
|
|
52
|
-
if (key.escape ||
|
|
88
|
+
if (key.escape || exit)
|
|
53
89
|
next = { ...prior, result: { kind: 'cancel', index: prior.index } };
|
|
54
90
|
else if (key.upArrow || key.downArrow)
|
|
55
91
|
next = { ...prior, index: (prior.index + count + (key.upArrow ? -1 : 1)) % count };
|
|
@@ -72,6 +108,11 @@ function Menu({ title, choices, focus, selection, change, interrupt, done }) {
|
|
|
72
108
|
next = { ...prior, selection: change({ kind: 'all' }) };
|
|
73
109
|
else if (row && input === ' ')
|
|
74
110
|
next = toggle();
|
|
111
|
+
// isIgnoredText 判定为组合回显:清屏强制重绘(机制见 invalidate)
|
|
112
|
+
if (next === prior && isIgnoredText(input, key)) {
|
|
113
|
+
invalidate?.();
|
|
114
|
+
next = { ...prior };
|
|
115
|
+
}
|
|
75
116
|
if (next.selection && !next.result)
|
|
76
117
|
next = { ...next, index: Math.min(next.index, next.selection.rows.length + 1) };
|
|
77
118
|
live.current = next;
|
|
@@ -99,7 +140,7 @@ function Menu({ title, choices, focus, selection, change, interrupt, done }) {
|
|
|
99
140
|
});
|
|
100
141
|
}
|
|
101
142
|
if (state.selection)
|
|
102
|
-
result.push({ label: state.selection.submitLabel, detail: '', index: labels.length, labelWidth: 0 }, { label:
|
|
143
|
+
result.push({ label: state.selection.submitLabel, detail: '', index: labels.length, labelWidth: 0 }, { label: BACK_TO_HOME, detail: '', index: labels.length + 1, labelWidth: 0 });
|
|
103
144
|
return result;
|
|
104
145
|
}, [choices, state.selection]);
|
|
105
146
|
const currentRow = state.selection?.rows[state.index];
|
|
@@ -117,15 +158,15 @@ function Menu({ title, choices, focus, selection, change, interrupt, done }) {
|
|
|
117
158
|
: '↑↓ 移动 · Enter 选择 · Esc 返回';
|
|
118
159
|
return (_jsx(Frame, { title: state.selection?.title ?? title, page: state.page, footer: footer, children: (height, width) => {
|
|
119
160
|
const activeRow = Math.max(0, rows.findIndex(row => row.index === state.index));
|
|
120
|
-
const start =
|
|
161
|
+
const start = windowStart(activeRow, height, rows.length);
|
|
121
162
|
return rows.slice(start, start + height).map((row, position) => {
|
|
122
163
|
if (row.index === null) {
|
|
123
|
-
const label = `
|
|
124
|
-
return (_jsxs(Text, { color: ACCENT, dimColor: true, wrap: "truncate-end", children: [label, '─'.repeat(Math.max(0, Math.min(
|
|
164
|
+
const label = ` ${GROUP_MARK}${safeText(row.label)} `;
|
|
165
|
+
return (_jsxs(Text, { color: ACCENT, dimColor: true, wrap: "truncate-end", children: [label, '─'.repeat(Math.max(0, Math.min(BANNER_WIDTH, width) - stringWidth(label)))] }, `heading-${start + position}`));
|
|
125
166
|
}
|
|
126
167
|
const active = row.index === state.index;
|
|
127
168
|
const selectedRow = state.selection?.rows[row.index];
|
|
128
|
-
const prefix = `${active ?
|
|
169
|
+
const prefix = `${active ? CURSOR_PREFIX : BLANK_PREFIX}${selectedRow ? (selectedRow.checked ? '[x] ' : '[ ] ') : ''}`;
|
|
129
170
|
return (_jsxs(Box, { flexShrink: 0, children: [_jsx(Text, { ...(active ? { color: ACCENT } : {}), bold: active, children: prefix }), _jsx(Box, { width: row.detail ? Math.min(row.labelWidth + 2, Math.max(10, width - 24)) : width - stringWidth(prefix), flexShrink: 0, children: _jsx(Text, { ...(active ? { color: ACCENT } : {}), bold: active, wrap: "truncate-end", children: safeText(row.label).replaceAll('\n', ' ') }) }), row.detail && (_jsx(Text, { ...(active ? { color: ACCENT } : {}), dimColor: !active, wrap: "truncate-end", children: safeText(row.detail) }))] }, row.index));
|
|
130
171
|
});
|
|
131
172
|
} }));
|
|
@@ -156,10 +197,13 @@ function editText(prior, event) {
|
|
|
156
197
|
cursor: prior.cursor + added.length,
|
|
157
198
|
};
|
|
158
199
|
}
|
|
159
|
-
function InlineForm({ title, fields, validate, interrupt, done, }) {
|
|
200
|
+
function InlineForm({ title, fields, validate, interrupt, done, invalidate, }) {
|
|
160
201
|
const live = useRef({
|
|
161
202
|
index: 0,
|
|
162
|
-
edits: fields.map(field =>
|
|
203
|
+
edits: fields.map(field => {
|
|
204
|
+
const chars = characters(field.value);
|
|
205
|
+
return { text: chars, cursor: chars.length };
|
|
206
|
+
}),
|
|
163
207
|
problem: null,
|
|
164
208
|
details: false,
|
|
165
209
|
page: 0,
|
|
@@ -231,21 +275,26 @@ function InlineForm({ title, fields, validate, interrupt, done, }) {
|
|
|
231
275
|
edits: prior.edits.map((edit, index) => (index === prior.index ? editText(edit, event) : edit)),
|
|
232
276
|
};
|
|
233
277
|
}
|
|
278
|
+
// 未处理按键(含组合回显)强制重绘,机制见 createTerminal.invalidate
|
|
279
|
+
if (next === prior && 'key' in event && isIgnoredText(event.input, event.key)) {
|
|
280
|
+
invalidate?.();
|
|
281
|
+
next = { ...prior };
|
|
282
|
+
}
|
|
234
283
|
live.current = next;
|
|
235
284
|
setState(next);
|
|
236
285
|
};
|
|
237
286
|
useInput((input, key) => dispatch({ input, key }));
|
|
238
287
|
usePaste(paste => dispatch({ paste }));
|
|
239
288
|
if (state.details)
|
|
240
|
-
return (_jsx(Frame, { title: `填写说明\n${state.problem?.detail ?? ''}`, page: state.page, footer: "PgUp/PgDn \u7FFB\u9875 \u00B7 Enter/Esc \u8FD4\u56DE", children: () =>
|
|
241
|
-
return (_jsx(Frame, { title: `${title}${state.problem ? `\n
|
|
289
|
+
return (_jsx(Frame, { title: `填写说明\n${state.problem?.detail ?? ''}`, page: state.page, footer: "PgUp/PgDn \u7FFB\u9875 \u00B7 Enter/Esc \u8FD4\u56DE", children: () => _jsxs(Text, { color: ACCENT, children: [CURSOR_PREFIX, "\u8FD4\u56DE\u7F16\u8F91"] }) }));
|
|
290
|
+
return (_jsx(Frame, { title: `${title}${state.problem ? `\n${PROBLEM_MARK}${state.problem.message}` : ''}`, footer: state.index < fields.length ? '输入/粘贴 · ↑↓/Tab 切换 · Esc 取消' : '↑↓ 选择 · Enter 确认 · Esc 取消', children: (height, width) => {
|
|
242
291
|
const labels = [
|
|
243
292
|
...fields.map(field => field.label),
|
|
244
293
|
'保存配置',
|
|
245
294
|
'返回',
|
|
246
295
|
...(state.problem?.detail ? ['查看详情'] : []),
|
|
247
296
|
];
|
|
248
|
-
const start =
|
|
297
|
+
const start = windowStart(state.index, height, labels.length);
|
|
249
298
|
return labels.slice(start, start + height).map((label, offset) => {
|
|
250
299
|
const index = start + offset;
|
|
251
300
|
const active = index === state.index;
|
|
@@ -262,16 +311,17 @@ function InlineForm({ title, fields, validate, interrupt, done, }) {
|
|
|
262
311
|
.split('\n')
|
|
263
312
|
.at(-1) ?? ''}▏${after || (!value ? (field?.placeholder ?? '') : '')}`;
|
|
264
313
|
}
|
|
265
|
-
return (_jsxs(Text, { ...(active ? { color: ACCENT } : {}), wrap: "truncate-end", children: [active ?
|
|
314
|
+
return (_jsxs(Text, { ...(active ? { color: ACCENT } : {}), wrap: "truncate-end", children: [active ? CURSOR_PREFIX : BLANK_PREFIX, label.padEnd(15), safeText(display)] }, fields[index]?.key ?? label));
|
|
266
315
|
});
|
|
267
316
|
} }));
|
|
268
317
|
}
|
|
269
318
|
function Waiting({ title, message = '检查环境', cancel, interrupt, }) {
|
|
270
319
|
const { frame } = useAnimation({ interval: 120 });
|
|
271
320
|
useInput((input, key) => {
|
|
272
|
-
|
|
321
|
+
const exit = isExit({ input, key });
|
|
322
|
+
if (key.escape || exit) {
|
|
273
323
|
cancel();
|
|
274
|
-
if (
|
|
324
|
+
if (exit)
|
|
275
325
|
interrupt();
|
|
276
326
|
}
|
|
277
327
|
});
|
|
@@ -297,13 +347,13 @@ function StatusRow({ row, text }) {
|
|
|
297
347
|
}
|
|
298
348
|
function DetailRow({ detail, width }) {
|
|
299
349
|
const color = toneColor(detail.tone);
|
|
300
|
-
const indent = width
|
|
350
|
+
const indent = detailIndent(width);
|
|
301
351
|
return (_jsxs(Box, { marginLeft: indent, children: [detail.symbol && (_jsx(Box, { width: 2, flexShrink: 0, children: _jsx(Text, { ...(color ? { color } : {}), dimColor: detail.tone === 'muted', children: detail.symbol }) })), _jsx(Text, { dimColor: detail.tone === 'muted', wrap: "truncate-end", children: safeText(detail.text) })] }));
|
|
302
352
|
}
|
|
303
353
|
function runLines(view, width) {
|
|
304
354
|
return view.rows.flatMap(row => {
|
|
305
355
|
const status = width < 24
|
|
306
|
-
? wrapAnsi(
|
|
356
|
+
? wrapAnsi(statusLine({ ...row, title: safeText(row.title) }), width, { hard: true, trim: false })
|
|
307
357
|
.split('\n')
|
|
308
358
|
.map(text => ({ kind: 'status', row, text }))
|
|
309
359
|
: [{ kind: 'status', row }];
|
|
@@ -311,7 +361,7 @@ function runLines(view, width) {
|
|
|
311
361
|
...status,
|
|
312
362
|
...row.details.flatMap(detail => {
|
|
313
363
|
const { symbol, ...appearance } = detail;
|
|
314
|
-
const indent = width
|
|
364
|
+
const indent = detailIndent(width);
|
|
315
365
|
return wrapAnsi(safeText(detail.text), Math.max(1, width - indent - (symbol ? 2 : 0)), {
|
|
316
366
|
hard: true,
|
|
317
367
|
trim: false,
|
|
@@ -326,9 +376,10 @@ function runLines(view, width) {
|
|
|
326
376
|
];
|
|
327
377
|
});
|
|
328
378
|
}
|
|
329
|
-
function RunScreen({ view, choices = [], focus = 0, cancelIndex = choices.length - 1, interrupt, done, }) {
|
|
379
|
+
function RunScreen({ view, choices = [], focus = 0, cancelIndex = choices.length - 1, interrupt, done, invalidate, }) {
|
|
330
380
|
const [offset, setOffset] = useState(null);
|
|
331
381
|
const [action, setAction] = useState(Math.max(0, Math.min(focus, choices.length - 1)));
|
|
382
|
+
const [, setRepaint] = useState(0);
|
|
332
383
|
const finished = useRef(false);
|
|
333
384
|
const viewport = useRef({ offset: 0, height: 1, total: 1 });
|
|
334
385
|
useInput((input, key) => {
|
|
@@ -353,6 +404,10 @@ function RunScreen({ view, choices = [], focus = 0, cancelIndex = choices.length
|
|
|
353
404
|
setOffset(previous => Math.min(Math.max(0, viewport.current.total - viewport.current.height), (previous ?? viewport.current.offset) + viewport.current.height));
|
|
354
405
|
if (key.end)
|
|
355
406
|
setOffset(null);
|
|
407
|
+
if (isIgnoredText(input, key)) {
|
|
408
|
+
invalidate?.();
|
|
409
|
+
setRepaint(count => count + 1);
|
|
410
|
+
}
|
|
356
411
|
});
|
|
357
412
|
const footer = choices.length
|
|
358
413
|
? '↑↓ 选择 · Enter 确认 · PgUp/PgDn 翻页 · Esc 返回'
|
|
@@ -363,12 +418,13 @@ function RunScreen({ view, choices = [], focus = 0, cancelIndex = choices.length
|
|
|
363
418
|
const available = Math.max(1, height - 1 - actionHeight);
|
|
364
419
|
const visible = Math.max(1, available - (lines.length > available ? 1 : 0));
|
|
365
420
|
const current = Math.max(0, lines.findIndex(line => line.kind === 'status' && line.row.id === view.activeId));
|
|
366
|
-
const automatic = view.phase === 'result' ? 0 :
|
|
367
|
-
const start =
|
|
421
|
+
const automatic = view.phase === 'result' ? 0 : windowStart(current, visible, lines.length);
|
|
422
|
+
const start = clampWindow(offset ?? automatic, visible, lines.length);
|
|
423
|
+
// Ink 同步渲染保证 viewport 每帧恰写一次
|
|
368
424
|
viewport.current = { offset: start, height: visible, total: lines.length };
|
|
369
425
|
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, wrap: "truncate-end", children: safeText(view.summary) }), lines
|
|
370
426
|
.slice(start, start + visible)
|
|
371
|
-
.map((line, index) => line.kind === 'status' ? (_jsx(StatusRow, { row: line.row, ...(line.text !== undefined ? { text: line.text } : {}) }, `${line.row.id}-status-${start + index}`)) : (_jsx(DetailRow, { detail: line.detail, width: width }, `${line.id}-detail-${start + index}`))), lines.length > visible && (
|
|
427
|
+
.map((line, index) => line.kind === 'status' ? (_jsx(StatusRow, { row: line.row, ...(line.text !== undefined ? { text: line.text } : {}) }, `${line.row.id}-status-${start + index}`)) : (_jsx(DetailRow, { detail: line.detail, width: width }, `${line.id}-detail-${start + index}`))), lines.length > visible && _jsx(Text, { dimColor: true, children: windowIndicator(start, visible, lines.length) }), choices.length > 0 && (_jsx(Box, { flexDirection: "column", marginTop: 1, children: choices.map((choice, index) => (_jsxs(Text, { ...(index === action ? { color: ACCENT } : {}), bold: index === action, children: [index === action ? CURSOR_PREFIX : BLANK_PREFIX, safeText(typeof choice === 'string' ? choice : `${choice.label} ${choice.detail ?? ''}`)] }, index))) }))] }));
|
|
372
428
|
} }));
|
|
373
429
|
}
|
|
374
430
|
function Host({ children, ready, }) {
|
|
@@ -396,6 +452,10 @@ export function createTerminal(interrupt = () => { }) {
|
|
|
396
452
|
const ready = (suspend) => {
|
|
397
453
|
suspension = suspend;
|
|
398
454
|
};
|
|
455
|
+
/** 擦除当前帧并重置帧高:下一次渲染将全量重绘,覆盖终端宿主画入的输入法组合回显 */
|
|
456
|
+
const invalidate = () => {
|
|
457
|
+
instance?.clear();
|
|
458
|
+
};
|
|
399
459
|
const display = (view) => {
|
|
400
460
|
if (closed)
|
|
401
461
|
throw new Error('terminal-closed');
|
|
@@ -415,7 +475,7 @@ export function createTerminal(interrupt = () => { }) {
|
|
|
415
475
|
rejectPending?.(new Error('terminal-closed'));
|
|
416
476
|
}, (error) => {
|
|
417
477
|
closed = true;
|
|
418
|
-
rejectPending?.(error
|
|
478
|
+
rejectPending?.(asError(error, 'terminal-failed'));
|
|
419
479
|
});
|
|
420
480
|
}
|
|
421
481
|
};
|
|
@@ -442,21 +502,21 @@ export function createTerminal(interrupt = () => { }) {
|
|
|
442
502
|
display(view(done));
|
|
443
503
|
}
|
|
444
504
|
catch (error) {
|
|
445
|
-
rejectPending(error
|
|
505
|
+
rejectPending(asError(error, 'terminal-failed'));
|
|
446
506
|
}
|
|
447
507
|
});
|
|
448
508
|
};
|
|
449
509
|
return {
|
|
450
510
|
choose(title, choices, focus = 0, cancelIndex = choices.length - 1) {
|
|
451
511
|
return typeof title === 'string'
|
|
452
|
-
? prompt(done => (_jsx(Menu, { title: title, choices: choices, focus: focus, interrupt: interrupt, done: result => done(result.kind === 'cancel' ? cancelIndex : result.index) }, ++sequence)))
|
|
453
|
-
: prompt(done => (_jsx(RunScreen, { view: title, choices: choices, focus: focus, cancelIndex: cancelIndex, interrupt: interrupt, done: done }, ++sequence)));
|
|
512
|
+
? prompt(done => (_jsx(Menu, { title: title, choices: choices, focus: focus, interrupt: interrupt, invalidate: invalidate, done: result => done(result.kind === 'cancel' ? cancelIndex : result.index) }, ++sequence)))
|
|
513
|
+
: prompt(done => (_jsx(RunScreen, { view: title, choices: choices, focus: focus, cancelIndex: cancelIndex, interrupt: interrupt, invalidate: invalidate, done: done }, ++sequence)));
|
|
454
514
|
},
|
|
455
515
|
select(page, change, focus = 0) {
|
|
456
|
-
return prompt(done => (_jsx(Menu, { title: page.title, choices: [], selection: page, change: change, focus: focus, interrupt: interrupt, done: done }, ++sequence)));
|
|
516
|
+
return prompt(done => (_jsx(Menu, { title: page.title, choices: [], selection: page, change: change, focus: focus, interrupt: interrupt, invalidate: invalidate, done: done }, ++sequence)));
|
|
457
517
|
},
|
|
458
518
|
form(title, fields, validate) {
|
|
459
|
-
return prompt(done => (_jsx(InlineForm, { title: title, fields: fields, validate: validate, interrupt: interrupt, done: done }, ++sequence)));
|
|
519
|
+
return prompt(done => (_jsx(InlineForm, { title: title, fields: fields, validate: validate, interrupt: interrupt, invalidate: invalidate, done: done }, ++sequence)));
|
|
460
520
|
},
|
|
461
521
|
async wait(title, work, signal, firstFrame) {
|
|
462
522
|
if (signal?.aborted)
|
|
@@ -481,7 +541,7 @@ export function createTerminal(interrupt = () => { }) {
|
|
|
481
541
|
.then(() => work(reading.signal, update))
|
|
482
542
|
.then(finish, (error) => {
|
|
483
543
|
if (!reading.signal.aborted)
|
|
484
|
-
rejectPending?.(error
|
|
544
|
+
rejectPending?.(asError(error, 'inspection-failed'));
|
|
485
545
|
});
|
|
486
546
|
try {
|
|
487
547
|
return await result;
|
|
@@ -504,8 +564,9 @@ export function createTerminal(interrupt = () => { }) {
|
|
|
504
564
|
finally {
|
|
505
565
|
isSuspended = false;
|
|
506
566
|
await ownership.resume();
|
|
567
|
+
// 交互命令仅限执行屏活动期发起;恢复重放最近执行视图
|
|
507
568
|
if (progressView !== undefined)
|
|
508
|
-
display(_jsx(RunScreen, { view: progressView, interrupt: interrupt }));
|
|
569
|
+
display(_jsx(RunScreen, { view: progressView, interrupt: interrupt, invalidate: invalidate }));
|
|
509
570
|
// 快速任务可能在 readable 监听恢复前结束;重新启动读取但不消费输入
|
|
510
571
|
process.stdin.read(0);
|
|
511
572
|
}
|
|
@@ -513,7 +574,7 @@ export function createTerminal(interrupt = () => { }) {
|
|
|
513
574
|
show(view) {
|
|
514
575
|
progressView = view;
|
|
515
576
|
if (!isSuspended)
|
|
516
|
-
display(_jsx(RunScreen, { view: view, interrupt: interrupt }));
|
|
577
|
+
display(_jsx(RunScreen, { view: view, interrupt: interrupt, invalidate: invalidate }));
|
|
517
578
|
},
|
|
518
579
|
async close() {
|
|
519
580
|
closed = true;
|