@linxiraos/pi-tui 1.4.6 → 1.4.9
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/CHANGELOG.md +162 -244
- package/README.md +41 -35
- package/dist/types/app-keybindings.d.ts +20 -0
- package/dist/types/apps/session-picker.d.ts +5 -0
- package/dist/types/charts/chart-plan.d.ts +9 -7
- package/dist/types/charts/table-data.d.ts +4 -2
- package/dist/types/chat/assistant-message.d.ts +15 -3
- package/dist/types/chat/bash-execution.d.ts +6 -1
- package/dist/types/chat/display-preferences.d.ts +2 -0
- package/dist/types/chat/eval-execution.d.ts +2 -0
- package/dist/types/chat/execution-shared.d.ts +14 -8
- package/dist/types/chat/extension-types.d.ts +31 -0
- package/dist/types/chat/figure-markdown.d.ts +2 -0
- package/dist/types/chat/reply-write.d.ts +48 -0
- package/dist/types/chat/svg-figure.d.ts +5 -0
- package/dist/types/chat/table-chart.d.ts +6 -3
- package/dist/types/chat/tool-execution.d.ts +1 -2
- package/dist/types/chat/transcript-outline.d.ts +7 -0
- package/dist/types/chat/transcript-render-helpers.d.ts +13 -3
- package/dist/types/chrome/dynamic-border.d.ts +6 -0
- package/dist/types/chrome/index.d.ts +1 -0
- package/dist/types/chrome/transcript-notice.d.ts +35 -0
- package/dist/types/chrome/transcript-status.d.ts +21 -9
- package/dist/types/components/editor.d.ts +23 -6
- package/dist/types/components/image.d.ts +6 -0
- package/dist/types/components/loader.d.ts +2 -0
- package/dist/types/components/markdown.d.ts +7 -0
- package/dist/types/keybinding-matchers.d.ts +7 -0
- package/dist/types/native/blobs.d.ts +2 -1
- package/dist/types/native/describe.d.ts +4 -2
- package/dist/types/native/node.d.ts +2 -3
- package/dist/types/native/overlay.d.ts +42 -2
- package/dist/types/native/picker.d.ts +4 -4
- package/dist/types/native/state.d.ts +4 -0
- package/dist/types/overlays/annotation-overlay.d.ts +7 -1
- package/dist/types/overlays/annotation-types.d.ts +28 -0
- package/dist/types/overlays/btw-history-panel.d.ts +15 -0
- package/dist/types/overlays/btw-history.d.ts +24 -0
- package/dist/types/overlays/btw-inject.d.ts +22 -0
- package/dist/types/overlays/btw-panel.d.ts +7 -0
- package/dist/types/overlays/hook-editor.d.ts +2 -0
- package/dist/types/overlays/jobs-panel.d.ts +4 -0
- package/dist/types/overlays/login-dialog.d.ts +5 -1
- package/dist/types/overlays/model-browser.d.ts +11 -2
- package/dist/types/overlays/oauth-selector.d.ts +23 -0
- package/dist/types/overlays/plan-review-overlay.d.ts +2 -0
- package/dist/types/overlays/rewind-selector.d.ts +1 -1
- package/dist/types/overlays/session-selector.d.ts +33 -4
- package/dist/types/prompt/composer.d.ts +56 -5
- package/dist/types/prompt/interactive-context-helpers.d.ts +10 -3
- package/dist/types/render/extension-links.d.ts +65 -0
- package/dist/types/render/hyperlink.d.ts +25 -7
- package/dist/types/render/index.d.ts +1 -0
- package/dist/types/render/render-utils.d.ts +23 -1
- package/dist/types/setup/scenes/glyph.d.ts +1 -1
- package/dist/types/setup/scenes/model.d.ts +1 -1
- package/dist/types/setup/scenes/outro.d.ts +5 -4
- package/dist/types/setup/scenes/sign-in.d.ts +13 -8
- package/dist/types/setup/scenes/types.d.ts +16 -1
- package/dist/types/setup/startup-splash.d.ts +1 -1
- package/dist/types/setup/wizard-overlay.d.ts +11 -7
- package/dist/types/setup/wizard.d.ts +5 -1
- package/dist/types/status-line/component.d.ts +1 -1
- package/dist/types/status-line/context-usage.d.ts +28 -6
- package/dist/types/status-line/host.d.ts +6 -2
- package/dist/types/status-line/startup.d.ts +0 -15
- package/dist/types/terminal-capabilities.d.ts +1 -1
- package/dist/types/theme/symbols.d.ts +3 -1
- package/dist/types/theme/theme-class.d.ts +1 -0
- package/dist/types/theme/theme.d.ts +1 -24
- package/dist/types/theme/tui-adapters.d.ts +2 -0
- package/dist/types/thinking.d.ts +8 -6
- package/dist/types/tools/ast-grep.d.ts +2 -0
- package/dist/types/tools/bash-interactive.d.ts +6 -0
- package/dist/types/tools/bash.d.ts +2 -0
- package/dist/types/tools/default-renderer.d.ts +6 -4
- package/dist/types/tools/eval.d.ts +2 -0
- package/dist/types/tools/find.d.ts +1 -1
- package/dist/types/tools/grouped-file-output.d.ts +100 -19
- package/dist/types/tools/hashline-format.d.ts +5 -0
- package/dist/types/tools/irc.d.ts +6 -0
- package/dist/types/tools/json-tree.d.ts +23 -4
- package/dist/types/tools/lsp.d.ts +2 -0
- package/dist/types/tools/mcp.d.ts +6 -5
- package/dist/types/tools/native-view.d.ts +3 -1
- package/dist/types/tools/output-meta.d.ts +27 -0
- package/dist/types/tools/read.d.ts +14 -4
- package/dist/types/tools/renderer.d.ts +2 -0
- package/dist/types/tools/streaming-output.d.ts +11 -0
- package/dist/types/tools/task.d.ts +13 -4
- package/dist/types/tools/url-scheme-host.d.ts +17 -0
- package/dist/types/tools/wait.d.ts +2 -0
- package/dist/types/tools/yield.d.ts +1 -1
- package/dist/types/tui.d.ts +19 -2
- package/dist/types/utils.d.ts +4 -0
- package/package.json +10 -14
- package/src/app-keybindings.d.ts +20 -0
- package/src/app-keybindings.ts +20 -0
- package/src/apps/git/git-tui.ts +10 -17
- package/src/apps/git/sidebar.ts +21 -35
- package/src/apps/ps-top.ts +4 -12
- package/src/apps/session-picker.ts +7 -0
- package/src/charts/chart-plan.d.ts +9 -7
- package/src/charts/chart-plan.ts +20 -79
- package/src/charts/table-data.d.ts +4 -2
- package/src/charts/table-data.ts +55 -6
- package/src/chat/advisor-message.ts +2 -0
- package/src/chat/assistant-message.d.ts +15 -3
- package/src/chat/assistant-message.ts +137 -19
- package/src/chat/background-tan-message.ts +4 -0
- package/src/chat/bash-execution.d.ts +6 -1
- package/src/chat/bash-execution.ts +26 -9
- package/src/chat/chat-transcript-builder.ts +63 -30
- package/src/chat/compaction-summary-message.ts +2 -1
- package/src/chat/display-preferences.d.ts +2 -0
- package/src/chat/display-preferences.ts +3 -0
- package/src/chat/eval-execution.d.ts +2 -0
- package/src/chat/eval-execution.ts +14 -7
- package/src/chat/execution-shared.d.ts +14 -8
- package/src/chat/execution-shared.ts +39 -18
- package/src/chat/extension-types.d.ts +31 -0
- package/src/chat/extension-types.ts +34 -0
- package/src/chat/figure-markdown.d.ts +2 -0
- package/src/chat/figure-markdown.ts +6 -4
- package/src/chat/read-tool-group.ts +56 -36
- package/src/chat/reply-write.d.ts +48 -0
- package/src/chat/reply-write.ts +127 -0
- package/src/chat/svg-figure.d.ts +5 -0
- package/src/chat/svg-figure.ts +55 -16
- package/src/chat/table-chart.d.ts +6 -3
- package/src/chat/table-chart.ts +29 -6
- package/src/chat/tool-execution.d.ts +1 -2
- package/src/chat/tool-execution.ts +20 -13
- package/src/chat/transcript-outline.d.ts +7 -0
- package/src/chat/transcript-outline.ts +27 -0
- package/src/chat/transcript-render-helpers.d.ts +13 -3
- package/src/chat/transcript-render-helpers.ts +134 -44
- package/src/chrome/dynamic-border.d.ts +6 -0
- package/src/chrome/dynamic-border.ts +28 -2
- package/src/chrome/index.ts +1 -0
- package/src/chrome/transcript-notice.d.ts +35 -0
- package/src/chrome/transcript-notice.ts +83 -0
- package/src/chrome/transcript-status.d.ts +21 -9
- package/src/chrome/transcript-status.ts +32 -30
- package/src/components/editor.d.ts +23 -6
- package/src/components/editor.ts +133 -25
- package/src/components/image.d.ts +6 -0
- package/src/components/image.ts +13 -0
- package/src/components/key-value-list.ts +9 -9
- package/src/components/loader.d.ts +2 -0
- package/src/components/loader.ts +7 -0
- package/src/components/markdown.d.ts +7 -0
- package/src/components/markdown.ts +116 -6
- package/src/components/section.ts +1 -9
- package/src/components/table.ts +1 -9
- package/src/hotkeys-markdown.ts +1 -0
- package/src/keybinding-matchers.d.ts +7 -0
- package/src/keybinding-matchers.ts +13 -0
- package/src/native/backend.ts +10 -67
- package/src/native/blobs.d.ts +2 -1
- package/src/native/blobs.ts +3 -2
- package/src/native/describe.d.ts +4 -2
- package/src/native/describe.ts +9 -4
- package/src/native/node.d.ts +2 -3
- package/src/native/node.ts +2 -3
- package/src/native/overlay.d.ts +42 -2
- package/src/native/overlay.ts +124 -16
- package/src/native/picker.d.ts +4 -4
- package/src/native/picker.ts +4 -4
- package/src/native/state.d.ts +4 -0
- package/src/native/state.ts +25 -5
- package/src/overlays/advisor-config.ts +1 -10
- package/src/overlays/annotation-overlay.ts +125 -37
- package/src/overlays/annotation-types.ts +24 -0
- package/src/overlays/btw-history-panel.ts +106 -14
- package/src/overlays/btw-history.ts +65 -0
- package/src/overlays/btw-inject.ts +91 -0
- package/src/overlays/btw-panel.ts +53 -12
- package/src/overlays/extensions/extension-dashboard.ts +7 -8
- package/src/overlays/hook-editor.ts +6 -0
- package/src/overlays/hook-selector.ts +2 -2
- package/src/overlays/jobs-panel.ts +82 -22
- package/src/overlays/login-dialog.ts +39 -31
- package/src/overlays/mcp-add-wizard.ts +1 -1
- package/src/overlays/model-browser.ts +106 -10
- package/src/overlays/model-hub.ts +1 -7
- package/src/overlays/model-picker.ts +1 -10
- package/src/overlays/oauth-selector.ts +44 -6
- package/src/overlays/plan-review-overlay.ts +13 -2
- package/src/overlays/rewind-selector.ts +29 -12
- package/src/overlays/session-selector.ts +338 -47
- package/src/overlays/settings-defs.ts +2 -2
- package/src/overlays/tree-selector.ts +83 -27
- package/src/overlays/usage-dashboard.ts +9 -18
- package/src/prompt/composer.ts +233 -6
- package/src/prompt/custom-editor.ts +6 -1
- package/src/prompt/emoji-autocomplete.ts +0 -2
- package/src/prompt/interactive-context-helpers.ts +29 -4
- package/src/render/code-cell.ts +1 -1
- package/src/render/extension-links.d.ts +65 -0
- package/src/render/extension-links.ts +214 -0
- package/src/render/file-list.ts +4 -7
- package/src/render/hyperlink.d.ts +25 -7
- package/src/render/hyperlink.ts +65 -9
- package/src/render/index.d.ts +1 -0
- package/src/render/index.ts +1 -0
- package/src/render/render-utils.d.ts +23 -1
- package/src/render/render-utils.ts +38 -6
- package/src/setup/scenes/composer.ts +2 -0
- package/src/setup/scenes/glyph.ts +4 -2
- package/src/setup/scenes/model.ts +192 -29
- package/src/setup/scenes/outro.ts +33 -15
- package/src/setup/scenes/sign-in.ts +196 -400
- package/src/setup/scenes/theme.ts +2 -0
- package/src/setup/scenes/types.ts +18 -1
- package/src/setup/startup-splash.ts +8 -7
- package/src/setup/wizard-overlay.ts +164 -35
- package/src/setup/wizard.ts +11 -2
- package/src/status-line/component.ts +4 -10
- package/src/status-line/context-usage.ts +72 -21
- package/src/status-line/host.ts +6 -2
- package/src/status-line/startup.ts +36 -70
- package/src/terminal-capabilities.d.ts +1 -1
- package/src/terminal-capabilities.ts +5 -0
- package/src/terminal.ts +24 -2
- package/src/theme/defaults.json +1 -0
- package/src/theme/loader.ts +1 -1
- package/src/theme/symbols.d.ts +3 -1
- package/src/theme/symbols.ts +16 -9
- package/src/theme/theme-class.d.ts +1 -0
- package/src/theme/theme-class.ts +15 -3
- package/src/theme/theme.d.ts +1 -24
- package/src/theme/theme.ts +3 -75
- package/src/theme/tui-adapters.d.ts +2 -0
- package/src/theme/tui-adapters.ts +8 -3
- package/src/thinking.d.ts +8 -6
- package/src/thinking.ts +17 -11
- package/src/tmux.ts +1 -0
- package/src/tools/agent-tree.ts +13 -11
- package/src/tools/ask.ts +24 -37
- package/src/tools/ast-edit.ts +48 -93
- package/src/tools/ast-grep.d.ts +2 -0
- package/src/tools/ast-grep.ts +31 -67
- package/src/tools/bash-interactive.d.ts +49 -0
- package/src/tools/bash-interactive.ts +6 -1
- package/src/tools/bash.d.ts +2 -0
- package/src/tools/bash.ts +9 -0
- package/src/tools/default-renderer.d.ts +6 -4
- package/src/tools/default-renderer.ts +10 -7
- package/src/tools/edit.ts +50 -43
- package/src/tools/eval.d.ts +2 -0
- package/src/tools/eval.ts +16 -4
- package/src/tools/fetch.ts +2 -1
- package/src/tools/find.d.ts +1 -1
- package/src/tools/find.ts +13 -5
- package/src/tools/github.ts +14 -46
- package/src/tools/glob.ts +2 -1
- package/src/tools/grep.ts +47 -277
- package/src/tools/grouped-file-output.d.ts +100 -19
- package/src/tools/grouped-file-output.ts +414 -103
- package/src/tools/hashline-format.d.ts +5 -0
- package/src/tools/hashline-format.ts +5 -0
- package/src/tools/irc.d.ts +6 -0
- package/src/tools/irc.ts +6 -0
- package/src/tools/job-widget.ts +13 -1
- package/src/tools/json-tree.d.ts +23 -4
- package/src/tools/json-tree.ts +132 -46
- package/src/tools/lsp.d.ts +2 -0
- package/src/tools/lsp.ts +246 -47
- package/src/tools/mcp.d.ts +6 -5
- package/src/tools/mcp.ts +20 -12
- package/src/tools/native-view.d.ts +3 -1
- package/src/tools/native-view.ts +12 -6
- package/src/tools/output-meta.d.ts +27 -0
- package/src/tools/output-meta.ts +68 -4
- package/src/tools/proc-render.ts +3 -3
- package/src/tools/read.d.ts +14 -4
- package/src/tools/read.ts +20 -5
- package/src/tools/renderer.d.ts +2 -0
- package/src/tools/renderer.ts +2 -0
- package/src/tools/streaming-output.d.ts +11 -0
- package/src/tools/streaming-output.ts +41 -0
- package/src/tools/task.d.ts +13 -4
- package/src/tools/task.ts +100 -97
- package/src/tools/url-scheme-host.d.ts +17 -0
- package/src/tools/url-scheme-host.ts +21 -0
- package/src/tools/vibe.ts +4 -4
- package/src/tools/wait.d.ts +2 -0
- package/src/tools/wait.ts +8 -5
- package/src/tools/write.ts +17 -27
- package/src/tools/yield.d.ts +1 -1
- package/src/tools/yield.ts +19 -10
- package/src/tui.d.ts +19 -2
- package/src/tui.ts +134 -24
- package/src/utils.d.ts +4 -0
- package/src/utils.ts +10 -0
- package/dist/types/theme/defaults/index.d.ts +0 -10289
- package/src/theme/defaults/alabaster.json +0 -103
- package/src/theme/defaults/amethyst.json +0 -106
- package/src/theme/defaults/anthracite.json +0 -103
- package/src/theme/defaults/basalt.json +0 -101
- package/src/theme/defaults/birch.json +0 -105
- package/src/theme/defaults/dark-abyss.json +0 -101
- package/src/theme/defaults/dark-arctic.json +0 -114
- package/src/theme/defaults/dark-aurora.json +0 -105
- package/src/theme/defaults/dark-catppuccin.json +0 -117
- package/src/theme/defaults/dark-cavern.json +0 -101
- package/src/theme/defaults/dark-celestial.json +0 -116
- package/src/theme/defaults/dark-copper.json +0 -105
- package/src/theme/defaults/dark-cosmos.json +0 -100
- package/src/theme/defaults/dark-cyberpunk.json +0 -112
- package/src/theme/defaults/dark-dracula.json +0 -108
- package/src/theme/defaults/dark-eclipse.json +0 -101
- package/src/theme/defaults/dark-ember.json +0 -105
- package/src/theme/defaults/dark-equinox.json +0 -100
- package/src/theme/defaults/dark-forest.json +0 -106
- package/src/theme/defaults/dark-github.json +0 -115
- package/src/theme/defaults/dark-gruvbox.json +0 -122
- package/src/theme/defaults/dark-lavender.json +0 -105
- package/src/theme/defaults/dark-lunar.json +0 -99
- package/src/theme/defaults/dark-midnight.json +0 -105
- package/src/theme/defaults/dark-monochrome.json +0 -104
- package/src/theme/defaults/dark-monokai.json +0 -108
- package/src/theme/defaults/dark-nebula.json +0 -100
- package/src/theme/defaults/dark-neon-noir.json +0 -110
- package/src/theme/defaults/dark-nord.json +0 -108
- package/src/theme/defaults/dark-ocean.json +0 -111
- package/src/theme/defaults/dark-one.json +0 -110
- package/src/theme/defaults/dark-poimandres.json +0 -125
- package/src/theme/defaults/dark-rainforest.json +0 -101
- package/src/theme/defaults/dark-reef.json +0 -101
- package/src/theme/defaults/dark-retro.json +0 -102
- package/src/theme/defaults/dark-rose-pine.json +0 -106
- package/src/theme/defaults/dark-sakura.json +0 -105
- package/src/theme/defaults/dark-slate.json +0 -105
- package/src/theme/defaults/dark-solarized.json +0 -107
- package/src/theme/defaults/dark-solstice.json +0 -100
- package/src/theme/defaults/dark-starfall.json +0 -101
- package/src/theme/defaults/dark-sunset.json +0 -109
- package/src/theme/defaults/dark-swamp.json +0 -100
- package/src/theme/defaults/dark-synthwave.json +0 -113
- package/src/theme/defaults/dark-taiga.json +0 -101
- package/src/theme/defaults/dark-terminal.json +0 -105
- package/src/theme/defaults/dark-tokyo-night.json +0 -111
- package/src/theme/defaults/dark-tundra.json +0 -101
- package/src/theme/defaults/dark-twilight.json +0 -101
- package/src/theme/defaults/dark-volcanic.json +0 -101
- package/src/theme/defaults/graphite.json +0 -102
- package/src/theme/defaults/index.d.ts +0 -10289
- package/src/theme/defaults/index.ts +0 -203
- package/src/theme/defaults/light-arctic.json +0 -117
- package/src/theme/defaults/light-aurora-day.json +0 -101
- package/src/theme/defaults/light-canyon.json +0 -101
- package/src/theme/defaults/light-catppuccin.json +0 -116
- package/src/theme/defaults/light-cirrus.json +0 -100
- package/src/theme/defaults/light-coral.json +0 -105
- package/src/theme/defaults/light-cyberpunk.json +0 -106
- package/src/theme/defaults/light-dawn.json +0 -100
- package/src/theme/defaults/light-dunes.json +0 -101
- package/src/theme/defaults/light-eucalyptus.json +0 -105
- package/src/theme/defaults/light-forest.json +0 -110
- package/src/theme/defaults/light-frost.json +0 -105
- package/src/theme/defaults/light-github.json +0 -125
- package/src/theme/defaults/light-glacier.json +0 -101
- package/src/theme/defaults/light-gruvbox.json +0 -118
- package/src/theme/defaults/light-haze.json +0 -100
- package/src/theme/defaults/light-honeycomb.json +0 -105
- package/src/theme/defaults/light-lagoon.json +0 -101
- package/src/theme/defaults/light-lavender.json +0 -105
- package/src/theme/defaults/light-meadow.json +0 -101
- package/src/theme/defaults/light-mint.json +0 -105
- package/src/theme/defaults/light-monochrome.json +0 -111
- package/src/theme/defaults/light-ocean.json +0 -109
- package/src/theme/defaults/light-one.json +0 -109
- package/src/theme/defaults/light-opal.json +0 -101
- package/src/theme/defaults/light-orchard.json +0 -101
- package/src/theme/defaults/light-paper.json +0 -105
- package/src/theme/defaults/light-poimandres.json +0 -125
- package/src/theme/defaults/light-prism.json +0 -100
- package/src/theme/defaults/light-retro.json +0 -108
- package/src/theme/defaults/light-sand.json +0 -105
- package/src/theme/defaults/light-savanna.json +0 -101
- package/src/theme/defaults/light-solarized.json +0 -112
- package/src/theme/defaults/light-soleil.json +0 -100
- package/src/theme/defaults/light-sunset.json +0 -109
- package/src/theme/defaults/light-synthwave.json +0 -108
- package/src/theme/defaults/light-tokyo-night.json +0 -121
- package/src/theme/defaults/light-wetland.json +0 -101
- package/src/theme/defaults/light-zenith.json +0 -99
- package/src/theme/defaults/limestone.json +0 -104
- package/src/theme/defaults/mahogany.json +0 -107
- package/src/theme/defaults/marble.json +0 -103
- package/src/theme/defaults/obsidian.json +0 -101
- package/src/theme/defaults/onyx.json +0 -101
- package/src/theme/defaults/pearl.json +0 -103
- package/src/theme/defaults/porcelain.json +0 -101
- package/src/theme/defaults/quartz.json +0 -106
- package/src/theme/defaults/sandstone.json +0 -105
- package/src/theme/defaults/titanium.json +0 -100
|
@@ -26,6 +26,12 @@ import { isBareMathEnvironment, latexToUnicode } from "../latex-to-unicode";
|
|
|
26
26
|
import { plainText } from "../native/spans";
|
|
27
27
|
import { md } from "../native/describe";
|
|
28
28
|
import type { DescribeContext, NativeNode } from "../native/node";
|
|
29
|
+
import {
|
|
30
|
+
extensionLinkScheme,
|
|
31
|
+
extensionLinksVersion,
|
|
32
|
+
formatExtensionLink,
|
|
33
|
+
stripExtensionLinkMarkers,
|
|
34
|
+
} from "../render/extension-links";
|
|
29
35
|
import type { SymbolTheme } from "../symbols";
|
|
30
36
|
import { TERMINAL } from "../terminal-capabilities";
|
|
31
37
|
import { getSymbolTheme, getThemeEpoch } from "../theme/theme";
|
|
@@ -136,6 +142,40 @@ function fenceOpenAt(text: string, end: number): boolean {
|
|
|
136
142
|
return open !== undefined;
|
|
137
143
|
}
|
|
138
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Whether `text` ends inside a code fence the source never closed. The
|
|
147
|
+
* renderer still draws such a fence's closing border, so a caller publishing a
|
|
148
|
+
* settled source prefix must drop that fabricated row: it is not a prefix of
|
|
149
|
+
* the live block, which reaches the border only once the closer arrives.
|
|
150
|
+
*/
|
|
151
|
+
export function endsInsideOpenFence(text: string): boolean {
|
|
152
|
+
return fenceOpenAt(text, text.length);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Offset of the settled prefix of the still-open fence that `text` ends in, or
|
|
157
|
+
* 0 when it holds none.
|
|
158
|
+
*
|
|
159
|
+
* An open fence's body only ever appends: nothing a later chunk adds can
|
|
160
|
+
* change a line that already ended. Those lines are therefore settled, and a
|
|
161
|
+
* stream may publish them into native scrollback instead of leaving the whole
|
|
162
|
+
* block in the mutable viewport until the closing fence finally arrives — a
|
|
163
|
+
* long streamed code block would otherwise lose every row that left the screen
|
|
164
|
+
* (#9780).
|
|
165
|
+
*
|
|
166
|
+
* The cut lands before the last complete line, not after it: a streamed chunk
|
|
167
|
+
* usually ends on a "\n", and the publisher requires non-blank source past the
|
|
168
|
+
* prefix it publishes, so cutting at the final "\n" would publish nothing on
|
|
169
|
+
* exactly those frames. Once the closing fence has arrived, the retained line
|
|
170
|
+
* is the one in front of it.
|
|
171
|
+
*/
|
|
172
|
+
function settledFenceBodyEnd(text: string): number {
|
|
173
|
+
const lastBreak = text.lastIndexOf("\n");
|
|
174
|
+
if (lastBreak <= 0) return 0;
|
|
175
|
+
const cut = text.lastIndexOf("\n", lastBreak - 1) + 1;
|
|
176
|
+
return cut > 0 && fenceOpenAt(text, cut) ? cut : 0;
|
|
177
|
+
}
|
|
178
|
+
|
|
139
179
|
/**
|
|
140
180
|
* Streaming `md` source for a native terminal, minus a still-growing table row:
|
|
141
181
|
* the unterminated last line when a GFM table (a run of pipe lines holding a
|
|
@@ -1354,6 +1394,15 @@ function inlineHasOpen(tokens: readonly Token[]): boolean {
|
|
|
1354
1394
|
return false;
|
|
1355
1395
|
}
|
|
1356
1396
|
|
|
1397
|
+
/** True when the inline token stream holds a link whose scheme an extension claimed. */
|
|
1398
|
+
function hasExtensionLink(tokens: readonly Token[]): boolean {
|
|
1399
|
+
for (const token of tokens) {
|
|
1400
|
+
if (token.type === "link" && typeof token.href === "string" && extensionLinkScheme(token.href)) return true;
|
|
1401
|
+
if ("tokens" in token && Array.isArray(token.tokens) && hasExtensionLink(token.tokens as Token[])) return true;
|
|
1402
|
+
}
|
|
1403
|
+
return false;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1357
1406
|
/** Isolated inline lex of a same-line delta. A single-line delta has no block
|
|
1358
1407
|
* structure, so the isolated inline pass equals the full lex's inline pass
|
|
1359
1408
|
* (marked's paragraph tokens run the same `inlineTokens` entry point). */
|
|
@@ -2129,6 +2178,7 @@ interface RenderSignature {
|
|
|
2129
2178
|
defaultTextStyleId: number;
|
|
2130
2179
|
imageProtocol: string;
|
|
2131
2180
|
hyperlinks: boolean;
|
|
2181
|
+
extensionLinks: number;
|
|
2132
2182
|
textSizing: boolean;
|
|
2133
2183
|
bgColorProbe: string;
|
|
2134
2184
|
headingProbe: string;
|
|
@@ -2300,6 +2350,8 @@ export class Markdown implements Component {
|
|
|
2300
2350
|
#cachedText?: string;
|
|
2301
2351
|
#cachedWidth?: number;
|
|
2302
2352
|
#cachedLines?: readonly string[];
|
|
2353
|
+
// Extension-link routing changes how links draw without changing text or width.
|
|
2354
|
+
#cachedExtensionLinks?: number;
|
|
2303
2355
|
#transientRenderCache = false;
|
|
2304
2356
|
|
|
2305
2357
|
// Streaming-lex cache: the largest blank-line-bounded prefix of #text whose
|
|
@@ -2322,6 +2374,12 @@ export class Markdown implements Component {
|
|
|
2322
2374
|
// The frozen prefix's leading run in front of the first of those openers:
|
|
2323
2375
|
// no append can change its tokens, so getLastRenderStableText publishes it.
|
|
2324
2376
|
#streamSettledText?: string;
|
|
2377
|
+
// The complete lines inside a still-open fence, with the fence's opening
|
|
2378
|
+
// line in front of them: an open fence never reaches a "\n\n" boundary, so
|
|
2379
|
+
// #streamSettledText holds nothing for it and a long streamed code block
|
|
2380
|
+
// would stay unretirable until the closing fence arrived. Kept while the
|
|
2381
|
+
// source extends it, so the published prefix never shrinks.
|
|
2382
|
+
#streamFenceSettledText?: string;
|
|
2325
2383
|
// The text in front of the newest top-level item of a list that is still
|
|
2326
2384
|
// streaming as the last block. Once an item's marker line has ended, no
|
|
2327
2385
|
// append can add to the items in front of it, and #renderList draws each
|
|
@@ -2373,6 +2431,9 @@ export class Markdown implements Component {
|
|
|
2373
2431
|
#fastTail?: FastTailRecipe; // undefined = disarmed
|
|
2374
2432
|
// B+ capture plumbing: #renderContentLines records the last rendered paragraph row.
|
|
2375
2433
|
#lastTailCapture?: { kind: "paragraph"; open: boolean; rowInput: string; rowRaw: string };
|
|
2434
|
+
/** Top-level token index and running count of the extension links drawn in it; see `#renderContentLines`. */
|
|
2435
|
+
#extensionLinkBlock = 0;
|
|
2436
|
+
#extensionLinkOrdinal = 0;
|
|
2376
2437
|
#ignoreTight = false;
|
|
2377
2438
|
#native?: { text: string; stream: boolean; node: NativeNode };
|
|
2378
2439
|
setIgnoreTight(ignore: boolean): this {
|
|
@@ -2517,9 +2578,31 @@ export class Markdown implements Component {
|
|
|
2517
2578
|
*/
|
|
2518
2579
|
getLastRenderStableText(): string {
|
|
2519
2580
|
if (!this.#transientRenderCache) return "";
|
|
2520
|
-
|
|
2581
|
+
// An open fence has no "\n\n" boundary, so the block walk above settles
|
|
2582
|
+
// nothing inside it. Its finished lines are settled all the same: no
|
|
2583
|
+
// append can change a line that already ended. Publish them, or a long
|
|
2584
|
+
// streamed code block (SQL, logs) stays unretirable in the mutable
|
|
2585
|
+
// viewport and its top rows are dropped as it outgrows the screen.
|
|
2586
|
+
const source = streamingMarkdownSource(this.#text);
|
|
2587
|
+
let fence = this.#streamFenceSettledText;
|
|
2588
|
+
if (fence !== undefined && !source.startsWith(fence)) {
|
|
2589
|
+
// A non-append edit rewound the text below what was published. Drop
|
|
2590
|
+
// the stored prefix as well: keeping it would fail this check on
|
|
2591
|
+
// every later frame and leave the block unretirable for the rest of
|
|
2592
|
+
// the stream.
|
|
2593
|
+
fence = undefined;
|
|
2594
|
+
this.#streamFenceSettledText = undefined;
|
|
2595
|
+
}
|
|
2596
|
+
const body = settledFenceBodyEnd(source);
|
|
2597
|
+
if (body > (fence?.length ?? 0)) {
|
|
2598
|
+
fence = source.slice(0, body);
|
|
2599
|
+
this.#streamFenceSettledText = fence;
|
|
2600
|
+
}
|
|
2601
|
+
let text = this.#streamSettledText ?? "";
|
|
2521
2602
|
const list = this.#streamListSettledText;
|
|
2522
|
-
|
|
2603
|
+
if (list !== undefined && list.length > text.length) text = list;
|
|
2604
|
+
if (fence !== undefined && fence.length > text.length) text = fence;
|
|
2605
|
+
return text;
|
|
2523
2606
|
}
|
|
2524
2607
|
|
|
2525
2608
|
get transientRenderCache(): boolean {
|
|
@@ -2553,6 +2636,7 @@ export class Markdown implements Component {
|
|
|
2553
2636
|
this.#streamingHighlightCache = undefined;
|
|
2554
2637
|
this.#streamingListCache = undefined;
|
|
2555
2638
|
this.#streamRewound = undefined;
|
|
2639
|
+
this.#streamFenceSettledText = undefined;
|
|
2556
2640
|
}
|
|
2557
2641
|
this.invalidate();
|
|
2558
2642
|
}
|
|
@@ -2914,7 +2998,12 @@ export class Markdown implements Component {
|
|
|
2914
2998
|
// instance at the same width (e.g. resize debounce, repeated redraws).
|
|
2915
2999
|
// Returning the cached reference is load-bearing: parents memoize their
|
|
2916
3000
|
// concatenation on reference equality.
|
|
2917
|
-
if (
|
|
3001
|
+
if (
|
|
3002
|
+
this.#cachedLines &&
|
|
3003
|
+
this.#cachedText === this.#text &&
|
|
3004
|
+
this.#cachedWidth === width &&
|
|
3005
|
+
this.#cachedExtensionLinks === extensionLinksVersion()
|
|
3006
|
+
) {
|
|
2918
3007
|
return this.#cachedLines;
|
|
2919
3008
|
}
|
|
2920
3009
|
|
|
@@ -2927,6 +3016,7 @@ export class Markdown implements Component {
|
|
|
2927
3016
|
this.#cachedText = this.#text;
|
|
2928
3017
|
this.#cachedWidth = width;
|
|
2929
3018
|
this.#cachedLines = EMPTY_RENDER_LINES;
|
|
3019
|
+
this.#cachedExtensionLinks = extensionLinksVersion();
|
|
2930
3020
|
return EMPTY_RENDER_LINES;
|
|
2931
3021
|
}
|
|
2932
3022
|
|
|
@@ -3011,6 +3101,8 @@ export class Markdown implements Component {
|
|
|
3011
3101
|
// into a table on a marker-free delta (`| --` + `--- | -`).
|
|
3012
3102
|
!FAST_TABLE_DELIM_ROW_RE.test(grownLastLine) &&
|
|
3013
3103
|
(!markerDelta || (!this.#lastTailCapture?.open && !pairSeamHazard && !inlineHasOpen(deltaTokens!))) &&
|
|
3104
|
+
// Extension link markers are numbered per block; a delta rendered alone can't continue that.
|
|
3105
|
+
!(deltaTokens && hasExtensionLink(deltaTokens)) &&
|
|
3014
3106
|
!FAST_URL_ANYWHERE_RE.test(seamWindow) &&
|
|
3015
3107
|
// A link or math span the grown row leaves open renders speculatively closed: re-lex.
|
|
3016
3108
|
speculativeInlineClose(grownLastLine) === undefined
|
|
@@ -3051,6 +3143,7 @@ export class Markdown implements Component {
|
|
|
3051
3143
|
this.#cachedText = this.#text;
|
|
3052
3144
|
this.#cachedWidth = width;
|
|
3053
3145
|
this.#cachedLines = fastResult;
|
|
3146
|
+
this.#cachedExtensionLinks = signature.extensionLinks;
|
|
3054
3147
|
this.#fastTail = {
|
|
3055
3148
|
lines: fastResult,
|
|
3056
3149
|
source: this.#text,
|
|
@@ -3113,6 +3206,7 @@ export class Markdown implements Component {
|
|
|
3113
3206
|
this.#cachedText = this.#text;
|
|
3114
3207
|
this.#cachedWidth = width;
|
|
3115
3208
|
this.#cachedLines = cached;
|
|
3209
|
+
this.#cachedExtensionLinks = signature.extensionLinks;
|
|
3116
3210
|
return cached;
|
|
3117
3211
|
}
|
|
3118
3212
|
}
|
|
@@ -3146,6 +3240,7 @@ export class Markdown implements Component {
|
|
|
3146
3240
|
this.#cachedText = this.#text;
|
|
3147
3241
|
this.#cachedWidth = width;
|
|
3148
3242
|
this.#cachedLines = result;
|
|
3243
|
+
this.#cachedExtensionLinks = signature.extensionLinks;
|
|
3149
3244
|
|
|
3150
3245
|
const fastEligible =
|
|
3151
3246
|
this.transientRenderCache &&
|
|
@@ -3200,6 +3295,7 @@ export class Markdown implements Component {
|
|
|
3200
3295
|
defaultTextStyleId: this.#defaultTextStyle ? objectId(this.#defaultTextStyle) : -1,
|
|
3201
3296
|
imageProtocol: TERMINAL.imageProtocol ?? "",
|
|
3202
3297
|
hyperlinks: TERMINAL.hyperlinks,
|
|
3298
|
+
extensionLinks: extensionLinksVersion(),
|
|
3203
3299
|
textSizing: TERMINAL.textSizing,
|
|
3204
3300
|
bgColorProbe,
|
|
3205
3301
|
headingProbe,
|
|
@@ -3212,7 +3308,7 @@ export class Markdown implements Component {
|
|
|
3212
3308
|
}
|
|
3213
3309
|
|
|
3214
3310
|
#renderCacheKey(normalizedText: string, signature: RenderSignature): string {
|
|
3215
|
-
return `${normalizedText}\x00${signature.width}\x00${signature.paddingX}\x00${signature.paddingY}\x00${signature.codeBlockIndent}\x00${signature.themeId}\x00${signature.defaultTextStyleId}\x00${signature.imageProtocol}\x00${signature.hyperlinks ? 1 : 0}\x00${signature.textSizing ? 1 : 0}\x00${signature.bgColorProbe}\x00${signature.headingProbe}\x00${signature.symbolsProbe}`;
|
|
3311
|
+
return `${normalizedText}\x00${signature.width}\x00${signature.paddingX}\x00${signature.paddingY}\x00${signature.codeBlockIndent}\x00${signature.themeId}\x00${signature.defaultTextStyleId}\x00${signature.imageProtocol}\x00${signature.hyperlinks ? 1 : 0}\x00${signature.extensionLinks}\x00${signature.textSizing ? 1 : 0}\x00${signature.bgColorProbe}\x00${signature.headingProbe}\x00${signature.symbolsProbe}`;
|
|
3216
3312
|
}
|
|
3217
3313
|
|
|
3218
3314
|
#renderStreamingContentLines(
|
|
@@ -3288,6 +3384,7 @@ export class Markdown implements Component {
|
|
|
3288
3384
|
if (cache.defaultTextStyleId !== signature.defaultTextStyleId) return undefined;
|
|
3289
3385
|
if (cache.imageProtocol !== signature.imageProtocol) return undefined;
|
|
3290
3386
|
if (cache.hyperlinks !== signature.hyperlinks) return undefined;
|
|
3387
|
+
if (cache.extensionLinks !== signature.extensionLinks) return undefined;
|
|
3291
3388
|
if (cache.textSizing !== signature.textSizing) return undefined;
|
|
3292
3389
|
if (cache.bgColorProbe !== signature.bgColorProbe) return undefined;
|
|
3293
3390
|
if (cache.headingProbe !== signature.headingProbe) return undefined;
|
|
@@ -3378,6 +3475,7 @@ export class Markdown implements Component {
|
|
|
3378
3475
|
if (cache.defaultTextStyleId !== signature.defaultTextStyleId) return start;
|
|
3379
3476
|
if (cache.imageProtocol !== signature.imageProtocol) return start;
|
|
3380
3477
|
if (cache.hyperlinks !== signature.hyperlinks) return start;
|
|
3478
|
+
if (cache.extensionLinks !== signature.extensionLinks) return start;
|
|
3381
3479
|
if (cache.textSizing !== signature.textSizing) return start;
|
|
3382
3480
|
if (cache.bgColorProbe !== signature.bgColorProbe) return start;
|
|
3383
3481
|
if (cache.headingProbe !== signature.headingProbe) return start;
|
|
@@ -3412,6 +3510,10 @@ export class Markdown implements Component {
|
|
|
3412
3510
|
const token = tokens[i];
|
|
3413
3511
|
const nextToken = tokens[i + 1];
|
|
3414
3512
|
const tokenWrappedRowStart = wrappedLines.length;
|
|
3513
|
+
// Extension links are numbered per top-level block, across its nested inline runs, so
|
|
3514
|
+
// identical links on neighbouring rows draw distinct markers that every render repeats.
|
|
3515
|
+
this.#extensionLinkBlock = i;
|
|
3516
|
+
this.#extensionLinkOrdinal = 0;
|
|
3415
3517
|
const renderedTokenLines = this.#renderToken(token, contentWidth, nextToken?.type);
|
|
3416
3518
|
for (const renderedRow of renderedTokenLines) {
|
|
3417
3519
|
// Lists wrap while their structural prefixes are still available, so
|
|
@@ -3864,7 +3966,8 @@ export class Markdown implements Component {
|
|
|
3864
3966
|
const headingText = this.#renderInlineTokens(token.tokens || [], this.#proseFgExemptContext(styleContext));
|
|
3865
3967
|
const headingPlainText = plainInlineTokens(token.tokens || []);
|
|
3866
3968
|
let styledHeading: string;
|
|
3867
|
-
|
|
3969
|
+
// A sized heading draws plain text, which would drop a clickable extension link's marker.
|
|
3970
|
+
if (headingLevel === 1 && TERMINAL.textSizing && stripExtensionLinkMarkers(headingText) === headingText) {
|
|
3868
3971
|
const plainWidth = visibleWidth(headingPlainText);
|
|
3869
3972
|
if (plainWidth > 0 && 2 * plainWidth <= width) {
|
|
3870
3973
|
const sizedHeading = encodeTextSizedHeading(headingPlainText, 2);
|
|
@@ -4183,8 +4286,15 @@ export class Markdown implements Component {
|
|
|
4183
4286
|
token.tokens || [],
|
|
4184
4287
|
this.#proseFgExemptContext(resolvedStyleContext),
|
|
4185
4288
|
);
|
|
4186
|
-
const styledLinkText = this.#theme.link(this.#theme.underline(linkText));
|
|
4187
4289
|
const href = typeof token.href === "string" ? token.href : "";
|
|
4290
|
+
// An extension owns this link: no suffix, and no hyperlink the terminal could open.
|
|
4291
|
+
// Its label gets its own (dotted) underline instead of the web-link one.
|
|
4292
|
+
if (href && extensionLinkScheme(href)) {
|
|
4293
|
+
const key = `${this.#extensionLinkBlock}\0${this.#extensionLinkOrdinal++}`;
|
|
4294
|
+
result += formatExtensionLink(this.#theme.link(linkText), href, key) + stylePrefix;
|
|
4295
|
+
break;
|
|
4296
|
+
}
|
|
4297
|
+
const styledLinkText = this.#theme.link(this.#theme.underline(linkText));
|
|
4188
4298
|
const target = (href && this.#theme.resolveLink?.(href)) || href;
|
|
4189
4299
|
const clickableLinkText = formatHyperlink(styledLinkText, target);
|
|
4190
4300
|
// If link text matches href, only show the link once. A missing
|
|
@@ -2,20 +2,12 @@ import { compactText, rowsText, styledSpans } from "../native/spans";
|
|
|
2
2
|
import { node } from "../native/describe";
|
|
3
3
|
import type { DescribeContext, NativeNode } from "../native/node";
|
|
4
4
|
import type { Component } from "../tui";
|
|
5
|
-
import { Ellipsis, getWidthConfigEpoch,
|
|
5
|
+
import { Ellipsis, finiteWidth, getWidthConfigEpoch, singleLine, truncateToWidth, visibleWidth } from "../utils";
|
|
6
6
|
|
|
7
7
|
function isComponent(body: Component | readonly string[]): body is Component {
|
|
8
8
|
return !Array.isArray(body);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
function finiteWidth(width: number): number {
|
|
12
|
-
return Number.isFinite(width) ? Math.max(0, Math.trunc(width)) : 0;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function singleLine(text: string): string {
|
|
16
|
-
return replaceTabs(text).replace(/[\r\n]+/g, " ");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
11
|
function fillCells(glyph: string, width: number): string {
|
|
20
12
|
const cleanGlyph = singleLine(glyph);
|
|
21
13
|
const glyphWidth = visibleWidth(cleanGlyph);
|
package/src/components/table.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { compactText, styleSpans } from "../native/spans";
|
|
|
3
3
|
import { node } from "../native/describe";
|
|
4
4
|
import type { DescribeContext, NativeNode } from "../native/node";
|
|
5
5
|
import type { Component } from "../tui";
|
|
6
|
-
import { Ellipsis, getWidthConfigEpoch,
|
|
6
|
+
import { Ellipsis, finiteWidth, getWidthConfigEpoch, singleLine, truncateToWidth, visibleWidth } from "../utils";
|
|
7
7
|
|
|
8
8
|
/** One table cell. Styling is applied after alignment so padding shares the cell style. */
|
|
9
9
|
export interface TableCell {
|
|
@@ -29,14 +29,6 @@ export interface TableOptions {
|
|
|
29
29
|
readonly fit?: boolean;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
function finiteWidth(width: number, fallback = 0): number {
|
|
33
|
-
return Number.isFinite(width) ? Math.max(0, Math.trunc(width)) : fallback;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function singleLine(text: string): string {
|
|
37
|
-
return replaceTabs(text).replace(/[\r\n]+/g, " ");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
32
|
function fitWidths(columns: readonly TableColumn[], maxWidth: number, gapWidth: number): number[] {
|
|
41
33
|
const widths = columns.map(column => finiteWidth(column.width));
|
|
42
34
|
let overflow = widths.reduce((sum, width) => sum + width, 0) + Math.max(0, columns.length - 1) * gapWidth - maxWidth;
|
package/src/hotkeys-markdown.ts
CHANGED
|
@@ -135,6 +135,7 @@ function hotkeyGroups(bindings: HotkeysMarkdownBindings): HotkeyGroup[] {
|
|
|
135
135
|
{ keys: [act("app.history.search")], action: "Search prompt history" },
|
|
136
136
|
{ keys: [act("app.tools.expand")], action: "Toggle tool output expansion" },
|
|
137
137
|
{ keys: [act("app.tools.toggleVisibility")], action: "Toggle tool activity visibility" },
|
|
138
|
+
{ keys: [act("app.links.hint")], action: "Pick an extension link on screen by its tag" },
|
|
138
139
|
{ keys: [act("app.ask.hide")], action: "Hide/show a pending ask question" },
|
|
139
140
|
{ keys: [act("app.approval.approve")], action: "Approve a pending tool call" },
|
|
140
141
|
{ keys: [act("app.thinking.toggle")], action: "Toggle thinking block visibility" },
|
|
@@ -42,3 +42,10 @@ export declare function matchesAppFollowUp(data: string): boolean;
|
|
|
42
42
|
export declare function appApproveKeys(): readonly KeyId[];
|
|
43
43
|
/** Match the tool-approval key, recognizing modifier-tagged LF as Ctrl+Enter like {@link matchesAppFollowUp}. */
|
|
44
44
|
export declare function matchesAppApprove(data: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Effective /btw inject key (Alt+I by default). No fallback: it sends text into the main
|
|
47
|
+
* session, so a user who unbinds it gets no key at all.
|
|
48
|
+
*/
|
|
49
|
+
export declare function appBtwInjectKey(): KeyId | undefined;
|
|
50
|
+
/** Match the key that sends a /btw answer's steering prompt to the main session. */
|
|
51
|
+
export declare function matchesAppBtwInject(data: string): boolean;
|
|
@@ -120,3 +120,16 @@ export function appApproveKeys(): readonly KeyId[] {
|
|
|
120
120
|
export function matchesAppApprove(data: string): boolean {
|
|
121
121
|
return matchesEffectiveKeys(data, appApproveKeys());
|
|
122
122
|
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Effective /btw inject key (Alt+I by default). No fallback: it sends text into the main
|
|
126
|
+
* session, so a user who unbinds it gets no key at all.
|
|
127
|
+
*/
|
|
128
|
+
export function appBtwInjectKey(): KeyId | undefined {
|
|
129
|
+
return getKeybindings().getKeys("app.btw.inject")[0];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Match the key that sends a /btw answer's steering prompt to the main session. */
|
|
133
|
+
export function matchesAppBtwInject(data: string): boolean {
|
|
134
|
+
return getKeybindings().matches(data, "app.btw.inject");
|
|
135
|
+
}
|
package/src/native/backend.ts
CHANGED
|
@@ -39,15 +39,7 @@ import {
|
|
|
39
39
|
type TspOp,
|
|
40
40
|
} from "@linxiraos/pi-wire";
|
|
41
41
|
import type { Terminal } from "../terminal";
|
|
42
|
-
import {
|
|
43
|
-
bindTheme,
|
|
44
|
-
getCurrentThemeName,
|
|
45
|
-
getNativeThemePalette,
|
|
46
|
-
getNativeThemePaletteKey,
|
|
47
|
-
isLightTheme,
|
|
48
|
-
type NativeThemePalette,
|
|
49
|
-
setNativeSymbolPreset,
|
|
50
|
-
} from "../theme/theme";
|
|
42
|
+
import { getCurrentThemeName, isLightTheme, setNativeSymbolPreset } from "../theme/theme";
|
|
51
43
|
import type { Component, OverlayOptions, RenderScheduler, RenderTimer } from "../tui";
|
|
52
44
|
import { TspDocument } from "./apply";
|
|
53
45
|
import { getNativeBlob, type NativeBlob } from "./blobs";
|
|
@@ -56,7 +48,7 @@ import { encodeTspJson, encodeTspMessage, type TspHello, TspReader, splitTspMess
|
|
|
56
48
|
import type { DescribeContext, NativeChild, NativeNode, NativeSurface, NativeUiEvent } from "./node";
|
|
57
49
|
import { NARROW_SHEET_COLS } from "./overlay";
|
|
58
50
|
import { nativeComponentId, Reconciler } from "./reconcile";
|
|
59
|
-
import { setNativeRendering } from "./state";
|
|
51
|
+
import { setNativeButtons, setNativeRendering } from "./state";
|
|
60
52
|
|
|
61
53
|
/** A visible TUI overlay, bottom to top. */
|
|
62
54
|
export interface NativeOverlay {
|
|
@@ -206,9 +198,11 @@ function sameSet(a: ReadonlySet<string>, b: ReadonlySet<string>): boolean {
|
|
|
206
198
|
/**
|
|
207
199
|
* Kinds newer than some Tern builds that answer `TERM_PROGRAM=tern`: used only
|
|
208
200
|
* once the real `hello` lists them, so the optimistic start never emits a node
|
|
209
|
-
* an older terminal cannot draw (`media`: files Tern loads by path
|
|
201
|
+
* an older terminal cannot draw (`media`: files Tern loads by path; `json`:
|
|
202
|
+
* raw JSON values Tern draws as its own tree; `button`: omp's buttons, which
|
|
203
|
+
* older builds get as role-styled rows).
|
|
210
204
|
*/
|
|
211
|
-
const UNASSUMED_KINDS: Partial<Record<TspKind, true>> = { media: true };
|
|
205
|
+
const UNASSUMED_KINDS: Partial<Record<TspKind, true>> = { media: true, json: true, button: true };
|
|
212
206
|
|
|
213
207
|
/**
|
|
214
208
|
* The reply a v1 terminal is assumed to give before its real `hello` arrives
|
|
@@ -313,11 +307,6 @@ export class NativeBackend {
|
|
|
313
307
|
#sawResize = false;
|
|
314
308
|
#live = false;
|
|
315
309
|
#overlayNodes = new Map<Component, { key: string; node: NativeNode }>();
|
|
316
|
-
#unbindTheme: (() => void) | undefined;
|
|
317
|
-
#palette: NativeThemePalette | undefined;
|
|
318
|
-
#paletteKey: string | undefined;
|
|
319
|
-
/** Serialized palette last sent, to skip resends of an unchanged theme. */
|
|
320
|
-
#paletteSent: string | undefined;
|
|
321
310
|
/** Pending delivery owns bytes until sent or confirmed held; settled descriptions may already be released. */
|
|
322
311
|
#blobs = new Map<string, NativeBlob | "sent">();
|
|
323
312
|
/** `blobs` queries sent, oldest first: the terminal answers each once, in order. */
|
|
@@ -366,54 +355,11 @@ export class NativeBackend {
|
|
|
366
355
|
if (this.#live) return;
|
|
367
356
|
this.#live = true;
|
|
368
357
|
this.#useNerdSymbols(true);
|
|
369
|
-
this.#watchTheme();
|
|
370
358
|
this.#open(this.#inline);
|
|
371
359
|
setNativeRendering(true);
|
|
372
360
|
this.render();
|
|
373
361
|
}
|
|
374
362
|
|
|
375
|
-
/**
|
|
376
|
-
* Any theme swap (switch, selector preview, auto light/dark, file reload)
|
|
377
|
-
* schedules a render; `render()` resends the palette when it changed, so
|
|
378
|
-
* bursts coalesce into one `t` and no frame is needed for it.
|
|
379
|
-
*/
|
|
380
|
-
#watchTheme(): void {
|
|
381
|
-
this.#unbindTheme?.();
|
|
382
|
-
let initial = true;
|
|
383
|
-
this.#unbindTheme = bindTheme(() => {
|
|
384
|
-
if (initial) return;
|
|
385
|
-
this.#host.requestRender();
|
|
386
|
-
});
|
|
387
|
-
initial = false;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/** The current palette, recomputed only when its inputs changed. */
|
|
391
|
-
#currentPalette(): NativeThemePalette {
|
|
392
|
-
const key = getNativeThemePaletteKey();
|
|
393
|
-
if (this.#palette === undefined || key !== this.#paletteKey) {
|
|
394
|
-
this.#paletteKey = key;
|
|
395
|
-
this.#palette = getNativeThemePalette();
|
|
396
|
-
}
|
|
397
|
-
return this.#palette;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/** Send the palette to `surface` (right after its `o`, before any `f`). */
|
|
401
|
-
#sendPalette(surface: Surface): void {
|
|
402
|
-
const palette = this.#currentPalette();
|
|
403
|
-
if (!palette.dark && !palette.light) return;
|
|
404
|
-
this.#paletteSent = JSON.stringify(palette);
|
|
405
|
-
this.#write("t", { sf: surface.id, ...palette });
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
/** Resend the palette to every open surface when the theme changed since it was sent. */
|
|
409
|
-
#refreshPalette(): void {
|
|
410
|
-
const key = this.#paletteKey;
|
|
411
|
-
const palette = this.#currentPalette();
|
|
412
|
-
if (key === this.#paletteKey || JSON.stringify(palette) === this.#paletteSent) return;
|
|
413
|
-
this.#sendPalette(this.#inline);
|
|
414
|
-
if (this.#screen) this.#sendPalette(this.#screen);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
363
|
/**
|
|
418
364
|
* Tern's font carries every Nerd Font glyph, and it never answers the Glyph
|
|
419
365
|
* Protocol, so icons come from the nerd preset (process-local, not the
|
|
@@ -435,8 +381,7 @@ export class NativeBackend {
|
|
|
435
381
|
this.#close(this.#inline, keep);
|
|
436
382
|
this.#inline.doc?.close();
|
|
437
383
|
setNativeRendering(false);
|
|
438
|
-
|
|
439
|
-
this.#unbindTheme = undefined;
|
|
384
|
+
setNativeButtons(false);
|
|
440
385
|
this.#useNerdSymbols(false);
|
|
441
386
|
this.#clearStallTimer();
|
|
442
387
|
// Replies no longer reach the backend: forget the queries outright.
|
|
@@ -455,7 +400,6 @@ export class NativeBackend {
|
|
|
455
400
|
this.#applyHello(hello);
|
|
456
401
|
this.#live = true;
|
|
457
402
|
this.#useNerdSymbols(true);
|
|
458
|
-
this.#watchTheme();
|
|
459
403
|
this.#resetBlobs();
|
|
460
404
|
const surface = this.#inline;
|
|
461
405
|
surface.reconciler.detachLive();
|
|
@@ -466,7 +410,6 @@ export class NativeBackend {
|
|
|
466
410
|
surface.focus = null;
|
|
467
411
|
surface.dirty = false;
|
|
468
412
|
this.#write("o", { id: surface.id, mode: "inline", title: "omp", role: SESSION_ROLE, adopt: true });
|
|
469
|
-
this.#sendPalette(surface);
|
|
470
413
|
// After the `o`, as in `start()`.
|
|
471
414
|
setNativeRendering(true);
|
|
472
415
|
this.render();
|
|
@@ -508,7 +451,6 @@ export class NativeBackend {
|
|
|
508
451
|
/** Reconcile and send a frame, unless the target surface is out of credits. */
|
|
509
452
|
render(): void {
|
|
510
453
|
if (!this.#live) return;
|
|
511
|
-
this.#refreshPalette();
|
|
512
454
|
const overlays = this.#host.overlays();
|
|
513
455
|
let fullscreen = -1;
|
|
514
456
|
for (let i = overlays.length - 1; i >= 0; i--) {
|
|
@@ -599,6 +541,8 @@ export class NativeBackend {
|
|
|
599
541
|
this.#limit = hello.apc !== undefined && hello.apc > 0 ? hello.apc : TSP_DEFAULT_APC_LIMIT;
|
|
600
542
|
this.#credits = hello.credits !== undefined && hello.credits > 0 ? hello.credits : TSP_DEFAULT_CREDITS;
|
|
601
543
|
this.#cx = new NativeContext(hello, hello.cols ?? this.#cx.cols);
|
|
544
|
+
// A changed vocabulary re-describes every component (`confirm`).
|
|
545
|
+
setNativeButtons(this.#cx.supports("button"));
|
|
602
546
|
this.#sawResize = false;
|
|
603
547
|
}
|
|
604
548
|
|
|
@@ -608,7 +552,6 @@ export class NativeBackend {
|
|
|
608
552
|
|
|
609
553
|
#open(surface: Surface): void {
|
|
610
554
|
this.#write("o", { id: surface.id, mode: surface.mode, title: "omp", role: surface.role });
|
|
611
|
-
this.#sendPalette(surface);
|
|
612
555
|
}
|
|
613
556
|
|
|
614
557
|
#close(surface: Surface, keep: boolean): void {
|
|
@@ -776,7 +719,7 @@ export class NativeBackend {
|
|
|
776
719
|
}
|
|
777
720
|
}
|
|
778
721
|
|
|
779
|
-
#write(verb: "o" | "f" | "
|
|
722
|
+
#write(verb: "o" | "f" | "x" | "q", body: unknown): void {
|
|
780
723
|
this.#record("out", verb, undefined, body);
|
|
781
724
|
this.#host.terminal.write(encodeTspJson(verb, body, undefined, this.#limit));
|
|
782
725
|
}
|
package/src/native/blobs.d.ts
CHANGED
|
@@ -29,7 +29,8 @@ export declare function base64ImageNode(data: string, mimeType: string, p?: Omit
|
|
|
29
29
|
/**
|
|
30
30
|
* Props that make an `image` node open the file at `filePath` (as a `file://` URL, the TSP
|
|
31
31
|
* open-target form): a click zooms the image in the terminal, and the file opens from its
|
|
32
|
-
* context menu.
|
|
32
|
+
* context menu. Always uses a local file URL because the open action runs locally,
|
|
33
|
+
* even when remote file handlers are configured. Empty without a file.
|
|
33
34
|
*/
|
|
34
35
|
export declare function openableImageProps(filePath: string | undefined): Pick<TspProps<"image">, "href" | "actions">;
|
|
35
36
|
/**
|
package/src/native/blobs.ts
CHANGED
|
@@ -97,10 +97,11 @@ export function base64ImageNode(
|
|
|
97
97
|
/**
|
|
98
98
|
* Props that make an `image` node open the file at `filePath` (as a `file://` URL, the TSP
|
|
99
99
|
* open-target form): a click zooms the image in the terminal, and the file opens from its
|
|
100
|
-
* context menu.
|
|
100
|
+
* context menu. Always uses a local file URL because the open action runs locally,
|
|
101
|
+
* even when remote file handlers are configured. Empty without a file.
|
|
101
102
|
*/
|
|
102
103
|
export function openableImageProps(filePath: string | undefined): Pick<TspProps<"image">, "href" | "actions"> {
|
|
103
|
-
const href = filePath ? tryFileUri(filePath) : undefined;
|
|
104
|
+
const href = filePath ? tryFileUri(filePath, { local: true }) : undefined;
|
|
104
105
|
return href ? { href, actions: { menu: ["open"] } } : {};
|
|
105
106
|
}
|
|
106
107
|
|
package/src/native/describe.d.ts
CHANGED
|
@@ -56,7 +56,9 @@ export declare function list(items: readonly NativeChild[], p?: TspProps<"list">
|
|
|
56
56
|
/** Terminal-clocked elapsed counter: `age` ms already elapsed; `stopped` freezes it there. */
|
|
57
57
|
export declare function elapsed(age: number, stopped?: boolean): NativeNode;
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
59
|
+
* The key names of one key id (`"ctrl+o"` → `["ctrl", "o"]`), as `kbd` and
|
|
60
|
+
* `button` `keys` take them. A literal `+` key survives (`"+"`, `"ctrl++"`).
|
|
61
61
|
*/
|
|
62
|
+
export declare function keyNames(key: string): string[];
|
|
63
|
+
/** Keycap for one key id ({@link keyNames}); the terminal draws platform glyphs. */
|
|
62
64
|
export declare function kbd(key: string, nodeKey?: string): NativeNode;
|
package/src/native/describe.ts
CHANGED
|
@@ -132,10 +132,15 @@ export function elapsed(age: number, stopped?: boolean): NativeNode {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
135
|
+
* The key names of one key id (`"ctrl+o"` → `["ctrl", "o"]`), as `kbd` and
|
|
136
|
+
* `button` `keys` take them. A literal `+` key survives (`"+"`, `"ctrl++"`).
|
|
137
137
|
*/
|
|
138
|
-
export function
|
|
138
|
+
export function keyNames(key: string): string[] {
|
|
139
139
|
const keys = key === "+" ? ["+"] : key.endsWith("++") ? [...key.slice(0, -2).split("+"), "+"] : key.split("+");
|
|
140
|
-
return
|
|
140
|
+
return keys.filter(part => part.length > 0);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Keycap for one key id ({@link keyNames}); the terminal draws platform glyphs. */
|
|
144
|
+
export function kbd(key: string, nodeKey?: string): NativeNode {
|
|
145
|
+
return node("kbd", { keys: keyNames(key) }, undefined, nodeKey);
|
|
141
146
|
}
|
package/src/native/node.d.ts
CHANGED
|
@@ -10,9 +10,8 @@
|
|
|
10
10
|
* reference contract as `render()`). A component without `describe` becomes a
|
|
11
11
|
* `rows` fallback node rendered through `render(cx.cols)`.
|
|
12
12
|
*
|
|
13
|
-
* See `packages/wire/src/tsp.ts` for the wire vocabulary
|
|
14
|
-
* the Tern
|
|
15
|
-
* Stencil repository, https://docs.stencil.so/tern/protocol/) for the spec.
|
|
13
|
+
* See `packages/wire/src/tsp.ts` for the wire vocabulary; the normative spec is
|
|
14
|
+
* the Tern Surface Protocol.
|
|
16
15
|
*/
|
|
17
16
|
import type { TspEvent, TspKind, TspProps, TspScrollBy, TspSpan } from "@linxiraos/pi-wire";
|
|
18
17
|
import type { Component } from "../tui";
|
package/src/native/node.ts
CHANGED
|
@@ -10,9 +10,8 @@
|
|
|
10
10
|
* reference contract as `render()`). A component without `describe` becomes a
|
|
11
11
|
* `rows` fallback node rendered through `render(cx.cols)`.
|
|
12
12
|
*
|
|
13
|
-
* See `packages/wire/src/tsp.ts` for the wire vocabulary
|
|
14
|
-
* the Tern
|
|
15
|
-
* Stencil repository, https://docs.stencil.so/tern/protocol/) for the spec.
|
|
13
|
+
* See `packages/wire/src/tsp.ts` for the wire vocabulary; the normative spec is
|
|
14
|
+
* the Tern Surface Protocol.
|
|
16
15
|
*/
|
|
17
16
|
import type { TspEvent, TspKind, TspProps, TspScrollBy, TspSpan } from "@linxiraos/pi-wire";
|
|
18
17
|
import type { Component } from "../tui";
|