@linxiraos/pi-tui 1.4.4 → 1.4.7
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 +208 -207
- package/README.md +34 -34
- 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/chat/assistant-message.d.ts +15 -3
- package/dist/types/chat/bash-execution.d.ts +2 -0
- package/dist/types/chat/display-preferences.d.ts +2 -0
- package/dist/types/chat/extension-types.d.ts +31 -0
- package/dist/types/chat/reply-write.d.ts +48 -0
- package/dist/types/chat/table-chart.d.ts +4 -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 +2 -0
- package/dist/types/chrome/context-map.d.ts +15 -0
- package/dist/types/chrome/context-presentation.d.ts +48 -0
- package/dist/types/chrome/context-view-model.d.ts +77 -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 +20 -8
- package/dist/types/components/editor.d.ts +8 -0
- package/dist/types/components/image.d.ts +20 -0
- package/dist/types/components/loader.d.ts +1 -1
- package/dist/types/components/markdown.d.ts +7 -0
- package/dist/types/native/blobs.d.ts +11 -1
- package/dist/types/native/picker.d.ts +4 -4
- package/dist/types/overlays/advisor-config.d.ts +6 -0
- package/dist/types/overlays/agent-hub-projection.d.ts +3 -1
- package/dist/types/overlays/annotation-overlay.d.ts +7 -1
- package/dist/types/overlays/annotation-types.d.ts +28 -0
- package/dist/types/overlays/ask-dialog.d.ts +12 -3
- package/dist/types/overlays/btw-history-panel.d.ts +16 -2
- package/dist/types/overlays/btw-history.d.ts +7 -0
- package/dist/types/overlays/btw-panel.d.ts +2 -0
- package/dist/types/overlays/context-viewer-format.d.ts +42 -0
- package/dist/types/overlays/context-viewer-overview.d.ts +70 -0
- package/dist/types/overlays/context-viewer.d.ts +25 -0
- package/dist/types/overlays/hook-input.d.ts +1 -0
- package/dist/types/overlays/login-dialog.d.ts +5 -1
- package/dist/types/overlays/mcp-add-wizard.d.ts +2 -0
- package/dist/types/overlays/model-browser.d.ts +10 -1
- package/dist/types/overlays/oauth-selector.d.ts +23 -0
- package/dist/types/overlays/pause-screen.d.ts +13 -3
- 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/running-subagent-badge.d.ts +7 -1
- package/dist/types/overlays/session-selector.d.ts +22 -2
- package/dist/types/prompt/composer.d.ts +43 -0
- package/dist/types/prompt/interactive-context-helpers.d.ts +10 -3
- package/dist/types/prompt/macos-spelling.d.ts +2 -2
- package/dist/types/render/extension-links.d.ts +65 -0
- package/dist/types/render/hyperlink.d.ts +38 -7
- package/dist/types/render/index.d.ts +1 -0
- package/dist/types/render/output-pane.d.ts +1 -1
- package/dist/types/render/render-utils.d.ts +7 -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 +3 -3
- package/dist/types/status-line/context-usage.d.ts +42 -35
- package/dist/types/status-line/host.d.ts +6 -2
- package/dist/types/terminal-capabilities.d.ts +7 -0
- package/dist/types/theme/symbols.d.ts +1 -1
- package/dist/types/theme/theme.d.ts +0 -23
- package/dist/types/tools/ask.d.ts +4 -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/edit.d.ts +3 -1
- package/dist/types/tools/fetch.d.ts +1 -0
- package/dist/types/tools/github.d.ts +3 -0
- package/dist/types/tools/grouped-file-output.d.ts +2 -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 +7 -6
- package/dist/types/tools/native-view.d.ts +1 -1
- package/dist/types/tools/read.d.ts +3 -0
- 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 +9 -1
- package/dist/types/tools/url-scheme-host.d.ts +17 -0
- package/dist/types/tools/wait.d.ts +16 -2
- package/dist/types/tools/yield.d.ts +1 -1
- package/dist/types/tui.d.ts +9 -2
- package/dist/types/vim.d.ts +39 -0
- package/package.json +10 -14
- package/src/app-keybindings.d.ts +20 -0
- package/src/app-keybindings.ts +20 -0
- package/src/apps/session-picker.ts +7 -0
- package/src/charts/chart-plan.d.ts +9 -7
- package/src/charts/chart-plan.ts +20 -50
- 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 +2 -0
- package/src/chat/bash-execution.ts +13 -1
- package/src/chat/chat-transcript-builder.ts +58 -28
- 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/extension-types.d.ts +31 -0
- package/src/chat/extension-types.ts +34 -0
- package/src/chat/read-tool-group.ts +1 -2
- package/src/chat/reply-write.d.ts +48 -0
- package/src/chat/reply-write.ts +127 -0
- package/src/chat/skill-message.ts +2 -6
- package/src/chat/table-chart.d.ts +4 -3
- package/src/chat/table-chart.ts +10 -4
- 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 +2 -0
- package/src/chat/transcript-render-helpers.ts +66 -24
- package/src/chrome/context-map.ts +62 -0
- package/src/chrome/context-presentation.ts +26 -0
- package/src/chrome/context-view-model.ts +73 -0
- package/src/chrome/index.ts +1 -0
- package/src/chrome/transcript-container.ts +89 -59
- package/src/chrome/transcript-notice.d.ts +35 -0
- package/src/chrome/transcript-notice.ts +83 -0
- package/src/chrome/transcript-status.d.ts +20 -8
- package/src/chrome/transcript-status.ts +29 -29
- package/src/components/editor.d.ts +8 -0
- package/src/components/editor.ts +465 -14
- package/src/components/image.d.ts +20 -0
- package/src/components/image.ts +83 -18
- package/src/components/loader.d.ts +1 -1
- package/src/components/loader.ts +1 -1
- package/src/components/markdown.d.ts +7 -0
- package/src/components/markdown.ts +225 -13
- package/src/hotkeys-markdown.ts +2 -0
- package/src/native/backend.ts +5 -66
- package/src/native/blobs.d.ts +11 -1
- package/src/native/blobs.ts +5 -3
- package/src/native/picker.d.ts +4 -4
- package/src/native/picker.ts +4 -4
- package/src/overlays/advisor-config.ts +10 -12
- package/src/overlays/agent-hub-projection.d.ts +3 -1
- package/src/overlays/agent-hub-projection.ts +6 -5
- package/src/overlays/agent-hub.ts +51 -42
- package/src/overlays/annotation-overlay.ts +125 -37
- package/src/overlays/annotation-types.ts +24 -0
- package/src/overlays/ask-dialog.ts +125 -35
- package/src/overlays/btw-history-panel.ts +124 -12
- package/src/overlays/btw-history.ts +11 -0
- package/src/overlays/btw-panel.ts +8 -4
- package/src/overlays/context-viewer-format.ts +145 -0
- package/src/overlays/context-viewer-overview.ts +381 -0
- package/src/overlays/context-viewer.ts +728 -0
- package/src/overlays/hook-input.ts +2 -0
- package/src/overlays/hook-selector.ts +2 -2
- package/src/overlays/login-dialog.ts +31 -5
- package/src/overlays/mcp-add-wizard.ts +6 -1
- package/src/overlays/model-browser.ts +37 -0
- 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/pause-screen.ts +166 -33
- package/src/overlays/plan-review-overlay.ts +13 -2
- package/src/overlays/rewind-selector.ts +29 -12
- package/src/overlays/running-subagent-badge.ts +12 -1
- package/src/overlays/session-selector.ts +313 -42
- package/src/overlays/settings-defs.ts +1 -0
- package/src/overlays/usage-dashboard.ts +20 -14
- package/src/prompt/composer.ts +216 -1
- 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/prompt/macos-spelling.ts +24 -15
- package/src/render/extension-links.d.ts +65 -0
- package/src/render/extension-links.ts +214 -0
- package/src/render/hyperlink.d.ts +38 -7
- package/src/render/hyperlink.ts +102 -23
- package/src/render/index.d.ts +1 -0
- package/src/render/index.ts +1 -0
- package/src/render/output-pane.d.ts +1 -1
- package/src/render/output-pane.ts +60 -17
- package/src/render/render-utils.d.ts +7 -1
- package/src/render/render-utils.ts +11 -2
- package/src/setup/scenes/composer.ts +2 -0
- package/src/setup/scenes/glyph.ts +3 -1
- package/src/setup/scenes/model.ts +192 -29
- package/src/setup/scenes/outro.ts +33 -15
- package/src/setup/scenes/sign-in.ts +194 -392
- 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 +10 -14
- package/src/status-line/context-usage.ts +122 -597
- package/src/status-line/host.ts +6 -2
- package/src/terminal-capabilities.d.ts +7 -0
- package/src/terminal-capabilities.ts +10 -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 +1 -1
- package/src/theme/symbols.ts +16 -0
- package/src/theme/theme.d.ts +0 -23
- package/src/theme/theme.ts +2 -75
- package/src/tools/ask.d.ts +4 -0
- package/src/tools/ask.ts +4 -0
- package/src/tools/ast-grep.ts +3 -2
- 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 +7 -23
- package/src/tools/default-renderer.d.ts +6 -4
- package/src/tools/default-renderer.ts +9 -6
- package/src/tools/edit.d.ts +3 -1
- package/src/tools/edit.ts +8 -4
- package/src/tools/eval.ts +14 -4
- package/src/tools/fetch.d.ts +1 -0
- package/src/tools/fetch.ts +1 -0
- package/src/tools/find.ts +3 -10
- package/src/tools/github.d.ts +3 -0
- package/src/tools/github.ts +23 -3
- package/src/tools/glob.ts +4 -3
- package/src/tools/grep.ts +3 -4
- package/src/tools/grouped-file-output.d.ts +2 -0
- package/src/tools/grouped-file-output.ts +8 -2
- 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 -42
- package/src/tools/lsp.d.ts +2 -0
- package/src/tools/lsp.ts +36 -15
- package/src/tools/mcp.d.ts +7 -6
- package/src/tools/mcp.ts +41 -15
- package/src/tools/native-view.d.ts +1 -1
- package/src/tools/native-view.ts +3 -3
- package/src/tools/read.d.ts +3 -0
- package/src/tools/read.ts +3 -1
- 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 +9 -1
- package/src/tools/task.ts +59 -16
- package/src/tools/url-scheme-host.d.ts +17 -0
- package/src/tools/url-scheme-host.ts +21 -0
- package/src/tools/vibe.ts +14 -3
- package/src/tools/wait.d.ts +16 -2
- package/src/tools/wait.ts +16 -2
- package/src/tools/yield.d.ts +1 -1
- package/src/tools/yield.ts +18 -9
- package/src/tui.d.ts +9 -2
- package/src/tui.ts +102 -34
- package/src/vim.d.ts +39 -0
- package/src/vim.ts +313 -22
- 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). */
|
|
@@ -1764,8 +1813,13 @@ type ListToken = Token & {
|
|
|
1764
1813
|
start?: number;
|
|
1765
1814
|
loose: boolean;
|
|
1766
1815
|
};
|
|
1767
|
-
type TableCellToken = { tokens?: Token[] };
|
|
1768
|
-
type TableToken = Token & {
|
|
1816
|
+
type TableCellToken = { tokens?: Token[]; align?: Tokens.TableCell["align"] };
|
|
1817
|
+
type TableToken = Token & {
|
|
1818
|
+
header: TableCellToken[];
|
|
1819
|
+
rows: TableCellToken[][];
|
|
1820
|
+
raw?: string;
|
|
1821
|
+
align?: Array<Tokens.TableCell["align"]>;
|
|
1822
|
+
};
|
|
1769
1823
|
|
|
1770
1824
|
/** `item` as marked lexes it inside a loose list: tight `text` blocks become paragraphs. */
|
|
1771
1825
|
function loosenListItem(item: Tokens.ListItem): Tokens.ListItem {
|
|
@@ -1819,6 +1873,63 @@ function formatHyperlink(text: string, target: string): string {
|
|
|
1819
1873
|
return `\x1b]8;;${safeTarget}\x07${text}\x1b]8;;\x07`;
|
|
1820
1874
|
}
|
|
1821
1875
|
|
|
1876
|
+
const CODE_ESCAPE_RE = /\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\))/y;
|
|
1877
|
+
const CODE_URL_RE = /(?<![A-Za-z0-9+.-])https?:\/\/[^\s\x00-\x1f\x7f<>"'`]+/g;
|
|
1878
|
+
const CODE_URL_TRAILING_RE = /[.,;:!?]+$/;
|
|
1879
|
+
const CODE_URL_OPENERS: Partial<Record<string, string>> = { ")": "(", "]": "[", "}": "{" };
|
|
1880
|
+
|
|
1881
|
+
/** Whether `url` ends in a closing bracket that has no matching opener inside it. */
|
|
1882
|
+
function endsWithUnbalancedCloser(url: string): boolean {
|
|
1883
|
+
const closer = url.at(-1) ?? "";
|
|
1884
|
+
const opener = CODE_URL_OPENERS[closer];
|
|
1885
|
+
return opener !== undefined && url.split(closer).length > url.split(opener).length;
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
/**
|
|
1889
|
+
* Wrap each http(s) URL in a highlighted code row with an OSC 8 hyperlink.
|
|
1890
|
+
* The row is hard-wrapped later; wrapTextWithAnsi reopens the link on every
|
|
1891
|
+
* fragment, so terminals open the whole URL instead of only the first visual
|
|
1892
|
+
* line. URLs are located in the visible text so syntax-highlight escapes
|
|
1893
|
+
* inside them stay in place and the visible width is unchanged.
|
|
1894
|
+
*/
|
|
1895
|
+
function linkifyCodeUrls(line: string): string {
|
|
1896
|
+
if (!TERMINAL.hyperlinks || !line.includes("://") || line.includes("\x1b]8;")) {
|
|
1897
|
+
return line;
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
let visible = "";
|
|
1901
|
+
const offsets: number[] = [];
|
|
1902
|
+
for (let i = 0; i < line.length;) {
|
|
1903
|
+
if (line.charCodeAt(i) === 0x1b) {
|
|
1904
|
+
CODE_ESCAPE_RE.lastIndex = i;
|
|
1905
|
+
const match = CODE_ESCAPE_RE.exec(line);
|
|
1906
|
+
if (match) {
|
|
1907
|
+
i += match[0].length;
|
|
1908
|
+
continue;
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
offsets.push(i);
|
|
1912
|
+
visible += line[i];
|
|
1913
|
+
i++;
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
let result = "";
|
|
1917
|
+
let copied = 0;
|
|
1918
|
+
for (const match of visible.matchAll(CODE_URL_RE)) {
|
|
1919
|
+
let url = match[0].replace(CODE_URL_TRAILING_RE, "");
|
|
1920
|
+
// A closer only belongs to the URL when it balances an opener inside it.
|
|
1921
|
+
while (endsWithUnbalancedCloser(url)) {
|
|
1922
|
+
url = url.slice(0, -1).replace(CODE_URL_TRAILING_RE, "");
|
|
1923
|
+
}
|
|
1924
|
+
if (!/:\/\/./.test(url)) continue;
|
|
1925
|
+
const start = offsets[match.index] ?? 0;
|
|
1926
|
+
const end = (offsets[match.index + url.length - 1] ?? start) + 1;
|
|
1927
|
+
result += line.slice(copied, start) + formatHyperlink(line.slice(start, end), url);
|
|
1928
|
+
copied = end;
|
|
1929
|
+
}
|
|
1930
|
+
return copied === 0 ? line : result + line.slice(copied);
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1822
1933
|
function isAsciiTextSizingPayload(text: string): boolean {
|
|
1823
1934
|
for (let i = 0; i < text.length; i++) {
|
|
1824
1935
|
const code = text.charCodeAt(i);
|
|
@@ -2067,6 +2178,7 @@ interface RenderSignature {
|
|
|
2067
2178
|
defaultTextStyleId: number;
|
|
2068
2179
|
imageProtocol: string;
|
|
2069
2180
|
hyperlinks: boolean;
|
|
2181
|
+
extensionLinks: number;
|
|
2070
2182
|
textSizing: boolean;
|
|
2071
2183
|
bgColorProbe: string;
|
|
2072
2184
|
headingProbe: string;
|
|
@@ -2238,6 +2350,8 @@ export class Markdown implements Component {
|
|
|
2238
2350
|
#cachedText?: string;
|
|
2239
2351
|
#cachedWidth?: number;
|
|
2240
2352
|
#cachedLines?: readonly string[];
|
|
2353
|
+
// Extension-link routing changes how links draw without changing text or width.
|
|
2354
|
+
#cachedExtensionLinks?: number;
|
|
2241
2355
|
#transientRenderCache = false;
|
|
2242
2356
|
|
|
2243
2357
|
// Streaming-lex cache: the largest blank-line-bounded prefix of #text whose
|
|
@@ -2260,6 +2374,12 @@ export class Markdown implements Component {
|
|
|
2260
2374
|
// The frozen prefix's leading run in front of the first of those openers:
|
|
2261
2375
|
// no append can change its tokens, so getLastRenderStableText publishes it.
|
|
2262
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;
|
|
2263
2383
|
// The text in front of the newest top-level item of a list that is still
|
|
2264
2384
|
// streaming as the last block. Once an item's marker line has ended, no
|
|
2265
2385
|
// append can add to the items in front of it, and #renderList draws each
|
|
@@ -2311,6 +2431,9 @@ export class Markdown implements Component {
|
|
|
2311
2431
|
#fastTail?: FastTailRecipe; // undefined = disarmed
|
|
2312
2432
|
// B+ capture plumbing: #renderContentLines records the last rendered paragraph row.
|
|
2313
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;
|
|
2314
2437
|
#ignoreTight = false;
|
|
2315
2438
|
#native?: { text: string; stream: boolean; node: NativeNode };
|
|
2316
2439
|
setIgnoreTight(ignore: boolean): this {
|
|
@@ -2455,9 +2578,31 @@ export class Markdown implements Component {
|
|
|
2455
2578
|
*/
|
|
2456
2579
|
getLastRenderStableText(): string {
|
|
2457
2580
|
if (!this.#transientRenderCache) return "";
|
|
2458
|
-
|
|
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 ?? "";
|
|
2459
2602
|
const list = this.#streamListSettledText;
|
|
2460
|
-
|
|
2603
|
+
if (list !== undefined && list.length > text.length) text = list;
|
|
2604
|
+
if (fence !== undefined && fence.length > text.length) text = fence;
|
|
2605
|
+
return text;
|
|
2461
2606
|
}
|
|
2462
2607
|
|
|
2463
2608
|
get transientRenderCache(): boolean {
|
|
@@ -2491,6 +2636,7 @@ export class Markdown implements Component {
|
|
|
2491
2636
|
this.#streamingHighlightCache = undefined;
|
|
2492
2637
|
this.#streamingListCache = undefined;
|
|
2493
2638
|
this.#streamRewound = undefined;
|
|
2639
|
+
this.#streamFenceSettledText = undefined;
|
|
2494
2640
|
}
|
|
2495
2641
|
this.invalidate();
|
|
2496
2642
|
}
|
|
@@ -2852,7 +2998,12 @@ export class Markdown implements Component {
|
|
|
2852
2998
|
// instance at the same width (e.g. resize debounce, repeated redraws).
|
|
2853
2999
|
// Returning the cached reference is load-bearing: parents memoize their
|
|
2854
3000
|
// concatenation on reference equality.
|
|
2855
|
-
if (
|
|
3001
|
+
if (
|
|
3002
|
+
this.#cachedLines &&
|
|
3003
|
+
this.#cachedText === this.#text &&
|
|
3004
|
+
this.#cachedWidth === width &&
|
|
3005
|
+
this.#cachedExtensionLinks === extensionLinksVersion()
|
|
3006
|
+
) {
|
|
2856
3007
|
return this.#cachedLines;
|
|
2857
3008
|
}
|
|
2858
3009
|
|
|
@@ -2865,6 +3016,7 @@ export class Markdown implements Component {
|
|
|
2865
3016
|
this.#cachedText = this.#text;
|
|
2866
3017
|
this.#cachedWidth = width;
|
|
2867
3018
|
this.#cachedLines = EMPTY_RENDER_LINES;
|
|
3019
|
+
this.#cachedExtensionLinks = extensionLinksVersion();
|
|
2868
3020
|
return EMPTY_RENDER_LINES;
|
|
2869
3021
|
}
|
|
2870
3022
|
|
|
@@ -2949,6 +3101,8 @@ export class Markdown implements Component {
|
|
|
2949
3101
|
// into a table on a marker-free delta (`| --` + `--- | -`).
|
|
2950
3102
|
!FAST_TABLE_DELIM_ROW_RE.test(grownLastLine) &&
|
|
2951
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)) &&
|
|
2952
3106
|
!FAST_URL_ANYWHERE_RE.test(seamWindow) &&
|
|
2953
3107
|
// A link or math span the grown row leaves open renders speculatively closed: re-lex.
|
|
2954
3108
|
speculativeInlineClose(grownLastLine) === undefined
|
|
@@ -2989,6 +3143,7 @@ export class Markdown implements Component {
|
|
|
2989
3143
|
this.#cachedText = this.#text;
|
|
2990
3144
|
this.#cachedWidth = width;
|
|
2991
3145
|
this.#cachedLines = fastResult;
|
|
3146
|
+
this.#cachedExtensionLinks = signature.extensionLinks;
|
|
2992
3147
|
this.#fastTail = {
|
|
2993
3148
|
lines: fastResult,
|
|
2994
3149
|
source: this.#text,
|
|
@@ -3051,6 +3206,7 @@ export class Markdown implements Component {
|
|
|
3051
3206
|
this.#cachedText = this.#text;
|
|
3052
3207
|
this.#cachedWidth = width;
|
|
3053
3208
|
this.#cachedLines = cached;
|
|
3209
|
+
this.#cachedExtensionLinks = signature.extensionLinks;
|
|
3054
3210
|
return cached;
|
|
3055
3211
|
}
|
|
3056
3212
|
}
|
|
@@ -3084,6 +3240,7 @@ export class Markdown implements Component {
|
|
|
3084
3240
|
this.#cachedText = this.#text;
|
|
3085
3241
|
this.#cachedWidth = width;
|
|
3086
3242
|
this.#cachedLines = result;
|
|
3243
|
+
this.#cachedExtensionLinks = signature.extensionLinks;
|
|
3087
3244
|
|
|
3088
3245
|
const fastEligible =
|
|
3089
3246
|
this.transientRenderCache &&
|
|
@@ -3138,6 +3295,7 @@ export class Markdown implements Component {
|
|
|
3138
3295
|
defaultTextStyleId: this.#defaultTextStyle ? objectId(this.#defaultTextStyle) : -1,
|
|
3139
3296
|
imageProtocol: TERMINAL.imageProtocol ?? "",
|
|
3140
3297
|
hyperlinks: TERMINAL.hyperlinks,
|
|
3298
|
+
extensionLinks: extensionLinksVersion(),
|
|
3141
3299
|
textSizing: TERMINAL.textSizing,
|
|
3142
3300
|
bgColorProbe,
|
|
3143
3301
|
headingProbe,
|
|
@@ -3150,7 +3308,7 @@ export class Markdown implements Component {
|
|
|
3150
3308
|
}
|
|
3151
3309
|
|
|
3152
3310
|
#renderCacheKey(normalizedText: string, signature: RenderSignature): string {
|
|
3153
|
-
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}`;
|
|
3154
3312
|
}
|
|
3155
3313
|
|
|
3156
3314
|
#renderStreamingContentLines(
|
|
@@ -3226,6 +3384,7 @@ export class Markdown implements Component {
|
|
|
3226
3384
|
if (cache.defaultTextStyleId !== signature.defaultTextStyleId) return undefined;
|
|
3227
3385
|
if (cache.imageProtocol !== signature.imageProtocol) return undefined;
|
|
3228
3386
|
if (cache.hyperlinks !== signature.hyperlinks) return undefined;
|
|
3387
|
+
if (cache.extensionLinks !== signature.extensionLinks) return undefined;
|
|
3229
3388
|
if (cache.textSizing !== signature.textSizing) return undefined;
|
|
3230
3389
|
if (cache.bgColorProbe !== signature.bgColorProbe) return undefined;
|
|
3231
3390
|
if (cache.headingProbe !== signature.headingProbe) return undefined;
|
|
@@ -3316,6 +3475,7 @@ export class Markdown implements Component {
|
|
|
3316
3475
|
if (cache.defaultTextStyleId !== signature.defaultTextStyleId) return start;
|
|
3317
3476
|
if (cache.imageProtocol !== signature.imageProtocol) return start;
|
|
3318
3477
|
if (cache.hyperlinks !== signature.hyperlinks) return start;
|
|
3478
|
+
if (cache.extensionLinks !== signature.extensionLinks) return start;
|
|
3319
3479
|
if (cache.textSizing !== signature.textSizing) return start;
|
|
3320
3480
|
if (cache.bgColorProbe !== signature.bgColorProbe) return start;
|
|
3321
3481
|
if (cache.headingProbe !== signature.headingProbe) return start;
|
|
@@ -3350,6 +3510,10 @@ export class Markdown implements Component {
|
|
|
3350
3510
|
const token = tokens[i];
|
|
3351
3511
|
const nextToken = tokens[i + 1];
|
|
3352
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;
|
|
3353
3517
|
const renderedTokenLines = this.#renderToken(token, contentWidth, nextToken?.type);
|
|
3354
3518
|
for (const renderedRow of renderedTokenLines) {
|
|
3355
3519
|
// Lists wrap while their structural prefixes are still available, so
|
|
@@ -3483,7 +3647,8 @@ export class Markdown implements Component {
|
|
|
3483
3647
|
const tokenText = "text" in token && typeof token.text === "string" ? token.text : "";
|
|
3484
3648
|
const lang = "lang" in token && typeof token.lang === "string" ? token.lang : undefined;
|
|
3485
3649
|
const addBodyLine = (line: string): void => {
|
|
3486
|
-
|
|
3650
|
+
const linked = linkifyCodeUrls(line);
|
|
3651
|
+
bodyLines.push(renderedLine(literalCode ? linked : codeIndent + linked, literalCode));
|
|
3487
3652
|
};
|
|
3488
3653
|
|
|
3489
3654
|
const streaming = this.transientRenderCache && !this.#renderingStablePrefix;
|
|
@@ -3801,7 +3966,8 @@ export class Markdown implements Component {
|
|
|
3801
3966
|
const headingText = this.#renderInlineTokens(token.tokens || [], this.#proseFgExemptContext(styleContext));
|
|
3802
3967
|
const headingPlainText = plainInlineTokens(token.tokens || []);
|
|
3803
3968
|
let styledHeading: string;
|
|
3804
|
-
|
|
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) {
|
|
3805
3971
|
const plainWidth = visibleWidth(headingPlainText);
|
|
3806
3972
|
if (plainWidth > 0 && 2 * plainWidth <= width) {
|
|
3807
3973
|
const sizedHeading = encodeTextSizedHeading(headingPlainText, 2);
|
|
@@ -4120,8 +4286,15 @@ export class Markdown implements Component {
|
|
|
4120
4286
|
token.tokens || [],
|
|
4121
4287
|
this.#proseFgExemptContext(resolvedStyleContext),
|
|
4122
4288
|
);
|
|
4123
|
-
const styledLinkText = this.#theme.link(this.#theme.underline(linkText));
|
|
4124
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));
|
|
4125
4298
|
const target = (href && this.#theme.resolveLink?.(href)) || href;
|
|
4126
4299
|
const clickableLinkText = formatHyperlink(styledLinkText, target);
|
|
4127
4300
|
// If link text matches href, only show the link once. A missing
|
|
@@ -4283,7 +4456,13 @@ export class Markdown implements Component {
|
|
|
4283
4456
|
|
|
4284
4457
|
// Process item tokens; nested-list lines arrive structurally tagged and
|
|
4285
4458
|
// already carry their own full indent.
|
|
4286
|
-
const itemLines = this.#renderListItem(
|
|
4459
|
+
const itemLines = this.#renderListItem(
|
|
4460
|
+
item.tokens || [],
|
|
4461
|
+
depth,
|
|
4462
|
+
width,
|
|
4463
|
+
Math.max(1, width - visibleWidth(continuationIndent)),
|
|
4464
|
+
styleContext,
|
|
4465
|
+
);
|
|
4287
4466
|
|
|
4288
4467
|
if (itemLines.length > 0) {
|
|
4289
4468
|
const firstLine = itemLines[0]!;
|
|
@@ -4335,11 +4514,13 @@ export class Markdown implements Component {
|
|
|
4335
4514
|
tokens: Token[],
|
|
4336
4515
|
parentDepth: number,
|
|
4337
4516
|
width: number,
|
|
4517
|
+
contentWidth: number,
|
|
4338
4518
|
styleContext?: InlineStyleContext,
|
|
4339
4519
|
): RenderedListItemLine[] {
|
|
4340
4520
|
const lines: RenderedListItemLine[] = [];
|
|
4341
4521
|
|
|
4342
|
-
for (
|
|
4522
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
4523
|
+
const token = tokens[i]!;
|
|
4343
4524
|
if (token.type === "list") {
|
|
4344
4525
|
// Nested list - render with one additional indent level
|
|
4345
4526
|
// These lines carry their own indent, so tag them for pass-through
|
|
@@ -4379,6 +4560,10 @@ export class Markdown implements Component {
|
|
|
4379
4560
|
lines.push({ ...bodyLine, nested: false });
|
|
4380
4561
|
}
|
|
4381
4562
|
lines.push({ text: this.#theme.codeBlockBorder("```"), nested: false });
|
|
4563
|
+
} else if (token.type === "table") {
|
|
4564
|
+
for (const row of this.#renderTable(token as TableToken, contentWidth, tokens[i + 1]?.type, styleContext)) {
|
|
4565
|
+
lines.push({ text: row, nested: false });
|
|
4566
|
+
}
|
|
4382
4567
|
} else if (isMathToken(token)) {
|
|
4383
4568
|
// Display math block inside a list item: stack fractions / matrix rows.
|
|
4384
4569
|
const apply = styleContext?.applyText ?? ((t: string) => this.#applyDefaultStyle(t));
|
|
@@ -4445,6 +4630,26 @@ export class Markdown implements Component {
|
|
|
4445
4630
|
});
|
|
4446
4631
|
}
|
|
4447
4632
|
|
|
4633
|
+
/**
|
|
4634
|
+
* Pad a table cell to the width of its column, following the column's GFM
|
|
4635
|
+
* alignment: a right-aligned cell ends at the column's right edge, a
|
|
4636
|
+
* centered one is surrounded by padding, and anything else stays flush left.
|
|
4637
|
+
*/
|
|
4638
|
+
#alignCellText(text: string, width: number, align: Tokens.TableCell["align"]): string {
|
|
4639
|
+
const gap = Math.max(0, width - visibleWidth(text));
|
|
4640
|
+
if (gap === 0) return text;
|
|
4641
|
+
switch (align) {
|
|
4642
|
+
case "right":
|
|
4643
|
+
return padding(gap) + text;
|
|
4644
|
+
case "center": {
|
|
4645
|
+
const left = Math.floor(gap / 2);
|
|
4646
|
+
return padding(left) + text + padding(gap - left);
|
|
4647
|
+
}
|
|
4648
|
+
default:
|
|
4649
|
+
return text + padding(gap);
|
|
4650
|
+
}
|
|
4651
|
+
}
|
|
4652
|
+
|
|
4448
4653
|
/**
|
|
4449
4654
|
* Render a table with width-aware cell wrapping.
|
|
4450
4655
|
* Cells that don't fit are wrapped to multiple lines.
|
|
@@ -4586,6 +4791,12 @@ export class Markdown implements Component {
|
|
|
4586
4791
|
const h = t.horizontal;
|
|
4587
4792
|
const v = t.vertical;
|
|
4588
4793
|
|
|
4794
|
+
// GFM alignment belongs to the column: the marker in the delimiter row
|
|
4795
|
+
// applies to the header and to every body cell below it.
|
|
4796
|
+
const columnAligns: Array<Tokens.TableCell["align"]> = token.header.map(
|
|
4797
|
+
(cell, i) => cell.align ?? token.align?.[i] ?? null,
|
|
4798
|
+
);
|
|
4799
|
+
|
|
4589
4800
|
// Render top border
|
|
4590
4801
|
const topBorderCells = columnWidths.map(w => h.repeat(w));
|
|
4591
4802
|
lines.push(`${t.topLeft}${h}${topBorderCells.join(`${h}${t.teeDown}${h}`)}${h}${t.topRight}`);
|
|
@@ -4600,7 +4811,7 @@ export class Markdown implements Component {
|
|
|
4600
4811
|
for (let lineIdx = 0; lineIdx < headerLineCount; lineIdx++) {
|
|
4601
4812
|
const rowParts = headerCellLines.map((cellLines, colIdx) => {
|
|
4602
4813
|
const text = cellLines[lineIdx] || "";
|
|
4603
|
-
const padded = text
|
|
4814
|
+
const padded = this.#alignCellText(text, columnWidths[colIdx], columnAligns[colIdx] ?? null);
|
|
4604
4815
|
return this.#theme.bold(padded);
|
|
4605
4816
|
});
|
|
4606
4817
|
lines.push(`${v} ${rowParts.join(` ${v} `)} ${v}`);
|
|
@@ -4644,7 +4855,8 @@ export class Markdown implements Component {
|
|
|
4644
4855
|
for (let lineIdx = 0; lineIdx < rowLineCount; lineIdx++) {
|
|
4645
4856
|
const rowParts = rowCellLines.map((cellLines, colIdx) => {
|
|
4646
4857
|
const text = cellLines[lineIdx] || "";
|
|
4647
|
-
|
|
4858
|
+
const align = row[colIdx]?.align ?? columnAligns[colIdx] ?? null;
|
|
4859
|
+
return this.#alignCellText(text, columnWidths[colIdx], align);
|
|
4648
4860
|
});
|
|
4649
4861
|
lines.push(`${v} ${rowParts.join(` ${v} `)} ${v}`);
|
|
4650
4862
|
}
|
package/src/hotkeys-markdown.ts
CHANGED
|
@@ -135,10 +135,12 @@ 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" },
|
|
141
142
|
{ keys: [act("app.editor.external")], action: "Edit message in external editor" },
|
|
143
|
+
{ keys: [act("app.local.open")], action: "Open a local:// file in external editor" },
|
|
142
144
|
{ keys: [act("app.retry")], action: "Retry last failed assistant turn" },
|
|
143
145
|
{ keys: [act("app.clipboard.pasteImage")], action: "Paste image or text from clipboard" },
|
|
144
146
|
{
|
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";
|
|
@@ -206,9 +198,10 @@ 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).
|
|
210
203
|
*/
|
|
211
|
-
const UNASSUMED_KINDS: Partial<Record<TspKind, true>> = { media: true };
|
|
204
|
+
const UNASSUMED_KINDS: Partial<Record<TspKind, true>> = { media: true, json: true };
|
|
212
205
|
|
|
213
206
|
/**
|
|
214
207
|
* The reply a v1 terminal is assumed to give before its real `hello` arrives
|
|
@@ -313,11 +306,6 @@ export class NativeBackend {
|
|
|
313
306
|
#sawResize = false;
|
|
314
307
|
#live = false;
|
|
315
308
|
#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
309
|
/** Pending delivery owns bytes until sent or confirmed held; settled descriptions may already be released. */
|
|
322
310
|
#blobs = new Map<string, NativeBlob | "sent">();
|
|
323
311
|
/** `blobs` queries sent, oldest first: the terminal answers each once, in order. */
|
|
@@ -366,54 +354,11 @@ export class NativeBackend {
|
|
|
366
354
|
if (this.#live) return;
|
|
367
355
|
this.#live = true;
|
|
368
356
|
this.#useNerdSymbols(true);
|
|
369
|
-
this.#watchTheme();
|
|
370
357
|
this.#open(this.#inline);
|
|
371
358
|
setNativeRendering(true);
|
|
372
359
|
this.render();
|
|
373
360
|
}
|
|
374
361
|
|
|
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
362
|
/**
|
|
418
363
|
* Tern's font carries every Nerd Font glyph, and it never answers the Glyph
|
|
419
364
|
* Protocol, so icons come from the nerd preset (process-local, not the
|
|
@@ -435,8 +380,6 @@ export class NativeBackend {
|
|
|
435
380
|
this.#close(this.#inline, keep);
|
|
436
381
|
this.#inline.doc?.close();
|
|
437
382
|
setNativeRendering(false);
|
|
438
|
-
this.#unbindTheme?.();
|
|
439
|
-
this.#unbindTheme = undefined;
|
|
440
383
|
this.#useNerdSymbols(false);
|
|
441
384
|
this.#clearStallTimer();
|
|
442
385
|
// Replies no longer reach the backend: forget the queries outright.
|
|
@@ -455,7 +398,6 @@ export class NativeBackend {
|
|
|
455
398
|
this.#applyHello(hello);
|
|
456
399
|
this.#live = true;
|
|
457
400
|
this.#useNerdSymbols(true);
|
|
458
|
-
this.#watchTheme();
|
|
459
401
|
this.#resetBlobs();
|
|
460
402
|
const surface = this.#inline;
|
|
461
403
|
surface.reconciler.detachLive();
|
|
@@ -466,7 +408,6 @@ export class NativeBackend {
|
|
|
466
408
|
surface.focus = null;
|
|
467
409
|
surface.dirty = false;
|
|
468
410
|
this.#write("o", { id: surface.id, mode: "inline", title: "omp", role: SESSION_ROLE, adopt: true });
|
|
469
|
-
this.#sendPalette(surface);
|
|
470
411
|
// After the `o`, as in `start()`.
|
|
471
412
|
setNativeRendering(true);
|
|
472
413
|
this.render();
|
|
@@ -508,7 +449,6 @@ export class NativeBackend {
|
|
|
508
449
|
/** Reconcile and send a frame, unless the target surface is out of credits. */
|
|
509
450
|
render(): void {
|
|
510
451
|
if (!this.#live) return;
|
|
511
|
-
this.#refreshPalette();
|
|
512
452
|
const overlays = this.#host.overlays();
|
|
513
453
|
let fullscreen = -1;
|
|
514
454
|
for (let i = overlays.length - 1; i >= 0; i--) {
|
|
@@ -608,7 +548,6 @@ export class NativeBackend {
|
|
|
608
548
|
|
|
609
549
|
#open(surface: Surface): void {
|
|
610
550
|
this.#write("o", { id: surface.id, mode: surface.mode, title: "omp", role: surface.role });
|
|
611
|
-
this.#sendPalette(surface);
|
|
612
551
|
}
|
|
613
552
|
|
|
614
553
|
#close(surface: Surface, keep: boolean): void {
|
|
@@ -776,7 +715,7 @@ export class NativeBackend {
|
|
|
776
715
|
}
|
|
777
716
|
}
|
|
778
717
|
|
|
779
|
-
#write(verb: "o" | "f" | "
|
|
718
|
+
#write(verb: "o" | "f" | "x" | "q", body: unknown): void {
|
|
780
719
|
this.#record("out", verb, undefined, body);
|
|
781
720
|
this.#host.terminal.write(encodeTspJson(verb, body, undefined, this.#limit));
|
|
782
721
|
}
|
package/src/native/blobs.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-addressed binary blobs (images) for `image` nodes.
|
|
3
|
+
*
|
|
4
|
+
* `describe()` registers the bytes and puts the returned id in `image.p.blob`;
|
|
5
|
+
* the native backend delivers each referenced blob once per terminal
|
|
6
|
+
* connection (asking the terminal first which it holds, or through its blob
|
|
7
|
+
* cache), else uploads it with verb `b` before the frame that first
|
|
8
|
+
* references it.
|
|
9
|
+
*/
|
|
1
10
|
import type { TspProps } from "@linxiraos/pi-wire";
|
|
2
11
|
import type { NativeChild, NativeNode } from "./node";
|
|
3
12
|
export interface NativeBlob {
|
|
@@ -20,7 +29,8 @@ export declare function base64ImageNode(data: string, mimeType: string, p?: Omit
|
|
|
20
29
|
/**
|
|
21
30
|
* Props that make an `image` node open the file at `filePath` (as a `file://` URL, the TSP
|
|
22
31
|
* open-target form): a click zooms the image in the terminal, and the file opens from its
|
|
23
|
-
* 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.
|
|
24
34
|
*/
|
|
25
35
|
export declare function openableImageProps(filePath: string | undefined): Pick<TspProps<"image">, "href" | "actions">;
|
|
26
36
|
/**
|
package/src/native/blobs.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* cache), else uploads it with verb `b` before the frame that first
|
|
8
8
|
* references it.
|
|
9
9
|
*/
|
|
10
|
-
import * as url from "node:url";
|
|
11
10
|
import type { TspProps } from "@linxiraos/pi-wire";
|
|
11
|
+
import { tryFileUri } from "../render/hyperlink";
|
|
12
12
|
import { resolveImageOptions } from "../render/render-utils";
|
|
13
13
|
import { getImageDimensions } from "../terminal-capabilities";
|
|
14
14
|
import { node } from "./describe";
|
|
@@ -97,10 +97,12 @@ 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
|
-
|
|
104
|
+
const href = filePath ? tryFileUri(filePath, { local: true }) : undefined;
|
|
105
|
+
return href ? { href, actions: { menu: ["open"] } } : {};
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
/**
|