@agi-fans/dsh-tui 0.18.0 → 0.20.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/lib/CHANGELOG.md +115 -1
- package/lib/chrome/box.d.ts +2 -0
- package/lib/chrome/box.js +6 -12
- package/lib/chrome/box.js.map +1 -1
- package/lib/chrome/code-highlight.d.ts +26 -18
- package/lib/chrome/code-highlight.js +114 -39
- package/lib/chrome/code-highlight.js.map +1 -1
- package/lib/chrome/diff-render.d.ts +1 -2
- package/lib/chrome/diff-render.js +41 -90
- package/lib/chrome/diff-render.js.map +1 -1
- package/lib/chrome/main-screen-renderer.d.ts +52 -30
- package/lib/chrome/main-screen-renderer.js +1730 -79
- package/lib/chrome/main-screen-renderer.js.map +1 -1
- package/lib/chrome/markdown.js +144 -101
- package/lib/chrome/markdown.js.map +1 -1
- package/lib/chrome/math.d.ts +4 -0
- package/lib/chrome/math.js +340 -0
- package/lib/chrome/math.js.map +1 -0
- package/lib/chrome/md-style.d.ts +3 -0
- package/lib/chrome/md-style.js.map +1 -1
- package/lib/chrome/mermaid.d.ts +6 -0
- package/lib/chrome/mermaid.js +56 -0
- package/lib/chrome/mermaid.js.map +1 -0
- package/lib/chrome/renderer.d.ts +78 -0
- package/lib/chrome/renderer.js.map +1 -1
- package/lib/chrome/status-config.d.ts +5 -0
- package/lib/chrome/status-config.js +3 -0
- package/lib/chrome/status-config.js.map +1 -1
- package/lib/chrome/status-line.d.ts +0 -21
- package/lib/chrome/status-line.js +8 -65
- package/lib/chrome/status-line.js.map +1 -1
- package/lib/chrome/terminal-images.d.ts +31 -0
- package/lib/chrome/terminal-images.js +34 -0
- package/lib/chrome/terminal-images.js.map +1 -0
- package/lib/chrome/theme.d.ts +23 -6
- package/lib/chrome/theme.js +217 -109
- package/lib/chrome/theme.js.map +1 -1
- package/lib/chrome/tool-args.d.ts +24 -1
- package/lib/chrome/tool-args.js +40 -1
- package/lib/chrome/tool-args.js.map +1 -1
- package/lib/chrome/tool-renderers.d.ts +11 -0
- package/lib/chrome/tool-renderers.js +55 -5
- package/lib/chrome/tool-renderers.js.map +1 -1
- package/lib/chrome/welcome-tips.js +2 -2
- package/lib/chrome/welcome-tips.js.map +1 -1
- package/lib/chrome/width.d.ts +7 -3
- package/lib/chrome/width.js +78 -14
- package/lib/chrome/width.js.map +1 -1
- package/lib/commands/diff.js +49 -3
- package/lib/commands/diff.js.map +1 -1
- package/lib/commands/export.js +28 -5
- package/lib/commands/export.js.map +1 -1
- package/lib/commands/files.d.ts +8 -0
- package/lib/commands/files.js +137 -0
- package/lib/commands/files.js.map +1 -0
- package/lib/commands/plugins.d.ts +8 -0
- package/lib/commands/plugins.js +158 -0
- package/lib/commands/plugins.js.map +1 -0
- package/lib/commands/session-configuration.d.ts +4 -0
- package/lib/commands/session-configuration.js +39 -8
- package/lib/commands/session-configuration.js.map +1 -1
- package/lib/commands/session.js +47 -15
- package/lib/commands/session.js.map +1 -1
- package/lib/commands/steer.js +2 -2
- package/lib/commands/steer.js.map +1 -1
- package/lib/commands/terminal.d.ts +7 -0
- package/lib/commands/terminal.js +99 -0
- package/lib/commands/terminal.js.map +1 -0
- package/lib/definition.d.ts +180 -14
- package/lib/definition.js.map +1 -1
- package/lib/input/clipboard.d.ts +12 -7
- package/lib/input/clipboard.js +79 -20
- package/lib/input/clipboard.js.map +1 -1
- package/lib/input/composer-files.d.ts +26 -0
- package/lib/input/composer-files.js +50 -0
- package/lib/input/composer-files.js.map +1 -0
- package/lib/input/editor-discovery.d.ts +21 -0
- package/lib/input/editor-discovery.js +99 -0
- package/lib/input/editor-discovery.js.map +1 -0
- package/lib/input/editor.d.ts +26 -1
- package/lib/input/editor.js +126 -12
- package/lib/input/editor.js.map +1 -1
- package/lib/input/external-editor.d.ts +5 -2
- package/lib/input/external-editor.js +14 -12
- package/lib/input/external-editor.js.map +1 -1
- package/lib/input/fuzzy-search.d.ts +9 -0
- package/lib/input/fuzzy-search.js +113 -0
- package/lib/input/fuzzy-search.js.map +1 -0
- package/lib/input/keybindings-config.d.ts +1 -1
- package/lib/input/keybindings-config.js +7 -1
- package/lib/input/keybindings-config.js.map +1 -1
- package/lib/input/keys.d.ts +17 -0
- package/lib/input/keys.js +21 -5
- package/lib/input/keys.js.map +1 -1
- package/lib/input/mouse-policy.d.ts +3 -0
- package/lib/input/mouse-policy.js +14 -0
- package/lib/input/mouse-policy.js.map +1 -0
- package/lib/input/paste-burst.d.ts +16 -0
- package/lib/input/paste-burst.js +61 -0
- package/lib/input/paste-burst.js.map +1 -0
- package/lib/input/text-selection.d.ts +20 -0
- package/lib/input/text-selection.js +195 -0
- package/lib/input/text-selection.js.map +1 -0
- package/lib/runtime/composer-images.d.ts +1 -0
- package/lib/runtime/composer-images.js +11 -3
- package/lib/runtime/composer-images.js.map +1 -1
- package/lib/runtime/file-open.d.ts +2 -0
- package/lib/runtime/file-open.js +12 -0
- package/lib/runtime/file-open.js.map +1 -0
- package/lib/runtime/file-review.d.ts +24 -0
- package/lib/runtime/file-review.js +188 -0
- package/lib/runtime/file-review.js.map +1 -0
- package/lib/runtime/herdr-agent.d.ts +7 -15
- package/lib/runtime/herdr-agent.js +151 -79
- package/lib/runtime/herdr-agent.js.map +1 -1
- package/lib/runtime/hook-settings.d.ts +17 -0
- package/lib/runtime/hook-settings.js +57 -0
- package/lib/runtime/hook-settings.js.map +1 -0
- package/lib/runtime/human-interaction.js +1 -1
- package/lib/runtime/human-interaction.js.map +1 -1
- package/lib/runtime/image-preview.d.ts +8 -0
- package/lib/runtime/image-preview.js +119 -0
- package/lib/runtime/image-preview.js.map +1 -0
- package/lib/runtime/plain-tui.d.ts +2 -0
- package/lib/runtime/plain-tui.js +2 -2
- package/lib/runtime/plain-tui.js.map +1 -1
- package/lib/runtime/plugin-settings.d.ts +17 -0
- package/lib/runtime/plugin-settings.js +154 -0
- package/lib/runtime/plugin-settings.js.map +1 -0
- package/lib/runtime/provider-local.d.ts +58 -7
- package/lib/runtime/provider-local.js +1394 -137
- package/lib/runtime/provider-local.js.map +1 -1
- package/lib/runtime/runner.js +3 -3
- package/lib/runtime/runner.js.map +1 -1
- package/lib/runtime/session-archive.d.ts +5 -0
- package/lib/runtime/session-archive.js +114 -0
- package/lib/runtime/session-archive.js.map +1 -0
- package/lib/runtime/subagent-model-selection.d.ts +5 -0
- package/lib/runtime/subagent-model-selection.js +15 -0
- package/lib/runtime/subagent-model-selection.js.map +1 -0
- package/lib/runtime/terminal-notifications.d.ts +8 -0
- package/lib/runtime/terminal-notifications.js +16 -0
- package/lib/runtime/terminal-notifications.js.map +1 -1
- package/lib/runtime/terminal-reader.d.ts +11 -0
- package/lib/runtime/terminal-reader.js +87 -0
- package/lib/runtime/terminal-reader.js.map +1 -0
- package/lib/runtime/tool-presentation.js +43 -30
- package/lib/runtime/tool-presentation.js.map +1 -1
- package/lib/session/composer-drafts.d.ts +20 -0
- package/lib/session/composer-drafts.js +103 -0
- package/lib/session/composer-drafts.js.map +1 -0
- package/lib/session/conversation-turns.d.ts +16 -0
- package/lib/session/conversation-turns.js +33 -0
- package/lib/session/conversation-turns.js.map +1 -0
- package/lib/session/feature-toggles.d.ts +79 -0
- package/lib/session/feature-toggles.js +139 -0
- package/lib/session/feature-toggles.js.map +1 -0
- package/lib/session/fold-policy.d.ts +4 -0
- package/lib/session/fold-policy.js +4 -0
- package/lib/session/fold-policy.js.map +1 -0
- package/lib/session/interaction-adapter.d.ts +2 -2
- package/lib/session/interaction-adapter.js +156 -25
- package/lib/session/interaction-adapter.js.map +1 -1
- package/lib/session/job-notice.d.ts +4 -0
- package/lib/session/job-notice.js +44 -3
- package/lib/session/job-notice.js.map +1 -1
- package/lib/session/message-queue.d.ts +22 -0
- package/lib/session/message-queue.js +157 -0
- package/lib/session/message-queue.js.map +1 -0
- package/lib/session/project-file-search.js +3 -21
- package/lib/session/project-file-search.js.map +1 -1
- package/lib/session/session-controller.d.ts +11 -18
- package/lib/session/session-controller.js +246 -100
- package/lib/session/session-controller.js.map +1 -1
- package/lib/session/session-library.d.ts +11 -3
- package/lib/session/session-library.js +48 -8
- package/lib/session/session-library.js.map +1 -1
- package/lib/session/session-tree.d.ts +26 -0
- package/lib/session/session-tree.js +112 -0
- package/lib/session/session-tree.js.map +1 -0
- package/lib/session/steering.d.ts +3 -0
- package/lib/session/steering.js +9 -0
- package/lib/session/steering.js.map +1 -0
- package/lib/session/tui-settings.d.ts +23 -1
- package/lib/session/tui-settings.js +15 -2
- package/lib/session/tui-settings.js.map +1 -1
- package/lib/session/workflow-projection.d.ts +9 -0
- package/lib/session/workflow-projection.js +44 -0
- package/lib/session/workflow-projection.js.map +1 -0
- package/lib/views/agent-hub.js +9 -4
- package/lib/views/agent-hub.js.map +1 -1
- package/lib/views/autocomplete.js +5 -25
- package/lib/views/autocomplete.js.map +1 -1
- package/lib/views/document-reader.d.ts +34 -0
- package/lib/views/document-reader.js +145 -0
- package/lib/views/document-reader.js.map +1 -0
- package/lib/views/event-views.d.ts +26 -2
- package/lib/views/event-views.js +196 -42
- package/lib/views/event-views.js.map +1 -1
- package/lib/views/hotkeys.d.ts +2 -0
- package/lib/views/hotkeys.js +20 -8
- package/lib/views/hotkeys.js.map +1 -1
- package/lib/views/prompt-selector.d.ts +33 -3
- package/lib/views/prompt-selector.js +287 -43
- package/lib/views/prompt-selector.js.map +1 -1
- package/lib/views/prompt-tree.d.ts +11 -0
- package/lib/views/prompt-tree.js +74 -0
- package/lib/views/prompt-tree.js.map +1 -0
- package/lib/views/session-files.d.ts +7 -0
- package/lib/views/session-files.js +62 -0
- package/lib/views/session-files.js.map +1 -0
- package/lib/views/settings-list.d.ts +32 -4
- package/lib/views/settings-list.js +148 -37
- package/lib/views/settings-list.js.map +1 -1
- package/lib/views/transcript-render.d.ts +117 -18
- package/lib/views/transcript-render.js +1084 -126
- package/lib/views/transcript-render.js.map +1 -1
- package/lib/views/transcript-types.d.ts +80 -2
- package/lib/views/transcript-types.js +11 -0
- package/lib/views/transcript-types.js.map +1 -1
- package/lib/views/workspace-changes.d.ts +27 -0
- package/lib/views/workspace-changes.js +128 -0
- package/lib/views/workspace-changes.js.map +1 -0
- package/package.json +77 -41
- package/lib/chrome/style.d.ts +0 -22
- package/lib/chrome/style.js +0 -23
- package/lib/chrome/style.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Interactive terminal selector used by resume, approval, and user questions. */
|
|
2
|
-
import type
|
|
2
|
+
import { type ImageProtocol } from '../chrome/terminal-images.ts';
|
|
3
|
+
import type { TuiDocumentPosition, TuiPrompt } from '../definition.ts';
|
|
3
4
|
import { type Theme } from '../chrome/theme.ts';
|
|
4
5
|
import { type HotkeyRow } from './hotkey-format.ts';
|
|
5
6
|
/** Presentation state owned by the terminal while a human prompt is active. */
|
|
@@ -9,10 +10,24 @@ export interface PromptSelectorState {
|
|
|
9
10
|
checked: ReadonlySet<number>;
|
|
10
11
|
/** Requested first document row for full-screen review surfaces. */
|
|
11
12
|
documentScroll?: number;
|
|
13
|
+
documentAnchor?: TuiDocumentPosition | undefined;
|
|
14
|
+
documentWordWrap?: boolean;
|
|
15
|
+
documentColumn?: number;
|
|
16
|
+
documentQuery?: string;
|
|
17
|
+
documentInput?: 'search' | 'line' | undefined;
|
|
18
|
+
documentError?: string | undefined;
|
|
19
|
+
documentOrigin?: TuiDocumentPosition;
|
|
20
|
+
documentOriginalQuery?: string;
|
|
21
|
+
documentTarget?: number | undefined;
|
|
22
|
+
collapsed?: ReadonlySet<string>;
|
|
23
|
+
previewScroll?: number;
|
|
12
24
|
/** Whether a rejected plan is collecting optional revision feedback. */
|
|
13
25
|
feedback?: boolean;
|
|
26
|
+
/** Editing or Take time paused this local countdown. */
|
|
27
|
+
waitHeld?: boolean;
|
|
14
28
|
}
|
|
15
29
|
export interface PromptSelectorFrame {
|
|
30
|
+
image?: import('../chrome/terminal-images.ts').ImagePlacement;
|
|
16
31
|
lines: string[];
|
|
17
32
|
cursor: {
|
|
18
33
|
row: number;
|
|
@@ -22,6 +37,7 @@ export interface PromptSelectorFrame {
|
|
|
22
37
|
start: number;
|
|
23
38
|
maxStart: number;
|
|
24
39
|
pageSize: number;
|
|
40
|
+
position?: TuiDocumentPosition;
|
|
25
41
|
};
|
|
26
42
|
cursorVisible?: boolean;
|
|
27
43
|
}
|
|
@@ -33,7 +49,17 @@ type PromptOption = NonNullable<TuiPrompt['options']>[number];
|
|
|
33
49
|
/** Preserve editor indices and line breaks while hiding every entered cell. */
|
|
34
50
|
export declare function maskPromptSecret(input: string): string;
|
|
35
51
|
/** Options matching the current full-screen selector query. */
|
|
36
|
-
export declare function filteredPromptOptions(request: TuiPrompt, query: string): readonly PromptOption[];
|
|
52
|
+
export declare function filteredPromptOptions(request: TuiPrompt, query: string, collapsed?: ReadonlySet<string>): readonly PromptOption[];
|
|
53
|
+
/** Keep the same live choice selected as entries arrive, move, or disappear. */
|
|
54
|
+
export declare function refreshPromptOptions<T extends PromptSelectorState>(state: T, options: NonNullable<TuiPrompt['options']>, query: string): T;
|
|
55
|
+
/** Page movement follows the list space remaining after wrapped action hints. */
|
|
56
|
+
export declare function promptTreePageSize(request: TuiPrompt, width: number, height: number): number;
|
|
57
|
+
/** A hierarchical choice with an independently scrollable content preview. */
|
|
58
|
+
export declare function renderPromptTreePage(state: PromptSelectorState, theme: Theme, width: number, height: number, input: string, inputCursor: number, appName: string): PromptSelectorFrame;
|
|
59
|
+
/** Fold/unfold a subtree or move to its parent, preserving selection by value. */
|
|
60
|
+
export declare function movePromptTree(state: PromptSelectorState, direction: 'left' | 'right', query: string): PromptSelectorState;
|
|
61
|
+
/** Start on a matching node instead of a context-only ancestor. */
|
|
62
|
+
export declare function searchPromptSelection(state: PromptSelectorState, query: string): PromptSelectorState;
|
|
37
63
|
/** Visible option window centered around the selected row. */
|
|
38
64
|
export declare function promptSelectorVisibleRange(count: number, selected: number, maxVisible?: number): {
|
|
39
65
|
start: number;
|
|
@@ -41,7 +67,11 @@ export declare function promptSelectorVisibleRange(count: number, selected: numb
|
|
|
41
67
|
};
|
|
42
68
|
/** Render an OMP-style full-height searchable selector with one outer frame. */
|
|
43
69
|
export declare function renderPromptSelectorPage(state: PromptSelectorState, theme: Theme, width: number, height: number, input: string, inputCursor: number, appName: string): PromptSelectorFrame;
|
|
44
|
-
/**
|
|
70
|
+
/** Reserve a bordered, padded rectangle; graphics never become display-row content. */
|
|
71
|
+
export declare function renderImagePreviewPage(state: PromptSelectorState, theme: Theme, width: number, height: number, appName: string, protocol?: ImageProtocol, cell?: {
|
|
72
|
+
width: number;
|
|
73
|
+
height: number;
|
|
74
|
+
}): PromptSelectorFrame;
|
|
45
75
|
export declare function renderPlanReviewPage(state: PromptSelectorState, theme: Theme, width: number, height: number, input: string, inputCursor: number, appName: string): PromptSelectorFrame;
|
|
46
76
|
/** Render the prompt card and its answer editor as one bottom-of-screen overlay. */
|
|
47
77
|
export declare function renderPromptSelector(state: PromptSelectorState, theme: Theme, width: number, input: string, inputCursor: number, maxVisible?: number): PromptSelectorFrame;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/** Interactive terminal selector used by resume, approval, and user questions. */
|
|
2
|
+
import { imageSize } from "../chrome/terminal-images.js";
|
|
3
|
+
import { documentLayout, documentMatches, documentModel, documentPosition, documentStart } from "./document-reader.js";
|
|
4
|
+
import { promptTreeRows } from "./prompt-tree.js";
|
|
5
|
+
import { rankSearchResults } from "../input/fuzzy-search.js";
|
|
2
6
|
import { renderEditor, renderFramedBlock } from "../chrome/box.js";
|
|
3
7
|
import { renderMarkdown } from "../chrome/markdown.js";
|
|
4
8
|
import { BOX, SYMBOL } from "../chrome/theme.js";
|
|
5
|
-
import { padToWidth, truncateToWidth, visibleWidth } from "../chrome/width.js";
|
|
9
|
+
import { padToWidth, truncateToWidth, visibleWidth, wrapText } from "../chrome/width.js";
|
|
6
10
|
import { formatHotkeyKeys, formatOverlayHint } from "./hotkey-format.js";
|
|
7
11
|
/** Maximum option rows retained in the prompt overlay before it windows. */
|
|
8
12
|
export const PROMPT_SELECTOR_MAX_VISIBLE = 10;
|
|
@@ -22,6 +26,8 @@ const HOTKEY_SUBMIT_NEWLINE = { keys: 'Ctrl+J', action: 'Submit — send revisio
|
|
|
22
26
|
const HOTKEY_BACK = { keys: 'Esc', action: 'Back — leave revision feedback' };
|
|
23
27
|
const HOTKEY_CANCEL = { keys: 'Esc', action: 'Cancel — dismiss the prompt' };
|
|
24
28
|
const HOTKEY_CANCEL_CTRL = { keys: 'Ctrl+C', action: 'Cancel — dismiss the prompt at any step' };
|
|
29
|
+
const HOTKEY_TAKE_TIME = { keys: 'Ctrl+T', action: 'Take time — pause the question countdown' };
|
|
30
|
+
const HOTKEY_SKIP = { keys: 'Ctrl+S', action: 'Skip this question explicitly' };
|
|
25
31
|
/** Keys the prompt selector accepts; `/help` and its bottom hints read this list. */
|
|
26
32
|
export const PROMPT_SELECTOR_HOTKEYS = [
|
|
27
33
|
HOTKEY_TEXT,
|
|
@@ -37,19 +43,141 @@ export const PROMPT_SELECTOR_HOTKEYS = [
|
|
|
37
43
|
HOTKEY_BACK,
|
|
38
44
|
HOTKEY_CANCEL,
|
|
39
45
|
HOTKEY_CANCEL_CTRL,
|
|
46
|
+
HOTKEY_TAKE_TIME,
|
|
47
|
+
HOTKEY_SKIP,
|
|
40
48
|
];
|
|
41
49
|
/** Preserve editor indices and line breaks while hiding every entered cell. */
|
|
42
50
|
export function maskPromptSecret(input) {
|
|
43
51
|
return input.replace(/[^\r\n]/g, '•');
|
|
44
52
|
}
|
|
45
53
|
/** Options matching the current full-screen selector query. */
|
|
46
|
-
export function filteredPromptOptions(request, query) {
|
|
54
|
+
export function filteredPromptOptions(request, query, collapsed) {
|
|
55
|
+
if (request.presentation === 'fullscreen-tree')
|
|
56
|
+
return promptTreeRows(request, collapsed, query).map(row => row.option);
|
|
47
57
|
const options = request.options ?? [];
|
|
48
|
-
|
|
49
|
-
if (request.filterable !== true || needle === '')
|
|
58
|
+
if (request.filterable !== true)
|
|
50
59
|
return options;
|
|
51
|
-
return options
|
|
52
|
-
.
|
|
60
|
+
return rankSearchResults(options, query, option => [option.label, option.value, option.preview, option.description, option.badge?.label]
|
|
61
|
+
.filter((value) => value !== undefined));
|
|
62
|
+
}
|
|
63
|
+
/** Keep the same live choice selected as entries arrive, move, or disappear. */
|
|
64
|
+
export function refreshPromptOptions(state, options, query) {
|
|
65
|
+
const previous = filteredPromptOptions(state.request, query, state.collapsed)[state.selected];
|
|
66
|
+
const request = { ...state.request, options };
|
|
67
|
+
const filtered = filteredPromptOptions(request, query, state.collapsed);
|
|
68
|
+
const found = filtered.findIndex(option => (option.value ?? option.label) === (previous?.value ?? previous?.label));
|
|
69
|
+
const selected = found < 0 ? Math.max(0, Math.min(state.selected, filtered.length - 1)) : found;
|
|
70
|
+
const checkedValues = new Set((state.request.options ?? []).filter((_, at) => state.checked.has(at)).map(option => option.value ?? option.label));
|
|
71
|
+
return { ...state, request, selected, checked: new Set(options.flatMap((option, at) => checkedValues.has(option.value ?? option.label) ? [at] : [])),
|
|
72
|
+
...((filtered[selected]?.value ?? filtered[selected]?.label) === (previous?.value ?? previous?.label) ? {} : { previewScroll: 0 }) };
|
|
73
|
+
}
|
|
74
|
+
const previewCache = new WeakMap();
|
|
75
|
+
function treePreview(option, theme, width) {
|
|
76
|
+
if (option === undefined)
|
|
77
|
+
return ['No matching conversation turns.'];
|
|
78
|
+
let cache = previewCache.get(option);
|
|
79
|
+
if (cache === undefined) {
|
|
80
|
+
cache = new Map();
|
|
81
|
+
previewCache.set(option, cache);
|
|
82
|
+
}
|
|
83
|
+
const key = `${width}:${theme.name}:${theme.colors}:${theme.trueColor}`;
|
|
84
|
+
const cached = cache.get(key);
|
|
85
|
+
if (cached !== undefined)
|
|
86
|
+
return cached;
|
|
87
|
+
const lines = renderMarkdown(option.preview ?? option.label, theme, width);
|
|
88
|
+
if (cache.size >= 4)
|
|
89
|
+
cache.clear();
|
|
90
|
+
cache.set(key, lines);
|
|
91
|
+
return lines;
|
|
92
|
+
}
|
|
93
|
+
function treePageLayout(request, width, height) {
|
|
94
|
+
const actions = (request.actions ?? []).map(item => `${item.key} ${item.label}`).join(' · ');
|
|
95
|
+
const hint = `↑↓ · ←→ fold${width >= 90 ? ' · type search' : ''}${actions === '' ? '' : ` · ${actions}`}${width >= 90 ? ' · Ctrl+↑↓ preview' : ''}`;
|
|
96
|
+
const hints = wrapText(hint, width - 4).slice(0, Math.max(1, Math.floor((height - 6) / 2)));
|
|
97
|
+
const middle = height - 6 - hints.length;
|
|
98
|
+
const listHeight = width >= 90 ? middle : Math.max(1, Math.floor((middle - 1) / 2));
|
|
99
|
+
const previewHeight = width >= 90 ? middle : middle - listHeight - 1;
|
|
100
|
+
return { hints, middle, listHeight, previewHeight };
|
|
101
|
+
}
|
|
102
|
+
/** Page movement follows the list space remaining after wrapped action hints. */
|
|
103
|
+
export function promptTreePageSize(request, width, height) {
|
|
104
|
+
return height < 10 || width < 20 ? Math.max(1, height - 8) : treePageLayout(request, width, height).listHeight;
|
|
105
|
+
}
|
|
106
|
+
/** A hierarchical choice with an independently scrollable content preview. */
|
|
107
|
+
export function renderPromptTreePage(state, theme, width, height, input, inputCursor, appName) {
|
|
108
|
+
if (height < 10 || width < 20)
|
|
109
|
+
return renderPromptSelector(state, theme, width, input, inputCursor, Math.max(1, height - 8));
|
|
110
|
+
const rows = promptTreeRows(state.request, state.collapsed, input);
|
|
111
|
+
const selected = Math.max(0, Math.min(state.selected, rows.length - 1));
|
|
112
|
+
const option = rows[selected]?.option;
|
|
113
|
+
const split = width >= 90;
|
|
114
|
+
const inner = width - 4;
|
|
115
|
+
const { hints, middle, listHeight, previewHeight } = treePageLayout(state.request, width, height);
|
|
116
|
+
const listWidth = split ? Math.floor((inner - 3) * 0.45) : inner;
|
|
117
|
+
const previewWidth = split ? inner - listWidth - 3 : inner;
|
|
118
|
+
const range = promptSelectorVisibleRange(rows.length, selected, listHeight);
|
|
119
|
+
const list = [];
|
|
120
|
+
for (let at = range.start; at < range.end; at++) {
|
|
121
|
+
const row = rows[at];
|
|
122
|
+
const marker = at === selected ? theme.fg('accent', SYMBOL.cursor + ' ') : ' ';
|
|
123
|
+
const fold = row.expandable ? state.collapsed?.has(row.option.value ?? row.option.label) && input === '' ? '▸ ' : '▾ ' : ' ';
|
|
124
|
+
const badge = row.option.badge?.label === undefined ? '' : `[${row.option.badge.label}] `;
|
|
125
|
+
const text = badge + row.option.label;
|
|
126
|
+
const prefixLimit = Math.max(1, Math.floor(listWidth / 3));
|
|
127
|
+
const prefix = row.prefix.length <= prefixLimit ? row.prefix : '…' + row.prefix.slice(-(prefixLimit - 1));
|
|
128
|
+
list.push(fit(marker + theme.fg('dim', prefix + fold) + (at === selected ? theme.fg('accent', text) : text), listWidth));
|
|
129
|
+
}
|
|
130
|
+
if (rows.length === 0)
|
|
131
|
+
list.push(fit(theme.fg('dim', state.request.emptyText ?? 'No matching conversation turns.'), listWidth));
|
|
132
|
+
const preview = treePreview(option, theme, Math.max(1, previewWidth));
|
|
133
|
+
const maxScroll = Math.max(0, preview.length - previewHeight);
|
|
134
|
+
const scroll = Math.max(0, Math.min(state.previewScroll ?? 0, maxScroll));
|
|
135
|
+
const lines = [pageTop(theme, width, appName), pageRow(theme, theme.bold(state.request.title), width),
|
|
136
|
+
pageRow(theme, theme.fg('dim', '> ') + input, width), pageDivider(theme, width)];
|
|
137
|
+
if (split) {
|
|
138
|
+
for (let at = 0; at < middle; at++)
|
|
139
|
+
lines.push(pageRow(theme, fit(list[at] ?? '', listWidth) + theme.fg('border', ' │ ') + fit(preview[scroll + at] ?? '', previewWidth), width));
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
for (let at = 0; at < listHeight; at++)
|
|
143
|
+
lines.push(pageRow(theme, list[at] ?? '', width));
|
|
144
|
+
lines.push(pageDivider(theme, width));
|
|
145
|
+
for (let at = 0; at < previewHeight; at++)
|
|
146
|
+
lines.push(pageRow(theme, preview[scroll + at] ?? '', width));
|
|
147
|
+
}
|
|
148
|
+
const action = option?.submitLabel ?? state.request.submitLabel ?? 'select';
|
|
149
|
+
lines.push(pageRow(theme, theme.fg('dim', `Enter ${action} · Esc back`), width), ...hints.map(hint => pageRow(theme, theme.fg('dim', hint), width)), pageBottom(theme, width));
|
|
150
|
+
return { lines, cursor: { row: 2, column: Math.min(width - 3, 4 + visibleWidth(input.slice(0, inputCursor))) },
|
|
151
|
+
document: { start: scroll, maxStart: maxScroll, pageSize: previewHeight }, cursorVisible: true };
|
|
152
|
+
}
|
|
153
|
+
/** Fold/unfold a subtree or move to its parent, preserving selection by value. */
|
|
154
|
+
export function movePromptTree(state, direction, query) {
|
|
155
|
+
const rows = promptTreeRows(state.request, state.collapsed, query);
|
|
156
|
+
const row = rows[state.selected];
|
|
157
|
+
if (row === undefined)
|
|
158
|
+
return state;
|
|
159
|
+
const value = row.option.value ?? row.option.label;
|
|
160
|
+
const collapsed = new Set(state.collapsed);
|
|
161
|
+
if (direction === 'left' && row.expandable && !collapsed.has(value) && query === '')
|
|
162
|
+
collapsed.add(value);
|
|
163
|
+
else if (direction === 'right' && collapsed.has(value))
|
|
164
|
+
collapsed.delete(value);
|
|
165
|
+
else if (direction === 'left') {
|
|
166
|
+
const parent = rows.findIndex(item => (item.option.value ?? item.option.label) === row.option.parentValue);
|
|
167
|
+
return parent < 0 ? state : { ...state, selected: parent, previewScroll: 0 };
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
const child = rows.findIndex(item => item.option.parentValue === value);
|
|
171
|
+
return child < 0 ? state : { ...state, selected: child, previewScroll: 0 };
|
|
172
|
+
}
|
|
173
|
+
const next = promptTreeRows(state.request, collapsed, query).findIndex(item => (item.option.value ?? item.option.label) === value);
|
|
174
|
+
return { ...state, collapsed, selected: Math.max(0, next), previewScroll: 0 };
|
|
175
|
+
}
|
|
176
|
+
/** Start on a matching node instead of a context-only ancestor. */
|
|
177
|
+
export function searchPromptSelection(state, query) {
|
|
178
|
+
const selected = state.request.presentation === 'fullscreen-tree'
|
|
179
|
+
? Math.max(0, promptTreeRows(state.request, state.collapsed, query).findIndex(row => row.matched)) : 0;
|
|
180
|
+
return { ...state, selected, previewScroll: 0 };
|
|
53
181
|
}
|
|
54
182
|
/** Visible option window centered around the selected row. */
|
|
55
183
|
export function promptSelectorVisibleRange(count, selected, maxVisible = PROMPT_SELECTOR_MAX_VISIBLE) {
|
|
@@ -116,7 +244,10 @@ export function renderPromptSelectorPage(state, theme, width, height, input, inp
|
|
|
116
244
|
const options = filteredPromptOptions(state.request, input);
|
|
117
245
|
const selected = Math.max(0, Math.min(state.selected, Math.max(0, options.length - 1)));
|
|
118
246
|
const compact = state.request.optionLayout === 'compact';
|
|
119
|
-
const
|
|
247
|
+
const actionHints = (state.request.actions ?? []).map(action => `${action.key} ${action.label}`).join(' · ');
|
|
248
|
+
const hints = wrapText(formatOverlayHint([HOTKEY_TEXT, HOTKEY_NAVIGATE, HOTKEY_SELECT, HOTKEY_CANCEL])
|
|
249
|
+
+ (actionHints === '' ? '' : ' · ' + actionHints), width - 4).slice(0, Math.max(1, Math.floor((height - 6) / 2)));
|
|
250
|
+
const fixedRows = (compact ? 9 : 11) + hints.length - 1;
|
|
120
251
|
const visibleCount = compact
|
|
121
252
|
? Math.max(1, pageHeight - fixedRows)
|
|
122
253
|
: Math.max(1, Math.floor((pageHeight - fixedRows) / 4));
|
|
@@ -169,48 +300,135 @@ export function renderPromptSelectorPage(state, theme, width, height, input, inp
|
|
|
169
300
|
lines.push(pageRow(theme, ' ' + description + separator + badge, width), pageRow(theme, '', width));
|
|
170
301
|
}
|
|
171
302
|
}
|
|
172
|
-
const footerRows =
|
|
303
|
+
const footerRows = 3 + hints.length;
|
|
173
304
|
const targetBeforeFooter = Math.max(0, pageHeight - footerRows);
|
|
174
305
|
if (lines.length > targetBeforeFooter)
|
|
175
306
|
lines.length = targetBeforeFooter;
|
|
176
307
|
while (lines.length < targetBeforeFooter)
|
|
177
308
|
lines.push(pageRow(theme, '', width));
|
|
178
|
-
const position = options.length === 0 ? '' :
|
|
179
|
-
|
|
180
|
-
const hint = `[${formatOverlayHint([HOTKEY_TEXT, HOTKEY_NAVIGATE, HOTKEY_SELECT, HOTKEY_CANCEL])}${actions === '' ? '' : ' · ' + actions}${position}]`;
|
|
181
|
-
lines.push(pageRow(theme, '', width), pageRow(theme, theme.fg('dim', hint), width), pageRow(theme, '', width), pageBottom(theme, width));
|
|
309
|
+
const position = options.length === 0 ? '' : `${selected + 1}/${options.length}`;
|
|
310
|
+
lines.push(pageRow(theme, theme.fg('dim', position.trim()), width), ...hints.map(hint => pageRow(theme, theme.fg('dim', hint), width)), pageRow(theme, '', width), pageBottom(theme, width));
|
|
182
311
|
const cursorColumn = Math.min(Math.max(1, width - 3), 4 + visibleWidth(input.slice(0, inputCursor)));
|
|
183
312
|
return {
|
|
184
313
|
lines,
|
|
185
314
|
cursor: { row: searchRow, column: cursorColumn },
|
|
186
315
|
};
|
|
187
316
|
}
|
|
188
|
-
|
|
317
|
+
const documentCache = new WeakMap();
|
|
318
|
+
function documentRows(request, theme, width) {
|
|
319
|
+
let cache = documentCache.get(request);
|
|
320
|
+
if (cache === undefined) {
|
|
321
|
+
cache = new Map();
|
|
322
|
+
documentCache.set(request, cache);
|
|
323
|
+
}
|
|
324
|
+
const key = `${width}:${theme.name}:${theme.getFgAnsi('accent')}`;
|
|
325
|
+
const cached = cache.get(key);
|
|
326
|
+
if (cached !== undefined)
|
|
327
|
+
return cached;
|
|
328
|
+
const lines = renderMarkdown(request.detail ?? '', theme, width);
|
|
329
|
+
if (cache.size >= 4)
|
|
330
|
+
cache.clear();
|
|
331
|
+
cache.set(key, lines);
|
|
332
|
+
return lines;
|
|
333
|
+
}
|
|
334
|
+
/** Render a bounded, scrollable Markdown document with fixed actions. */
|
|
335
|
+
function documentActionRows(state, theme, width, pageHeight) {
|
|
336
|
+
const actionRows = [];
|
|
337
|
+
let actionRow = '';
|
|
338
|
+
const actionWidth = Math.max(1, width - 5);
|
|
339
|
+
for (const [index, option] of (state.request.options ?? []).entries()) {
|
|
340
|
+
const label = truncateToWidth(`${index === state.selected ? '› ' : ' '}[ ${option.label} ]`, actionWidth);
|
|
341
|
+
if (actionRow !== '' && visibleWidth(actionRow) + 3 + visibleWidth(label) > actionWidth) {
|
|
342
|
+
actionRows.push(actionRow);
|
|
343
|
+
actionRow = '';
|
|
344
|
+
}
|
|
345
|
+
const painted = index === state.selected ? theme.bold(theme.fg('accent', label)) : theme.fg('muted', label);
|
|
346
|
+
actionRow += (actionRow === '' ? '' : theme.fg('dim', ' ')) + painted;
|
|
347
|
+
}
|
|
348
|
+
actionRows.push(actionRow);
|
|
349
|
+
if (actionRows.length > Math.max(1, pageHeight - 9)) {
|
|
350
|
+
const selected = state.request.options?.[state.selected];
|
|
351
|
+
actionRows.splice(0, actionRows.length, selected === undefined ? ''
|
|
352
|
+
: theme.bold(theme.fg('accent', truncateToWidth(`› [ ${selected.label} ]`, actionWidth))));
|
|
353
|
+
}
|
|
354
|
+
return actionRows;
|
|
355
|
+
}
|
|
356
|
+
/** Reserve a bordered, padded rectangle; graphics never become display-row content. */
|
|
357
|
+
export function renderImagePreviewPage(state, theme, width, height, appName, protocol, cell) {
|
|
358
|
+
const image = state.request.documentImage;
|
|
359
|
+
if (width < 16 || height < 10)
|
|
360
|
+
return renderPromptSelector({ ...state, request: { ...state.request,
|
|
361
|
+
detail: image.description + '\nEnlarge the terminal or use Open to view the image.' } }, theme, width, '', 0, Math.max(1, height - 8));
|
|
362
|
+
const actions = documentActionRows(state, theme, width, height);
|
|
363
|
+
const hints = 'Tab/←→ actions · Enter activate · Esc back';
|
|
364
|
+
const bodyRows = Math.max(1, height - 8 - actions.length);
|
|
365
|
+
const lines = [pageTop(theme, width, appName + ' · ' + state.request.title), pageRow(theme, state.request.question, width),
|
|
366
|
+
pageRow(theme, theme.fg('muted', image.description), width), pageDivider(theme, width)];
|
|
367
|
+
const top = lines.length;
|
|
368
|
+
const canOpen = state.request.options?.some(option => option.value === 'open') === true;
|
|
369
|
+
const fallback = protocol === undefined ? wrapText('Inline images are unavailable in this terminal. '
|
|
370
|
+
+ (canOpen ? 'Use Open to view the original.' : 'This attachment has no local original to open.'), width - 8) : [];
|
|
371
|
+
for (let at = 0; at < bodyRows; at++)
|
|
372
|
+
lines.push(pageRow(theme, ' ' + (fallback[at] ?? ''), width));
|
|
373
|
+
lines.push(pageDivider(theme, width), pageRow(theme, theme.fg('muted', (state.request.detail ?? '').replace(/[\r\n]+/gu, ' ')), width), ...actions.map(row => pageRow(theme, ' ' + row, width)), pageRow(theme, theme.fg('dim', hints), width), pageBottom(theme, width));
|
|
374
|
+
const size = imageSize(image, width - 8, bodyRows, cell);
|
|
375
|
+
return { lines, cursor: { row: height - 1, column: 0 }, cursorVisible: false,
|
|
376
|
+
...(protocol === undefined ? {} : { image: { image, protocol, row: top + Math.floor((bodyRows - size.rows) / 2),
|
|
377
|
+
column: 4 + Math.floor((width - 8 - size.columns) / 2), ...size } }) };
|
|
378
|
+
}
|
|
189
379
|
export function renderPlanReviewPage(state, theme, width, height, input, inputCursor, appName) {
|
|
190
380
|
const pageHeight = Math.max(1, height);
|
|
191
|
-
|
|
192
|
-
|
|
381
|
+
const source = state.request.documentSource;
|
|
382
|
+
if ((source === undefined && (pageHeight < 10 || width < 24)) || pageHeight < 7 || width < 12) {
|
|
383
|
+
return renderPromptSelector(source === undefined ? state : { ...state, request: { ...state.request, detail: source.text } }, theme, width, input, inputCursor, Math.max(1, pageHeight - 8));
|
|
193
384
|
}
|
|
194
385
|
const feedback = state.feedback === true;
|
|
195
|
-
const
|
|
196
|
-
const
|
|
386
|
+
const actionRows = documentActionRows(state, theme, width, pageHeight);
|
|
387
|
+
const readerInput = source !== undefined && state.documentInput !== undefined;
|
|
388
|
+
let readerHints = source === undefined ? [] : wrapText(readerInput ? 'Enter apply · Esc cancel'
|
|
389
|
+
: 'W wrap · Alt+←→ pan · ↑↓/PgUp/PgDn scroll · ' + (state.request.documentTail === true ? 'Home start · End follow' : 'Home/End edges') + ' · / find · Ctrl+N/P match · G line' + (source.diff ? ' · [/] hunk' : '')
|
|
390
|
+
+ ' · Tab/←→ actions · Enter activate · ' + (state.request.actions ?? []).map(action => `${action.key.toUpperCase()} ${action.label}`).join(' · ') + ' · Esc back', width - 4);
|
|
391
|
+
const maxHints = Math.max(1, Math.min(4, pageHeight - 8 - actionRows.length));
|
|
392
|
+
if (readerHints.length > maxHints)
|
|
393
|
+
readerHints = [...readerHints.slice(0, maxHints - 1), 'Tab actions · Enter · Esc back'];
|
|
394
|
+
const compactReader = source !== undefined && pageHeight < 10;
|
|
395
|
+
if (compactReader)
|
|
396
|
+
readerHints = [];
|
|
397
|
+
const footerRows = feedback ? 5 : actionRows.length + 3 + (source === undefined ? 0 : readerHints.length);
|
|
398
|
+
const bodyRows = Math.max(1, pageHeight - (source === undefined ? 5 : compactReader ? 2 : 3) - footerRows);
|
|
197
399
|
const markdownWidth = Math.max(1, width - 6);
|
|
198
|
-
const
|
|
400
|
+
const layout = source === undefined ? undefined : documentLayout(source, theme, markdownWidth, {
|
|
401
|
+
wordWrap: state.documentWordWrap ?? state.request.documentPosition?.wordWrap ?? true,
|
|
402
|
+
column: state.documentColumn ?? state.request.documentPosition?.column ?? 0,
|
|
403
|
+
});
|
|
404
|
+
const document = layout?.rows ?? documentRows(state.request, theme, markdownWidth);
|
|
199
405
|
const maxStart = Math.max(0, document.length - bodyRows);
|
|
200
|
-
const start = Math.max(0, Math.min(state.documentScroll
|
|
406
|
+
const start = Math.max(0, Math.min(state.documentScroll === Number.POSITIVE_INFINITY ? maxStart : layout !== undefined && state.documentAnchor !== undefined
|
|
407
|
+
? documentStart(layout, state.documentAnchor) : state.documentScroll ?? state.request.documentPosition?.row ?? 0, maxStart));
|
|
201
408
|
const visible = document.slice(start, start + bodyRows);
|
|
409
|
+
const query = state.documentQuery ?? '';
|
|
410
|
+
const matches = source === undefined ? [] : documentMatches(source, query);
|
|
411
|
+
const matching = new Set(matches);
|
|
412
|
+
if (layout !== undefined)
|
|
413
|
+
for (let at = 0; at < visible.length; at++) {
|
|
414
|
+
if (matching.has(layout.sourceRows[start + at] ?? -1)) {
|
|
415
|
+
const row = visible[at] ?? '';
|
|
416
|
+
visible[at] = theme.inverse(layout.gutterWidth === 0 ? row : '›' + row.slice(1));
|
|
417
|
+
}
|
|
418
|
+
}
|
|
202
419
|
while (visible.length < bodyRows)
|
|
203
420
|
visible.push('');
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
421
|
+
const subject = state.request.presentation === 'document' ? 'document' : 'plan';
|
|
422
|
+
if (source === undefined && start > 0)
|
|
423
|
+
visible[0] = theme.fg('dim', `… ↑ ${start} earlier ${subject} lines`);
|
|
424
|
+
if (source === undefined && start + bodyRows < document.length) {
|
|
425
|
+
visible[Math.max(0, visible.length - 1)] = theme.fg('dim', `… ↓ ${document.length - start - bodyRows} later ${subject} lines`);
|
|
208
426
|
}
|
|
209
427
|
const lines = [
|
|
210
|
-
pageTop(theme, width, `${appName} · ${state.request.title}`),
|
|
211
|
-
pageRow(theme, '', width),
|
|
212
|
-
pageRow(theme, ' ' + theme.bold(state.request.question), width),
|
|
213
|
-
pageRow(theme, '', width),
|
|
428
|
+
pageTop(theme, width, `${appName} · ${compactReader ? state.request.question : state.request.title}`),
|
|
429
|
+
...(source === undefined ? [pageRow(theme, '', width)] : []),
|
|
430
|
+
...(compactReader ? [] : [pageRow(theme, ' ' + theme.bold(state.request.question), width)]),
|
|
431
|
+
...(source === undefined ? [pageRow(theme, '', width)] : []),
|
|
214
432
|
pageDivider(theme, width),
|
|
215
433
|
...visible.map(line => pageRow(theme, ' ' + line, width)),
|
|
216
434
|
pageDivider(theme, width),
|
|
@@ -234,29 +452,49 @@ export function renderPlanReviewPage(state, theme, width, height, input, inputCu
|
|
|
234
452
|
};
|
|
235
453
|
}
|
|
236
454
|
else {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
455
|
+
if (source !== undefined) {
|
|
456
|
+
const row = layout?.sourceRows[start] ?? 0;
|
|
457
|
+
const model = documentModel(source);
|
|
458
|
+
const line = model.numbers[row]?.next ?? model.numbers[row]?.old;
|
|
459
|
+
const position = source.diff ? `Diff row ${row + 1}/${model.lines.length}` : `Line ${line ?? 1}/${(source.firstLine ?? 1) + model.lines.length - 1}`;
|
|
460
|
+
const following = state.request.documentTail !== true ? '' : state.documentScroll === Number.POSITIVE_INFINITY ? ' · Following' : ' · Paused';
|
|
461
|
+
const horizontal = layout?.wordWrap === false ? ` · No wrap · Col ${layout.column + 1}` : '';
|
|
462
|
+
const match = matches.indexOf(state.documentTarget ?? row);
|
|
463
|
+
const search = query === '' ? '' : ` · ${match < 0 ? matches.length : `${match + 1}/${matches.length}`} matching lines · “${query}”`;
|
|
464
|
+
const label = state.documentInput === 'search' ? 'Find: ' : 'Line: ';
|
|
465
|
+
const value = input.replace(/\r?\n/gu, ' ');
|
|
466
|
+
const status = (readerInput ? label + value + (state.documentError === undefined ? '' : ` · ${state.documentError}`)
|
|
467
|
+
: position + horizontal + following + (source.status === undefined ? '' : ` · ${source.status}`) + search + (state.documentError === undefined ? '' : ` · ${state.documentError}`)).replace(/[\r\n]+/gu, ' ');
|
|
468
|
+
cursor = { row: lines.length, column: Math.min(width - 3, 2 + visibleWidth(label + value.slice(0, inputCursor))) };
|
|
469
|
+
lines.push(pageRow(theme, theme.fg('muted', status), width));
|
|
470
|
+
}
|
|
471
|
+
lines.push(...actionRows.map(row => pageRow(theme, ' ' + row, width)));
|
|
472
|
+
const shortcuts = state.request.presentation === 'document' && state.request.actions?.length
|
|
473
|
+
? 'Tab/←→ select · Enter activate · ' + state.request.actions.map(action => `${action.key.toUpperCase()} ${action.label}`).join(' · ') + ' · Esc back'
|
|
474
|
+
: formatOverlayHint([HOTKEY_PAGE, HOTKEY_NAVIGATE_TAB, HOTKEY_SELECT, HOTKEY_CANCEL]);
|
|
475
|
+
lines.push(...(source === undefined ? [`[${shortcuts}]`] : readerHints).map(hint => pageRow(theme, theme.fg('dim', hint), width)));
|
|
246
476
|
lines.push(pageBottom(theme, width));
|
|
247
477
|
}
|
|
248
478
|
return {
|
|
249
479
|
lines,
|
|
250
480
|
cursor,
|
|
251
|
-
document: { start, maxStart, pageSize: Math.max(1, bodyRows - 1)
|
|
252
|
-
|
|
481
|
+
document: { start, maxStart, pageSize: Math.max(1, bodyRows - 1),
|
|
482
|
+
...(layout === undefined ? state.request.presentation === 'document' ? { position: { row: start, wrap: 0, query: '' } } : {} : { position: { ...documentPosition(layout, start, query),
|
|
483
|
+
...(state.request.documentTail === true ? { following: state.documentScroll === Number.POSITIVE_INFINITY } : {}) } }) },
|
|
484
|
+
cursorVisible: feedback || readerInput,
|
|
253
485
|
};
|
|
254
486
|
}
|
|
255
487
|
/** Render the prompt card and its answer editor as one bottom-of-screen overlay. */
|
|
256
488
|
export function renderPromptSelector(state, theme, width, input, inputCursor, maxVisible = PROMPT_SELECTOR_MAX_VISIBLE) {
|
|
257
|
-
const options = state.request
|
|
489
|
+
const options = filteredPromptOptions(state.request, input, state.collapsed);
|
|
258
490
|
const contentWidth = Math.max(1, width - 4);
|
|
259
491
|
const body = [state.request.question];
|
|
492
|
+
if (state.request.wait !== undefined) {
|
|
493
|
+
const remaining = Math.max(0, Math.ceil((state.request.wait.deadline - Date.now()) / 1_000));
|
|
494
|
+
body.push(theme.fg('dim', state.waitHeld === true
|
|
495
|
+
? 'Take your time · waiting for your answer'
|
|
496
|
+
: `Continues in ${remaining}s · ${formatHotkeyKeys(HOTKEY_TAKE_TIME)} take time`));
|
|
497
|
+
}
|
|
260
498
|
if (state.request.detail !== undefined && state.request.detail !== '')
|
|
261
499
|
body.push('', state.request.detail);
|
|
262
500
|
if (options.length > 0) {
|
|
@@ -275,7 +513,12 @@ export function renderPromptSelector(state, theme, width, input, inputCursor, ma
|
|
|
275
513
|
: state.request.multiSelect === true
|
|
276
514
|
? `${formatOverlayHint([HOTKEY_NAVIGATE])} · ${formatOverlayHint([HOTKEY_TOGGLE])} · ${select} · ${formatOverlayHint([HOTKEY_CANCEL])}`
|
|
277
515
|
: `${formatOverlayHint([HOTKEY_NAVIGATE])} · ${select} · ${formatOverlayHint([HOTKEY_CANCEL])}`;
|
|
278
|
-
|
|
516
|
+
const dismiss = state.request.dismissLabel;
|
|
517
|
+
const hints = [
|
|
518
|
+
dismiss === undefined ? navigation : navigation.replace(formatOverlayHint([HOTKEY_CANCEL]), `${formatHotkeyKeys(HOTKEY_CANCEL)} ${dismiss.toLowerCase()}`),
|
|
519
|
+
...(state.request.skippable === true ? [formatOverlayHint([HOTKEY_SKIP])] : []),
|
|
520
|
+
];
|
|
521
|
+
body.push('', theme.fg('dim', hints.join(' · ')));
|
|
279
522
|
const card = renderFramedBlock({
|
|
280
523
|
header: state.request.title,
|
|
281
524
|
state: 'warning',
|
|
@@ -313,7 +556,7 @@ export function movePromptSelection(state, next, count = state.request.options?.
|
|
|
313
556
|
if (count === 0)
|
|
314
557
|
return state;
|
|
315
558
|
const selected = (next % count + count) % count;
|
|
316
|
-
return selected === state.selected ? state : { ...state, selected };
|
|
559
|
+
return selected === state.selected ? state : { ...state, selected, previewScroll: 0 };
|
|
317
560
|
}
|
|
318
561
|
/** Toggle the active row for a multi-select prompt. */
|
|
319
562
|
export function togglePromptSelection(state) {
|
|
@@ -328,7 +571,8 @@ export function togglePromptSelection(state) {
|
|
|
328
571
|
}
|
|
329
572
|
/** Resolve the selected labels in stable option order. */
|
|
330
573
|
export function selectedPromptAnswer(state) {
|
|
331
|
-
const options = state.request.
|
|
574
|
+
const options = state.request.presentation === 'fullscreen-tree'
|
|
575
|
+
? filteredPromptOptions(state.request, '', state.collapsed) : state.request.options ?? [];
|
|
332
576
|
if (options.length === 0)
|
|
333
577
|
return null;
|
|
334
578
|
if (state.request.multiSelect !== true) {
|
|
@@ -340,7 +584,7 @@ export function selectedPromptAnswer(state) {
|
|
|
340
584
|
}
|
|
341
585
|
/** Resolve the selected answer after applying a full-screen selector query. */
|
|
342
586
|
export function selectedFilteredPromptAnswer(state, query) {
|
|
343
|
-
const option = filteredPromptOptions(state.request, query)[state.selected];
|
|
587
|
+
const option = filteredPromptOptions(state.request, query, state.collapsed)[state.selected];
|
|
344
588
|
return option?.value ?? option?.label ?? null;
|
|
345
589
|
}
|
|
346
590
|
//# sourceMappingURL=prompt-selector.js.map
|