@kabmo-labs/kabmo 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +805 -736
- package/dist/client/static/js/index-bc9aa4mx.css +1 -0
- package/dist/client/static/js/{index-ph0q59rs.js → index-ga8cbpt4.js} +1071 -1171
- package/package.json +2 -4
- package/src/cli/lib/args.js +24 -1
- package/src/cli/lib/args.test.js +16 -0
- package/src/cli/lib/commands/session.js +233 -0
- package/src/cli/lib/commands/session.test.js +103 -0
- package/src/cli/main.js +1 -1
- package/src/client/components/common/ComposerPicker.tsx +3 -0
- package/src/client/components/common/Modal.tsx +2 -6
- package/src/client/components/common/code-surface/shiki.test.ts +82 -0
- package/src/client/components/common/code-surface/shiki.ts +28 -7
- package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +113 -0
- package/src/client/components/common/session-actions-menu/index.tsx +33 -2
- package/src/client/components/common/session-row/StatusSlot.tsx +4 -4
- package/src/client/components/common/session-row/index.tsx +27 -1
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
- package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +25 -12
- package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +66 -0
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +28 -3
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +20 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +59 -12
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +94 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +120 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +47 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.test.tsx +122 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +55 -46
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +18 -5
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +21 -4
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +27 -5
- package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +31 -0
- package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +49 -0
- package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
- package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +135 -118
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
- package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +4 -0
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +4 -3
- package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +11 -20
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/GroupedAsk.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/QuestionBlock.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +2 -1
- package/src/client/components/workspace/file-explorer/index.test.ts +25 -0
- package/src/client/components/workspace/file-explorer/index.tsx +9 -3
- package/src/client/components/workspace/model-dropdown/harness-models.test.ts +17 -0
- package/src/client/components/workspace/model-dropdown/harness-models.ts +33 -18
- package/src/client/components/workspace/model-dropdown/index.tsx +3 -3
- package/src/client/components/workspace/model-dropdown/popover-metrics.ts +4 -1
- package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
- package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
- package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
- package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
- package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
- package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
- package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
- package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
- package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
- package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
- package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
- package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
- package/src/client/data/settings/omp-schema.json +5 -5
- package/src/client/data/theme/terminal.test.ts +25 -0
- package/src/client/data/theme/terminal.ts +96 -79
- package/src/client/hooks/chat/composer/items.test.ts +12 -26
- package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
- package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
- package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
- package/src/client/hooks/chat/timeline/actions.ts +2 -2
- package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
- package/src/client/hooks/chat/timeline/new-chat-open.test.ts +86 -0
- package/src/client/hooks/chat/timeline/new-chat-open.ts +23 -5
- package/src/client/hooks/chat/timeline/new-chat.test.ts +32 -4
- package/src/client/hooks/chat/timeline/new-chat.ts +18 -6
- package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
- package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
- package/src/client/hooks/chat/timeline/rewind-actions.test.ts +24 -1
- package/src/client/hooks/chat/timeline/rewind-actions.ts +15 -11
- package/src/client/hooks/chat/timeline/run-identity.test.ts +52 -0
- package/src/client/hooks/chat/timeline/run-identity.ts +23 -11
- package/src/client/hooks/chat/timeline/send-execute.test.ts +56 -0
- package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
- package/src/client/hooks/chat/timeline/send-props.ts +5 -3
- package/src/client/hooks/chat/timeline/send-steer.test.ts +4 -4
- package/src/client/hooks/chat/timeline/send.test-util.ts +8 -2
- package/src/client/hooks/chat/timeline/send.test.ts +4 -4
- package/src/client/hooks/chat/timeline/send.ts +59 -53
- package/src/client/hooks/chat/timeline/session-load.test-util.ts +6 -2
- package/src/client/hooks/chat/timeline/session-load.test.ts +31 -0
- package/src/client/hooks/chat/timeline/session-load.ts +6 -14
- package/src/client/hooks/chat/timeline/session-shapes.ts +32 -0
- package/src/client/hooks/chat/timeline/use-fork-session.ts +49 -0
- package/src/client/hooks/models/harness-catalog.ts +114 -0
- package/src/client/hooks/models/provider-writes.test.ts +81 -0
- package/src/client/hooks/models/provider-writes.ts +10 -3
- package/src/client/hooks/models/use-harness-update.test.ts +193 -0
- package/src/client/hooks/models/use-harness-update.ts +202 -0
- package/src/client/hooks/models/use-harnesses-controller.ts +57 -0
- package/src/client/hooks/models/use-harnesses-signal.test.ts +128 -0
- package/src/client/hooks/models/use-harnesses.test.ts +2 -1
- package/src/client/hooks/models/use-harnesses.ts +48 -114
- package/src/client/hooks/workspace/child-expansion.ts +33 -0
- package/src/client/hooks/workspace/terminal/index.ts +17 -3
- package/src/client/hooks/workspace/terminal/socket.ts +9 -4
- package/src/client/lib/session-tree.test.ts +50 -0
- package/src/client/lib/session-tree.ts +59 -0
- package/src/client/tailwind.css +26 -12
- package/src/server/index.ts +2 -0
- package/src/server/lib/auth/guard.ts +10 -0
- package/src/server/lib/btw/session-copy.server.ts +6 -44
- package/src/server/lib/btw/session-copy.test.ts +2 -1
- package/src/server/lib/db/schema.ts +4 -0
- package/src/server/lib/db/seed-terminal.test.ts +1 -1
- package/src/server/lib/db/seed.test.ts +1 -1
- package/src/server/lib/harness/acp/activation.test.ts +81 -0
- package/src/server/lib/harness/acp/activation.ts +72 -0
- package/src/server/lib/harness/acp/background-work.test.ts +262 -0
- package/src/server/lib/harness/acp/background-work.ts +320 -0
- package/src/server/lib/harness/acp/client.ts +2 -2
- package/src/server/lib/harness/acp/frames.test.ts +50 -1
- package/src/server/lib/harness/acp/frames.ts +17 -5
- package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
- package/src/server/lib/harness/acp/gateway-env.ts +70 -0
- package/src/server/lib/harness/acp/mapper.ts +6 -4
- package/src/server/lib/harness/acp/prompt.test.ts +20 -0
- package/src/server/lib/harness/acp/prompt.ts +19 -3
- package/src/server/lib/harness/acp/session-background.test.ts +129 -0
- package/src/server/lib/harness/acp/session-config.test.ts +73 -0
- package/src/server/lib/harness/acp/session-config.ts +87 -6
- package/src/server/lib/harness/acp/session-exit.ts +31 -0
- package/src/server/lib/harness/acp/session-handshake.test.ts +108 -0
- package/src/server/lib/harness/acp/session-handshake.ts +36 -3
- package/src/server/lib/harness/acp/session-idle.ts +51 -0
- package/src/server/lib/harness/acp/session-listeners.ts +31 -0
- package/src/server/lib/harness/acp/session-notifications.ts +19 -3
- package/src/server/lib/harness/acp/session-observers.test.ts +9 -0
- package/src/server/lib/harness/acp/session-options.ts +33 -0
- package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
- package/src/server/lib/harness/acp/session-requests.ts +47 -0
- package/src/server/lib/harness/acp/session-turns.ts +20 -5
- package/src/server/lib/harness/acp/session.test-util.ts +54 -3
- package/src/server/lib/harness/acp/session.test.ts +65 -3
- package/src/server/lib/harness/acp/session.ts +79 -79
- package/src/server/lib/harness/acp/turn.test.ts +81 -0
- package/src/server/lib/harness/acp/turn.ts +54 -13
- package/src/server/lib/harness/acp/verbs.ts +12 -2
- package/src/server/lib/harness/auto-probe.server.test.ts +121 -0
- package/src/server/lib/harness/auto-probe.server.ts +178 -0
- package/src/server/lib/harness/config.server.test.ts +1 -1
- package/src/server/lib/harness/config.server.ts +1 -1
- package/src/server/lib/harness/launch-table.ts +195 -0
- package/src/server/lib/harness/launch.test.ts +37 -0
- package/src/server/lib/harness/launch.ts +16 -116
- package/src/server/lib/harness/provider-entry.ts +32 -0
- package/src/server/lib/harness/provider-file.server.ts +3 -0
- package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
- package/src/server/lib/harness/provider-sources.server.ts +26 -2
- package/src/server/lib/harness/provider-write.server.ts +21 -32
- package/src/server/lib/harness/provider-zcode.server.test.ts +270 -0
- package/src/server/lib/harness/provider-zcode.server.ts +324 -0
- package/src/server/lib/harness/spawn.server.ts +15 -2
- package/src/server/lib/harness/update-job-store.test.ts +126 -0
- package/src/server/lib/harness/update-job-store.ts +109 -0
- package/src/server/lib/harness/update-job.server.ts +203 -0
- package/src/server/lib/harness/update-state.server.ts +15 -20
- package/src/server/lib/harness/update-worker.test.ts +153 -0
- package/src/server/lib/harness/update-worker.ts +197 -0
- package/src/server/lib/lifecycle/after-listen.ts +7 -0
- package/src/server/lib/lifecycle/paths.ts +23 -0
- package/src/server/lib/models/registry-refresh.server.test.ts +87 -0
- package/src/server/lib/models/registry-refresh.server.ts +98 -0
- package/src/server/lib/omp/rpc/child-config.ts +5 -4
- package/src/server/lib/omp/rpc/constants.test.ts +2 -1
- package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
- package/src/server/lib/omp/rpc/manager.ts +5 -5
- package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
- package/src/server/lib/omp/rpc/session-registry.ts +14 -2
- package/src/server/lib/omp/rpc/terminal-settle.ts +53 -5
- package/src/server/lib/omp/session/delete-flow.server.ts +62 -8
- package/src/server/lib/omp/session/delete.server.ts +17 -0
- package/src/server/lib/omp/session/rewind-file.ts +39 -21
- package/src/server/lib/omp/session/sidebar-data.server.ts +6 -6
- package/src/server/lib/omp/session/transcript-copy.ts +123 -0
- package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
- package/src/server/lib/sessions/agent-token.server.ts +134 -0
- package/src/server/lib/sessions/answers.server.test.ts +33 -0
- package/src/server/lib/sessions/answers.server.ts +37 -0
- package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
- package/src/server/lib/sessions/dispatch.server.ts +128 -0
- package/src/server/lib/sessions/fork.server.test.ts +209 -0
- package/src/server/lib/sessions/fork.server.ts +304 -0
- package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
- package/src/server/lib/sessions/lifecycle.server.ts +71 -0
- package/src/server/lib/sessions/notify.server.test.ts +112 -0
- package/src/server/lib/sessions/notify.server.ts +212 -0
- package/src/server/lib/sessions/relation-types.ts +76 -0
- package/src/server/lib/sessions/relations.server.test.ts +207 -0
- package/src/server/lib/sessions/relations.server.ts +337 -0
- package/src/server/lib/sessions/resolve.server.ts +106 -0
- package/src/server/lib/sessions/schema.server.ts +82 -0
- package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
- package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
- package/src/server/lib/sessions/spawn.server.test.ts +196 -0
- package/src/server/lib/sessions/spawn.server.ts +310 -0
- package/src/server/lib/terminal/attach-replay.test.ts +2 -2
- package/src/server/lib/terminal/output.test.ts +2 -2
- package/src/server/lib/terminal/output.ts +1 -1
- package/src/server/lib/terminal/resize.test.ts +99 -0
- package/src/server/lib/terminal/runtime.server.ts +26 -6
- package/src/server/lib/terminal/send-result.test.ts +18 -1
- package/src/server/lib/terminal/send-result.ts +26 -2
- package/src/server/lib/terminal/session.server.ts +6 -6
- package/src/server/lib/usage/new-api.test.ts +92 -0
- package/src/server/lib/usage/new-api.ts +131 -0
- package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
- package/src/server/lib/usage/provider-key.ts +33 -0
- package/src/server/lib/usage/providers.server.ts +10 -3
- package/src/server/lib/usage/vendor-balance.server.ts +4 -53
- package/src/server/lib/usage/vendor-http.ts +41 -0
- package/src/server/lib/usage/window.ts +55 -0
- package/src/server/routes/agent/command.ts +14 -1
- package/src/server/routes/agent/harness-command.ts +6 -0
- package/src/server/routes/agent/new.ts +15 -0
- package/src/server/routes/chat/rewind.test.ts +147 -0
- package/src/server/routes/chat/rewind.ts +29 -7
- package/src/server/routes/chat/session.test.ts +165 -10
- package/src/server/routes/chat/session.ts +60 -7
- package/src/server/routes/harness/add-provider.test.ts +9 -1
- package/src/server/routes/harness/import-action.ts +22 -4
- package/src/server/routes/harness/import.test.ts +1 -1
- package/src/server/routes/harness/index.ts +5 -1
- package/src/server/routes/harness/root.ts +8 -49
- package/src/server/routes/harness/toggle.test.ts +20 -0
- package/src/server/routes/harness/update-status.ts +26 -0
- package/src/server/routes/harness/update.test.ts +119 -0
- package/src/server/routes/harness/update.ts +67 -113
- package/src/server/routes/harness/versions.ts +5 -1
- package/src/server/routes/sessions/answer.ts +24 -0
- package/src/server/routes/sessions/batch-delete.ts +11 -5
- package/src/server/routes/sessions/delete-acp.test.ts +227 -0
- package/src/server/routes/sessions/delete.ts +4 -2
- package/src/server/routes/sessions/fork.ts +74 -0
- package/src/server/routes/sessions/index.ts +14 -0
- package/src/server/routes/sessions/relations.ts +85 -0
- package/src/server/routes/sessions/session.ts +4 -0
- package/src/server/routes/sessions/spawn.ts +134 -0
- package/src/server/routes/settings/model-override.ts +5 -2
- package/src/server/routes/settings/provider-entry.ts +2 -2
- package/src/server/routes/settings/provider-model.ts +2 -2
- package/src/server/routes/settings/provider-models.ts +2 -2
- package/src/server/routes/settings/provider-refresh.ts +6 -4
- package/src/server/routes/settings/providers.ts +3 -1
- package/src/server/routes/settings/settings-config-routes.test.ts +10 -2
- package/src/server/routes/terminal/ws.ts +3 -3
- package/src/shared/lib/chat/ask-form/fields.ts +76 -0
- package/src/shared/lib/chat/ask-form/index.ts +323 -0
- package/src/shared/lib/chat/ask-form/tokens.ts +199 -0
- package/src/shared/lib/chat/ask-form/types.ts +43 -0
- package/src/shared/lib/chat/ask-form.test.ts +137 -0
- package/src/shared/lib/chat/ask-questions.test.ts +65 -1
- package/src/shared/lib/chat/ask-questions.ts +51 -145
- package/src/shared/lib/chat/ask-results.ts +198 -0
- package/src/shared/lib/chat/composer/client.ts +31 -2
- package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
- package/src/shared/lib/chat/composer/delegation.ts +206 -0
- package/src/shared/lib/chat/notice-text.ts +1 -1
- package/src/shared/lib/chat/timeline/omp-callbacks.ts +13 -1
- package/src/shared/lib/chat/timeline/prompt-error.test.ts +146 -0
- package/src/shared/lib/chat/timeline/prompt-error.ts +88 -0
- package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
- package/src/shared/lib/code/ansi.ts +1 -1
- package/src/shared/lib/fonts/nerd-symbols.css +4 -3
- package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
- package/src/shared/lib/harness/catalog.test.ts +1 -1
- package/src/shared/lib/harness/config-fields.test.ts +4 -0
- package/src/shared/lib/harness/config-fields.ts +19 -4
- package/src/shared/lib/harness/dialects.test.ts +8 -0
- package/src/shared/lib/harness/dialects.ts +12 -0
- package/src/shared/lib/harness/provider-facts.test.ts +59 -8
- package/src/shared/lib/harness/provider-facts.ts +46 -11
- package/src/shared/lib/harness/providers.ts +44 -1
- package/src/shared/lib/harness/rewind.ts +24 -0
- package/src/shared/lib/harness/update-job.ts +33 -0
- package/src/shared/lib/harness/update-plan.test.ts +69 -4
- package/src/shared/lib/harness/update-plan.ts +57 -9
- package/src/shared/lib/harness/updates.test.ts +22 -0
- package/src/shared/lib/harness/updates.ts +24 -1
- package/src/shared/lib/models/client.ts +10 -1
- package/src/shared/lib/omp/dialog-methods.ts +4 -3
- package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
- package/src/shared/lib/omp/session/wait-idle.ts +12 -2
- package/src/shared/lib/theme/catalog.test.ts +13 -9
- package/src/shared/lib/theme/color.test.ts +2 -2
- package/src/shared/lib/theme/color.ts +4 -4
- package/src/shared/lib/theme/css.ts +2 -0
- package/src/shared/lib/theme/ink-scale.ts +21 -1
- package/src/shared/lib/theme/theme.test.ts +26 -10
- package/src/shared/lib/ui/safe-area.test.ts +28 -0
- package/src/shared/lib/ui/safe-area.ts +42 -0
- package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
- package/src/shared/lib/workspace/terminal/input.ts +33 -0
- package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
- package/src/shared/lib/workspace/terminal/keys.ts +7 -7
- package/src/shared/types/chat.ts +1 -1
- package/src/shared/types/harness-update.ts +65 -0
- package/src/shared/types/harness.ts +30 -4
- package/src/shared/types/omp/agent.ts +19 -2
- package/src/shared/types/workspace.ts +4 -0
- package/src/test-support/fake-omp-fork.ts +16 -2
- package/src/test-support/file-explorer-render.test-util.ts +37 -0
- package/src/test-support/file-explorer.test-util.ts +20 -18
- package/src/test-support/harness-table.test-util.ts +21 -4
- package/dist/client/static/js/index-jhmg4w91.css +0 -1
- package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
- package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
|
@@ -4,49 +4,61 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Mounts
|
|
7
|
+
* Mounts a ghostty-web terminal on a container and keeps it bound to a PTY.
|
|
8
8
|
*
|
|
9
|
-
* Extracted from the view component so the mount lifecycle (
|
|
9
|
+
* Extracted from the view component so the mount lifecycle (WASM import, fit
|
|
10
10
|
* addon, input wiring, observers) stays readable and the component remains a
|
|
11
11
|
* render layer. Everything the caller must know travels through `callbacks`;
|
|
12
12
|
* the returned handle is the only way back in.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
14
|
+
* Three behaviours here are deliberate:
|
|
15
15
|
*
|
|
16
16
|
* - **Attach waits for a real grid.** The terminal panel stays mounted while
|
|
17
17
|
* its view is CSS-hidden (that is what keeps a shell alive across panel
|
|
18
|
-
* switches), and a hidden container measures 0px — fitting is skipped and
|
|
19
|
-
*
|
|
20
|
-
* size the panel never had, and the retained scrollback would replay at
|
|
21
|
-
* width forever. So attach is driven by the same ResizeObserver that
|
|
22
|
-
* the panel becoming visible.
|
|
23
|
-
* - **Raw bytes in, raw bytes out.**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
18
|
+
* switches), and a hidden container measures 0px — fitting is skipped and the
|
|
19
|
+
* terminal keeps its 80x24 default. Attaching then would create the shell at
|
|
20
|
+
* a size the panel never had, and the retained scrollback would replay at
|
|
21
|
+
* that width forever. So attach is driven by the same ResizeObserver that
|
|
22
|
+
* detects the panel becoming visible.
|
|
23
|
+
* - **Raw bytes in, raw bytes out.** ghostty-web's WASM parser accepts a
|
|
24
|
+
* `Uint8Array`, so a character split across two PTY reads is reassembled by
|
|
25
|
+
* the parser rather than by a decode step here. `onData` text is forwarded
|
|
26
|
+
* unless it is a legacy X10 mouse report, which is a latin-1 byte payload
|
|
27
|
+
* (see `shared/lib/workspace/terminal/input.ts`).
|
|
28
|
+
* - **The renderer is dynamically imported on purpose.** ghostty-web is
|
|
29
|
+
* ~700 KB and is only needed once the terminal panel is opened, so it stays
|
|
30
|
+
* out of the initial client bundle.
|
|
31
|
+
*
|
|
32
|
+
* A theme change cannot recolor a running terminal: the WASM palette is fixed
|
|
33
|
+
* when the terminal is created and ANSI cells carry resolved RGB. `setTheme`
|
|
34
|
+
* therefore rebuilds the terminal with the new palette and clears it; the
|
|
35
|
+
* caller reattaches the socket so the server replays the retained scrollback.
|
|
36
|
+
* `clear()` after every open/reset is not cosmetic — the WASM allocator reuses
|
|
37
|
+
* pages and can hand a fresh terminal the previous screen's cells.
|
|
30
38
|
*/
|
|
31
39
|
|
|
32
|
-
import type { Terminal } from '
|
|
33
|
-
import
|
|
34
|
-
import {
|
|
40
|
+
import type { FitAddon, Ghostty, Terminal } from 'ghostty-web';
|
|
41
|
+
import { terminalInputFrame } from '@/shared/lib/workspace/terminal/input';
|
|
42
|
+
import {
|
|
43
|
+
installCellMetrics,
|
|
44
|
+
waitForTerminalFonts,
|
|
45
|
+
watchTerminalFonts,
|
|
46
|
+
} from '@/client/components/workspace/terminal-panel/fonts';
|
|
47
|
+
import { installFullWidthFit } from '@/client/components/workspace/terminal-panel/fit';
|
|
48
|
+
import { createGridAnnouncer } from '@/client/components/workspace/terminal-panel/grid';
|
|
49
|
+
import { attachTouchScroll, handleKeyNavigation } from '@/client/components/workspace/terminal-panel/navigation';
|
|
35
50
|
import {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
safePatchRenderService,
|
|
41
|
-
type XtermCore,
|
|
42
|
-
type XtermModule,
|
|
51
|
+
getTerminalTheme,
|
|
52
|
+
TERMINAL_FONT_FAMILY,
|
|
53
|
+
TERMINAL_FONT_SIZE,
|
|
54
|
+
TERMINAL_SCROLLBACK_BYTES,
|
|
43
55
|
} from '@/client/data/theme/terminal';
|
|
44
56
|
|
|
45
|
-
export interface
|
|
57
|
+
export interface TerminalMountCallbacks {
|
|
46
58
|
/** Keystrokes, paste, mouse reports — straight to the PTY. */
|
|
47
59
|
onInput: (data: string) => void;
|
|
48
|
-
/** Non-UTF-8 payloads
|
|
49
|
-
onBinaryInput: (
|
|
60
|
+
/** Non-UTF-8 payloads (legacy X10 mouse reports), as latin-1 bytes. */
|
|
61
|
+
onBinaryInput: (bytes: Uint8Array) => void;
|
|
50
62
|
/** The grid changed; the PTY must be resized to match. */
|
|
51
63
|
onGridChange: (cols: number, rows: number) => void;
|
|
52
64
|
/** The terminal is measurable and knows its size; attach with these. */
|
|
@@ -55,126 +67,163 @@ export interface XtermMountCallbacks {
|
|
|
55
67
|
onScrolledUpChange: (scrolledUp: boolean) => void;
|
|
56
68
|
}
|
|
57
69
|
|
|
58
|
-
export interface
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
export interface TerminalMount {
|
|
71
|
+
/** Raw PTY output. Bytes, not text: the WASM parser reassembles them. */
|
|
72
|
+
write: (bytes: Uint8Array) => void;
|
|
61
73
|
/**
|
|
62
74
|
* Lay the retained scrollback out at the size it was drawn for, then fit the
|
|
63
75
|
* panel. Grid reports are suppressed until the replay has been consumed.
|
|
64
76
|
*/
|
|
65
77
|
writeReplay: (bytes: Uint8Array, cols: number, rows: number) => void;
|
|
78
|
+
/** Drop the buffer and reset the cursor — used when the shell is replaced. */
|
|
79
|
+
reset: () => void;
|
|
80
|
+
focus: () => void;
|
|
81
|
+
/** The shell's DECCKM state, read when a key-bar button is pressed. */
|
|
82
|
+
applicationCursorKeys: () => boolean;
|
|
83
|
+
/** The current selection, empty when nothing is selected. */
|
|
84
|
+
getSelection: () => string;
|
|
85
|
+
/** Feed text in as a paste, with bracketed-paste markers when requested. */
|
|
86
|
+
paste: (text: string) => void;
|
|
87
|
+
scrollToBottom: () => void;
|
|
66
88
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* again re-creates the context on the next shown frame.
|
|
89
|
+
* Rebuild the terminal with another palette. The caller must reattach the
|
|
90
|
+
* socket afterwards: the rebuilt terminal has no scrollback of its own.
|
|
70
91
|
*/
|
|
71
|
-
|
|
92
|
+
setTheme: (themeId: string) => void;
|
|
72
93
|
dispose: () => void;
|
|
73
94
|
}
|
|
74
95
|
|
|
96
|
+
interface TerminalInstance {
|
|
97
|
+
term: Terminal;
|
|
98
|
+
fitAddon: FitAddon;
|
|
99
|
+
disposables: { dispose(): void }[];
|
|
100
|
+
}
|
|
101
|
+
|
|
75
102
|
/**
|
|
76
|
-
* Mount
|
|
77
|
-
* loaded or the component unmounted while importing.
|
|
103
|
+
* Mount the terminal inside `container`. Resolves to null when the module could
|
|
104
|
+
* not be loaded or the component unmounted while importing.
|
|
78
105
|
*/
|
|
79
|
-
export async function
|
|
106
|
+
export async function mountTerminal(
|
|
80
107
|
container: HTMLElement,
|
|
81
108
|
themeId: string,
|
|
82
|
-
callbacks:
|
|
109
|
+
callbacks: TerminalMountCallbacks,
|
|
83
110
|
isCancelled: () => boolean,
|
|
84
|
-
): Promise<
|
|
85
|
-
//
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
safePatchFitAddon(FitAddonClass);
|
|
111
|
+
): Promise<TerminalMount | null> {
|
|
112
|
+
// One dynamic import, and the WASM module is loaded once per page. Fonts are
|
|
113
|
+
// fetched in parallel: the renderer measures its cell box at `open()`, and a
|
|
114
|
+
// face that lands after that is repaired by `watchTerminalFonts`.
|
|
115
|
+
// Dynamic on purpose: ghostty-web and its ~424 KB WASM are only needed once
|
|
116
|
+
// the terminal panel is opened, so a static import would put them in the
|
|
117
|
+
// initial client bundle for every page.
|
|
118
|
+
const module = await import('ghostty-web');
|
|
119
|
+
const [ghostty] = await Promise.all([module.Ghostty.load(), waitForTerminalFonts()]);
|
|
120
|
+
if (isCancelled()) return null;
|
|
96
121
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
theme: getXtermTheme(themeId),
|
|
104
|
-
// No `convertEol`: the PTY already emits CRLF, and converting a lone LF
|
|
105
|
-
// would re-introduce the line-feed doubling a real terminal avoids.
|
|
106
|
-
scrollback: 10000,
|
|
107
|
-
scrollSensitivity: 1.5,
|
|
108
|
-
fastScrollSensitivity: 5,
|
|
109
|
-
smoothScrollDuration: 0,
|
|
110
|
-
allowProposedApi: true,
|
|
111
|
-
}) as Terminal;
|
|
112
|
-
|
|
113
|
-
term.open(container);
|
|
114
|
-
safePatchRenderService(term);
|
|
115
|
-
|
|
116
|
-
// WebGL renderer: powerline glyphs stay seamless, and the context is held only
|
|
117
|
-
// while this panel is on screen (`webgl.ts` owns that decision and the numbers
|
|
118
|
-
// behind it — 541.8 MB of graphics in an 817.7 MB footprint). It is attached by
|
|
119
|
-
// the caller, which is the only thing that knows whether this view is the one
|
|
120
|
-
// being looked at.
|
|
121
|
-
const webgl = await createWebglControl(term);
|
|
122
|
-
|
|
123
|
-
const fitAddon = new FitAddonClass() as FitAddon;
|
|
124
|
-
term.loadAddon(fitAddon);
|
|
122
|
+
let currentThemeId = themeId;
|
|
123
|
+
let current: TerminalInstance | null = null;
|
|
124
|
+
let replaying = false;
|
|
125
|
+
let fitTimer: ReturnType<typeof setTimeout> | undefined;
|
|
126
|
+
let frame: number | null = null;
|
|
127
|
+
let disposed = false;
|
|
125
128
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
const wire = (instance: TerminalInstance): void => {
|
|
130
|
+
const { term } = instance;
|
|
131
|
+
// ghostty-web's custom handler returns TRUE to consume the event, the
|
|
132
|
+
// inverse of xterm's contract. `handleKeyNavigation` is written for this
|
|
133
|
+
// one.
|
|
134
|
+
term.attachCustomKeyEventHandler((event: globalThis.KeyboardEvent) => handleKeyNavigation(term, event));
|
|
135
|
+
instance.disposables.push(
|
|
136
|
+
term.onScroll((viewportY: number) => callbacks.onScrolledUpChange(viewportY > 0)),
|
|
137
|
+
term.onData((data: string) => {
|
|
138
|
+
const frame = terminalInputFrame(data);
|
|
139
|
+
if (frame.bytes) callbacks.onBinaryInput(frame.bytes);
|
|
140
|
+
else callbacks.onInput(frame.text);
|
|
141
|
+
}),
|
|
142
|
+
// FitAddon changes the grid on fit; the shell has to hear about it or a
|
|
143
|
+
// TUI keeps drawing at the old width. The report goes through the settle
|
|
144
|
+
// gate in `grid.ts` — a fit during the panel's opening animation is a
|
|
145
|
+
// squeezed grid, not a size to send. Reports are dropped while the replay
|
|
146
|
+
// is being laid out: that grid belongs to the recorded history, not the
|
|
147
|
+
// panel.
|
|
148
|
+
term.onResize(() => {
|
|
149
|
+
if (replaying) return;
|
|
150
|
+
grid.schedule();
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
};
|
|
130
154
|
|
|
131
|
-
|
|
155
|
+
const create = (nextThemeId: string): TerminalInstance => {
|
|
156
|
+
const term = new module.Terminal({
|
|
157
|
+
cursorBlink: true,
|
|
158
|
+
cursorStyle: 'block',
|
|
159
|
+
fontSize: TERMINAL_FONT_SIZE,
|
|
160
|
+
fontFamily: TERMINAL_FONT_FAMILY,
|
|
161
|
+
theme: getTerminalTheme(nextThemeId),
|
|
162
|
+
// A byte budget, not xterm's line count. See `theme/terminal.ts`.
|
|
163
|
+
scrollback: TERMINAL_SCROLLBACK_BYTES,
|
|
164
|
+
// No `convertEol`: the PTY already emits CRLF, and converting a lone LF
|
|
165
|
+
// would re-introduce the line-feed doubling a real terminal avoids.
|
|
166
|
+
smoothScrollDuration: 0,
|
|
167
|
+
ghostty: ghostty as Ghostty,
|
|
168
|
+
});
|
|
169
|
+
term.open(container);
|
|
170
|
+
installCellMetrics(term);
|
|
171
|
+
// The WASM allocator reuses pages: a fresh terminal can inherit the previous
|
|
172
|
+
// screen's cells until something overwrites them. Clear before the first
|
|
173
|
+
// byte is shown.
|
|
174
|
+
term.clear();
|
|
175
|
+
const fitAddon = new module.FitAddon();
|
|
176
|
+
term.loadAddon(fitAddon);
|
|
177
|
+
installFullWidthFit(fitAddon, term);
|
|
178
|
+
const instance: TerminalInstance = { term, fitAddon, disposables: [] };
|
|
179
|
+
wire(instance);
|
|
180
|
+
return instance;
|
|
181
|
+
};
|
|
132
182
|
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
];
|
|
183
|
+
const disposeInstance = (instance: TerminalInstance | null): void => {
|
|
184
|
+
if (!instance) return;
|
|
185
|
+
for (const disposable of instance.disposables) {
|
|
186
|
+
try {
|
|
187
|
+
disposable.dispose();
|
|
188
|
+
} catch {}
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
instance.fitAddon.dispose();
|
|
192
|
+
} catch {}
|
|
193
|
+
try {
|
|
194
|
+
instance.term.dispose();
|
|
195
|
+
} catch {}
|
|
196
|
+
};
|
|
148
197
|
|
|
149
|
-
let attached = false;
|
|
150
|
-
let fitTimer: ReturnType<typeof setTimeout> | null = null;
|
|
151
|
-
let frame: number | null = null;
|
|
152
198
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
* never chose, which is how a reattach used to print a second prompt.
|
|
199
|
+
* Fit to the container. Returns false when no fit was possible — the panel is
|
|
200
|
+
* hidden, or the cell has not been measured yet — which is what keeps the
|
|
201
|
+
* terminal's 80×24 default from ever being announced as a grid.
|
|
157
202
|
*/
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (
|
|
163
|
-
const core = (term as unknown as XtermCore)._core;
|
|
164
|
-
const dims = core?._renderService?.dimensions;
|
|
165
|
-
if (!dims?.css?.cell?.width || !dims?.css?.cell?.height) return;
|
|
203
|
+
const safeFit = (): boolean => {
|
|
204
|
+
if (disposed) return false;
|
|
205
|
+
if (container.clientWidth <= 0 || container.clientHeight <= 0) return false;
|
|
206
|
+
const metrics = current?.term.renderer?.getMetrics();
|
|
207
|
+
if (!metrics?.width || !metrics.height) return false;
|
|
166
208
|
try {
|
|
167
|
-
fitAddon.fit();
|
|
168
|
-
|
|
209
|
+
current?.fitAddon.fit();
|
|
210
|
+
return true;
|
|
211
|
+
} catch {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
169
214
|
};
|
|
170
215
|
|
|
171
|
-
/** Fit now, once
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
216
|
+
/** Fit now, once the terminal has consumed everything already queued. */
|
|
217
|
+
const finishReplay = (): void => {
|
|
218
|
+
if (disposed) return;
|
|
219
|
+
replaying = false;
|
|
220
|
+
safeFit();
|
|
221
|
+
// The replay laid the terminal out at the recorded grid, so the panel's own
|
|
222
|
+
// size has to be stated again: a resize the server already applied is a
|
|
223
|
+
// no-op, and one it missed (a mount that measured a squeezed panel) is
|
|
224
|
+
// corrected here instead of at the next page load.
|
|
225
|
+
grid.restate();
|
|
226
|
+
grid.schedule();
|
|
178
227
|
};
|
|
179
228
|
|
|
180
229
|
/**
|
|
@@ -182,137 +231,112 @@ export async function mountXterm(
|
|
|
182
231
|
* on the panel's grid. Re-wrapping history at another width leaves wrapped
|
|
183
232
|
* fragments the shell's own redraw never clears.
|
|
184
233
|
*/
|
|
185
|
-
const writeReplay = (bytes: Uint8Array, cols: number, rows: number) => {
|
|
234
|
+
const writeReplay = (bytes: Uint8Array, cols: number, rows: number): void => {
|
|
235
|
+
const term = current?.term;
|
|
236
|
+
if (!term) return;
|
|
186
237
|
replaying = true;
|
|
187
238
|
if (term.cols !== cols || term.rows !== rows) term.resize(cols, rows);
|
|
188
239
|
if (bytes.length === 0) {
|
|
189
|
-
|
|
240
|
+
// ghostty-web's `write('')` throws: its zero-length allocation is not a
|
|
241
|
+
// valid TypedArray offset. Finish on the next frame instead.
|
|
242
|
+
requestAnimationFrame(finishReplay);
|
|
190
243
|
return;
|
|
191
244
|
}
|
|
192
|
-
term.write(bytes,
|
|
245
|
+
term.write(bytes, finishReplay);
|
|
193
246
|
};
|
|
194
247
|
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
};
|
|
248
|
+
const grid = createGridAnnouncer({
|
|
249
|
+
current: () => current?.term,
|
|
250
|
+
fit: safeFit,
|
|
251
|
+
onReady: (cols, rows) => {
|
|
252
|
+
callbacks.onReady(cols, rows);
|
|
253
|
+
current?.term.focus();
|
|
254
|
+
},
|
|
255
|
+
onGridChange: callbacks.onGridChange,
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
current = create(currentThemeId);
|
|
259
|
+
safeFit();
|
|
260
|
+
grid.schedule();
|
|
204
261
|
|
|
205
262
|
const resizeObserver = new ResizeObserver(() => {
|
|
206
|
-
|
|
263
|
+
clearTimeout(fitTimer);
|
|
207
264
|
fitTimer = setTimeout(() => {
|
|
208
265
|
safeFit();
|
|
209
266
|
// A panel that was hidden at mount becomes measurable here, which is when
|
|
210
267
|
// the shell should be created — at its real size.
|
|
211
|
-
|
|
268
|
+
grid.schedule();
|
|
212
269
|
}, 35);
|
|
213
270
|
});
|
|
214
271
|
resizeObserver.observe(container);
|
|
215
272
|
|
|
216
|
-
const
|
|
273
|
+
const stopFontWatch = watchTerminalFonts(() => {
|
|
274
|
+
const term = current?.term;
|
|
275
|
+
if (!term) return;
|
|
276
|
+
const size = term.options.fontSize ?? TERMINAL_FONT_SIZE;
|
|
277
|
+
// ghostty-web measures once; a font-size round-trip is its public way to
|
|
278
|
+
// re-measure and resize the canvas.
|
|
279
|
+
term.options.fontSize = size + 0.1;
|
|
280
|
+
term.options.fontSize = size;
|
|
281
|
+
safeFit();
|
|
282
|
+
grid.schedule();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
const touch = attachTouchScroll(container, () => current?.term ?? null);
|
|
217
286
|
|
|
218
287
|
// The container may already be measurable (the view was active at mount), in
|
|
219
288
|
// which case the observer never fires a first time.
|
|
220
289
|
frame = requestAnimationFrame(() => {
|
|
221
290
|
safeFit();
|
|
222
|
-
|
|
291
|
+
grid.schedule();
|
|
223
292
|
});
|
|
224
293
|
|
|
225
294
|
return {
|
|
226
|
-
|
|
227
|
-
|
|
295
|
+
write(bytes: Uint8Array) {
|
|
296
|
+
current?.term.write(bytes);
|
|
297
|
+
},
|
|
228
298
|
writeReplay,
|
|
229
|
-
|
|
299
|
+
reset() {
|
|
300
|
+
const term = current?.term;
|
|
301
|
+
if (!term) return;
|
|
302
|
+
term.reset();
|
|
303
|
+
// The rebuilt WASM terminal reuses pages; see `create`.
|
|
304
|
+
term.clear();
|
|
305
|
+
safeFit();
|
|
306
|
+
},
|
|
307
|
+
focus() {
|
|
308
|
+
current?.term.focus();
|
|
309
|
+
},
|
|
310
|
+
applicationCursorKeys() {
|
|
311
|
+
return current?.term.wasmTerm?.getMode(1, false) ?? false;
|
|
312
|
+
},
|
|
313
|
+
getSelection() {
|
|
314
|
+
return current?.term.getSelection() ?? '';
|
|
315
|
+
},
|
|
316
|
+
paste(text: string) {
|
|
317
|
+
current?.term.paste(text);
|
|
318
|
+
},
|
|
319
|
+
scrollToBottom() {
|
|
320
|
+
current?.term.scrollToBottom();
|
|
321
|
+
},
|
|
322
|
+
setTheme(nextThemeId: string) {
|
|
323
|
+
if (disposed || nextThemeId === currentThemeId) return;
|
|
324
|
+
currentThemeId = nextThemeId;
|
|
325
|
+
disposeInstance(current);
|
|
326
|
+
current = create(nextThemeId);
|
|
327
|
+
safeFit();
|
|
328
|
+
},
|
|
230
329
|
dispose() {
|
|
330
|
+
disposed = true;
|
|
231
331
|
if (frame !== null) cancelAnimationFrame(frame);
|
|
232
|
-
clearTimeout(fitTimer
|
|
233
|
-
|
|
332
|
+
clearTimeout(fitTimer);
|
|
333
|
+
grid.dispose();
|
|
334
|
+
stopFontWatch();
|
|
234
335
|
touch();
|
|
235
|
-
for (const disposable of disposables) disposable.dispose();
|
|
236
336
|
resizeObserver.disconnect();
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
} catch {}
|
|
240
|
-
try {
|
|
241
|
-
term.dispose();
|
|
242
|
-
} catch {}
|
|
337
|
+
disposeInstance(current);
|
|
338
|
+
current = null;
|
|
243
339
|
},
|
|
244
340
|
};
|
|
245
341
|
}
|
|
246
342
|
|
|
247
|
-
/**
|
|
248
|
-
* Re-rasterize the terminal once the bundled symbols face has loaded.
|
|
249
|
-
*
|
|
250
|
-
* xterm has no `document.fonts` listener: it rasterizes a glyph the first time
|
|
251
|
-
* it draws it and keeps the result in a texture atlas, so a PUA glyph written
|
|
252
|
-
* before the face arrived stays whatever the fallback painted — a tofu box —
|
|
253
|
-
* for the life of the buffer. The browser does re-lay-out DOM text when a face
|
|
254
|
-
* lands late (verified on the DOM renderer), but xterm's canvas does not get
|
|
255
|
-
* that for free.
|
|
256
|
-
*
|
|
257
|
-
* `loadingdone` naming our own family is exactly the signal that this machine
|
|
258
|
-
* had no Nerd Font of its own: the face is declared last in the stack and its
|
|
259
|
-
* `unicode-range` covers only PUA, so a device with an installed Nerd Font
|
|
260
|
-
* never fetches it (verified: zero requests with a local family present). That
|
|
261
|
-
* makes this a no-op on the developer's laptop and the fix on a phone.
|
|
262
|
-
*
|
|
263
|
-
* `clearTextureAtlas()` drops the atlas and forces a full refresh, which is
|
|
264
|
-
* what re-rasterizes the glyphs. It is a public API on `Terminal`, and the
|
|
265
|
-
* atlas is small enough that a full refresh is cheap — this runs at most once
|
|
266
|
-
* per page load.
|
|
267
|
-
*
|
|
268
|
-
* Returns a disposer.
|
|
269
|
-
*/
|
|
270
|
-
function refreshAtlasWhenNerdFaceLoads(term: Terminal): () => void {
|
|
271
|
-
if (typeof document === 'undefined' || !document.fonts) return () => {};
|
|
272
|
-
|
|
273
|
-
const onLoadingDone = (event: FontFaceSetLoadEvent) => {
|
|
274
|
-
const loaded = [...event.fontfaces].some((face) => face.family.replace(/['"]/g, '') === NERD_SYMBOLS_FAMILY);
|
|
275
|
-
if (!loaded) return;
|
|
276
|
-
try {
|
|
277
|
-
term.clearTextureAtlas();
|
|
278
|
-
} catch {
|
|
279
|
-
// A disposed terminal has no render service; nothing to refresh.
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
document.fonts.addEventListener('loadingdone', onLoadingDone);
|
|
284
|
-
return () => document.fonts.removeEventListener('loadingdone', onLoadingDone);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/** Shift+PageUp/Home/End scroll the viewport instead of reaching the shell. */
|
|
288
|
-
function handleKeyNavigation(term: Terminal, event: globalThis.KeyboardEvent): boolean {
|
|
289
|
-
if (event.type !== 'keydown' || !event.shiftKey) return true;
|
|
290
|
-
if (event.key === 'PageUp') { term.scrollPages(-1); return false; }
|
|
291
|
-
if (event.key === 'PageDown') { term.scrollPages(1); return false; }
|
|
292
|
-
if (event.key === 'Home') { term.scrollToTop(); return false; }
|
|
293
|
-
if (event.key === 'End') { term.scrollToBottom(); return false; }
|
|
294
|
-
if (event.key === 'ArrowUp') { term.scrollLines(-1); return false; }
|
|
295
|
-
if (event.key === 'ArrowDown') { term.scrollLines(1); return false; }
|
|
296
|
-
return true;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/** Touch drags scroll the scrollback; xterm has no touch handling of its own. */
|
|
300
|
-
function attachTouchScroll(container: HTMLElement, term: Terminal): () => void {
|
|
301
|
-
let startY = 0;
|
|
302
|
-
const onStart = (event: globalThis.TouchEvent) => {
|
|
303
|
-
if (event.touches.length === 1) startY = event.touches[0].clientY;
|
|
304
|
-
};
|
|
305
|
-
const onMove = (event: globalThis.TouchEvent) => {
|
|
306
|
-
if (event.touches.length !== 1) return;
|
|
307
|
-
const deltaY = startY - event.touches[0].clientY;
|
|
308
|
-
if (Math.abs(deltaY) < 16) return;
|
|
309
|
-
term.scrollLines(Math.trunc(deltaY / 16));
|
|
310
|
-
startY = event.touches[0].clientY;
|
|
311
|
-
};
|
|
312
|
-
container.addEventListener('touchstart', onStart, { passive: true });
|
|
313
|
-
container.addEventListener('touchmove', onMove, { passive: true });
|
|
314
|
-
return () => {
|
|
315
|
-
container.removeEventListener('touchstart', onStart);
|
|
316
|
-
container.removeEventListener('touchmove', onMove);
|
|
317
|
-
};
|
|
318
|
-
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, expect, test } from 'bun:test';
|
|
7
|
+
import type { Terminal } from 'ghostty-web';
|
|
8
|
+
import { handleKeyNavigation } from '@/client/components/workspace/terminal-panel/navigation';
|
|
9
|
+
|
|
10
|
+
function fakeTerminal() {
|
|
11
|
+
const calls: string[] = [];
|
|
12
|
+
const term = {
|
|
13
|
+
scrollPages: (amount: number) => calls.push(`pages:${amount}`),
|
|
14
|
+
scrollLines: (amount: number) => calls.push(`lines:${amount}`),
|
|
15
|
+
scrollToTop: () => calls.push('top'),
|
|
16
|
+
scrollToBottom: () => calls.push('bottom'),
|
|
17
|
+
} as unknown as Terminal;
|
|
18
|
+
return { term, calls };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface KeyInit extends KeyboardEventInit {
|
|
22
|
+
type: string;
|
|
23
|
+
key: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function key(init: KeyInit): globalThis.KeyboardEvent {
|
|
27
|
+
// The helpers read only `type`, `key` and `shiftKey`; a full DOM event is
|
|
28
|
+
// unavailable under Bun.
|
|
29
|
+
return init as unknown as globalThis.KeyboardEvent;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('handleKeyNavigation', () => {
|
|
33
|
+
test('consumes Shift+PageUp and scrolls the viewport', () => {
|
|
34
|
+
const { term, calls } = fakeTerminal();
|
|
35
|
+
expect(handleKeyNavigation(term, key({ type: 'keydown', key: 'PageUp', shiftKey: true }))).toBe(true);
|
|
36
|
+
expect(calls).toEqual(['pages:-1']);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('lets an unmodified key reach the terminal encoder', () => {
|
|
40
|
+
const { term, calls } = fakeTerminal();
|
|
41
|
+
expect(handleKeyNavigation(term, key({ type: 'keydown', key: 'PageUp' }))).toBe(false);
|
|
42
|
+
expect(handleKeyNavigation(term, key({ type: 'keydown', key: 'a', shiftKey: true }))).toBe(false);
|
|
43
|
+
expect(calls).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('Shift+Home/End/Arrows are viewport gestures, not shell input', () => {
|
|
47
|
+
const { term, calls } = fakeTerminal();
|
|
48
|
+
handleKeyNavigation(term, key({ type: 'keydown', key: 'Home', shiftKey: true }));
|
|
49
|
+
handleKeyNavigation(term, key({ type: 'keydown', key: 'End', shiftKey: true }));
|
|
50
|
+
handleKeyNavigation(term, key({ type: 'keydown', key: 'ArrowUp', shiftKey: true }));
|
|
51
|
+
handleKeyNavigation(term, key({ type: 'keydown', key: 'ArrowDown', shiftKey: true }));
|
|
52
|
+
expect(calls).toEqual(['top', 'bottom', 'lines:-1', 'lines:1']);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Keyboard and touch gestures the canvas renderer does not implement.
|
|
8
|
+
*
|
|
9
|
+
* ghostty-web's custom key handler returns `true` to CONSUME an event, which is
|
|
10
|
+
* the inverse of xterm's contract. This module is written for ghostty's one:
|
|
11
|
+
* an ordinary key must return false so the terminal's own encoder sees it.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { Terminal } from 'ghostty-web';
|
|
15
|
+
|
|
16
|
+
/** Shift+PageUp/Home/End scroll the viewport instead of reaching the shell. */
|
|
17
|
+
export function handleKeyNavigation(term: Terminal, event: globalThis.KeyboardEvent): boolean {
|
|
18
|
+
if (event.type !== 'keydown' || !event.shiftKey) return false;
|
|
19
|
+
if (event.key === 'PageUp') { term.scrollPages(-1); return true; }
|
|
20
|
+
if (event.key === 'PageDown') { term.scrollPages(1); return true; }
|
|
21
|
+
if (event.key === 'Home') { term.scrollToTop(); return true; }
|
|
22
|
+
if (event.key === 'End') { term.scrollToBottom(); return true; }
|
|
23
|
+
if (event.key === 'ArrowUp') { term.scrollLines(-1); return true; }
|
|
24
|
+
if (event.key === 'ArrowDown') { term.scrollLines(1); return true; }
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Touch drags scroll the scrollback; ghostty-web has no touch handling. */
|
|
29
|
+
export function attachTouchScroll(container: HTMLElement, getTerminal: () => Terminal | null): () => void {
|
|
30
|
+
let startY = 0;
|
|
31
|
+
const onStart = (event: globalThis.TouchEvent) => {
|
|
32
|
+
if (event.touches.length === 1) startY = event.touches[0].clientY;
|
|
33
|
+
};
|
|
34
|
+
const onMove = (event: globalThis.TouchEvent) => {
|
|
35
|
+
if (event.touches.length !== 1) return;
|
|
36
|
+
const deltaY = startY - event.touches[0].clientY;
|
|
37
|
+
if (Math.abs(deltaY) < 16) return;
|
|
38
|
+
getTerminal()?.scrollLines(Math.trunc(deltaY / 16));
|
|
39
|
+
startY = event.touches[0].clientY;
|
|
40
|
+
};
|
|
41
|
+
container.addEventListener('touchstart', onStart, { passive: true });
|
|
42
|
+
container.addEventListener('touchmove', onMove, { passive: true });
|
|
43
|
+
return () => {
|
|
44
|
+
container.removeEventListener('touchstart', onStart);
|
|
45
|
+
container.removeEventListener('touchmove', onMove);
|
|
46
|
+
};
|
|
47
|
+
}
|