@agi-fans/dsh-tui 0.21.0 → 0.23.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/LICENSE +26 -0
- package/lib/CHANGELOG.md +356 -1
- package/lib/chrome/box.d.ts +32 -18
- package/lib/chrome/box.js +131 -132
- package/lib/chrome/box.js.map +1 -1
- package/lib/chrome/code-highlight.d.ts +15 -0
- package/lib/chrome/code-highlight.js +61 -5
- package/lib/chrome/code-highlight.js.map +1 -1
- package/lib/chrome/command-output.d.ts +28 -2
- package/lib/chrome/command-output.js +106 -4
- package/lib/chrome/command-output.js.map +1 -1
- package/lib/chrome/goal-bar.js +1 -1
- package/lib/chrome/goal-bar.js.map +1 -1
- package/lib/chrome/main-screen-renderer.d.ts +16 -0
- package/lib/chrome/main-screen-renderer.js +57 -8
- package/lib/chrome/main-screen-renderer.js.map +1 -1
- package/lib/chrome/markdown.d.ts +3 -3
- package/lib/chrome/markdown.js +101 -32
- package/lib/chrome/markdown.js.map +1 -1
- package/lib/chrome/md-style.d.ts +5 -2
- package/lib/chrome/md-style.js +13 -4
- package/lib/chrome/md-style.js.map +1 -1
- package/lib/chrome/relative-time.d.ts +17 -0
- package/lib/chrome/relative-time.js +36 -0
- package/lib/chrome/relative-time.js.map +1 -1
- package/lib/chrome/renderer.d.ts +37 -1
- package/lib/chrome/renderer.js.map +1 -1
- package/lib/chrome/secret-mask.d.ts +35 -0
- package/lib/chrome/secret-mask.js +180 -0
- package/lib/chrome/secret-mask.js.map +1 -0
- package/lib/chrome/status-config.d.ts +161 -51
- package/lib/chrome/status-config.js +237 -126
- package/lib/chrome/status-config.js.map +1 -1
- package/lib/chrome/status-line.d.ts +6 -5
- package/lib/chrome/status-line.js +110 -68
- package/lib/chrome/status-line.js.map +1 -1
- package/lib/chrome/terminal-colors.d.ts +85 -0
- package/lib/chrome/terminal-colors.js +230 -0
- package/lib/chrome/terminal-colors.js.map +1 -0
- package/lib/chrome/terminal-images.d.ts +9 -1
- package/lib/chrome/terminal-images.js +27 -4
- package/lib/chrome/terminal-images.js.map +1 -1
- package/lib/chrome/theme.d.ts +38 -10
- package/lib/chrome/theme.js +537 -542
- package/lib/chrome/theme.js.map +1 -1
- package/lib/chrome/tool-renderers.js +69 -13
- package/lib/chrome/tool-renderers.js.map +1 -1
- package/lib/chrome/tools-list.d.ts +1 -4
- package/lib/chrome/tools-list.js +1 -41
- package/lib/chrome/tools-list.js.map +1 -1
- package/lib/commands/auth-account.d.ts +9 -0
- package/lib/commands/auth-account.js +202 -0
- package/lib/commands/auth-account.js.map +1 -0
- package/lib/commands/auth-ids.d.ts +25 -0
- package/lib/commands/auth-ids.js +27 -0
- package/lib/commands/auth-ids.js.map +1 -0
- package/lib/commands/auth-input.d.ts +34 -0
- package/lib/commands/auth-input.js +96 -0
- package/lib/commands/auth-input.js.map +1 -0
- package/lib/commands/auth-providers.d.ts +39 -0
- package/lib/commands/auth-providers.js +125 -0
- package/lib/commands/auth-providers.js.map +1 -0
- package/lib/commands/auth.d.ts +12 -20
- package/lib/commands/auth.js +264 -627
- package/lib/commands/auth.js.map +1 -1
- package/lib/commands/btw.d.ts +13 -1
- package/lib/commands/btw.js +37 -104
- package/lib/commands/btw.js.map +1 -1
- package/lib/commands/diff.js +23 -112
- package/lib/commands/diff.js.map +1 -1
- package/lib/commands/export.d.ts +0 -1
- package/lib/commands/export.js +98 -57
- package/lib/commands/export.js.map +1 -1
- package/lib/commands/files.d.ts +17 -1
- package/lib/commands/files.js +68 -114
- package/lib/commands/files.js.map +1 -1
- package/lib/commands/integrations.d.ts +12 -1
- package/lib/commands/integrations.js +120 -23
- package/lib/commands/integrations.js.map +1 -1
- package/lib/commands/jobs-browser.d.ts +3 -0
- package/lib/commands/jobs-browser.js +152 -0
- package/lib/commands/jobs-browser.js.map +1 -0
- package/lib/commands/jobs.d.ts +12 -8
- package/lib/commands/jobs.js +65 -14
- package/lib/commands/jobs.js.map +1 -1
- package/lib/commands/model.d.ts +3 -0
- package/lib/commands/model.js +223 -114
- package/lib/commands/model.js.map +1 -1
- package/lib/commands/open-external.d.ts +2 -0
- package/lib/commands/open-external.js +19 -0
- package/lib/commands/open-external.js.map +1 -0
- package/lib/commands/permission.js +70 -60
- package/lib/commands/permission.js.map +1 -1
- package/lib/commands/plugins.js +427 -68
- package/lib/commands/plugins.js.map +1 -1
- package/lib/commands/schedule-catalog.d.ts +12 -0
- package/lib/commands/schedule-catalog.js +41 -0
- package/lib/commands/schedule-catalog.js.map +1 -0
- package/lib/commands/schedule-history.d.ts +4 -0
- package/lib/commands/schedule-history.js +62 -0
- package/lib/commands/schedule-history.js.map +1 -0
- package/lib/commands/schedule.d.ts +16 -9
- package/lib/commands/schedule.js +226 -162
- package/lib/commands/schedule.js.map +1 -1
- package/lib/commands/session-configuration.d.ts +3 -0
- package/lib/commands/session-configuration.js +58 -32
- package/lib/commands/session-configuration.js.map +1 -1
- package/lib/commands/session.js +118 -97
- package/lib/commands/session.js.map +1 -1
- package/lib/commands/terminal.d.ts +14 -8
- package/lib/commands/terminal.js +32 -185
- package/lib/commands/terminal.js.map +1 -1
- package/lib/commands/trajectory.js +4 -1
- package/lib/commands/trajectory.js.map +1 -1
- package/lib/definition.d.ts +226 -29
- package/lib/definition.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/input/actions.d.ts +51 -0
- package/lib/input/actions.js +123 -0
- package/lib/input/actions.js.map +1 -0
- package/lib/input/composer-files.d.ts +2 -0
- package/lib/input/composer-files.js +13 -3
- package/lib/input/composer-files.js.map +1 -1
- package/lib/input/editor.d.ts +0 -10
- package/lib/input/editor.js +11 -9
- package/lib/input/editor.js.map +1 -1
- package/lib/input/image-paste.d.ts +12 -1
- package/lib/input/image-paste.js +86 -1
- package/lib/input/image-paste.js.map +1 -1
- package/lib/input/key-test.d.ts +5 -0
- package/lib/input/key-test.js +19 -0
- package/lib/input/key-test.js.map +1 -0
- package/lib/input/keybindings-config.d.ts +12 -5
- package/lib/input/keybindings-config.js +30 -57
- package/lib/input/keybindings-config.js.map +1 -1
- package/lib/input/keys.d.ts +18 -0
- package/lib/input/keys.js +42 -4
- package/lib/input/keys.js.map +1 -1
- package/lib/input/wheel-scroll.d.ts +46 -0
- package/lib/input/wheel-scroll.js +69 -0
- package/lib/input/wheel-scroll.js.map +1 -0
- package/lib/locale/index.d.ts +6 -0
- package/lib/locale/index.js +32 -0
- package/lib/locale/index.js.map +1 -0
- package/lib/locale/prompt.d.ts +4 -0
- package/lib/locale/prompt.js +24 -0
- package/lib/locale/prompt.js.map +1 -0
- package/lib/locale/zh.d.ts +1114 -0
- package/lib/locale/zh.js +1115 -0
- package/lib/locale/zh.js.map +1 -0
- package/lib/prompt-intents.d.ts +186 -0
- package/lib/prompt-intents.js +131 -0
- package/lib/prompt-intents.js.map +1 -0
- package/lib/runtime/account-settings.d.ts +18 -0
- package/lib/runtime/account-settings.js +241 -0
- package/lib/runtime/account-settings.js.map +1 -0
- package/lib/runtime/agent-profile.d.ts +3 -3
- package/lib/runtime/agent-profile.js +4 -4
- package/lib/runtime/agent-profile.js.map +1 -1
- package/lib/runtime/btw-policy.js +2 -1
- package/lib/runtime/btw-policy.js.map +1 -1
- package/lib/runtime/btw.js +1 -2
- package/lib/runtime/btw.js.map +1 -1
- package/lib/runtime/cancellable.d.ts +75 -0
- package/lib/runtime/cancellable.js +76 -0
- package/lib/runtime/cancellable.js.map +1 -0
- package/lib/runtime/composer-images.d.ts +2 -2
- package/lib/runtime/composer-images.js +7 -6
- package/lib/runtime/composer-images.js.map +1 -1
- package/lib/runtime/composer-shell.d.ts +17 -2
- package/lib/runtime/composer-shell.js +133 -41
- package/lib/runtime/composer-shell.js.map +1 -1
- package/lib/runtime/file-browser.d.ts +19 -0
- package/lib/runtime/file-browser.js +291 -0
- package/lib/runtime/file-browser.js.map +1 -0
- package/lib/runtime/file-recovery-review.d.ts +0 -1
- package/lib/runtime/file-recovery-review.js +29 -30
- package/lib/runtime/file-recovery-review.js.map +1 -1
- package/lib/runtime/file-recovery-store.js +5 -1
- package/lib/runtime/file-recovery-store.js.map +1 -1
- package/lib/runtime/file-review.d.ts +6 -9
- package/lib/runtime/file-review.js +92 -8
- package/lib/runtime/file-review.js.map +1 -1
- package/lib/runtime/help-reader.d.ts +12 -0
- package/lib/runtime/help-reader.js +50 -0
- package/lib/runtime/help-reader.js.map +1 -0
- package/lib/runtime/hook-settings.d.ts +2 -2
- package/lib/runtime/human-interaction.js +1 -1
- package/lib/runtime/human-interaction.js.map +1 -1
- package/lib/runtime/model-catalog-editor.d.ts +12 -0
- package/lib/runtime/model-catalog-editor.js +215 -0
- package/lib/runtime/model-catalog-editor.js.map +1 -0
- package/lib/runtime/model-settings.d.ts +11 -0
- package/lib/runtime/model-settings.js +404 -0
- package/lib/runtime/model-settings.js.map +1 -0
- package/lib/runtime/plain-tui.d.ts +2 -0
- package/lib/runtime/plain-tui.js +7 -1
- package/lib/runtime/plain-tui.js.map +1 -1
- package/lib/runtime/plugin-settings.d.ts +4 -1
- package/lib/runtime/plugin-settings.js +170 -92
- package/lib/runtime/plugin-settings.js.map +1 -1
- package/lib/runtime/prompt-browser.d.ts +9 -0
- package/lib/runtime/prompt-browser.js +19 -0
- package/lib/runtime/prompt-browser.js.map +1 -0
- package/lib/runtime/provider-local.d.ts +80 -38
- package/lib/runtime/provider-local.js +2280 -683
- package/lib/runtime/provider-local.js.map +1 -1
- package/lib/runtime/reference-reader.d.ts +15 -0
- package/lib/runtime/reference-reader.js +78 -0
- package/lib/runtime/reference-reader.js.map +1 -0
- package/lib/runtime/runner.js +42 -39
- package/lib/runtime/runner.js.map +1 -1
- package/lib/runtime/session-runtime.js +1 -1
- package/lib/runtime/session-runtime.js.map +1 -1
- package/lib/runtime/settings-draft.d.ts +21 -0
- package/lib/runtime/settings-draft.js +166 -0
- package/lib/runtime/settings-draft.js.map +1 -0
- package/lib/runtime/settings-preferences.js +1 -1
- package/lib/runtime/settings-preferences.js.map +1 -1
- package/lib/runtime/startup-notices.d.ts +0 -1
- package/lib/runtime/startup-notices.js +35 -4
- package/lib/runtime/startup-notices.js.map +1 -1
- package/lib/runtime/subagent-model-selection.js +2 -1
- package/lib/runtime/subagent-model-selection.js.map +1 -1
- package/lib/runtime/subagent-settings.d.ts +14 -0
- package/lib/runtime/subagent-settings.js +288 -0
- package/lib/runtime/subagent-settings.js.map +1 -0
- package/lib/runtime/terminal-modes.d.ts +47 -0
- package/lib/runtime/terminal-modes.js +86 -0
- package/lib/runtime/terminal-modes.js.map +1 -0
- package/lib/runtime/terminal-notifications.d.ts +6 -5
- package/lib/runtime/terminal-notifications.js +17 -16
- package/lib/runtime/terminal-notifications.js.map +1 -1
- package/lib/runtime/terminal-probe.d.ts +38 -0
- package/lib/runtime/terminal-probe.js +46 -0
- package/lib/runtime/terminal-probe.js.map +1 -0
- package/lib/runtime/terminal-session.d.ts +57 -0
- package/lib/runtime/terminal-session.js +164 -0
- package/lib/runtime/terminal-session.js.map +1 -0
- package/lib/runtime/tool-presentation.js.map +1 -1
- package/lib/runtime/tool-reader.d.ts +5 -0
- package/lib/runtime/tool-reader.js +27 -0
- package/lib/runtime/tool-reader.js.map +1 -0
- package/lib/runtime/web-settings.d.ts +14 -0
- package/lib/runtime/web-settings.js +339 -0
- package/lib/runtime/web-settings.js.map +1 -0
- package/lib/session/command-attachments.d.ts +17 -0
- package/lib/session/command-attachments.js +50 -0
- package/lib/session/command-attachments.js.map +1 -0
- package/lib/session/context-diagnostics.d.ts +16 -0
- package/lib/session/context-diagnostics.js +15 -0
- package/lib/session/context-diagnostics.js.map +1 -1
- package/lib/session/external-agents.d.ts +3 -1
- package/lib/session/external-agents.js +35 -10
- package/lib/session/external-agents.js.map +1 -1
- package/lib/session/generation-continuation.d.ts +11 -0
- package/lib/session/generation-continuation.js +34 -0
- package/lib/session/generation-continuation.js.map +1 -0
- package/lib/session/goal-controls.d.ts +5 -0
- package/lib/session/goal-controls.js +81 -0
- package/lib/session/goal-controls.js.map +1 -0
- package/lib/session/interaction-adapter.d.ts +7 -3
- package/lib/session/interaction-adapter.js +125 -54
- package/lib/session/interaction-adapter.js.map +1 -1
- package/lib/session/message-queue.d.ts +2 -0
- package/lib/session/message-queue.js +102 -17
- package/lib/session/message-queue.js.map +1 -1
- package/lib/session/package-metadata.d.ts +8 -0
- package/lib/session/package-metadata.js +8 -0
- package/lib/session/package-metadata.js.map +1 -1
- package/lib/session/pending-inputs.d.ts +30 -0
- package/lib/session/pending-inputs.js +183 -0
- package/lib/session/pending-inputs.js.map +1 -0
- package/lib/session/session-configuration.js +1 -1
- package/lib/session/session-configuration.js.map +1 -1
- package/lib/session/session-controller.d.ts +42 -24
- package/lib/session/session-controller.js +534 -106
- package/lib/session/session-controller.js.map +1 -1
- package/lib/session/session-tree.d.ts +2 -0
- package/lib/session/session-tree.js +2 -0
- package/lib/session/session-tree.js.map +1 -1
- package/lib/session/subagent-roster.d.ts +1 -0
- package/lib/session/subagent-roster.js +16 -5
- package/lib/session/subagent-roster.js.map +1 -1
- package/lib/session/subagent-tracker.d.ts +2 -0
- package/lib/session/subagent-tracker.js +18 -0
- package/lib/session/subagent-tracker.js.map +1 -1
- package/lib/session/tui-settings.d.ts +48 -15
- package/lib/session/tui-settings.js +75 -34
- package/lib/session/tui-settings.js.map +1 -1
- package/lib/session/workflow-projection.d.ts +2 -1
- package/lib/session/workflow-projection.js +34 -4
- package/lib/session/workflow-projection.js.map +1 -1
- package/lib/views/autocomplete.d.ts +28 -9
- package/lib/views/autocomplete.js +90 -70
- package/lib/views/autocomplete.js.map +1 -1
- package/lib/views/context-overview.d.ts +4 -0
- package/lib/views/context-overview.js +43 -0
- package/lib/views/context-overview.js.map +1 -0
- package/lib/views/copy-targets.d.ts +18 -15
- package/lib/views/copy-targets.js +35 -60
- package/lib/views/copy-targets.js.map +1 -1
- package/lib/views/document-reader.d.ts +10 -1
- package/lib/views/document-reader.js +76 -9
- package/lib/views/document-reader.js.map +1 -1
- package/lib/views/event-views.js +71 -17
- package/lib/views/event-views.js.map +1 -1
- package/lib/views/file-actions.js +21 -0
- package/lib/views/file-actions.js.map +1 -1
- package/lib/views/file-browser.d.ts +98 -0
- package/lib/views/file-browser.js +120 -0
- package/lib/views/file-browser.js.map +1 -0
- package/lib/views/history-search.js +19 -25
- package/lib/views/history-search.js.map +1 -1
- package/lib/views/hotkey-format.d.ts +3 -2
- package/lib/views/hotkey-format.js +4 -3
- package/lib/views/hotkey-format.js.map +1 -1
- package/lib/views/hotkeys.d.ts +7 -1
- package/lib/views/hotkeys.js +59 -37
- package/lib/views/hotkeys.js.map +1 -1
- package/lib/views/list-navigation.d.ts +62 -0
- package/lib/views/list-navigation.js +73 -0
- package/lib/views/list-navigation.js.map +1 -0
- package/lib/views/list-view.d.ts +99 -0
- package/lib/views/list-view.js +170 -0
- package/lib/views/list-view.js.map +1 -0
- package/lib/views/prompt-selector.d.ts +54 -4
- package/lib/views/prompt-selector.js +349 -162
- package/lib/views/prompt-selector.js.map +1 -1
- package/lib/views/session-files.d.ts +1 -2
- package/lib/views/session-files.js +1 -11
- package/lib/views/session-files.js.map +1 -1
- package/lib/views/settings-list.d.ts +16 -9
- package/lib/views/settings-list.js +171 -315
- package/lib/views/settings-list.js.map +1 -1
- package/lib/views/tool-actions.d.ts +16 -0
- package/lib/views/tool-actions.js +29 -0
- package/lib/views/tool-actions.js.map +1 -0
- package/lib/views/trajectory-timeline.d.ts +71 -0
- package/lib/views/trajectory-timeline.js +143 -0
- package/lib/views/trajectory-timeline.js.map +1 -0
- package/lib/views/trajectory.d.ts +36 -4
- package/lib/views/trajectory.js +842 -190
- package/lib/views/trajectory.js.map +1 -1
- package/lib/views/transcript-render.d.ts +132 -38
- package/lib/views/transcript-render.js +792 -260
- package/lib/views/transcript-render.js.map +1 -1
- package/lib/views/transcript-search.d.ts +39 -6
- package/lib/views/transcript-search.js +46 -11
- package/lib/views/transcript-search.js.map +1 -1
- package/lib/views/transcript-types.d.ts +64 -5
- package/lib/views/transcript-types.js +23 -11
- package/lib/views/transcript-types.js.map +1 -1
- package/lib/views/workflow.d.ts +16 -0
- package/lib/views/workflow.js +42 -0
- package/lib/views/workflow.js.map +1 -0
- package/package.json +74 -90
- package/lib/chrome/welcome-tips.d.ts +0 -11
- package/lib/chrome/welcome-tips.js +0 -44
- package/lib/chrome/welcome-tips.js.map +0 -1
- package/lib/commands/advisor.d.ts +0 -15
- package/lib/commands/advisor.js +0 -200
- package/lib/commands/advisor.js.map +0 -1
- package/lib/commands/loop.d.ts +0 -52
- package/lib/commands/loop.js +0 -307
- package/lib/commands/loop.js.map +0 -1
- package/lib/commands/rate.d.ts +0 -33
- package/lib/commands/rate.js +0 -212
- package/lib/commands/rate.js.map +0 -1
- package/lib/commands/steer.d.ts +0 -5
- package/lib/commands/steer.js +0 -24
- package/lib/commands/steer.js.map +0 -1
- package/lib/commands/worktree.d.ts +0 -5
- package/lib/commands/worktree.js +0 -103
- package/lib/commands/worktree.js.map +0 -1
- package/lib/runtime/terminal-reader.d.ts +0 -11
- package/lib/runtime/terminal-reader.js +0 -87
- package/lib/runtime/terminal-reader.js.map +0 -1
- package/lib/session/steering.d.ts +0 -3
- package/lib/session/steering.js +0 -9
- package/lib/session/steering.js.map +0 -1
- package/lib/views/agent-hub.d.ts +0 -32
- package/lib/views/agent-hub.js +0 -209
- package/lib/views/agent-hub.js.map +0 -1
- package/lib/views/copy-selector.d.ts +0 -54
- package/lib/views/copy-selector.js +0 -170
- package/lib/views/copy-selector.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** Interactive terminal selector used by resume, approval, and user questions. */
|
|
2
|
+
import { uiText } from "../locale/index.js";
|
|
2
3
|
import { imageSize } from "../chrome/terminal-images.js";
|
|
3
4
|
import { documentLayout, documentMatches, documentModel, documentPosition, documentStart } from "./document-reader.js";
|
|
4
5
|
import { promptTreeRows } from "./prompt-tree.js";
|
|
@@ -6,8 +7,9 @@ import { rankSearchResults } from "../input/fuzzy-search.js";
|
|
|
6
7
|
import { renderEditor, renderFramedBlock } from "../chrome/box.js";
|
|
7
8
|
import { renderMarkdown } from "../chrome/markdown.js";
|
|
8
9
|
import { BOX, SYMBOL } from "../chrome/theme.js";
|
|
9
|
-
import { padToWidth, truncateToWidth, visibleWidth,
|
|
10
|
+
import { expandTabs, padToWidth, sliceCells, stripAnsi, truncateToWidth, visibleWidth, wrapTextStable } from "../chrome/width.js";
|
|
10
11
|
import { formatHotkeyKeys, formatOverlayHint } from "./hotkey-format.js";
|
|
12
|
+
import { renderListRow } from "./list-view.js";
|
|
11
13
|
/** Maximum option rows retained in the prompt overlay before it windows. */
|
|
12
14
|
export const PROMPT_SELECTOR_MAX_VISIBLE = 10;
|
|
13
15
|
// Every key the prompt handlers accept, covering the inline card, the full-screen
|
|
@@ -20,6 +22,7 @@ const HOTKEY_CHOOSE = { keys: '←→', action: 'Choose — move between the pla
|
|
|
20
22
|
const HOTKEY_PAGE = { keys: 'PgUp / PgDn', action: 'Scroll — page the options or the plan' };
|
|
21
23
|
const HOTKEY_EDGE = { keys: 'Home / End', action: 'Jump to the first or last option, or the plan edges' };
|
|
22
24
|
const HOTKEY_TOGGLE = { keys: 'Space', action: 'Toggle — check or clear a multi-select option' };
|
|
25
|
+
const HOTKEY_ANSWER_TOGGLE = { keys: 'Ctrl+G', action: 'Toggle — check or clear a multi-select option' };
|
|
23
26
|
const HOTKEY_SELECT = { keys: 'Enter', action: 'Select the highlighted option' };
|
|
24
27
|
const HOTKEY_SUBMIT = { keys: 'Enter', action: 'Submit — send revision feedback, or keep planning when empty' };
|
|
25
28
|
const HOTKEY_SUBMIT_NEWLINE = { keys: 'Ctrl+J', action: 'Submit — send revision feedback like Enter' };
|
|
@@ -37,6 +40,7 @@ export const PROMPT_SELECTOR_HOTKEYS = [
|
|
|
37
40
|
HOTKEY_PAGE,
|
|
38
41
|
HOTKEY_EDGE,
|
|
39
42
|
HOTKEY_TOGGLE,
|
|
43
|
+
HOTKEY_ANSWER_TOGGLE,
|
|
40
44
|
HOTKEY_SELECT,
|
|
41
45
|
HOTKEY_SUBMIT,
|
|
42
46
|
HOTKEY_SUBMIT_NEWLINE,
|
|
@@ -52,11 +56,13 @@ export function maskPromptSecret(input) {
|
|
|
52
56
|
}
|
|
53
57
|
/** Options matching the current full-screen selector query. */
|
|
54
58
|
export function filteredPromptOptions(request, query, collapsed) {
|
|
55
|
-
if (request.presentation === '
|
|
59
|
+
if (request.presentation === 'tree')
|
|
56
60
|
return promptTreeRows(request, collapsed, query).map(row => row.option);
|
|
57
61
|
const options = request.options ?? [];
|
|
58
62
|
if (request.filterable !== true)
|
|
59
63
|
return options;
|
|
64
|
+
if (request.filterOptions !== undefined)
|
|
65
|
+
return request.filterOptions(query);
|
|
60
66
|
return rankSearchResults(options, query, option => [option.label, option.value, option.preview, option.description, option.badge?.label]
|
|
61
67
|
.filter((value) => value !== undefined));
|
|
62
68
|
}
|
|
@@ -74,34 +80,40 @@ export function refreshPromptOptions(state, options, query) {
|
|
|
74
80
|
const previewCache = new WeakMap();
|
|
75
81
|
function treePreview(option, theme, width) {
|
|
76
82
|
if (option === undefined)
|
|
77
|
-
return ['No matching conversation turns.'];
|
|
83
|
+
return [theme.text('No matching conversation turns.')];
|
|
78
84
|
let cache = previewCache.get(option);
|
|
79
85
|
if (cache === undefined) {
|
|
80
86
|
cache = new Map();
|
|
81
87
|
previewCache.set(option, cache);
|
|
82
88
|
}
|
|
83
|
-
const key = `${width}:${theme.
|
|
89
|
+
const key = `${width}:${theme.key}`;
|
|
84
90
|
const cached = cache.get(key);
|
|
85
91
|
if (cached !== undefined)
|
|
86
92
|
return cached;
|
|
87
|
-
const
|
|
93
|
+
const source = option.preview ?? option.label;
|
|
94
|
+
// One default for one field: plain text unless the caller says markdown. The
|
|
95
|
+
// tree page used to render markdown unconditionally while the card rendered
|
|
96
|
+
// text, so the same `preview` meant two things depending on the surface.
|
|
97
|
+
const lines = option.previewFormat === 'markdown'
|
|
98
|
+
? renderMarkdown(source, theme, width)
|
|
99
|
+
: wrapTextStable(source, width);
|
|
88
100
|
if (cache.size >= 4)
|
|
89
101
|
cache.clear();
|
|
90
102
|
cache.set(key, lines);
|
|
91
103
|
return lines;
|
|
92
104
|
}
|
|
93
|
-
function treePageLayout(request, width, height) {
|
|
105
|
+
function treePageLayout(request, width, height, language = 'en') {
|
|
94
106
|
const actions = (request.actions ?? []).map(item => `${item.key} ${item.label}`).join(' · ');
|
|
95
|
-
const hint =
|
|
96
|
-
const hints =
|
|
107
|
+
const hint = [uiText(language, '↑↓ · ←→ fold'), ...(width >= 90 ? [uiText(language, 'type search')] : []), ...(actions === '' ? [] : [actions]), ...(width >= 90 ? [uiText(language, 'Ctrl+↑↓ preview')] : [])].join(' · ');
|
|
108
|
+
const hints = wrapTextStable(hint, width - 4).slice(0, Math.max(1, Math.floor((height - 6) / 2)));
|
|
97
109
|
const middle = height - 6 - hints.length;
|
|
98
110
|
const listHeight = width >= 90 ? middle : Math.max(1, Math.floor((middle - 1) / 2));
|
|
99
111
|
const previewHeight = width >= 90 ? middle : middle - listHeight - 1;
|
|
100
112
|
return { hints, middle, listHeight, previewHeight };
|
|
101
113
|
}
|
|
102
114
|
/** 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;
|
|
115
|
+
export function promptTreePageSize(request, width, height, language = 'en') {
|
|
116
|
+
return height < 10 || width < 20 ? Math.max(1, height - 8) : treePageLayout(request, width, height, language).listHeight;
|
|
105
117
|
}
|
|
106
118
|
/** A hierarchical choice with an independently scrollable content preview. */
|
|
107
119
|
export function renderPromptTreePage(state, theme, width, height, input, inputCursor, appName) {
|
|
@@ -112,7 +124,7 @@ export function renderPromptTreePage(state, theme, width, height, input, inputCu
|
|
|
112
124
|
const option = rows[selected]?.option;
|
|
113
125
|
const split = width >= 90;
|
|
114
126
|
const inner = width - 4;
|
|
115
|
-
const { hints, middle, listHeight, previewHeight } = treePageLayout(state.request, width, height);
|
|
127
|
+
const { hints, middle, listHeight, previewHeight } = treePageLayout(state.request, width, height, theme.language);
|
|
116
128
|
const listWidth = split ? Math.floor((inner - 3) * 0.45) : inner;
|
|
117
129
|
const previewWidth = split ? inner - listWidth - 3 : inner;
|
|
118
130
|
const range = promptSelectorVisibleRange(rows.length, selected, listHeight);
|
|
@@ -121,14 +133,34 @@ export function renderPromptTreePage(state, theme, width, height, input, inputCu
|
|
|
121
133
|
const row = rows[at];
|
|
122
134
|
const marker = at === selected ? theme.fg('accent', SYMBOL.cursor + ' ') : ' ';
|
|
123
135
|
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
136
|
const prefixLimit = Math.max(1, Math.floor(listWidth / 3));
|
|
127
137
|
const prefix = row.prefix.length <= prefixLimit ? row.prefix : '…' + row.prefix.slice(-(prefixLimit - 1));
|
|
128
|
-
|
|
138
|
+
const head = marker + theme.fg('dim', prefix + fold);
|
|
139
|
+
/**
|
|
140
|
+
* A row says everything the option knows.
|
|
141
|
+
*
|
|
142
|
+
* The card mode already drew the badge in its tone and the description in a
|
|
143
|
+
* column; this page drew neither, so a tree opened full screen lost the
|
|
144
|
+
* agent's phase colour and its elapsed time — the two things that tell two
|
|
145
|
+
* similar-looking nodes apart.
|
|
146
|
+
*/
|
|
147
|
+
const badge = row.option.badge === undefined
|
|
148
|
+
? ''
|
|
149
|
+
: theme.fg(row.option.badge.tone ?? 'muted', `[${row.option.badge.label}] `);
|
|
150
|
+
const label = badge + row.option.label;
|
|
151
|
+
// A heading is focusable but not an answer, so it never takes the cursor colour.
|
|
152
|
+
const text = row.option.disabled === true
|
|
153
|
+
? theme.fg('muted', label)
|
|
154
|
+
: at === selected ? theme.fg('accent', label) : theme.fg('text', label);
|
|
155
|
+
const used = visibleWidth(head) + visibleWidth(label);
|
|
156
|
+
const room = listWidth - used - 2;
|
|
157
|
+
const description = row.option.description === undefined || row.option.description === '' || room < 8
|
|
158
|
+
? ''
|
|
159
|
+
: theme.fg('dim', ' ' + truncateToWidth(row.option.description, room));
|
|
160
|
+
list.push(fit(head + text + description, listWidth));
|
|
129
161
|
}
|
|
130
162
|
if (rows.length === 0)
|
|
131
|
-
list.push(fit(theme.fg('dim', state.request.emptyText ?? 'No matching conversation turns.'), listWidth));
|
|
163
|
+
list.push(fit(theme.fg('dim', state.request.emptyText ?? theme.text('No matching conversation turns.')), listWidth));
|
|
132
164
|
const preview = treePreview(option, theme, Math.max(1, previewWidth));
|
|
133
165
|
const maxScroll = Math.max(0, preview.length - previewHeight);
|
|
134
166
|
const scroll = Math.max(0, Math.min(state.previewScroll ?? 0, maxScroll));
|
|
@@ -146,8 +178,9 @@ export function renderPromptTreePage(state, theme, width, height, input, inputCu
|
|
|
146
178
|
lines.push(pageRow(theme, preview[scroll + at] ?? '', width));
|
|
147
179
|
}
|
|
148
180
|
const action = option?.submitLabel ?? state.request.submitLabel ?? 'select';
|
|
149
|
-
|
|
150
|
-
|
|
181
|
+
const navigation = option === undefined || option.disabled === true ? theme.text('Esc back') : theme.text(`Enter ${action} · Esc back`);
|
|
182
|
+
lines.push(pageRow(theme, theme.fg('dim', navigation), width), ...hints.map(hint => pageRow(theme, theme.fg('dim', hint), width)), pageBottom(theme, width));
|
|
183
|
+
return { lines, choices: rows.slice(range.start, range.end).map((row, index) => ({ row: 4 + index, column: 2, width: listWidth, index: range.start + index, value: row.option.value ?? row.option.label })), cursor: { row: 2, column: Math.min(width - 3, 4 + visibleWidth(input.slice(0, inputCursor))) },
|
|
151
184
|
document: { start: scroll, maxStart: maxScroll, pageSize: previewHeight }, cursorVisible: true };
|
|
152
185
|
}
|
|
153
186
|
/** Fold/unfold a subtree or move to its parent, preserving selection by value. */
|
|
@@ -175,26 +208,43 @@ export function movePromptTree(state, direction, query) {
|
|
|
175
208
|
}
|
|
176
209
|
/** Start on a matching node instead of a context-only ancestor. */
|
|
177
210
|
export function searchPromptSelection(state, query) {
|
|
178
|
-
const selected = state.request.presentation === '
|
|
211
|
+
const selected = state.request.presentation === 'tree'
|
|
179
212
|
? Math.max(0, promptTreeRows(state.request, state.collapsed, query).findIndex(row => row.matched)) : 0;
|
|
180
213
|
return { ...state, selected, previewScroll: 0 };
|
|
181
214
|
}
|
|
182
|
-
/** Visible option window centered around the selected row. */
|
|
183
215
|
export function promptSelectorVisibleRange(count, selected, maxVisible = PROMPT_SELECTOR_MAX_VISIBLE) {
|
|
184
216
|
const max = Math.max(1, maxVisible);
|
|
185
217
|
const index = Math.max(0, Math.min(selected, Math.max(0, count - 1)));
|
|
186
218
|
const start = Math.max(0, Math.min(index - Math.floor(max / 2), Math.max(0, count - max)));
|
|
187
219
|
return { start, end: Math.min(count, start + max) };
|
|
188
220
|
}
|
|
189
|
-
function optionRow(option, index, state, theme, width
|
|
190
|
-
|
|
191
|
-
|
|
221
|
+
function optionRow(option, index, state, theme, width,
|
|
222
|
+
/**
|
|
223
|
+
* The option's index in the request, when the visible row is a filtered one.
|
|
224
|
+
*
|
|
225
|
+
* Checked state is keyed by the request's order, not the filtered list's: a
|
|
226
|
+
* query that hides the row above must not move every checkbox below it.
|
|
227
|
+
*/
|
|
228
|
+
identity = index) {
|
|
229
|
+
// The multi-select marker is part of the label so the shared row keeps one
|
|
230
|
+
// cursor cell and one description gap for every prompt, checked or not.
|
|
231
|
+
if (option.disabled === true) {
|
|
232
|
+
// Same reason as the tree: focusable, dimmed, and not a value.
|
|
233
|
+
const row = { label: option.label, ...(option.description === undefined ? {} : { description: option.description }), secondary: true };
|
|
234
|
+
return renderListRow(row, theme, Math.max(1, width), { selected: index === state.selected });
|
|
235
|
+
}
|
|
236
|
+
const checked = state.checked.has(identity);
|
|
192
237
|
const marker = state.request.multiSelect === true
|
|
193
|
-
? theme.fg(
|
|
238
|
+
? theme.fg(checked ? 'success' : 'dim', checked ? '[x] ' : '[ ] ')
|
|
194
239
|
: '';
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
240
|
+
const row = {
|
|
241
|
+
label: marker + option.label,
|
|
242
|
+
...(option.description === undefined ? {} : { description: option.description }),
|
|
243
|
+
// A badge is part of what the row says — a session's status, a command's
|
|
244
|
+
// kind. The paged list drew it, so the card must draw it too.
|
|
245
|
+
...(option.badge?.label === undefined ? {} : { value: theme.fg(option.badge.tone ?? 'muted', option.badge.label) }),
|
|
246
|
+
};
|
|
247
|
+
return renderListRow(row, theme, Math.max(1, width), { selected: index === state.selected });
|
|
198
248
|
}
|
|
199
249
|
function fit(text, width) {
|
|
200
250
|
if (width <= 0)
|
|
@@ -222,102 +272,51 @@ function pageDivider(theme, width) {
|
|
|
222
272
|
function pageBottom(theme, width) {
|
|
223
273
|
return pageBorder(theme, BOX.bottomLeft + BOX.horizontal.repeat(Math.max(0, width - 2)) + BOX.bottomRight);
|
|
224
274
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const visibleChecked = new Set(options.flatMap((option, index) => state.checked.has(state.request.options?.indexOf(option) ?? -1) ? [index] : []));
|
|
243
|
-
if (pageHeight < 10 || width < 16) {
|
|
244
|
-
return renderPromptSelector({ ...state, request: { ...state.request, options }, checked: visibleChecked }, theme, width, input, inputCursor, Math.max(1, pageHeight - 8));
|
|
245
|
-
}
|
|
246
|
-
const selected = Math.max(0, Math.min(state.selected, Math.max(0, options.length - 1)));
|
|
247
|
-
const compact = state.request.optionLayout === 'compact';
|
|
248
|
-
const actionHints = (state.request.actions ?? []).map(action => `${action.key} ${action.label}`).join(' · ');
|
|
249
|
-
const hints = wrapText(formatOverlayHint([HOTKEY_TEXT, HOTKEY_NAVIGATE, ...(state.request.multiSelect === true ? [HOTKEY_TOGGLE] : []), HOTKEY_SELECT, HOTKEY_CANCEL])
|
|
250
|
-
+ (actionHints === '' ? '' : ' · ' + actionHints), width - 4).slice(0, Math.max(1, Math.floor((height - 6) / 2)));
|
|
251
|
-
const fixedRows = (compact ? 9 : 11) + hints.length - 1;
|
|
252
|
-
const visibleCount = compact
|
|
253
|
-
? Math.max(1, pageHeight - fixedRows)
|
|
254
|
-
: Math.max(1, Math.floor((pageHeight - fixedRows) / 4));
|
|
255
|
-
const { start, end } = promptSelectorVisibleRange(options.length, selected, visibleCount);
|
|
256
|
-
const detail = state.request.detail === undefined || state.request.detail === ''
|
|
257
|
-
? ''
|
|
258
|
-
: ' ' + theme.fg('muted', `(${state.request.detail})`);
|
|
259
|
-
const heading = theme.bold(state.request.title) + detail;
|
|
260
|
-
const lines = compact
|
|
261
|
-
? [
|
|
262
|
-
pageTop(theme, width, appName),
|
|
263
|
-
pageRow(theme, ' ' + heading, width),
|
|
264
|
-
pageDivider(theme, width),
|
|
265
|
-
]
|
|
266
|
-
: [
|
|
267
|
-
pageTop(theme, width, appName),
|
|
268
|
-
pageRow(theme, '', width),
|
|
269
|
-
pageRow(theme, ' ' + heading, width),
|
|
270
|
-
pageRow(theme, '', width),
|
|
271
|
-
pageDivider(theme, width),
|
|
272
|
-
];
|
|
273
|
-
const searchPrefix = theme.fg('dim', '> ');
|
|
274
|
-
const searchText = truncateToWidth(input, Math.max(1, width - 8));
|
|
275
|
-
const searchRow = lines.length;
|
|
276
|
-
lines.push(pageRow(theme, searchPrefix + searchText, width), pageRow(theme, '', width));
|
|
277
|
-
if (options.length === 0) {
|
|
278
|
-
// The generic line is a fallback only: this selector also serves approvals
|
|
279
|
-
// and questions, whose empty states have nothing to do with sessions.
|
|
280
|
-
const fallback = state.request.emptyText ?? 'No matching options.';
|
|
281
|
-
const empty = input === '' ? fallback : `No match for “${input}”.`;
|
|
282
|
-
lines.push(pageRow(theme, ' ' + theme.fg('muted', empty), width));
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
for (let index = start; index < end; index += 1) {
|
|
286
|
-
const option = options[index];
|
|
287
|
-
if (option === undefined)
|
|
288
|
-
continue;
|
|
289
|
-
if (compact) {
|
|
290
|
-
lines.push(pageRow(theme, optionRow(option, index, { ...state, selected, checked: visibleChecked }, theme, Math.max(1, width - 6)), width));
|
|
291
|
-
continue;
|
|
292
|
-
}
|
|
293
|
-
const active = index === selected;
|
|
294
|
-
const marker = active ? theme.fg('accent', SYMBOL.cursor + ' ') : ' ';
|
|
295
|
-
const check = state.request.multiSelect === true ? visibleChecked.has(index) ? '[x] ' : '[ ] ' : '';
|
|
296
|
-
const label = active ? theme.bold(option.label) : option.label;
|
|
297
|
-
lines.push(pageRow(theme, marker + check + label, width));
|
|
298
|
-
lines.push(pageRow(theme, ' ' + theme.fg('dim', option.preview ?? ''), width));
|
|
299
|
-
const badge = optionBadge(option, theme);
|
|
300
|
-
const description = option.description === undefined ? '' : theme.fg('dim', option.description);
|
|
301
|
-
const separator = description !== '' && badge !== '' ? theme.fg('dim', ' · ') : '';
|
|
302
|
-
lines.push(pageRow(theme, ' ' + description + separator + badge, width), pageRow(theme, '', width));
|
|
275
|
+
const documentCache = new WeakMap();
|
|
276
|
+
/**
|
|
277
|
+
* Case-insensitive find over rows the reader can already see.
|
|
278
|
+
*
|
|
279
|
+
* A rendered page has no source model to search, so the rows are the document.
|
|
280
|
+
* Offsets are display cells, not string indexes, so CJK and emoji highlights land
|
|
281
|
+
* on the glyphs the reader pointed at rather than shearing them.
|
|
282
|
+
*/
|
|
283
|
+
export function findInRows(rows, query) {
|
|
284
|
+
const needle = query.trim().toLowerCase();
|
|
285
|
+
if (needle === '')
|
|
286
|
+
return [];
|
|
287
|
+
const matches = [];
|
|
288
|
+
for (const [row, line] of rows.entries()) {
|
|
289
|
+
const plain = stripAnsi(line).toLowerCase();
|
|
290
|
+
for (let at = plain.indexOf(needle); at >= 0; at = plain.indexOf(needle, at + needle.length)) {
|
|
291
|
+
matches.push({ row, start: visibleWidth(stripAnsi(line).slice(0, at)), width: visibleWidth(query.trim()) });
|
|
303
292
|
}
|
|
304
293
|
}
|
|
305
|
-
|
|
306
|
-
const targetBeforeFooter = Math.max(0, pageHeight - footerRows);
|
|
307
|
-
if (lines.length > targetBeforeFooter)
|
|
308
|
-
lines.length = targetBeforeFooter;
|
|
309
|
-
while (lines.length < targetBeforeFooter)
|
|
310
|
-
lines.push(pageRow(theme, '', width));
|
|
311
|
-
const position = options.length === 0 ? '' : `${selected + 1}/${options.length}`;
|
|
312
|
-
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));
|
|
313
|
-
const cursorColumn = Math.min(Math.max(1, width - 3), 4 + visibleWidth(input.slice(0, inputCursor)));
|
|
314
|
-
return {
|
|
315
|
-
lines,
|
|
316
|
-
cursor: { row: searchRow, column: cursorColumn },
|
|
317
|
-
};
|
|
294
|
+
return matches;
|
|
318
295
|
}
|
|
319
|
-
|
|
320
|
-
function
|
|
296
|
+
/** Invert the matched cells of one styled row. */
|
|
297
|
+
export function highlightMatches(line, spans, theme) {
|
|
298
|
+
if (spans.length === 0)
|
|
299
|
+
return line;
|
|
300
|
+
const plain = stripAnsi(line);
|
|
301
|
+
const total = visibleWidth(plain);
|
|
302
|
+
const ordered = [...spans].sort((left, right) => left.start - right.start);
|
|
303
|
+
let out = '';
|
|
304
|
+
let at = 0;
|
|
305
|
+
for (const span of ordered) {
|
|
306
|
+
const start = Math.max(at, Math.min(span.start, total));
|
|
307
|
+
const end = Math.min(total, Math.max(start, span.start + span.width));
|
|
308
|
+
if (start > at)
|
|
309
|
+
out += sliceCells(line, at, start - at);
|
|
310
|
+
if (end > start)
|
|
311
|
+
out += theme.inverse(sliceCells(line, start, end - start));
|
|
312
|
+
at = end;
|
|
313
|
+
}
|
|
314
|
+
if (at < total)
|
|
315
|
+
out += sliceCells(line, at, total - at);
|
|
316
|
+
return out;
|
|
317
|
+
}
|
|
318
|
+
/** The rows a rendered document shows, shared with the find that searches them. */
|
|
319
|
+
export function documentRows(request, theme, width) {
|
|
321
320
|
let cache = documentCache.get(request);
|
|
322
321
|
if (cache === undefined) {
|
|
323
322
|
cache = new Map();
|
|
@@ -333,9 +332,25 @@ function documentRows(request, theme, width) {
|
|
|
333
332
|
cache.set(key, lines);
|
|
334
333
|
return lines;
|
|
335
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* Does this prompt need the whole screen?
|
|
337
|
+
*
|
|
338
|
+
* Only a tree does. Length is not the question — a long list is still a list, and
|
|
339
|
+
* the card windows its rows, filters by typing, and draws the selected row's
|
|
340
|
+
* preview — so counting rows was the wrong variable. Choosing is a different act
|
|
341
|
+
* from reading, and a choice belongs beside the conversation it interrupted.
|
|
342
|
+
*/
|
|
343
|
+
export function promptNeedsPage(request) {
|
|
344
|
+
// A list is a choice, and a choice belongs beside the conversation whatever its
|
|
345
|
+
// length: the card windows its rows, filters by typing, and shows the selected
|
|
346
|
+
// row's preview. Counting rows was the wrong variable — a long list is still a
|
|
347
|
+
// list. Only a tree has structure the card cannot show.
|
|
348
|
+
return request.presentation === 'tree';
|
|
349
|
+
}
|
|
336
350
|
/** Render a bounded, scrollable Markdown document with fixed actions. */
|
|
337
351
|
function documentActionRows(state, theme, width, pageHeight) {
|
|
338
352
|
const actionRows = [];
|
|
353
|
+
const actions = [];
|
|
339
354
|
let actionRow = '';
|
|
340
355
|
const actionWidth = Math.max(1, width - 5);
|
|
341
356
|
for (const [index, option] of (state.request.options ?? []).entries()) {
|
|
@@ -344,6 +359,7 @@ function documentActionRows(state, theme, width, pageHeight) {
|
|
|
344
359
|
actionRows.push(actionRow);
|
|
345
360
|
actionRow = '';
|
|
346
361
|
}
|
|
362
|
+
actions.push({ row: actionRows.length, column: 3 + visibleWidth(actionRow) + (actionRow === '' ? 0 : 3), width: visibleWidth(label), index });
|
|
347
363
|
const painted = index === state.selected ? theme.bold(theme.fg('accent', label)) : theme.fg('muted', label);
|
|
348
364
|
actionRow += (actionRow === '' ? '' : theme.fg('dim', ' ')) + painted;
|
|
349
365
|
}
|
|
@@ -352,8 +368,9 @@ function documentActionRows(state, theme, width, pageHeight) {
|
|
|
352
368
|
const selected = state.request.options?.[state.selected];
|
|
353
369
|
actionRows.splice(0, actionRows.length, selected === undefined ? ''
|
|
354
370
|
: theme.bold(theme.fg('accent', truncateToWidth(`› [ ${selected.label} ]`, actionWidth))));
|
|
371
|
+
actions.splice(0, actions.length, ...(selected === undefined ? [] : [{ row: 0, column: 3, width: visibleWidth(actionRows[0]), index: state.selected }]));
|
|
355
372
|
}
|
|
356
|
-
return actionRows;
|
|
373
|
+
return { lines: actionRows, actions };
|
|
357
374
|
}
|
|
358
375
|
/** Reserve a bordered, padded rectangle; graphics never become display-row content. */
|
|
359
376
|
export function renderImagePreviewPage(state, theme, width, height, appName, protocol, cell) {
|
|
@@ -361,14 +378,14 @@ export function renderImagePreviewPage(state, theme, width, height, appName, pro
|
|
|
361
378
|
if (width < 16 || height < 10)
|
|
362
379
|
return renderPromptSelector({ ...state, request: { ...state.request,
|
|
363
380
|
detail: image.description + '\nEnlarge the terminal or use Open to view the image.' } }, theme, width, '', 0, Math.max(1, height - 8));
|
|
364
|
-
const actions = documentActionRows(state, theme, width, height);
|
|
381
|
+
const { lines: actions } = documentActionRows(state, theme, width, height);
|
|
365
382
|
const hints = 'Tab/←→ actions · Enter activate · Esc back';
|
|
366
383
|
const bodyRows = Math.max(1, height - 8 - actions.length);
|
|
367
384
|
const lines = [pageTop(theme, width, appName + ' · ' + state.request.title), pageRow(theme, state.request.question, width),
|
|
368
385
|
pageRow(theme, theme.fg('muted', image.description), width), pageDivider(theme, width)];
|
|
369
386
|
const top = lines.length;
|
|
370
387
|
const canOpen = state.request.options?.some(option => option.value === 'open') === true;
|
|
371
|
-
const fallback = protocol === undefined ?
|
|
388
|
+
const fallback = protocol === undefined ? wrapTextStable('Inline images are unavailable in this terminal. '
|
|
372
389
|
+ (canOpen ? 'Use Open to view the original.' : 'This attachment has no local original to open.'), width - 8) : [];
|
|
373
390
|
for (let at = 0; at < bodyRows; at++)
|
|
374
391
|
lines.push(pageRow(theme, ' ' + (fallback[at] ?? ''), width));
|
|
@@ -385,11 +402,19 @@ export function renderPlanReviewPage(state, theme, width, height, input, inputCu
|
|
|
385
402
|
return renderPromptSelector(source === undefined ? state : { ...state, request: { ...state.request, detail: source.text } }, theme, width, input, inputCursor, Math.max(1, pageHeight - 8));
|
|
386
403
|
}
|
|
387
404
|
const feedback = state.feedback === true;
|
|
388
|
-
const
|
|
389
|
-
const
|
|
405
|
+
const actionLayout = documentActionRows(state, theme, width, pageHeight);
|
|
406
|
+
const actionRows = actionLayout.lines;
|
|
407
|
+
const readerInput = state.documentInput !== undefined;
|
|
390
408
|
const customHints = (state.request.actions ?? []).map(action => `${action.key.toUpperCase()} ${action.label}`);
|
|
391
|
-
|
|
392
|
-
|
|
409
|
+
const renderedReader = source === undefined && state.request.presentation === 'document';
|
|
410
|
+
let renderedHints = renderedReader ? wrapTextStable(readerInput ? 'Enter find · Esc cancel'
|
|
411
|
+
: ['↑↓/PgUp/PgDn/wheel scroll', '/ find', 'Ctrl+N/P match', ...customHints,
|
|
412
|
+
...(state.request.options && state.request.options.length > 1 ? ['Tab actions · Enter'] : []), 'Esc back'].join(' · '), Math.max(1, width - 4)) : [];
|
|
413
|
+
const maxRenderedHints = Math.max(1, pageHeight - (state.request.question === '' ? 5 : 6) - actionRows.length - (readerInput || state.documentQuery ? 1 : 0));
|
|
414
|
+
if (renderedHints.length > maxRenderedHints)
|
|
415
|
+
renderedHints = [...renderedHints.slice(0, maxRenderedHints - 1), '/ find · Esc back'];
|
|
416
|
+
let readerHints = source === undefined ? [] : wrapTextStable(readerInput ? 'Enter apply · Esc cancel'
|
|
417
|
+
: (state.request.interrupt === undefined ? '' : 'Ctrl+C interrupt · ') + 'W wrap · Alt+←→ pan · ↑↓/PgUp/PgDn/wheel scroll · ' + (state.request.documentTail === true ? 'Home start · End follow' : 'Home/End edges') + ' · / find · Ctrl+N/P match · G line' + (source.diff ? ' · [/] hunk' : '')
|
|
393
418
|
+ ' · ' + ['Tab/←→ actions', 'Enter activate', ...customHints, 'Esc back'].join(' · '), width - 4);
|
|
394
419
|
const maxHints = Math.max(1, Math.min(4, pageHeight - 8 - actionRows.length));
|
|
395
420
|
if (readerHints.length > maxHints)
|
|
@@ -397,20 +422,28 @@ export function renderPlanReviewPage(state, theme, width, height, input, inputCu
|
|
|
397
422
|
const compactReader = source !== undefined && pageHeight < 10;
|
|
398
423
|
if (compactReader)
|
|
399
424
|
readerHints = [];
|
|
400
|
-
const
|
|
401
|
-
const
|
|
425
|
+
const renderedSearchRows = readerInput || state.documentQuery ? 1 : 0;
|
|
426
|
+
const hintRows = renderedReader ? renderedHints.length - 1 + renderedSearchRows : readerHints.length;
|
|
427
|
+
const footerRows = feedback ? 5 : actionRows.length + 3 + hintRows;
|
|
428
|
+
const headerRows = renderedReader ? 2 + Number(state.request.question !== '')
|
|
429
|
+
: source === undefined ? 5 : compactReader ? 2 : 3;
|
|
430
|
+
const bodyRows = Math.max(1, pageHeight - headerRows - footerRows);
|
|
402
431
|
const markdownWidth = Math.max(1, width - 6);
|
|
403
432
|
const layout = source === undefined ? undefined : documentLayout(source, theme, markdownWidth, {
|
|
404
433
|
wordWrap: state.documentWordWrap ?? state.request.documentPosition?.wordWrap ?? true,
|
|
405
434
|
column: state.documentColumn ?? state.request.documentPosition?.column ?? 0,
|
|
406
435
|
});
|
|
407
|
-
const
|
|
436
|
+
const textDocument = layout === undefined
|
|
437
|
+
? state.renderDocument?.(theme, markdownWidth) ?? documentRows(state.request, theme, markdownWidth)
|
|
438
|
+
: undefined;
|
|
439
|
+
const document = layout?.rows ?? textDocument ?? [];
|
|
408
440
|
const maxStart = Math.max(0, document.length - bodyRows);
|
|
409
441
|
const start = Math.max(0, Math.min(state.documentScroll === Number.POSITIVE_INFINITY ? maxStart : layout !== undefined && state.documentAnchor !== undefined
|
|
410
442
|
? documentStart(layout, state.documentAnchor) : state.documentScroll ?? state.request.documentPosition?.row ?? 0, maxStart));
|
|
411
443
|
const visible = document.slice(start, start + bodyRows);
|
|
412
444
|
const query = state.documentQuery ?? '';
|
|
413
445
|
const matches = source === undefined ? [] : documentMatches(source, query);
|
|
446
|
+
const textMatches = textDocument === undefined ? [] : findInRows(textDocument, query);
|
|
414
447
|
const matching = new Set(matches);
|
|
415
448
|
if (layout !== undefined)
|
|
416
449
|
for (let at = 0; at < visible.length; at++) {
|
|
@@ -419,6 +452,15 @@ export function renderPlanReviewPage(state, theme, width, height, input, inputCu
|
|
|
419
452
|
visible[at] = theme.inverse(layout.gutterWidth === 0 ? row : '›' + row.slice(1));
|
|
420
453
|
}
|
|
421
454
|
}
|
|
455
|
+
if (textMatches.length > 0) {
|
|
456
|
+
// Paint the hits themselves, so the reader sees the word, not just the row.
|
|
457
|
+
for (const match of textMatches) {
|
|
458
|
+
const at = match.row - start;
|
|
459
|
+
if (at < 0 || at >= visible.length)
|
|
460
|
+
continue;
|
|
461
|
+
visible[at] = highlightMatches(visible[at] ?? '', [match], theme);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
422
464
|
while (visible.length < bodyRows)
|
|
423
465
|
visible.push('');
|
|
424
466
|
const subject = state.request.presentation === 'document' ? 'document' : 'plan';
|
|
@@ -429,16 +471,17 @@ export function renderPlanReviewPage(state, theme, width, height, input, inputCu
|
|
|
429
471
|
}
|
|
430
472
|
const lines = [
|
|
431
473
|
pageTop(theme, width, `${appName} · ${compactReader ? state.request.question : state.request.title}`),
|
|
432
|
-
...(source === undefined ? [pageRow(theme, '', width)] : []),
|
|
433
|
-
...(compactReader ? [] : [pageRow(theme, ' ' + theme.bold(state.request.question), width)]),
|
|
434
|
-
...(source === undefined ? [pageRow(theme, '', width)] : []),
|
|
474
|
+
...(source === undefined && !renderedReader ? [pageRow(theme, '', width)] : []),
|
|
475
|
+
...(compactReader || renderedReader && state.request.question === '' ? [] : [pageRow(theme, ' ' + theme.bold(state.request.question), width)]),
|
|
476
|
+
...(source === undefined && !renderedReader ? [pageRow(theme, '', width)] : []),
|
|
435
477
|
pageDivider(theme, width),
|
|
436
478
|
...visible.map(line => pageRow(theme, ' ' + line, width)),
|
|
437
479
|
pageDivider(theme, width),
|
|
438
480
|
];
|
|
481
|
+
const actions = [];
|
|
439
482
|
let cursor = { row: Math.max(0, lines.length - 1), column: 1 };
|
|
440
483
|
if (feedback) {
|
|
441
|
-
lines.push(pageRow(theme, ' ' + theme.bold('Revision feedback') + theme.fg('dim', ' · optional'), width));
|
|
484
|
+
lines.push(pageRow(theme, ' ' + theme.bold(theme.text('Revision feedback')) + theme.fg('dim', ' · optional'), width));
|
|
442
485
|
const prefix = theme.fg('accent', '> ');
|
|
443
486
|
const available = Math.max(1, width - 8);
|
|
444
487
|
const displayInput = input.replace(/\r?\n/gu, ' ↵ ');
|
|
@@ -447,7 +490,7 @@ export function renderPlanReviewPage(state, theme, width, height, input, inputCu
|
|
|
447
490
|
const inputRow = lines.length;
|
|
448
491
|
lines.push(pageRow(theme, ' ' + prefix + value, width));
|
|
449
492
|
// "empty Enter keeps planning" is prose, but it names the key through the catalog.
|
|
450
|
-
lines.push(pageRow(theme, theme.fg('dim', `[${formatOverlayHint([HOTKEY_SUBMIT, HOTKEY_BACK, HOTKEY_CANCEL_CTRL])} · Ctrl+X editor · empty ${formatHotkeyKeys(HOTKEY_SUBMIT)} keeps planning]`), width));
|
|
493
|
+
lines.push(pageRow(theme, theme.fg('dim', `[${formatOverlayHint([HOTKEY_SUBMIT, HOTKEY_BACK, HOTKEY_CANCEL_CTRL], 'lowercase', theme.language)} · Ctrl+X editor · empty ${formatHotkeyKeys(HOTKEY_SUBMIT)} keeps planning]`), width));
|
|
451
494
|
lines.push(pageBottom(theme, width));
|
|
452
495
|
cursor = {
|
|
453
496
|
row: inputRow,
|
|
@@ -455,6 +498,19 @@ export function renderPlanReviewPage(state, theme, width, height, input, inputCu
|
|
|
455
498
|
};
|
|
456
499
|
}
|
|
457
500
|
else {
|
|
501
|
+
if (source === undefined && (readerInput || query !== '')) {
|
|
502
|
+
// A rendered page has no line numbers to cite, so the status is the find
|
|
503
|
+
// itself: the query, how many hits it has, and where the reader is in them.
|
|
504
|
+
const index = textMatches.findIndex(match => match.row === state.documentTarget);
|
|
505
|
+
const hits = textMatches.length === 0
|
|
506
|
+
? theme.text('No match')
|
|
507
|
+
: `${index < 0 ? 1 : index + 1}/${textMatches.length} matching rows`;
|
|
508
|
+
const label = state.documentInput === 'search' ? 'Find: ' : '';
|
|
509
|
+
const value = input.replace(/\r?\n/gu, ' ');
|
|
510
|
+
const status = readerInput ? label + value : `${hits} · “${query}”`;
|
|
511
|
+
cursor = { row: lines.length, column: Math.min(width - 3, 2 + visibleWidth(label + value.slice(0, inputCursor))) };
|
|
512
|
+
lines.push(pageRow(theme, theme.fg('muted', status), width));
|
|
513
|
+
}
|
|
458
514
|
if (source !== undefined) {
|
|
459
515
|
const row = layout?.sourceRows[start] ?? 0;
|
|
460
516
|
const model = documentModel(source);
|
|
@@ -471,62 +527,145 @@ export function renderPlanReviewPage(state, theme, width, height, input, inputCu
|
|
|
471
527
|
cursor = { row: lines.length, column: Math.min(width - 3, 2 + visibleWidth(label + value.slice(0, inputCursor))) };
|
|
472
528
|
lines.push(pageRow(theme, theme.fg('muted', status), width));
|
|
473
529
|
}
|
|
530
|
+
actions.push(...actionLayout.actions.map(action => ({ ...action, row: action.row + lines.length })));
|
|
474
531
|
lines.push(...actionRows.map(row => pageRow(theme, ' ' + row, width)));
|
|
475
532
|
const shortcuts = state.request.presentation === 'document' && state.request.actions?.length
|
|
476
533
|
? 'Tab/←→ select · Enter activate · ' + state.request.actions.map(action => `${action.key.toUpperCase()} ${action.label}`).join(' · ') + ' · Esc back'
|
|
477
|
-
: formatOverlayHint([HOTKEY_PAGE, HOTKEY_NAVIGATE_TAB, HOTKEY_SELECT, HOTKEY_CANCEL])
|
|
478
|
-
+ (state.request.presentation === 'plan-review' ? ' · Ctrl+X editor' : '');
|
|
479
|
-
|
|
534
|
+
: formatOverlayHint([HOTKEY_PAGE, HOTKEY_NAVIGATE_TAB, HOTKEY_SELECT, HOTKEY_CANCEL], 'lowercase', theme.language)
|
|
535
|
+
+ (state.request.presentation === 'plan-review' && state.request.allowCustom !== false ? ' · Ctrl+X editor' : '');
|
|
536
|
+
// A page long enough to need scrolling is a page someone will want to search.
|
|
537
|
+
const pageHint = source === undefined && state.request.presentation === 'document'
|
|
538
|
+
? `[${shortcuts} · / find · Ctrl+N/P match]`
|
|
539
|
+
: `[${shortcuts}]`;
|
|
540
|
+
const hints = renderedReader ? renderedHints : source === undefined ? [pageHint] : readerHints;
|
|
541
|
+
lines.push(...hints.map(hint => pageRow(theme, theme.fg('dim', hint), width)));
|
|
480
542
|
lines.push(pageBottom(theme, width));
|
|
481
543
|
}
|
|
482
544
|
return {
|
|
483
545
|
lines,
|
|
484
546
|
cursor,
|
|
547
|
+
actions,
|
|
485
548
|
document: { start, maxStart, pageSize: Math.max(1, bodyRows - 1),
|
|
486
|
-
...(layout === undefined ? state.request.presentation === 'document' ? { position: { row: start, wrap: 0, query
|
|
549
|
+
...(layout === undefined ? state.request.presentation === 'document' ? { position: { row: start, wrap: 0, query } } : {} : { position: { ...documentPosition(layout, start, query),
|
|
487
550
|
...(state.request.documentTail === true ? { following: state.documentScroll === Number.POSITIVE_INFINITY } : {}) } }) },
|
|
488
551
|
cursorVisible: feedback || readerInput,
|
|
489
552
|
};
|
|
490
553
|
}
|
|
554
|
+
/** Rows of the selected option's preview the card shows before it truncates. */
|
|
555
|
+
const CARD_PREVIEW_LINES = 3;
|
|
556
|
+
/** The reader's query as it reads in a sentence, quoted so blanks are visible. */
|
|
557
|
+
function quote(text) {
|
|
558
|
+
return `“${text}”`;
|
|
559
|
+
}
|
|
491
560
|
/** Render the prompt card and its answer editor as one bottom-of-screen overlay. */
|
|
492
561
|
export function renderPromptSelector(state, theme, width, input, inputCursor, maxVisible = PROMPT_SELECTOR_MAX_VISIBLE) {
|
|
493
562
|
const options = filteredPromptOptions(state.request, input, state.collapsed);
|
|
563
|
+
const filtering = input !== '';
|
|
494
564
|
const contentWidth = Math.max(1, width - 4);
|
|
495
565
|
const body = [state.request.question];
|
|
566
|
+
const choices = [];
|
|
567
|
+
const actions = [];
|
|
568
|
+
const bodyRow = () => 1 + body.reduce((count, line) => count + wrapTextStable(expandTabs(line, 8, 2), contentWidth).length, 0);
|
|
496
569
|
if (state.request.wait !== undefined) {
|
|
497
570
|
const remaining = Math.max(0, Math.ceil((state.request.wait.deadline - Date.now()) / 1_000));
|
|
498
571
|
body.push(theme.fg('dim', state.waitHeld === true
|
|
499
|
-
? 'Take your time · waiting for your answer'
|
|
500
|
-
:
|
|
572
|
+
? theme.text('Take your time · waiting for your answer')
|
|
573
|
+
: theme.text('Continues in {seconds}s · {key} take time', { seconds: remaining, key: formatHotkeyKeys(HOTKEY_TAKE_TIME) })));
|
|
501
574
|
}
|
|
502
575
|
if (state.request.detail !== undefined && state.request.detail !== '')
|
|
503
576
|
body.push('', state.request.detail);
|
|
504
577
|
if (options.length > 0) {
|
|
505
578
|
const { start, end } = promptSelectorVisibleRange(options.length, state.selected, maxVisible);
|
|
506
|
-
body.push(''
|
|
579
|
+
body.push('');
|
|
580
|
+
for (let index = start; index < end; index++) {
|
|
581
|
+
const option = options[index];
|
|
582
|
+
choices.push({ row: bodyRow(), column: 2, width: contentWidth, index, value: option.value ?? option.label });
|
|
583
|
+
body.push(optionRow(option, index, state, theme, contentWidth, (state.request.options ?? []).indexOf(option)));
|
|
584
|
+
}
|
|
507
585
|
if (options.length > maxVisible) {
|
|
508
|
-
body.push(theme.fg('dim', ` ${state.selected + 1}/${options.length} · scroll for more`));
|
|
586
|
+
body.push(theme.fg('dim', ` ${state.selected + 1}/${options.length} · ${theme.text('scroll for more')}`));
|
|
509
587
|
}
|
|
588
|
+
// The paged list draws the selected row's preview beside the rows; the card
|
|
589
|
+
// gives it three lines underneath, so demoting a previewed list keeps the
|
|
590
|
+
// content it was being browsed for.
|
|
591
|
+
const preview = options[state.selected]?.preview;
|
|
592
|
+
if (preview !== undefined && preview !== '') {
|
|
593
|
+
const previewWidth = Math.max(1, contentWidth - 2);
|
|
594
|
+
const wrapped = options[state.selected]?.previewFormat === 'markdown'
|
|
595
|
+
? renderMarkdown(preview, theme, previewWidth)
|
|
596
|
+
: wrapTextStable(expandTabs(preview, 8, 4), previewWidth);
|
|
597
|
+
body.push('', ...wrapped.slice(0, CARD_PREVIEW_LINES).map(line => theme.fg('dim', ' ' + line)));
|
|
598
|
+
if (wrapped.length > CARD_PREVIEW_LINES) {
|
|
599
|
+
body.push(theme.fg('dim', ` … ${wrapped.length - CARD_PREVIEW_LINES} more lines`));
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
else if (state.request.options !== undefined) {
|
|
604
|
+
// A filter that matches nothing has to say so. An empty frame reads as a
|
|
605
|
+
// broken list, and the reader cannot tell a typo from an empty transcript.
|
|
606
|
+
body.push('', theme.fg('dim', ` ${state.request.emptyText
|
|
607
|
+
?? (filtering ? theme.text('No match for {query}.', { query: quote(input) }) : theme.text('Nothing to choose.'))}`));
|
|
510
608
|
}
|
|
511
|
-
|
|
512
|
-
|
|
609
|
+
/**
|
|
610
|
+
* The query, drawn where the reader types it.
|
|
611
|
+
*
|
|
612
|
+
* Every filterable card filters on the composer text, and the paged list used
|
|
613
|
+
* to print it — so demoting a list to a card made the query invisible: the rows
|
|
614
|
+
* narrowed while the reader's own words appeared nowhere, and a card with no
|
|
615
|
+
* hits looked broken rather than empty.
|
|
616
|
+
*/
|
|
617
|
+
const filterRow = state.request.filterable === true && state.request.presentation !== 'progress'
|
|
618
|
+
? bodyRow() + 1
|
|
619
|
+
: undefined;
|
|
620
|
+
if (filterRow !== undefined) {
|
|
621
|
+
// The query and what it kept belong on one line: the reader typed one thing
|
|
622
|
+
// and the list answered with a count.
|
|
623
|
+
const count = filtering ? theme.fg('dim', ` · ${options.length === 0 ? 'no match' : `${state.selected + 1}/${options.length}`}`) : '';
|
|
624
|
+
body.push('', input === ''
|
|
625
|
+
? theme.fg('muted', ' ' + theme.text('type to filter'))
|
|
626
|
+
: ' ' + theme.fg('text', input) + count);
|
|
627
|
+
}
|
|
628
|
+
// A request that has options but no match has nothing to submit: advertising
|
|
629
|
+
// `enter select` there promises a key the handler swallows.
|
|
630
|
+
const exhausted = options.length === 0 && state.request.options !== undefined && state.request.allowCustom === false;
|
|
631
|
+
const submit = (state.request.multiSelect === true ? state.request.submitLabel : options[state.selected]?.submitLabel ?? state.request.submitLabel)?.trim()
|
|
632
|
+
|| (options.length === 0 ? theme.text('answer') : state.request.multiSelect === true ? theme.text('confirm') : theme.text('select'));
|
|
513
633
|
// The request supplies the submit verb; the key itself comes from the catalog.
|
|
514
634
|
const select = `${formatHotkeyKeys(HOTKEY_SELECT)} ${submit}`;
|
|
515
635
|
const navigation = state.request.presentation === 'progress'
|
|
516
|
-
? formatOverlayHint([HOTKEY_CANCEL, HOTKEY_CANCEL_CTRL], 'catalog')
|
|
517
|
-
:
|
|
518
|
-
?
|
|
519
|
-
:
|
|
520
|
-
? `${
|
|
521
|
-
:
|
|
636
|
+
? formatOverlayHint([HOTKEY_CANCEL, HOTKEY_CANCEL_CTRL], 'catalog', theme.language)
|
|
637
|
+
: exhausted
|
|
638
|
+
? formatOverlayHint([HOTKEY_CANCEL], 'lowercase', theme.language)
|
|
639
|
+
: options.length === 0
|
|
640
|
+
? `${select} · ${formatOverlayHint([HOTKEY_CANCEL], 'lowercase', theme.language)}`
|
|
641
|
+
: state.request.multiSelect === true
|
|
642
|
+
? `${formatOverlayHint([HOTKEY_NAVIGATE], 'lowercase', theme.language)} · ${formatOverlayHint([state.request.answerFormat === 'json' ? HOTKEY_ANSWER_TOGGLE : HOTKEY_TOGGLE], 'lowercase', theme.language)} · ${formatOverlayHint([HOTKEY_CANCEL], 'lowercase', theme.language)}`
|
|
643
|
+
: `${formatOverlayHint([HOTKEY_NAVIGATE], 'lowercase', theme.language)} · ${formatOverlayHint([HOTKEY_CANCEL], 'lowercase', theme.language)}`;
|
|
522
644
|
const dismiss = state.request.dismissLabel;
|
|
523
645
|
const actionHints = (state.request.actions ?? []).map(action => `${action.key} ${action.label}`);
|
|
524
646
|
const hints = [
|
|
525
|
-
dismiss === undefined ? navigation : navigation.replace(formatOverlayHint([HOTKEY_CANCEL]), `${formatHotkeyKeys(HOTKEY_CANCEL)} ${dismiss.toLowerCase()}`),
|
|
526
|
-
...(state.request.skippable === true ? [formatOverlayHint([HOTKEY_SKIP])] : []),
|
|
527
|
-
...actionHints,
|
|
647
|
+
dismiss === undefined ? navigation : navigation.replace(formatOverlayHint([HOTKEY_CANCEL], 'lowercase', theme.language), `${formatHotkeyKeys(HOTKEY_CANCEL)} ${dismiss.toLowerCase()}`),
|
|
648
|
+
...(state.request.skippable === true ? [formatOverlayHint([HOTKEY_SKIP], 'lowercase', theme.language)] : []),
|
|
528
649
|
];
|
|
529
|
-
body.push('', theme.fg('dim', hints.join(' · ')));
|
|
650
|
+
body.push('', theme.fg('dim', theme.text(hints.join(' · '))));
|
|
651
|
+
if (state.request.options !== undefined) {
|
|
652
|
+
const buttons = [...(options.length === 0 ? [] : [{ key: 'enter', label: submit }]), ...(state.request.actions ?? []).filter(action => options.length > 0 || action.scope === 'list')];
|
|
653
|
+
let line = '';
|
|
654
|
+
for (const button of buttons) {
|
|
655
|
+
const label = truncateToWidth(`[ ${button.key === 'enter' ? 'Enter' : button.key} ${button.label} ]`, contentWidth);
|
|
656
|
+
if (line !== '' && visibleWidth(line + ' ' + label) > contentWidth) {
|
|
657
|
+
body.push(line);
|
|
658
|
+
line = '';
|
|
659
|
+
}
|
|
660
|
+
const gap = line === '' ? '' : ' ';
|
|
661
|
+
actions.push({ row: bodyRow(), column: 2 + visibleWidth(line + gap), width: visibleWidth(label), index: -1, key: button.key.toLowerCase() });
|
|
662
|
+
line += gap + theme.fg('accent', label);
|
|
663
|
+
}
|
|
664
|
+
if (line !== '')
|
|
665
|
+
body.push(line);
|
|
666
|
+
}
|
|
667
|
+
else if (actionHints.length > 0)
|
|
668
|
+
body.push(theme.fg('dim', actionHints.join(' · ')));
|
|
530
669
|
const card = renderFramedBlock({
|
|
531
670
|
header: state.request.title,
|
|
532
671
|
state: 'warning',
|
|
@@ -535,26 +674,60 @@ export function renderPromptSelector(state, theme, width, input, inputCursor, ma
|
|
|
535
674
|
applyBg: false,
|
|
536
675
|
}, theme);
|
|
537
676
|
if (state.request.allowCustom === false || state.request.presentation === 'progress') {
|
|
677
|
+
// With a filter line the caret follows the editor's insertion point;
|
|
678
|
+
// without one it stays on body padding, because the selector glyph
|
|
679
|
+
// owns focus while no text editor is present.
|
|
538
680
|
return {
|
|
539
|
-
lines: card,
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
cursorVisible:
|
|
681
|
+
lines: card, choices, actions,
|
|
682
|
+
cursor: filterRow === undefined
|
|
683
|
+
? { row: Math.min(1, Math.max(0, card.length - 1)), column: 1 }
|
|
684
|
+
: { row: filterRow, column: 4 + visibleWidth(input.slice(0, inputCursor)) },
|
|
685
|
+
cursorVisible: filterRow !== undefined,
|
|
544
686
|
};
|
|
545
687
|
}
|
|
546
688
|
const secret = state.request.secret === true;
|
|
547
689
|
const displayInput = secret ? maskPromptSecret(input) : input;
|
|
690
|
+
/**
|
|
691
|
+
* A question that is only text is the composer, not a card above it.
|
|
692
|
+
*
|
|
693
|
+
* This path used to draw a framed question and then a second framed editor
|
|
694
|
+
* under it: two borders that each looked like the place to type, two hint
|
|
695
|
+
* lines saying what Enter does, and a label reading `answer` that named
|
|
696
|
+
* nothing the reader had not already been told. A modal question is an
|
|
697
|
+
* interaction state the composer can carry itself — label in the top rule,
|
|
698
|
+
* question as the placeholder, keys in the bottom rule — which is also how pi
|
|
699
|
+
* mounts a dialog, in the editor's own slot.
|
|
700
|
+
*
|
|
701
|
+
* A prompt that also offers options keeps the card: a list plus a text field
|
|
702
|
+
* genuinely is two things. So does one that carries supporting copy, and one
|
|
703
|
+
* counting down a deadline — both need rows the bottom rule cannot give them.
|
|
704
|
+
*/
|
|
705
|
+
const detail = state.request.detail ?? '';
|
|
706
|
+
if (options.length === 0 && detail === '' && state.request.wait === undefined) {
|
|
707
|
+
const label = secret ? `${state.request.title} · hidden` : state.request.title;
|
|
708
|
+
const editor = renderEditor({
|
|
709
|
+
width,
|
|
710
|
+
input: displayInput,
|
|
711
|
+
inputCursor,
|
|
712
|
+
status: ' ' + theme.fg('accent', label) + ' ',
|
|
713
|
+
...(displayInput !== '' || state.request.question === '' ? {} : { inlineHint: state.request.question }),
|
|
714
|
+
// The keys live on the bottom rule so the frame says how to answer without
|
|
715
|
+
// spending a row on it.
|
|
716
|
+
...(hints.length === 0 ? {} : { note: theme.text(hints.join(' · ')) }),
|
|
717
|
+
border: 'accent',
|
|
718
|
+
}, theme);
|
|
719
|
+
return { lines: editor.lines, cursor: editor.cursor, cursorVisible: true };
|
|
720
|
+
}
|
|
548
721
|
const editor = renderEditor({
|
|
549
722
|
width,
|
|
550
723
|
input: displayInput,
|
|
551
724
|
inputCursor,
|
|
552
|
-
status: theme.fg('muted', secret ? 'API key · hidden' : input === '' ? 'answer' : 'custom answer'),
|
|
725
|
+
status: theme.fg('muted', secret ? theme.text('API key · hidden') : input === '' ? theme.text('answer') : theme.text('custom answer')),
|
|
553
726
|
border: 'accent',
|
|
554
727
|
}, theme);
|
|
555
728
|
const editorStart = card.length + 1;
|
|
556
729
|
return {
|
|
557
|
-
lines: [...card, '', ...editor.lines],
|
|
730
|
+
lines: [...card, '', ...editor.lines], choices, actions,
|
|
558
731
|
cursor: { row: editorStart + editor.cursor.row, column: editor.cursor.column },
|
|
559
732
|
cursorVisible: true,
|
|
560
733
|
};
|
|
@@ -581,14 +754,25 @@ export function togglePromptSelection(state, query = '') {
|
|
|
581
754
|
checked.add(index);
|
|
582
755
|
return { ...state, checked };
|
|
583
756
|
}
|
|
757
|
+
/** Keep option values and free text separate, including punctuation in labels. */
|
|
758
|
+
export function structuredPromptAnswer(state, custom) {
|
|
759
|
+
const options = state.request.options ?? [];
|
|
760
|
+
const selected = state.request.multiSelect === true
|
|
761
|
+
? options.flatMap((option, index) => state.checked.has(index) && !option.disabled ? [option.value ?? option.label] : [])
|
|
762
|
+
: custom.trim() !== '' || options[state.selected] === undefined || options[state.selected]?.disabled === true
|
|
763
|
+
? [] : [options[state.selected].value ?? options[state.selected].label];
|
|
764
|
+
return { selected, ...(custom.trim() === '' ? {} : { custom: custom.trim() }) };
|
|
765
|
+
}
|
|
584
766
|
/** Resolve the selected labels in stable option order. */
|
|
585
767
|
export function selectedPromptAnswer(state) {
|
|
586
|
-
const options = state.request.presentation === '
|
|
768
|
+
const options = state.request.presentation === 'tree'
|
|
587
769
|
? filteredPromptOptions(state.request, '', state.collapsed) : state.request.options ?? [];
|
|
588
770
|
if (options.length === 0)
|
|
589
771
|
return null;
|
|
590
772
|
if (state.request.multiSelect !== true) {
|
|
591
773
|
const option = options[state.selected];
|
|
774
|
+
if (option?.disabled === true)
|
|
775
|
+
return null;
|
|
592
776
|
return option?.value ?? option?.label ?? null;
|
|
593
777
|
}
|
|
594
778
|
const labels = options.flatMap((option, index) => state.checked.has(index) ? [option.value ?? option.label] : []);
|
|
@@ -597,6 +781,9 @@ export function selectedPromptAnswer(state) {
|
|
|
597
781
|
/** Resolve the selected answer after applying a full-screen selector query. */
|
|
598
782
|
export function selectedFilteredPromptAnswer(state, query) {
|
|
599
783
|
const option = filteredPromptOptions(state.request, query, state.collapsed)[state.selected];
|
|
784
|
+
// A disabled row is focusable but carries no answer, filtered or not.
|
|
785
|
+
if (option?.disabled === true)
|
|
786
|
+
return null;
|
|
600
787
|
return option?.value ?? option?.label ?? null;
|
|
601
788
|
}
|
|
602
789
|
//# sourceMappingURL=prompt-selector.js.map
|