@autopilot-agent/cli 0.3.0 → 0.4.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 +8 -4
- package/dist/activity-animation.d.ts +1 -0
- package/dist/activity-animation.js +4 -2
- package/dist/browser-client.d.ts +14 -0
- package/dist/browser-client.js +156 -0
- package/dist/composition-root.d.ts +12 -2
- package/dist/composition-root.js +33 -15
- package/dist/context-report.d.ts +1 -1
- package/dist/context-report.js +1 -1
- package/dist/controller.d.ts +48 -1
- package/dist/controller.js +50 -24
- package/dist/design-tokens.d.ts +7 -2
- package/dist/design-tokens.js +11 -3
- package/dist/desktop-status.d.ts +35 -0
- package/dist/desktop-status.js +304 -0
- package/dist/file-mention-budget.d.ts +16 -0
- package/dist/file-mention-budget.js +82 -0
- package/dist/file-mention-context.d.ts +26 -1
- package/dist/file-mention-context.js +70 -22
- package/dist/main.d.ts +3 -0
- package/dist/main.js +76 -10
- package/dist/managed-attach.d.ts +3 -0
- package/dist/managed-attach.js +132 -0
- package/dist/managed-controller.d.ts +49 -0
- package/dist/managed-controller.js +171 -0
- package/dist/orchestration-templates.d.ts +27 -0
- package/dist/orchestration-templates.js +20 -0
- package/dist/parser.d.ts +1 -1
- package/dist/parser.js +14 -4
- package/dist/thread-host.d.ts +5 -0
- package/dist/thread-host.js +3 -0
- package/dist/tui/app.js +82 -18
- package/dist/tui/approval.js +1 -1
- package/dist/tui/brand/brand-header.d.ts +1 -3
- package/dist/tui/brand/brand-header.js +6 -8
- package/dist/tui/brand/logo.d.ts +3 -0
- package/dist/tui/brand/logo.js +89 -0
- package/dist/tui/brand/startup.d.ts +18 -0
- package/dist/tui/brand/startup.js +136 -0
- package/dist/tui/constants.d.ts +1 -1
- package/dist/tui/constants.js +1 -1
- package/dist/tui/context.js +1 -3
- package/dist/tui/desktop-resize.d.ts +9 -0
- package/dist/tui/desktop-resize.js +95 -0
- package/dist/tui/hooks/use-file-mention-index.js +9 -4
- package/dist/tui/hooks/use-prompt-input.d.ts +2 -1
- package/dist/tui/hooks/use-prompt-input.js +12 -7
- package/dist/tui/hooks/use-viewport.d.ts +2 -1
- package/dist/tui/hooks/use-viewport.js +15 -8
- package/dist/tui/input-area.d.ts +4 -1
- package/dist/tui/input-area.js +12 -7
- package/dist/tui/lifecycle.d.ts +1 -1
- package/dist/tui/lifecycle.js +82 -11
- package/dist/tui/pickers/permission.js +1 -1
- package/dist/tui/pickers/slash.d.ts +11 -2
- package/dist/tui/pickers/slash.js +21 -7
- package/dist/tui/prompt-input.d.ts +1 -0
- package/dist/tui/prompt-input.js +2 -2
- package/dist/tui/render-mode.d.ts +4 -0
- package/dist/tui/render-mode.js +12 -0
- package/dist/tui/run.js +17 -7
- package/dist/tui/session-manager.d.ts +1 -0
- package/dist/tui/session-manager.js +1 -0
- package/dist/tui/status-line.d.ts +1 -0
- package/dist/tui/status-line.js +29 -14
- package/dist/tui/store.d.ts +3 -1
- package/dist/tui/store.js +33 -9
- package/dist/tui/transcript.d.ts +1 -0
- package/dist/tui/transcript.js +24 -4
- package/dist/tui/types.d.ts +10 -1
- package/dist/tui/viewport/selection.d.ts +2 -2
- package/dist/tui/viewport/selection.js +13 -6
- package/dist/tui/viewport/sources.js +7 -1
- package/dist/types.d.ts +9 -2
- package/package.json +4 -4
package/dist/tui/constants.js
CHANGED
package/dist/tui/context.js
CHANGED
|
@@ -3,9 +3,7 @@ import { Box, Text } from "ink";
|
|
|
3
3
|
import { formatContextReportLines } from "../context-report.js";
|
|
4
4
|
/** 渲染当前 Context 报告覆盖视图;按键由 app.tsx 统一分发,避免创建第二套输入器。 */
|
|
5
5
|
export function TuiContextReport(props) {
|
|
6
|
-
|
|
7
|
-
const decorative = props.useColor && !(props.screenReader ?? false);
|
|
8
|
-
const lines = formatContextReportLines(props.usage, props.expanded, { grid: decorative, columns: props.columns });
|
|
6
|
+
const lines = formatContextReportLines(props.usage, props.expanded, { grid: !props.screenReader, columns: props.columns });
|
|
9
7
|
return _jsxs(Box, { flexDirection: "column", width: props.columns, children: [lines.map(function renderReportLine(line, index) {
|
|
10
8
|
return _jsx(Text, { children: line }, String(index));
|
|
11
9
|
}), _jsxs(Text, { dimColor: props.useColor, children: ["Esc \u8FD4\u56DE\u804A\u5929", props.screenReader ? " · context report" : ""] })] });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TuiOutputStream, TuiTerminalSizeSource } from "./types.js";
|
|
2
|
+
/** 仅接受宿主创建的随机本机管道;布局预提交不更改真实 TTY 尺寸。 */
|
|
3
|
+
export declare function createDesktopResize(source: TuiOutputStream, env: NodeJS.ProcessEnv): {
|
|
4
|
+
source: TuiTerminalSizeSource;
|
|
5
|
+
/** 只有真实输出已适合两阶段网格才确认;OSC 让 renderer 等到该帧解析完成。 */
|
|
6
|
+
written(chunk: string): void;
|
|
7
|
+
/** 退出只关闭本进程的管道与监听,不影响持久 shell。 */
|
|
8
|
+
close(): void;
|
|
9
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/** Windows Desktop 缩网格前先提交可同时容纳于旧、新网格的动态帧;普通 CLI 不启用。 */
|
|
2
|
+
import { createServer } from "node:net";
|
|
3
|
+
import { stripVTControlCharacters } from "node:util";
|
|
4
|
+
import stringWidth from "string-width";
|
|
5
|
+
/** 仅接受宿主创建的随机本机管道;布局预提交不更改真实 TTY 尺寸。 */
|
|
6
|
+
export function createDesktopResize(source, env) {
|
|
7
|
+
const pipe = env.AUTOPILOT_DESKTOP_RESIZE_PIPE;
|
|
8
|
+
const enabled = process.platform === "win32" && env.TERM_PROGRAM === "autopilot-desktop" && /^\\\\\.\\pipe\\autopilot-desktop-[a-f0-9-]{36}$/.test(pipe ?? "");
|
|
9
|
+
let target;
|
|
10
|
+
let latestFrame = "";
|
|
11
|
+
let pending;
|
|
12
|
+
const listeners = new Set();
|
|
13
|
+
const layoutSource = {
|
|
14
|
+
get columns() { return target ? Math.min(source.columns ?? 80, target.columns) : source.columns; },
|
|
15
|
+
get rows() { return target ? Math.min(source.rows ?? 24, target.rows) : source.rows; },
|
|
16
|
+
on(event, listener) { if (event === "resize")
|
|
17
|
+
listeners.add(listener); },
|
|
18
|
+
off(event, listener) { if (event === "resize")
|
|
19
|
+
listeners.delete(listener); },
|
|
20
|
+
};
|
|
21
|
+
/** 发布布局目标,仍由现有 React/Ink 路径计算和输出帧。 */
|
|
22
|
+
function notify() { for (const listener of listeners)
|
|
23
|
+
listener(); }
|
|
24
|
+
/** 仅目标网格确已应用才解除预排版;迟到的旧 resize 不能恢复旧宽帧。 */
|
|
25
|
+
function resized() {
|
|
26
|
+
if (!target || source.columns === target.columns && source.rows === target.rows)
|
|
27
|
+
target = undefined;
|
|
28
|
+
notify();
|
|
29
|
+
}
|
|
30
|
+
/** 已输出帧若本来就能容纳目标网格,放大时无需等待一次无变化的 Ink 写入。 */
|
|
31
|
+
function confirmFrame() {
|
|
32
|
+
if (!pending || !target || !latestFrame)
|
|
33
|
+
return;
|
|
34
|
+
const lines = stripVTControlCharacters(latestFrame).trimEnd().split("\n");
|
|
35
|
+
if (lines.length > layoutSource.rows || lines.some(function tooWide(line) { return stringWidth(line) > layoutSource.columns; }))
|
|
36
|
+
return;
|
|
37
|
+
const request = pending;
|
|
38
|
+
pending = undefined;
|
|
39
|
+
clearTimeout(request.timer);
|
|
40
|
+
const write = source.write;
|
|
41
|
+
write.call(source, `\x1b]777;autopilot-resize;${request.token}\x07`, function flushed() { request.socket.end(request.token); });
|
|
42
|
+
}
|
|
43
|
+
const server = enabled ? createServer(function connected(socket) {
|
|
44
|
+
let input = "";
|
|
45
|
+
socket.setTimeout(1500, function timedOut() { socket.destroy(); });
|
|
46
|
+
socket.on("error", function ignored() { });
|
|
47
|
+
socket.on("data", function received(data) {
|
|
48
|
+
input += data.toString();
|
|
49
|
+
if (input.length > 160 || pending) {
|
|
50
|
+
socket.destroy();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!input.endsWith("\n"))
|
|
54
|
+
return;
|
|
55
|
+
const match = /^(\d{1,4}) (\d{1,4}) ([a-f0-9-]{36})\n$/.exec(input);
|
|
56
|
+
if (!match || +match[1] < 2 || +match[1] > 1000 || +match[2] < 1 || +match[2] > 1000) {
|
|
57
|
+
socket.destroy();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
target = { columns: +match[1], rows: +match[2] };
|
|
61
|
+
const timer = setTimeout(function abandoned() { pending = undefined; target = undefined; socket.destroy(); notify(); }, 1500);
|
|
62
|
+
pending = { socket, token: match[3], timer };
|
|
63
|
+
notify();
|
|
64
|
+
confirmFrame();
|
|
65
|
+
});
|
|
66
|
+
}) : undefined;
|
|
67
|
+
// 无可用管道时保留原 CLI 展示;不输出本机地址或原始错误。
|
|
68
|
+
server?.on("error", function unavailable() { });
|
|
69
|
+
server?.listen(pipe);
|
|
70
|
+
if (enabled)
|
|
71
|
+
source.on?.("resize", resized);
|
|
72
|
+
return {
|
|
73
|
+
source: enabled ? layoutSource : source,
|
|
74
|
+
/** 只有真实输出已适合两阶段网格才确认;OSC 让 renderer 等到该帧解析完成。 */
|
|
75
|
+
written(chunk) {
|
|
76
|
+
if (!enabled)
|
|
77
|
+
return;
|
|
78
|
+
const text = stripVTControlCharacters(chunk);
|
|
79
|
+
if (!text.includes("\n"))
|
|
80
|
+
return;
|
|
81
|
+
latestFrame = chunk;
|
|
82
|
+
confirmFrame();
|
|
83
|
+
},
|
|
84
|
+
/** 退出只关闭本进程的管道与监听,不影响持久 shell。 */
|
|
85
|
+
close() {
|
|
86
|
+
if (pending) {
|
|
87
|
+
clearTimeout(pending.timer);
|
|
88
|
+
pending.socket.destroy();
|
|
89
|
+
}
|
|
90
|
+
if (enabled)
|
|
91
|
+
source.off?.("resize", resized);
|
|
92
|
+
server?.close();
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { useEffect, useState } from "react";
|
|
6
6
|
import { listWorkspaceFiles } from "@autopilot-agent/core";
|
|
7
|
+
import { resolveTrustedFileMentionRoot } from "../../file-mention-context.js";
|
|
7
8
|
let cachedMentionEntries;
|
|
8
9
|
let cachedMentionLoad;
|
|
9
10
|
/** 清空模块级 @ 索引缓存;仅供测试在用例间隔离。 */
|
|
@@ -23,6 +24,13 @@ function buildMentionEntries(files) {
|
|
|
23
24
|
return left.localeCompare(right);
|
|
24
25
|
});
|
|
25
26
|
}
|
|
27
|
+
/** 枚举前后核对受信根,防止其被重定向时把其他目录的文件名显示为候选。 */
|
|
28
|
+
async function loadMentionEntries(workspaceRoot) {
|
|
29
|
+
const root = await resolveTrustedFileMentionRoot(workspaceRoot);
|
|
30
|
+
const { files } = await listWorkspaceFiles({ workspaceRoot: root });
|
|
31
|
+
await resolveTrustedFileMentionRoot(root);
|
|
32
|
+
return buildMentionEntries(files);
|
|
33
|
+
}
|
|
26
34
|
/** 挂载后预热 @ 文件索引;workspaceRoot 缺失或 Core 枚举失败时静默降级为空候选,不影响普通输入。 */
|
|
27
35
|
export function useFileMentionIndex(workspaceRoot) {
|
|
28
36
|
const [entries, setEntries] = useState(function readCachedEntries() {
|
|
@@ -35,10 +43,7 @@ export function useFileMentionIndex(workspaceRoot) {
|
|
|
35
43
|
if (!workspaceRoot || cachedMentionEntries !== undefined)
|
|
36
44
|
return;
|
|
37
45
|
if (!cachedMentionLoad) {
|
|
38
|
-
cachedMentionLoad =
|
|
39
|
-
.then(function collect(result) {
|
|
40
|
-
return buildMentionEntries(result.files);
|
|
41
|
-
})
|
|
46
|
+
cachedMentionLoad = loadMentionEntries(workspaceRoot)
|
|
42
47
|
.catch(function degradeOnFailure() {
|
|
43
48
|
return [];
|
|
44
49
|
});
|
|
@@ -7,6 +7,7 @@ import type { CliTuiStore } from "../types.js";
|
|
|
7
7
|
import { type CliDraftImage } from "../input/clipboard-image.js";
|
|
8
8
|
/** usePromptInput 的运行依赖;派生值(slash 建议、视口按键)由 app.tsx 通过 ref 注入。 */
|
|
9
9
|
export interface UsePromptInputInput {
|
|
10
|
+
parseInput?: import("../../controller.js").CliController["parseInput"];
|
|
10
11
|
store: CliTuiStore;
|
|
11
12
|
columns: number;
|
|
12
13
|
draftRef?: {
|
|
@@ -48,7 +49,7 @@ export interface UsePromptInputInput {
|
|
|
48
49
|
current: {
|
|
49
50
|
slashCommandSuggestions: CliSlashCommand[];
|
|
50
51
|
fileMentionSuggestions: string[];
|
|
51
|
-
handleTuiViewportKey: (key: Key) => boolean;
|
|
52
|
+
handleTuiViewportKey: (key: Key, value?: string) => boolean;
|
|
52
53
|
handleApprovalKey?: (value: string, key: Key) => boolean;
|
|
53
54
|
};
|
|
54
55
|
};
|
|
@@ -127,6 +127,8 @@ export function usePromptInput(input) {
|
|
|
127
127
|
/** 分发终端按键并保持图片占位符与草稿身份一致。 */
|
|
128
128
|
function handleInput(value, key) {
|
|
129
129
|
recordTuiPerformanceDiagnostic("input_key_arrived", value && !key.ctrl && !key.meta ? "text" : "control");
|
|
130
|
+
if (!bracketedPasteRef.current && (key.ctrl && (value.toLowerCase() === "c" || value === "\u0003") || /^(?:\u001b)?\[99;6u$/.test(value)) && derivedRef.current.handleTuiViewportKey(key, value))
|
|
131
|
+
return;
|
|
130
132
|
const controlAction = parseTuiControlAction(value, key);
|
|
131
133
|
if (controlAction === "eof") {
|
|
132
134
|
onEof();
|
|
@@ -187,12 +189,12 @@ export function usePromptInput(input) {
|
|
|
187
189
|
}
|
|
188
190
|
if (derivedRef.current.slashCommandSuggestions.length > 0) {
|
|
189
191
|
const slashCommandSuggestions = derivedRef.current.slashCommandSuggestions;
|
|
190
|
-
const
|
|
192
|
+
const commandCount = slashCommandSuggestions.length;
|
|
193
|
+
const selectedIndex = Math.max(0, Math.min(slashCommandIndexRef.current, commandCount - 1));
|
|
194
|
+
const selectedCommand = slashCommandSuggestions[selectedIndex];
|
|
191
195
|
if (selectedCommand && (key.upArrow || key.downArrow)) {
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
: Math.min(slashCommandSuggestions.length - 1, slashCommandIndexRef.current + 1);
|
|
195
|
-
updateSlashCommandIndex(nextIndex);
|
|
196
|
+
const step = key.upArrow ? -1 : 1;
|
|
197
|
+
updateSlashCommandIndex((selectedIndex + step + commandCount) % commandCount);
|
|
196
198
|
return;
|
|
197
199
|
}
|
|
198
200
|
if (selectedCommand && key.tab) {
|
|
@@ -252,7 +254,7 @@ export function usePromptInput(input) {
|
|
|
252
254
|
}
|
|
253
255
|
if (derivedRef.current.handleTuiViewportKey(key))
|
|
254
256
|
return;
|
|
255
|
-
if (busy.current && !isActiveTuiStatus(current.status))
|
|
257
|
+
if (current.compacting || busy.current && !isActiveTuiStatus(current.status) && !input.parseInput)
|
|
256
258
|
return;
|
|
257
259
|
const deleteDirection = resolveTuiDeleteDirection(value, key, rawInputSequenceRef.current);
|
|
258
260
|
if (deleteDirection) {
|
|
@@ -332,6 +334,9 @@ export function usePromptInput(input) {
|
|
|
332
334
|
}
|
|
333
335
|
pasteCarriageReturnRef.current = false;
|
|
334
336
|
if (key.return) {
|
|
337
|
+
// 受管远端提交期间允许继续编辑草稿,但不丢弃尚未可提交的下一条消息。
|
|
338
|
+
if (busy.current && !isActiveTuiStatus(current.status))
|
|
339
|
+
return;
|
|
335
340
|
if (pastingCountRef.current > 0) {
|
|
336
341
|
store.addNotice("图片仍在处理,请稍候发送");
|
|
337
342
|
return;
|
|
@@ -345,7 +350,7 @@ export function usePromptInput(input) {
|
|
|
345
350
|
return;
|
|
346
351
|
}
|
|
347
352
|
const images = spans.map(function image(span) { return imageDraftsRef.current.get(span.id); });
|
|
348
|
-
const parsed = parseSlashAction(content);
|
|
353
|
+
const parsed = input.parseInput?.(content) ?? parseSlashAction(content);
|
|
349
354
|
if (parsed.kind === "error") {
|
|
350
355
|
store.addNotice(parsed.message);
|
|
351
356
|
return;
|
|
@@ -14,9 +14,10 @@ export declare function useViewport(input: {
|
|
|
14
14
|
write(chunk: string): void;
|
|
15
15
|
};
|
|
16
16
|
onCopyText?: (text: string) => void;
|
|
17
|
+
onCopyError: () => void;
|
|
17
18
|
}): {
|
|
18
19
|
viewportState: ScrollViewportState;
|
|
19
20
|
selection: TuiTextSelection;
|
|
20
21
|
handleTuiMouseEvent: (event: TuiSgrMouseEvent, wheelNotches: number) => void;
|
|
21
|
-
handleTuiViewportKey: (key: Key) => boolean;
|
|
22
|
+
handleTuiViewportKey: (key: Key, value?: string) => boolean;
|
|
22
23
|
};
|
|
@@ -4,7 +4,7 @@ import { createScrollViewportState, resizeScrollViewport, scrollViewportDown, sc
|
|
|
4
4
|
import { copyTuiSelectedText, getTuiSelectedText, resolveTuiVisualLineOffset, } from "../viewport/selection.js";
|
|
5
5
|
/** 管理备用屏视口的滚动、鼠标事件与文字划选状态。 */
|
|
6
6
|
export function useViewport(input) {
|
|
7
|
-
const { isViewportMode, columns, viewportLines, viewportHeight, stdout, onCopyText } = input;
|
|
7
|
+
const { isViewportMode, columns, viewportLines, viewportHeight, stdout, onCopyText, onCopyError } = input;
|
|
8
8
|
const [selection, setSelection] = useState({});
|
|
9
9
|
const selectionRef = useRef(selection);
|
|
10
10
|
const scrollbarDraggingRef = useRef(false);
|
|
@@ -23,6 +23,10 @@ export function useViewport(input) {
|
|
|
23
23
|
selectionRef.current = next;
|
|
24
24
|
setSelection(next);
|
|
25
25
|
}
|
|
26
|
+
/** 剪贴板失败进入既有通知,不让子进程错误静默丢失。 */
|
|
27
|
+
function copySelection(text) {
|
|
28
|
+
void Promise.resolve().then(function copy() { return onCopyText ? onCopyText(text) : copyTuiSelectedText(text, stdout); }).catch(onCopyError);
|
|
29
|
+
}
|
|
26
30
|
/** 将视口内鼠标坐标转换成时间线来源坐标;固定输入区和滚动条不参与划选。 */
|
|
27
31
|
function resolveTuiSelectionPoint(event) {
|
|
28
32
|
if (event.column >= columns || event.row < 1 || event.row > viewportStateRef.current.viewportHeight)
|
|
@@ -52,12 +56,8 @@ export function useViewport(input) {
|
|
|
52
56
|
updateTuiTextSelection({ ...selectionRef.current, focus: selectionPoint });
|
|
53
57
|
selectionDraggingRef.current = false;
|
|
54
58
|
const text = getTuiSelectedText(viewportLines, selectionPoint ? { ...selectionRef.current, focus: selectionPoint } : selectionRef.current);
|
|
55
|
-
if (text)
|
|
56
|
-
|
|
57
|
-
onCopyText(text);
|
|
58
|
-
else
|
|
59
|
-
copyTuiSelectedText(text, stdout);
|
|
60
|
-
}
|
|
59
|
+
if (text)
|
|
60
|
+
copySelection(text);
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
if (event.released) {
|
|
@@ -85,9 +85,16 @@ export function useViewport(input) {
|
|
|
85
85
|
updateViewportState({ ...current, scrollTop, pinnedToBottom: scrollTop >= maximumTop });
|
|
86
86
|
}
|
|
87
87
|
/** 在真实备用屏中处理半视口与顶底跳转;picker 和审批由前置键位分支优先消费。 */
|
|
88
|
-
function handleTuiViewportKey(key) {
|
|
88
|
+
function handleTuiViewportKey(key, value = "") {
|
|
89
89
|
if (!isViewportMode)
|
|
90
90
|
return false;
|
|
91
|
+
const explicitCopy = value === "[99;6u" || value === "\u001b[99;6u" || Boolean(key.ctrl && key.shift && value.toLowerCase() === "c");
|
|
92
|
+
if (explicitCopy || key.ctrl && (value === "c" || value === "\u0003")) {
|
|
93
|
+
const text = getTuiSelectedText(viewportLines, selectionRef.current);
|
|
94
|
+
if (text)
|
|
95
|
+
copySelection(text);
|
|
96
|
+
return explicitCopy || Boolean(text);
|
|
97
|
+
}
|
|
91
98
|
const current = viewportStateRef.current;
|
|
92
99
|
const jump = Math.max(1, Math.floor(current.viewportHeight / 2));
|
|
93
100
|
if (key.pageUp) {
|
package/dist/tui/input-area.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { CliTuiStore } from "./types.js";
|
|
|
9
9
|
export interface TuiInputDerivedState {
|
|
10
10
|
slashCommandSuggestions: CliSlashCommand[];
|
|
11
11
|
fileMentionSuggestions: string[];
|
|
12
|
-
handleTuiViewportKey: (key: Key) => boolean;
|
|
12
|
+
handleTuiViewportKey: (key: Key, value?: string) => boolean;
|
|
13
13
|
handleApprovalKey?: (value: string, key: Key) => boolean;
|
|
14
14
|
}
|
|
15
15
|
/** React ref 形状;输入子树与父级共享同一份派生值容器。 */
|
|
@@ -25,8 +25,11 @@ type TuiDispatchAction = (action: CliAction, prompt?: string, preserveSkillPicke
|
|
|
25
25
|
/** 将 prompt 状态、输入分发和 picker 展示隔离到独立子树。 */
|
|
26
26
|
export declare const TuiInputArea: import("react").NamedExoticComponent<{
|
|
27
27
|
store: CliTuiStore;
|
|
28
|
+
parseInput?: import("../controller.js").CliController["parseInput"];
|
|
29
|
+
suggestSlashCommands?: import("../controller.js").CliController["suggestSlashCommands"];
|
|
28
30
|
draftRef?: CliTuiDraftRef;
|
|
29
31
|
columns: number;
|
|
32
|
+
availableRows: number;
|
|
30
33
|
maximumPromptRows?: number;
|
|
31
34
|
busy: {
|
|
32
35
|
current: boolean;
|
package/dist/tui/input-area.js
CHANGED
|
@@ -12,7 +12,7 @@ import { TuiFileMentionMenu, TUI_FILE_MENTION_VISIBLE_ROWS } from "./pickers/fil
|
|
|
12
12
|
import { TuiModelPicker } from "./pickers/model.js";
|
|
13
13
|
import { TuiPermissionPicker } from "./pickers/permission.js";
|
|
14
14
|
import { TuiSkillPicker } from "./pickers/skill.js";
|
|
15
|
-
import { TuiSlashCommandMenu } from "./pickers/slash.js";
|
|
15
|
+
import { getTuiSlashMenuLayout, TuiSlashCommandMenu } from "./pickers/slash.js";
|
|
16
16
|
import { TuiPromptInput } from "./prompt-input.js";
|
|
17
17
|
/** 根据当前 picker 估算固定区高度,供备用屏计算可用视口高度。 */
|
|
18
18
|
function getTuiPickerHeight(input) {
|
|
@@ -24,8 +24,8 @@ function getTuiPickerHeight(input) {
|
|
|
24
24
|
return input.efforts.length + 5;
|
|
25
25
|
if (input.skills)
|
|
26
26
|
return Math.min(8, input.skills.length) + 8;
|
|
27
|
-
if (input.
|
|
28
|
-
return input.
|
|
27
|
+
if (input.slashMenuHeight > 0)
|
|
28
|
+
return input.slashMenuHeight;
|
|
29
29
|
if (input.fileMentionCandidates.length > 0)
|
|
30
30
|
return Math.min(TUI_FILE_MENTION_VISIBLE_ROWS, input.fileMentionCandidates.length) + 5;
|
|
31
31
|
return 0;
|
|
@@ -34,6 +34,7 @@ function getTuiPickerHeight(input) {
|
|
|
34
34
|
export const TuiInputArea = memo(function TuiInputArea(props) {
|
|
35
35
|
const pickers = props.pickers;
|
|
36
36
|
const { input, cursorIndex, handleInput } = usePromptInput({
|
|
37
|
+
parseInput: props.parseInput,
|
|
37
38
|
draftRef: props.draftRef,
|
|
38
39
|
store: props.store,
|
|
39
40
|
columns: props.columns,
|
|
@@ -57,7 +58,7 @@ export const TuiInputArea = memo(function TuiInputArea(props) {
|
|
|
57
58
|
setFileMentionDismissedInput: pickers.setFileMentionDismissedInput,
|
|
58
59
|
derivedRef: props.derivedRef,
|
|
59
60
|
});
|
|
60
|
-
const slashCommandSuggestions = getSlashCommandSuggestions(input);
|
|
61
|
+
const slashCommandSuggestions = (props.suggestSlashCommands ?? getSlashCommandSuggestions)(input);
|
|
61
62
|
props.derivedRef.current.slashCommandSuggestions = slashCommandSuggestions;
|
|
62
63
|
// @ 菜单派生:索引就绪且未被 Esc 关闭时,按当前 token 的四档评分过滤候选池。
|
|
63
64
|
const fileMentionToken = props.fileMentionIndex?.ready ? extractFileMentionToken(input, cursorIndex) : null;
|
|
@@ -65,9 +66,13 @@ export const TuiInputArea = memo(function TuiInputArea(props) {
|
|
|
65
66
|
? filterFileMentionCandidates(props.fileMentionIndex?.entries ?? [], fileMentionToken.query)
|
|
66
67
|
: [];
|
|
67
68
|
props.derivedRef.current.fileMentionSuggestions = fileMentionSuggestions;
|
|
68
|
-
const
|
|
69
|
+
const promptRows = Math.min(props.maximumPromptRows ?? Infinity, createTuiPromptLayout(input, cursorIndex, Math.max(1, props.columns - 4)).lines.length);
|
|
70
|
+
const showSlash = props.showInput && !pickers.isPickerActive && slashCommandSuggestions.length > 0;
|
|
71
|
+
const compactPrompt = showSlash && props.availableRows <= promptRows + 3;
|
|
72
|
+
const promptHeight = props.showInput ? compactPrompt ? 1 : promptRows + 3 : 0;
|
|
73
|
+
const slashLayout = showSlash ? getTuiSlashMenuLayout(slashCommandSuggestions.length, props.availableRows - promptHeight, props.columns) : undefined;
|
|
69
74
|
const pickerHeight = props.showInput
|
|
70
|
-
? getTuiPickerHeight({ permissions: pickers.permissionPickerOptions, models: pickers.modelPickerOptions, efforts: pickers.effortPickerOptions, skills: pickers.skillPickerSkills,
|
|
75
|
+
? getTuiPickerHeight({ permissions: pickers.permissionPickerOptions, models: pickers.modelPickerOptions, efforts: pickers.effortPickerOptions, skills: pickers.skillPickerSkills, slashMenuHeight: slashLayout?.height ?? 0, fileMentionCandidates: fileMentionSuggestions })
|
|
71
76
|
: 0;
|
|
72
77
|
useLayoutEffect(function notifyInputLayoutChange() {
|
|
73
78
|
props.onLayoutChange?.({ promptHeight, pickerHeight });
|
|
@@ -100,5 +105,5 @@ export const TuiInputArea = memo(function TuiInputArea(props) {
|
|
|
100
105
|
useInput(handleActiveInput, { isActive: !props.bindInputHandler && props.isRawModeSupported && props.isInputActive });
|
|
101
106
|
if (!props.showInput)
|
|
102
107
|
return null;
|
|
103
|
-
return _jsxs(_Fragment, { children: [_jsx(TuiPromptInput, { maximumRows: props.maximumPromptRows, input: input, cursorIndex: cursorIndex, columns: props.columns, useColor: props.useColor, screenReader: props.screenReader, busy: props.busy.current }), pickers.permissionPickerOptions ? (_jsx(TuiPermissionPicker, { options: pickers.permissionPickerOptions, selectedIndex: pickers.permissionPickerIndex, useColor: props.useColor, screenReader: props.screenReader })) : pickers.modelPickerOptions ? (_jsx(TuiModelPicker, { options: pickers.modelPickerOptions, selectedIndex: pickers.modelPickerIndex, useColor: props.useColor, screenReader: props.screenReader })) : pickers.effortPickerOptions ? (_jsx(TuiEffortPicker, { options: pickers.effortPickerOptions, selectedIndex: pickers.effortPickerIndex, useColor: props.useColor, screenReader: props.screenReader })) : pickers.skillPickerSkills ? (_jsx(TuiSkillPicker, { skills: pickers.skillPickerSkills, query: pickers.skillPickerQuery, selectedIndex: pickers.skillPickerIndex, useColor: props.useColor, screenReader: props.screenReader })) :
|
|
108
|
+
return _jsxs(_Fragment, { children: [_jsx(TuiPromptInput, { compact: compactPrompt, maximumRows: compactPrompt ? 1 : props.maximumPromptRows, input: input, cursorIndex: cursorIndex, columns: props.columns, useColor: props.useColor, screenReader: props.screenReader, busy: props.busy.current }), pickers.permissionPickerOptions ? (_jsx(TuiPermissionPicker, { options: pickers.permissionPickerOptions, selectedIndex: pickers.permissionPickerIndex, useColor: props.useColor, screenReader: props.screenReader })) : pickers.modelPickerOptions ? (_jsx(TuiModelPicker, { options: pickers.modelPickerOptions, selectedIndex: pickers.modelPickerIndex, useColor: props.useColor, screenReader: props.screenReader })) : pickers.effortPickerOptions ? (_jsx(TuiEffortPicker, { options: pickers.effortPickerOptions, selectedIndex: pickers.effortPickerIndex, useColor: props.useColor, screenReader: props.screenReader })) : pickers.skillPickerSkills ? (_jsx(TuiSkillPicker, { skills: pickers.skillPickerSkills, query: pickers.skillPickerQuery, selectedIndex: pickers.skillPickerIndex, useColor: props.useColor, screenReader: props.screenReader })) : slashLayout ? (_jsx(TuiSlashCommandMenu, { commands: slashCommandSuggestions, selectedIndex: pickers.slashCommandIndex, layout: slashLayout, useColor: props.useColor, screenReader: props.screenReader })) : fileMentionSuggestions.length > 0 ? (_jsx(TuiFileMentionMenu, { candidates: fileMentionSuggestions, selectedIndex: pickers.fileMentionIndex, useColor: props.useColor, screenReader: props.screenReader })) : null] });
|
|
104
109
|
});
|
package/dist/tui/lifecycle.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { TuiOutputStream } from "./types.js";
|
|
|
6
6
|
export declare function createTuiRenderStdout(source: TuiOutputStream, initialSize: {
|
|
7
7
|
columns: number;
|
|
8
8
|
rows: number;
|
|
9
|
-
}): {
|
|
9
|
+
}, reflow?: boolean, onWritten?: (chunk: string) => void, replayOnWidthChange?: boolean): {
|
|
10
10
|
stdout: TuiOutputStream;
|
|
11
11
|
setSize(size: {
|
|
12
12
|
columns: number;
|
package/dist/tui/lifecycle.js
CHANGED
|
@@ -1,49 +1,120 @@
|
|
|
1
1
|
/** TUI 终端生命周期:鼠标事件入口、Ink stdin 包装与幂等的控制序列生命周期。 */
|
|
2
2
|
import { PassThrough } from "node:stream";
|
|
3
|
+
import { stripVTControlCharacters } from "node:util";
|
|
4
|
+
import wrapAnsi from "wrap-ansi";
|
|
3
5
|
import { TUI_ALTERNATE_SCREEN_DISABLE, TUI_ALTERNATE_SCREEN_ENABLE, TUI_BRACKETED_PASTE_DISABLE, TUI_BRACKETED_PASTE_ENABLE, TUI_MOUSE_TRACKING_DISABLE, TUI_MOUSE_TRACKING_ENABLE, TUI_TERMINAL_FOCUS_DISABLE, TUI_TERMINAL_FOCUS_ENABLE, } from "./constants.js";
|
|
4
6
|
/** Ink 使用的稳定尺寸输出代理;它转发写入并在新布局提交后通知 resize。 */
|
|
5
7
|
class StableTuiOutputStream {
|
|
6
8
|
source;
|
|
9
|
+
reflow;
|
|
10
|
+
onWritten;
|
|
11
|
+
replayOnWidthChange;
|
|
7
12
|
size;
|
|
13
|
+
frame = "";
|
|
14
|
+
replayInkOutput = false;
|
|
15
|
+
observedColumns;
|
|
16
|
+
replayPending = false;
|
|
17
|
+
replayTimer;
|
|
18
|
+
observeWidth = this.observeTerminalWidth.bind(this);
|
|
8
19
|
resizeListeners = new Set();
|
|
9
|
-
constructor(source, initialSize) {
|
|
20
|
+
constructor(source, initialSize, reflow = false, onWritten, replayOnWidthChange = false) {
|
|
10
21
|
this.source = source;
|
|
22
|
+
this.reflow = reflow;
|
|
23
|
+
this.onWritten = onWritten;
|
|
24
|
+
this.replayOnWidthChange = replayOnWidthChange;
|
|
11
25
|
this.size = initialSize;
|
|
26
|
+
this.observedColumns = initialSize.columns;
|
|
27
|
+
}
|
|
28
|
+
/** 按真实列宽记录整次拖动;即使最后回到原宽,也要清掉中间宽度留下的历史边线。 */
|
|
29
|
+
observeTerminalWidth() {
|
|
30
|
+
const columns = this.source.columns;
|
|
31
|
+
if (columns === undefined || columns === this.observedColumns)
|
|
32
|
+
return;
|
|
33
|
+
this.observedColumns = columns;
|
|
34
|
+
this.replayPending = true;
|
|
35
|
+
clearTimeout(this.replayTimer);
|
|
36
|
+
this.replayTimer = setTimeout(function replayWhenSettled(stream) {
|
|
37
|
+
stream.replayTimer = undefined;
|
|
38
|
+
stream.setSize(stream.size);
|
|
39
|
+
}, 200, this);
|
|
12
40
|
}
|
|
13
41
|
get columns() { return this.size.columns; }
|
|
14
|
-
|
|
42
|
+
// Ink 在上一帧达到输出高度时会清屏并重放 Static。只在同步 resize 回调中触发一次。
|
|
43
|
+
get rows() { return this.replayInkOutput ? 0 : this.size.rows; }
|
|
15
44
|
get isTTY() { return this.source.isTTY; }
|
|
16
|
-
/**
|
|
45
|
+
/** 转发 Ink 输出,并在适用的 ConPTY 宿主按旧帧实际占行修正动态擦除。 */
|
|
17
46
|
write(chunk, ...args) {
|
|
47
|
+
// ConPTY 会重排旧动态帧,Ink 仍按旧逻辑行数擦除,须按实际新宽度计物理行。
|
|
48
|
+
let columns = this.source.columns ?? this.size.columns;
|
|
49
|
+
if (this.reflow) {
|
|
50
|
+
// Node20 的 columns 缓存直到 resize 事件才更新,ConPTY 可在该事件前完成重排。
|
|
51
|
+
const handle = this.source._handle;
|
|
52
|
+
const actual = [0, 0];
|
|
53
|
+
if (handle?.getWindowSize(actual) === 0 && actual[0] > 0)
|
|
54
|
+
columns = actual[0];
|
|
55
|
+
}
|
|
56
|
+
const erase = /\x1b\[2K(?:\x1b\[1A\x1b\[2K)*\x1b\[G/;
|
|
57
|
+
const eraseMatch = chunk.match(erase);
|
|
58
|
+
if (this.reflow && this.frame && eraseMatch) {
|
|
59
|
+
// Ink 的整屏回放含 Static 历史;仅当逻辑行数与本次动态擦除一致时使用捕获帧。
|
|
60
|
+
const logicalRows = eraseMatch[0].match(/\x1b\[2K/g).length;
|
|
61
|
+
if (logicalRows === this.frame.split("\n").length) {
|
|
62
|
+
const rows = wrapAnsi(this.frame, Math.max(1, columns), { hard: true, wordWrap: false, trim: false }).split("\n").length;
|
|
63
|
+
chunk = chunk.replace(erase, "\x1b[2K" + "\x1b[1A\x1b[2K".repeat(rows - 1) + "\x1b[G");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (this.reflow) {
|
|
67
|
+
const text = stripVTControlCharacters(chunk);
|
|
68
|
+
if (text.includes("\n") || erase.test(chunk))
|
|
69
|
+
this.frame = text;
|
|
70
|
+
}
|
|
18
71
|
const write = this.source.write;
|
|
19
72
|
const result = write.call(this.source, chunk, ...args);
|
|
73
|
+
this.onWritten?.(chunk);
|
|
20
74
|
return result !== false;
|
|
21
75
|
}
|
|
22
76
|
/** 保存 Ink 的 resize 监听,等待应用布局提交后再触发。 */
|
|
23
77
|
on(event, listener) {
|
|
24
|
-
if (event === "resize")
|
|
78
|
+
if (event === "resize") {
|
|
79
|
+
if (this.replayOnWidthChange && !this.resizeListeners.size)
|
|
80
|
+
this.source.on?.("resize", this.observeWidth);
|
|
25
81
|
this.resizeListeners.add(listener);
|
|
82
|
+
}
|
|
26
83
|
return this;
|
|
27
84
|
}
|
|
28
85
|
/** 移除 Ink 的 resize 监听,满足 Ink 卸载时的监听清理。 */
|
|
29
86
|
off(event, listener) {
|
|
30
|
-
if (event === "resize")
|
|
31
|
-
this.
|
|
87
|
+
if (event === "resize" && this.resizeListeners.delete(listener) && !this.resizeListeners.size && this.replayOnWidthChange) {
|
|
88
|
+
this.source.off?.("resize", this.observeWidth);
|
|
89
|
+
clearTimeout(this.replayTimer);
|
|
90
|
+
this.replayTimer = undefined;
|
|
91
|
+
this.replayPending = false;
|
|
92
|
+
}
|
|
32
93
|
return this;
|
|
33
94
|
}
|
|
34
95
|
/** 更新 Ink 后续布局使用的稳定尺寸,并交由 Ink 自身失效旧输出缓存后重绘。 */
|
|
35
96
|
setSize(size) {
|
|
36
97
|
const changed = size.columns !== this.size.columns || size.rows !== this.size.rows;
|
|
98
|
+
// 拖动停稳且布局已提交最终列宽后,只重放一次静态历史和当前帧。
|
|
99
|
+
const replay = this.replayPending && this.replayTimer === undefined && size.columns === this.observedColumns;
|
|
37
100
|
this.size = size;
|
|
38
|
-
if (!changed)
|
|
101
|
+
if (!changed && !replay)
|
|
39
102
|
return;
|
|
40
|
-
|
|
41
|
-
|
|
103
|
+
if (replay)
|
|
104
|
+
this.replayPending = false;
|
|
105
|
+
this.replayInkOutput = replay;
|
|
106
|
+
try {
|
|
107
|
+
for (const listener of this.resizeListeners)
|
|
108
|
+
listener();
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
this.replayInkOutput = false;
|
|
112
|
+
}
|
|
42
113
|
}
|
|
43
114
|
}
|
|
44
115
|
/** 创建跨 DPI resize 时使用的 Ink 输出代理与尺寸提交函数。 */
|
|
45
|
-
export function createTuiRenderStdout(source, initialSize) {
|
|
46
|
-
const stable = new StableTuiOutputStream(source, initialSize);
|
|
116
|
+
export function createTuiRenderStdout(source, initialSize, reflow = false, onWritten, replayOnWidthChange = false) {
|
|
117
|
+
const stable = new StableTuiOutputStream(source, initialSize, reflow, onWritten, replayOnWidthChange);
|
|
47
118
|
return {
|
|
48
119
|
stdout: stable,
|
|
49
120
|
setSize(size) { stable.setSize(size); },
|
|
@@ -9,5 +9,5 @@ export function TuiPermissionPicker(props) {
|
|
|
9
9
|
const focused = index === selectedIndex;
|
|
10
10
|
const checkboxColor = option.mode === "full_access" && option.selected && props.useColor ? CLI_TUI_COLORS.permissionFullAccess : undefined;
|
|
11
11
|
return _jsxs(Text, { bold: focused, color: focused && props.useColor ? TUI_ACCENT_COLOR : undefined, children: [focused ? "› " : " ", _jsxs(Text, { color: checkboxColor, dimColor: false, children: ["[", option.selected ? "on" : "off", "]"] }), " ", option.label, " (", option.mode, ")"] }, option.mode);
|
|
12
|
-
}), selectedOption ? _jsxs(Text, { dimColor: props.useColor, children: [" ", selectedOption.description] }) : null, _jsxs(Text, { dimColor: props.useColor, children: [selectedOption?.selected ? "已选择;Enter
|
|
12
|
+
}), selectedOption ? _jsxs(Text, { dimColor: props.useColor, children: [" ", selectedOption.description] }) : null, _jsxs(Text, { dimColor: props.useColor, children: [selectedOption?.selected ? "已选择;Enter 保存,下次安全恢复或新回合生效" : "Space 选择此权限模式", props.screenReader ? " · permission selector" : ""] })] }));
|
|
13
13
|
}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
/** `/`
|
|
1
|
+
/** `/` 触发的命令目录,按终端可用行数展示选中项所在的候选窗口。 */
|
|
2
2
|
import { type ReactNode } from "react";
|
|
3
3
|
import type { CliSlashCommand } from "../../types.js";
|
|
4
|
-
/**
|
|
4
|
+
/** 保证每条候选占一行;边框、引导和计数也从同一行数预算扣除。 */
|
|
5
|
+
export declare function getTuiSlashMenuLayout(commandCount: number, availableRows: number, columns: number): {
|
|
6
|
+
framed: boolean;
|
|
7
|
+
inlineCount: boolean;
|
|
8
|
+
visibleRows: number;
|
|
9
|
+
height: number;
|
|
10
|
+
columns: number;
|
|
11
|
+
};
|
|
12
|
+
/** 展示选中项所在的窗口,仍按整个候选目录编号。 */
|
|
5
13
|
export declare function TuiSlashCommandMenu(props: {
|
|
6
14
|
commands: CliSlashCommand[];
|
|
7
15
|
selectedIndex: number;
|
|
16
|
+
layout: ReturnType<typeof getTuiSlashMenuLayout>;
|
|
8
17
|
useColor: boolean;
|
|
9
18
|
screenReader: boolean;
|
|
10
19
|
}): ReactNode;
|
|
@@ -1,11 +1,25 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from "ink";
|
|
3
3
|
import { TUI_ACCENT_COLOR } from "../../design-tokens.js";
|
|
4
|
-
/**
|
|
4
|
+
/** 保证每条候选占一行;边框、引导和计数也从同一行数预算扣除。 */
|
|
5
|
+
export function getTuiSlashMenuLayout(commandCount, availableRows, columns) {
|
|
6
|
+
const framed = availableRows >= 7 && columns >= 24;
|
|
7
|
+
const inlineCount = availableRows <= 1;
|
|
8
|
+
const chromeRows = framed ? 6 : inlineCount ? 0 : 1;
|
|
9
|
+
const visibleRows = Math.max(1, Math.min(commandCount, availableRows - chromeRows));
|
|
10
|
+
return { framed, inlineCount, visibleRows, height: visibleRows + chromeRows, columns };
|
|
11
|
+
}
|
|
12
|
+
/** 展示选中项所在的窗口,仍按整个候选目录编号。 */
|
|
5
13
|
export function TuiSlashCommandMenu(props) {
|
|
6
|
-
const selectedIndex = Math.max(0, Math.min(props.selectedIndex,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
const selectedIndex = Math.max(0, Math.min(props.selectedIndex, props.commands.length - 1));
|
|
15
|
+
const { framed, inlineCount, visibleRows, columns } = props.layout;
|
|
16
|
+
const start = Math.max(0, selectedIndex - visibleRows + 1);
|
|
17
|
+
const count = `${selectedIndex + 1}/${props.commands.length}`;
|
|
18
|
+
return (_jsxs(Box, { marginTop: framed ? 1 : 0, borderStyle: framed ? "single" : undefined, borderColor: props.useColor ? TUI_ACCENT_COLOR : undefined, paddingX: framed ? 1 : 0, flexDirection: "column", "aria-role": "listbox", children: [framed ? _jsxs(_Fragment, { children: [_jsx(Text, { bold: true, color: props.useColor ? TUI_ACCENT_COLOR : undefined, children: "Commands" }), _jsx(Text, { wrap: "truncate-end", dimColor: props.useColor, children: columns >= 55 ? "↑↓ select · Tab complete · Enter choose · Esc close" : "↑↓ · Tab/Enter · Esc" })] }) : null, props.commands.slice(start, start + visibleRows).map(function renderSlashCommand(command, offset) {
|
|
19
|
+
const selected = start + offset === selectedIndex;
|
|
20
|
+
const label = !inlineCount ? command.usage : command.name.length + count.length + 3 <= columns
|
|
21
|
+
? `${command.name} ${count}`
|
|
22
|
+
: `${count} ${command.name}`;
|
|
23
|
+
return (_jsxs(Text, { wrap: "truncate-end", bold: selected, color: selected && props.useColor ? TUI_ACCENT_COLOR : undefined, children: [selected ? "› " : " ", label, " ", _jsx(Text, { dimColor: props.useColor, children: command.description })] }, command.name));
|
|
24
|
+
}), inlineCount ? null : _jsxs(Text, { wrap: "truncate-end", dimColor: props.useColor, children: [count, " commands", props.screenReader ? " · command selector" : ""] })] }));
|
|
11
25
|
}
|
package/dist/tui/prompt-input.js
CHANGED
|
@@ -46,7 +46,7 @@ function renderLineWithCursor(lineText, cursorOffset, useColor, lineKey) {
|
|
|
46
46
|
}
|
|
47
47
|
/** 渲染带可视光标的多行输入;所有 prompt 文本放进同一个 Text,避免兄弟节点分别换行。 */
|
|
48
48
|
export function TuiPromptInput(props) {
|
|
49
|
-
const layout = createTuiPromptLayout(props.input, props.cursorIndex, Math.max(1, props.columns - 4));
|
|
49
|
+
const layout = createTuiPromptLayout(props.input, props.cursorIndex, Math.max(1, props.columns - (props.compact ? 0 : 4)));
|
|
50
50
|
const nodes = [];
|
|
51
51
|
const placeholder = props.screenReader && !props.input ? "prompt" : "";
|
|
52
52
|
const startLine = Math.max(0, layout.cursorLine - (props.maximumRows ?? layout.lines.length) + 1);
|
|
@@ -71,5 +71,5 @@ export function TuiPromptInput(props) {
|
|
|
71
71
|
if (isCursorLine && placeholder)
|
|
72
72
|
nodes.push(placeholder);
|
|
73
73
|
}
|
|
74
|
-
return (_jsx(Box, { "aria-role": "textbox", "aria-state": { busy: props.busy, multiline: true }, width: props.columns, flexShrink: 0, marginTop: 1, borderStyle: "single", borderColor: props.useColor ? TUI_ACCENT_COLOR : undefined, paddingX: 1, children: _jsx(Text, { wrap: "wrap", children: nodes }) }));
|
|
74
|
+
return (_jsx(Box, { "aria-role": "textbox", "aria-state": { busy: props.busy, multiline: true }, width: props.columns, flexShrink: 0, marginTop: props.compact ? 0 : 1, borderStyle: props.compact ? undefined : "single", borderColor: props.useColor ? TUI_ACCENT_COLOR : undefined, paddingX: props.compact ? 0 : 1, children: _jsx(Text, { wrap: "wrap", children: nodes }) }));
|
|
75
75
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/** TUI 启动期一次性解析的渲染模式纯函数:颜色/读屏/降级/渲染模式策略。 */
|
|
2
2
|
import type { TuiRenderMode } from "./types.js";
|
|
3
|
+
/** 编排受管终端的局部样式,只由受管入口开启,并在读屏模式禁用。 */
|
|
4
|
+
export declare const TuiManagedTerminalStyles: import("react").Context<boolean>;
|
|
5
|
+
/** 资源管理器启动的 cmd 可由 Windows Terminal 承载,但不继承 WT_SESSION。 */
|
|
6
|
+
export declare function getWindowsTuiResizeHost(isTTY: boolean | undefined, env: NodeJS.ProcessEnv, platform?: NodeJS.Platform): "desktop" | "external" | undefined;
|
|
3
7
|
/** 判断当前环境是否要求关闭 ANSI 颜色。 */
|
|
4
8
|
export declare function resolveNoColor(env: NodeJS.ProcessEnv): boolean;
|
|
5
9
|
/** 解析 Ink screen-reader 开关,并保留 Ink 官方环境变量兼容性。 */
|