@deepseek-harness-tui/dsh-tui 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +235 -0
- package/bin/dsh-tui.js +95 -0
- package/cordis.patch.yml +218 -0
- package/cordis.yml +185 -0
- package/lib/invariant.js +28 -0
- package/lib/types/activityPrefs.d.ts +29 -0
- package/lib/types/activityPrefs.d.ts.map +1 -0
- package/lib/types/activityPrefs.js +60 -0
- package/lib/types/bootstrap/state.d.ts +13 -0
- package/lib/types/bootstrap/state.d.ts.map +1 -0
- package/lib/types/bootstrap/state.js +12 -0
- package/lib/types/cc/cliHighlight.d.ts +20 -0
- package/lib/types/cc/cliHighlight.d.ts.map +1 -0
- package/lib/types/cc/cliHighlight.js +53 -0
- package/lib/types/cc/figures.d.ts +59 -0
- package/lib/types/cc/figures.d.ts.map +1 -0
- package/lib/types/cc/figures.js +69 -0
- package/lib/types/cc/format.d.ts +26 -0
- package/lib/types/cc/format.d.ts.map +1 -0
- package/lib/types/cc/format.js +55 -0
- package/lib/types/cc/hash.d.ts +25 -0
- package/lib/types/cc/hash.d.ts.map +1 -0
- package/lib/types/cc/hash.js +41 -0
- package/lib/types/cc/hyperlink.d.ts +21 -0
- package/lib/types/cc/hyperlink.d.ts.map +1 -0
- package/lib/types/cc/hyperlink.js +31 -0
- package/lib/types/cc/markdown.d.ts +43 -0
- package/lib/types/cc/markdown.d.ts.map +1 -0
- package/lib/types/cc/markdown.js +345 -0
- package/lib/types/cc/spinnerVerbs.d.ts +3 -0
- package/lib/types/cc/spinnerVerbs.d.ts.map +1 -0
- package/lib/types/cc/spinnerVerbs.js +190 -0
- package/lib/types/cc/terminal.d.ts +15 -0
- package/lib/types/cc/terminal.d.ts.map +1 -0
- package/lib/types/cc/terminal.js +84 -0
- package/lib/types/channel.d.ts +672 -0
- package/lib/types/channel.d.ts.map +1 -0
- package/lib/types/channel.js +2427 -0
- package/lib/types/childStderr.d.ts +63 -0
- package/lib/types/childStderr.d.ts.map +1 -0
- package/lib/types/childStderr.js +161 -0
- package/lib/types/commands.d.ts +55 -0
- package/lib/types/commands.d.ts.map +1 -0
- package/lib/types/commands.js +101 -0
- package/lib/types/components/ActivityLine.d.ts +29 -0
- package/lib/types/components/ActivityLine.d.ts.map +1 -0
- package/lib/types/components/ActivityLine.js +47 -0
- package/lib/types/components/ActivityPicker.d.ts +13 -0
- package/lib/types/components/ActivityPicker.d.ts.map +1 -0
- package/lib/types/components/ActivityPicker.js +24 -0
- package/lib/types/components/CommandSuggestions.d.ts +14 -0
- package/lib/types/components/CommandSuggestions.d.ts.map +1 -0
- package/lib/types/components/CommandSuggestions.js +33 -0
- package/lib/types/components/FileSuggestions.d.ts +12 -0
- package/lib/types/components/FileSuggestions.d.ts.map +1 -0
- package/lib/types/components/FileSuggestions.js +26 -0
- package/lib/types/components/GoalTodoPanel.d.ts +13 -0
- package/lib/types/components/GoalTodoPanel.d.ts.map +1 -0
- package/lib/types/components/GoalTodoPanel.js +57 -0
- package/lib/types/components/HelpMenu.d.ts +12 -0
- package/lib/types/components/HelpMenu.d.ts.map +1 -0
- package/lib/types/components/HelpMenu.js +12 -0
- package/lib/types/components/HistorySearchDialog.d.ts +16 -0
- package/lib/types/components/HistorySearchDialog.d.ts.map +1 -0
- package/lib/types/components/HistorySearchDialog.js +31 -0
- package/lib/types/components/InterruptedByUser.d.ts +7 -0
- package/lib/types/components/InterruptedByUser.d.ts.map +1 -0
- package/lib/types/components/InterruptedByUser.js +9 -0
- package/lib/types/components/LoadedContextPanel.d.ts +20 -0
- package/lib/types/components/LoadedContextPanel.d.ts.map +1 -0
- package/lib/types/components/LoadedContextPanel.js +30 -0
- package/lib/types/components/LogoV2.d.ts +23 -0
- package/lib/types/components/LogoV2.d.ts.map +1 -0
- package/lib/types/components/LogoV2.js +95 -0
- package/lib/types/components/Markdown.d.ts +24 -0
- package/lib/types/components/Markdown.d.ts.map +1 -0
- package/lib/types/components/Markdown.js +106 -0
- package/lib/types/components/MarkdownTable.d.ts +17 -0
- package/lib/types/components/MarkdownTable.d.ts.map +1 -0
- package/lib/types/components/MarkdownTable.js +272 -0
- package/lib/types/components/MessageList.d.ts +41 -0
- package/lib/types/components/MessageList.d.ts.map +1 -0
- package/lib/types/components/MessageList.js +303 -0
- package/lib/types/components/ModelPicker.d.ts +14 -0
- package/lib/types/components/ModelPicker.d.ts.map +1 -0
- package/lib/types/components/ModelPicker.js +15 -0
- package/lib/types/components/PresetPicker.d.ts +17 -0
- package/lib/types/components/PresetPicker.d.ts.map +1 -0
- package/lib/types/components/PresetPicker.js +25 -0
- package/lib/types/components/PromptInput.d.ts +67 -0
- package/lib/types/components/PromptInput.d.ts.map +1 -0
- package/lib/types/components/PromptInput.js +778 -0
- package/lib/types/components/ResumePicker.d.ts +15 -0
- package/lib/types/components/ResumePicker.d.ts.map +1 -0
- package/lib/types/components/ResumePicker.js +34 -0
- package/lib/types/components/RewindPicker.d.ts +14 -0
- package/lib/types/components/RewindPicker.d.ts.map +1 -0
- package/lib/types/components/RewindPicker.js +23 -0
- package/lib/types/components/SearchBox.d.ts +20 -0
- package/lib/types/components/SearchBox.d.ts.map +1 -0
- package/lib/types/components/SearchBox.js +33 -0
- package/lib/types/components/Select.d.ts +22 -0
- package/lib/types/components/Select.d.ts.map +1 -0
- package/lib/types/components/Select.js +19 -0
- package/lib/types/components/Spinner/GlimmerMessage.d.ts +19 -0
- package/lib/types/components/Spinner/GlimmerMessage.d.ts.map +1 -0
- package/lib/types/components/Spinner/GlimmerMessage.js +78 -0
- package/lib/types/components/Spinner/SpinnerAnimationRow.d.ts +31 -0
- package/lib/types/components/Spinner/SpinnerAnimationRow.d.ts.map +1 -0
- package/lib/types/components/Spinner/SpinnerAnimationRow.js +162 -0
- package/lib/types/components/Spinner/SpinnerGlyph.d.ts +16 -0
- package/lib/types/components/Spinner/SpinnerGlyph.d.ts.map +1 -0
- package/lib/types/components/Spinner/SpinnerGlyph.js +36 -0
- package/lib/types/components/Spinner/spinnerMode.d.ts +6 -0
- package/lib/types/components/Spinner/spinnerMode.d.ts.map +1 -0
- package/lib/types/components/Spinner/spinnerMode.js +1 -0
- package/lib/types/components/Spinner/spinnerUtils.d.ts +41 -0
- package/lib/types/components/Spinner/spinnerUtils.d.ts.map +1 -0
- package/lib/types/components/Spinner/spinnerUtils.js +104 -0
- package/lib/types/components/Spinner/useStalledAnimation.d.ts +16 -0
- package/lib/types/components/Spinner/useStalledAnimation.d.ts.map +1 -0
- package/lib/types/components/Spinner/useStalledAnimation.js +71 -0
- package/lib/types/components/StreamingMarkdown.d.ts +12 -0
- package/lib/types/components/StreamingMarkdown.d.ts.map +1 -0
- package/lib/types/components/StreamingMarkdown.js +39 -0
- package/lib/types/components/ThemePicker.d.ts +22 -0
- package/lib/types/components/ThemePicker.d.ts.map +1 -0
- package/lib/types/components/ThemePicker.js +51 -0
- package/lib/types/components/ThinkingToggle.d.ts +17 -0
- package/lib/types/components/ThinkingToggle.d.ts.map +1 -0
- package/lib/types/components/ThinkingToggle.js +30 -0
- package/lib/types/components/ToolUseLoader.d.ts +13 -0
- package/lib/types/components/ToolUseLoader.d.ts.map +1 -0
- package/lib/types/components/ToolUseLoader.js +17 -0
- package/lib/types/components/Whale.d.ts +22 -0
- package/lib/types/components/Whale.d.ts.map +1 -0
- package/lib/types/components/Whale.js +78 -0
- package/lib/types/components/WorkingSpinner.d.ts +26 -0
- package/lib/types/components/WorkingSpinner.d.ts.map +1 -0
- package/lib/types/components/WorkingSpinner.js +68 -0
- package/lib/types/components/activityFrames.d.ts +31 -0
- package/lib/types/components/activityFrames.d.ts.map +1 -0
- package/lib/types/components/activityFrames.js +83 -0
- package/lib/types/components/bigfont.d.ts +28 -0
- package/lib/types/components/bigfont.d.ts.map +1 -0
- package/lib/types/components/bigfont.js +91 -0
- package/lib/types/components/design-system/Byline.d.ts +14 -0
- package/lib/types/components/design-system/Byline.d.ts.map +1 -0
- package/lib/types/components/design-system/Byline.js +17 -0
- package/lib/types/components/design-system/Divider.d.ts +40 -0
- package/lib/types/components/design-system/Divider.d.ts.map +1 -0
- package/lib/types/components/design-system/Divider.js +24 -0
- package/lib/types/components/design-system/KeyboardShortcutHint.d.ts +19 -0
- package/lib/types/components/design-system/KeyboardShortcutHint.d.ts.map +1 -0
- package/lib/types/components/design-system/KeyboardShortcutHint.js +14 -0
- package/lib/types/components/design-system/ListItem.d.ts +36 -0
- package/lib/types/components/design-system/ListItem.d.ts.map +1 -0
- package/lib/types/components/design-system/ListItem.js +48 -0
- package/lib/types/components/design-system/LoadingState.d.ts +19 -0
- package/lib/types/components/design-system/LoadingState.d.ts.map +1 -0
- package/lib/types/components/design-system/LoadingState.js +22 -0
- package/lib/types/components/design-system/Pane.d.ts +17 -0
- package/lib/types/components/design-system/Pane.d.ts.map +1 -0
- package/lib/types/components/design-system/Pane.js +15 -0
- package/lib/types/components/design-system/ProgressBar.d.ts +22 -0
- package/lib/types/components/design-system/ProgressBar.d.ts.map +1 -0
- package/lib/types/components/design-system/ProgressBar.js +27 -0
- package/lib/types/components/design-system/StatusIcon.d.ts +15 -0
- package/lib/types/components/design-system/StatusIcon.d.ts.map +1 -0
- package/lib/types/components/design-system/StatusIcon.js +20 -0
- package/lib/types/components/design-system/ThemeProvider.d.ts +11 -0
- package/lib/types/components/design-system/ThemeProvider.d.ts.map +1 -0
- package/lib/types/components/design-system/ThemeProvider.js +135 -0
- package/lib/types/components/design-system/ThemedBox.d.ts +37 -0
- package/lib/types/components/design-system/ThemedBox.d.ts.map +1 -0
- package/lib/types/components/design-system/ThemedBox.js +26 -0
- package/lib/types/components/design-system/ThemedText.d.ts +56 -0
- package/lib/types/components/design-system/ThemedText.d.ts.map +1 -0
- package/lib/types/components/design-system/ThemedText.js +45 -0
- package/lib/types/components/messages/AssistantTextMessage.d.ts +18 -0
- package/lib/types/components/messages/AssistantTextMessage.d.ts.map +1 -0
- package/lib/types/components/messages/AssistantTextMessage.js +15 -0
- package/lib/types/components/messages/AssistantThinkingMessage.d.ts +23 -0
- package/lib/types/components/messages/AssistantThinkingMessage.d.ts.map +1 -0
- package/lib/types/components/messages/AssistantThinkingMessage.js +23 -0
- package/lib/types/components/messages/AssistantToolUseMessage.d.ts +23 -0
- package/lib/types/components/messages/AssistantToolUseMessage.d.ts.map +1 -0
- package/lib/types/components/messages/AssistantToolUseMessage.js +220 -0
- package/lib/types/components/messages/MessageMetadata.d.ts +15 -0
- package/lib/types/components/messages/MessageMetadata.d.ts.map +1 -0
- package/lib/types/components/messages/MessageMetadata.js +20 -0
- package/lib/types/components/messages/UserPromptMessage.d.ts +19 -0
- package/lib/types/components/messages/UserPromptMessage.d.ts.map +1 -0
- package/lib/types/components/messages/UserPromptMessage.js +15 -0
- package/lib/types/components/questions/AskUserQuestionPanel.d.ts +39 -0
- package/lib/types/components/questions/AskUserQuestionPanel.d.ts.map +1 -0
- package/lib/types/components/questions/AskUserQuestionPanel.js +228 -0
- package/lib/types/components/shimmer.d.ts +35 -0
- package/lib/types/components/shimmer.d.ts.map +1 -0
- package/lib/types/components/shimmer.js +43 -0
- package/lib/types/components/whaleFrames.d.ts +25 -0
- package/lib/types/components/whaleFrames.d.ts.map +1 -0
- package/lib/types/components/whaleFrames.js +419 -0
- package/lib/types/customTheme.d.ts +104 -0
- package/lib/types/customTheme.d.ts.map +1 -0
- package/lib/types/customTheme.js +268 -0
- package/lib/types/effortPrefs.d.ts +22 -0
- package/lib/types/effortPrefs.d.ts.map +1 -0
- package/lib/types/effortPrefs.js +45 -0
- package/lib/types/history.d.ts +24 -0
- package/lib/types/history.d.ts.map +1 -0
- package/lib/types/history.js +75 -0
- package/lib/types/hooks/useBlink.d.ts +11 -0
- package/lib/types/hooks/useBlink.d.ts.map +1 -0
- package/lib/types/hooks/useBlink.js +20 -0
- package/lib/types/i18n.d.ts +926 -0
- package/lib/types/i18n.d.ts.map +1 -0
- package/lib/types/i18n.js +356 -0
- package/lib/types/index.d.ts +70 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +31 -0
- package/lib/types/ink/Ansi.d.ts +11 -0
- package/lib/types/ink/Ansi.d.ts.map +1 -0
- package/lib/types/ink/Ansi.js +269 -0
- package/lib/types/ink/bidi.d.ts +18 -0
- package/lib/types/ink/bidi.d.ts.map +1 -0
- package/lib/types/ink/bidi.js +119 -0
- package/lib/types/ink/clearTerminal.d.ts +22 -0
- package/lib/types/ink/clearTerminal.d.ts.map +1 -0
- package/lib/types/ink/clearTerminal.js +72 -0
- package/lib/types/ink/colorize.d.ts +33 -0
- package/lib/types/ink/colorize.d.ts.map +1 -0
- package/lib/types/ink/colorize.js +213 -0
- package/lib/types/ink/components/AlternateScreen.d.ts +22 -0
- package/lib/types/ink/components/AlternateScreen.d.ts.map +1 -0
- package/lib/types/ink/components/AlternateScreen.js +74 -0
- package/lib/types/ink/components/App.d.ts +73 -0
- package/lib/types/ink/components/App.d.ts.map +1 -0
- package/lib/types/ink/components/App.js +597 -0
- package/lib/types/ink/components/AppContext.d.ts +15 -0
- package/lib/types/ink/components/AppContext.d.ts.map +1 -0
- package/lib/types/ink/components/AppContext.js +11 -0
- package/lib/types/ink/components/Box.d.ts +49 -0
- package/lib/types/ink/components/Box.d.ts.map +1 -0
- package/lib/types/ink/components/Box.js +153 -0
- package/lib/types/ink/components/Button.d.ts +37 -0
- package/lib/types/ink/components/Button.d.ts.map +1 -0
- package/lib/types/ink/components/Button.js +166 -0
- package/lib/types/ink/components/ClockContext.d.ts +10 -0
- package/lib/types/ink/components/ClockContext.d.ts.map +1 -0
- package/lib/types/ink/components/ClockContext.js +108 -0
- package/lib/types/ink/components/CursorDeclarationContext.d.ts +30 -0
- package/lib/types/ink/components/CursorDeclarationContext.d.ts.map +1 -0
- package/lib/types/ink/components/CursorDeclarationContext.js +6 -0
- package/lib/types/ink/components/ErrorOverview.d.ts +7 -0
- package/lib/types/ink/components/ErrorOverview.d.ts.map +1 -0
- package/lib/types/ink/components/ErrorOverview.js +49 -0
- package/lib/types/ink/components/Link.d.ts +8 -0
- package/lib/types/ink/components/Link.d.ts.map +1 -0
- package/lib/types/ink/components/Link.js +33 -0
- package/lib/types/ink/components/Newline.d.ts +13 -0
- package/lib/types/ink/components/Newline.d.ts.map +1 -0
- package/lib/types/ink/components/Newline.js +29 -0
- package/lib/types/ink/components/NoSelect.d.ts +20 -0
- package/lib/types/ink/components/NoSelect.d.ts.map +1 -0
- package/lib/types/ink/components/NoSelect.js +56 -0
- package/lib/types/ink/components/RawAnsi.d.ts +17 -0
- package/lib/types/ink/components/RawAnsi.d.ts.map +1 -0
- package/lib/types/ink/components/RawAnsi.js +45 -0
- package/lib/types/ink/components/ScrollBox.d.ts +78 -0
- package/lib/types/ink/components/ScrollBox.d.ts.map +1 -0
- package/lib/types/ink/components/ScrollBox.js +174 -0
- package/lib/types/ink/components/Spacer.d.ts +6 -0
- package/lib/types/ink/components/Spacer.d.ts.map +1 -0
- package/lib/types/ink/components/Spacer.js +19 -0
- package/lib/types/ink/components/StdinContext.d.ts +32 -0
- package/lib/types/ink/components/StdinContext.d.ts.map +1 -0
- package/lib/types/ink/components/StdinContext.js +16 -0
- package/lib/types/ink/components/TerminalFocusContext.d.ts +11 -0
- package/lib/types/ink/components/TerminalFocusContext.d.ts.map +1 -0
- package/lib/types/ink/components/TerminalFocusContext.js +45 -0
- package/lib/types/ink/components/TerminalSizeContext.d.ts +6 -0
- package/lib/types/ink/components/TerminalSizeContext.d.ts.map +1 -0
- package/lib/types/ink/components/TerminalSizeContext.js +3 -0
- package/lib/types/ink/components/Text.d.ts +56 -0
- package/lib/types/ink/components/Text.d.ts.map +1 -0
- package/lib/types/ink/components/Text.js +194 -0
- package/lib/types/ink/constants.d.ts +3 -0
- package/lib/types/ink/constants.d.ts.map +1 -0
- package/lib/types/ink/constants.js +2 -0
- package/lib/types/ink/cursor.d.ts +11 -0
- package/lib/types/ink/cursor.d.ts.map +1 -0
- package/lib/types/ink/cursor.js +1 -0
- package/lib/types/ink/devtools.d.ts +7 -0
- package/lib/types/ink/devtools.d.ts.map +1 -0
- package/lib/types/ink/devtools.js +1 -0
- package/lib/types/ink/dom.d.ts +178 -0
- package/lib/types/ink/dom.d.ts.map +1 -0
- package/lib/types/ink/dom.js +424 -0
- package/lib/types/ink/events/click-event.d.ts +32 -0
- package/lib/types/ink/events/click-event.d.ts.map +1 -0
- package/lib/types/ink/events/click-event.js +36 -0
- package/lib/types/ink/events/dispatcher.d.ts +63 -0
- package/lib/types/ink/events/dispatcher.d.ts.map +1 -0
- package/lib/types/ink/events/dispatcher.js +194 -0
- package/lib/types/ink/events/emitter.d.ts +20 -0
- package/lib/types/ink/events/emitter.d.ts.map +1 -0
- package/lib/types/ink/events/emitter.js +43 -0
- package/lib/types/ink/events/event-handlers.d.ts +47 -0
- package/lib/types/ink/events/event-handlers.d.ts.map +1 -0
- package/lib/types/ink/events/event-handlers.js +30 -0
- package/lib/types/ink/events/event.d.ts +19 -0
- package/lib/types/ink/events/event.d.ts.map +1 -0
- package/lib/types/ink/events/event.js +22 -0
- package/lib/types/ink/events/focus-event.d.ts +19 -0
- package/lib/types/ink/events/focus-event.d.ts.map +1 -0
- package/lib/types/ink/events/focus-event.js +21 -0
- package/lib/types/ink/events/input-event.d.ts +53 -0
- package/lib/types/ink/events/input-event.d.ts.map +1 -0
- package/lib/types/ink/events/input-event.js +180 -0
- package/lib/types/ink/events/keyboard-event.d.ts +40 -0
- package/lib/types/ink/events/keyboard-event.d.ts.map +1 -0
- package/lib/types/ink/events/keyboard-event.js +65 -0
- package/lib/types/ink/events/paste-event.d.ts +11 -0
- package/lib/types/ink/events/paste-event.d.ts.map +1 -0
- package/lib/types/ink/events/paste-event.js +13 -0
- package/lib/types/ink/events/resize-event.d.ts +13 -0
- package/lib/types/ink/events/resize-event.d.ts.map +1 -0
- package/lib/types/ink/events/resize-event.js +16 -0
- package/lib/types/ink/events/terminal-event.d.ts +112 -0
- package/lib/types/ink/events/terminal-event.d.ts.map +1 -0
- package/lib/types/ink/events/terminal-event.js +131 -0
- package/lib/types/ink/events/terminal-focus-event.d.ts +21 -0
- package/lib/types/ink/events/terminal-focus-event.d.ts.map +1 -0
- package/lib/types/ink/events/terminal-focus-event.js +18 -0
- package/lib/types/ink/focus.d.ts +74 -0
- package/lib/types/ink/focus.d.ts.map +1 -0
- package/lib/types/ink/focus.js +188 -0
- package/lib/types/ink/frame.d.ts +119 -0
- package/lib/types/ink/frame.d.ts.map +1 -0
- package/lib/types/ink/frame.js +43 -0
- package/lib/types/ink/get-max-width.d.ts +20 -0
- package/lib/types/ink/get-max-width.d.ts.map +1 -0
- package/lib/types/ink/get-max-width.js +25 -0
- package/lib/types/ink/hit-test.d.ts +47 -0
- package/lib/types/ink/hit-test.d.ts.map +1 -0
- package/lib/types/ink/hit-test.js +126 -0
- package/lib/types/ink/hooks/use-animation-frame.d.ts +27 -0
- package/lib/types/ink/hooks/use-animation-frame.d.ts.map +1 -0
- package/lib/types/ink/hooks/use-animation-frame.js +48 -0
- package/lib/types/ink/hooks/use-app.d.ts +8 -0
- package/lib/types/ink/hooks/use-app.d.ts.map +1 -0
- package/lib/types/ink/hooks/use-app.js +8 -0
- package/lib/types/ink/hooks/use-copy-on-select.d.ts +22 -0
- package/lib/types/ink/hooks/use-copy-on-select.d.ts.map +1 -0
- package/lib/types/ink/hooks/use-copy-on-select.js +40 -0
- package/lib/types/ink/hooks/use-declared-cursor.d.ts +31 -0
- package/lib/types/ink/hooks/use-declared-cursor.d.ts.map +1 -0
- package/lib/types/ink/hooks/use-declared-cursor.js +65 -0
- package/lib/types/ink/hooks/use-input.d.ts +41 -0
- package/lib/types/ink/hooks/use-input.d.ts.map +1 -0
- package/lib/types/ink/hooks/use-input.js +73 -0
- package/lib/types/ink/hooks/use-interval.d.ts +23 -0
- package/lib/types/ink/hooks/use-interval.d.ts.map +1 -0
- package/lib/types/ink/hooks/use-interval.js +58 -0
- package/lib/types/ink/hooks/use-search-highlight.d.ts +34 -0
- package/lib/types/ink/hooks/use-search-highlight.d.ts.map +1 -0
- package/lib/types/ink/hooks/use-search-highlight.js +35 -0
- package/lib/types/ink/hooks/use-selection.d.ts +44 -0
- package/lib/types/ink/hooks/use-selection.d.ts.map +1 -0
- package/lib/types/ink/hooks/use-selection.js +64 -0
- package/lib/types/ink/hooks/use-stdin.d.ts +8 -0
- package/lib/types/ink/hooks/use-stdin.d.ts.map +1 -0
- package/lib/types/ink/hooks/use-stdin.js +8 -0
- package/lib/types/ink/hooks/use-tab-status.d.ts +18 -0
- package/lib/types/ink/hooks/use-tab-status.d.ts.map +1 -0
- package/lib/types/ink/hooks/use-tab-status.js +58 -0
- package/lib/types/ink/hooks/use-terminal-focus.d.ts +11 -0
- package/lib/types/ink/hooks/use-terminal-focus.d.ts.map +1 -0
- package/lib/types/ink/hooks/use-terminal-focus.js +15 -0
- package/lib/types/ink/hooks/use-terminal-size.d.ts +6 -0
- package/lib/types/ink/hooks/use-terminal-size.d.ts.map +1 -0
- package/lib/types/ink/hooks/use-terminal-size.js +12 -0
- package/lib/types/ink/hooks/use-terminal-title.d.ts +14 -0
- package/lib/types/ink/hooks/use-terminal-title.d.ts.map +1 -0
- package/lib/types/ink/hooks/use-terminal-title.js +30 -0
- package/lib/types/ink/hooks/use-terminal-viewport.d.ts +32 -0
- package/lib/types/ink/hooks/use-terminal-viewport.d.ts.map +1 -0
- package/lib/types/ink/hooks/use-terminal-viewport.js +79 -0
- package/lib/types/ink/ink.d.ts +370 -0
- package/lib/types/ink/ink.d.ts.map +1 -0
- package/lib/types/ink/ink.js +1665 -0
- package/lib/types/ink/instances.d.ts +10 -0
- package/lib/types/ink/instances.d.ts.map +1 -0
- package/lib/types/ink/instances.js +13 -0
- package/lib/types/ink/layout/engine.d.ts +7 -0
- package/lib/types/ink/layout/engine.d.ts.map +1 -0
- package/lib/types/ink/layout/engine.js +8 -0
- package/lib/types/ink/layout/geometry.d.ts +86 -0
- package/lib/types/ink/layout/geometry.d.ts.map +1 -0
- package/lib/types/ink/layout/geometry.js +95 -0
- package/lib/types/ink/layout/node.d.ts +151 -0
- package/lib/types/ink/layout/node.d.ts.map +1 -0
- package/lib/types/ink/layout/node.js +72 -0
- package/lib/types/ink/layout/yoga.d.ts +69 -0
- package/lib/types/ink/layout/yoga.d.ts.map +1 -0
- package/lib/types/ink/layout/yoga.js +249 -0
- package/lib/types/ink/line-width-cache.d.ts +9 -0
- package/lib/types/ink/line-width-cache.d.ts.map +1 -0
- package/lib/types/ink/line-width-cache.js +45 -0
- package/lib/types/ink/log-update.d.ts +57 -0
- package/lib/types/ink/log-update.d.ts.map +1 -0
- package/lib/types/ink/log-update.js +710 -0
- package/lib/types/ink/measure-element.d.ts +19 -0
- package/lib/types/ink/measure-element.d.ts.map +1 -0
- package/lib/types/ink/measure-element.js +10 -0
- package/lib/types/ink/measure-text.d.ts +13 -0
- package/lib/types/ink/measure-text.d.ts.map +1 -0
- package/lib/types/ink/measure-text.js +38 -0
- package/lib/types/ink/node-cache.d.ts +33 -0
- package/lib/types/ink/node-cache.d.ts.map +1 -0
- package/lib/types/ink/node-cache.js +42 -0
- package/lib/types/ink/optimizer.d.ts +18 -0
- package/lib/types/ink/optimizer.d.ts.map +1 -0
- package/lib/types/ink/optimizer.js +83 -0
- package/lib/types/ink/output.d.ts +200 -0
- package/lib/types/ink/output.d.ts.map +1 -0
- package/lib/types/ink/output.js +663 -0
- package/lib/types/ink/parse-keypress.d.ts +132 -0
- package/lib/types/ink/parse-keypress.d.ts.map +1 -0
- package/lib/types/ink/parse-keypress.js +707 -0
- package/lib/types/ink/reconciler.d.ts +43 -0
- package/lib/types/ink/reconciler.d.ts.map +1 -0
- package/lib/types/ink/reconciler.js +413 -0
- package/lib/types/ink/render-border.d.ts +36 -0
- package/lib/types/ink/render-border.d.ts.map +1 -0
- package/lib/types/ink/render-border.js +143 -0
- package/lib/types/ink/render-node-to-output.d.ts +93 -0
- package/lib/types/ink/render-node-to-output.d.ts.map +1 -0
- package/lib/types/ink/render-node-to-output.js +1290 -0
- package/lib/types/ink/render-to-screen.d.ts +65 -0
- package/lib/types/ink/render-to-screen.d.ts.map +1 -0
- package/lib/types/ink/render-to-screen.js +189 -0
- package/lib/types/ink/renderer.d.ts +24 -0
- package/lib/types/ink/renderer.d.ts.map +1 -0
- package/lib/types/ink/renderer.js +136 -0
- package/lib/types/ink/root.d.ts +91 -0
- package/lib/types/ink/root.d.ts.map +1 -0
- package/lib/types/ink/root.js +93 -0
- package/lib/types/ink/screen.d.ts +443 -0
- package/lib/types/ink/screen.d.ts.map +1 -0
- package/lib/types/ink/screen.js +1295 -0
- package/lib/types/ink/searchHighlight.d.ts +25 -0
- package/lib/types/ink/searchHighlight.d.ts.map +1 -0
- package/lib/types/ink/searchHighlight.js +82 -0
- package/lib/types/ink/selection.d.ts +323 -0
- package/lib/types/ink/selection.d.ts.map +1 -0
- package/lib/types/ink/selection.js +881 -0
- package/lib/types/ink/squash-text-nodes.d.ts +30 -0
- package/lib/types/ink/squash-text-nodes.d.ts.map +1 -0
- package/lib/types/ink/squash-text-nodes.js +63 -0
- package/lib/types/ink/stringWidth.d.ts +11 -0
- package/lib/types/ink/stringWidth.d.ts.map +1 -0
- package/lib/types/ink/stringWidth.js +209 -0
- package/lib/types/ink/styles.d.ts +324 -0
- package/lib/types/ink/styles.d.ts.map +1 -0
- package/lib/types/ink/styles.js +307 -0
- package/lib/types/ink/supports-hyperlinks.d.ts +20 -0
- package/lib/types/ink/supports-hyperlinks.d.ts.map +1 -0
- package/lib/types/ink/supports-hyperlinks.js +44 -0
- package/lib/types/ink/tabstops.d.ts +9 -0
- package/lib/types/ink/tabstops.d.ts.map +1 -0
- package/lib/types/ink/tabstops.js +46 -0
- package/lib/types/ink/terminal-focus-state.d.ts +35 -0
- package/lib/types/ink/terminal-focus-state.d.ts.map +1 -0
- package/lib/types/ink/terminal-focus-state.js +57 -0
- package/lib/types/ink/terminal-querier.d.ts +161 -0
- package/lib/types/ink/terminal-querier.d.ts.map +1 -0
- package/lib/types/ink/terminal-querier.js +204 -0
- package/lib/types/ink/terminal.d.ts +80 -0
- package/lib/types/ink/terminal.d.ts.map +1 -0
- package/lib/types/ink/terminal.js +268 -0
- package/lib/types/ink/termio/ansi.d.ts +75 -0
- package/lib/types/ink/termio/ansi.d.ts.map +1 -0
- package/lib/types/ink/termio/ansi.js +79 -0
- package/lib/types/ink/termio/csi.d.ts +253 -0
- package/lib/types/ink/termio/csi.d.ts.map +1 -0
- package/lib/types/ink/termio/csi.js +347 -0
- package/lib/types/ink/termio/dec.d.ts +61 -0
- package/lib/types/ink/termio/dec.d.ts.map +1 -0
- package/lib/types/ink/termio/dec.js +76 -0
- package/lib/types/ink/termio/esc.d.ts +15 -0
- package/lib/types/ink/termio/esc.d.ts.map +1 -0
- package/lib/types/ink/termio/esc.js +57 -0
- package/lib/types/ink/termio/osc.d.ts +208 -0
- package/lib/types/ink/termio/osc.d.ts.map +1 -0
- package/lib/types/ink/termio/osc.js +466 -0
- package/lib/types/ink/termio/parser.d.ts +46 -0
- package/lib/types/ink/termio/parser.d.ts.map +1 -0
- package/lib/types/ink/termio/parser.js +366 -0
- package/lib/types/ink/termio/sgr.d.ts +17 -0
- package/lib/types/ink/termio/sgr.d.ts.map +1 -0
- package/lib/types/ink/termio/sgr.js +300 -0
- package/lib/types/ink/termio/tokenize.d.ts +50 -0
- package/lib/types/ink/termio/tokenize.d.ts.map +1 -0
- package/lib/types/ink/termio/tokenize.js +266 -0
- package/lib/types/ink/termio/types.d.ts +211 -0
- package/lib/types/ink/termio/types.d.ts.map +1 -0
- package/lib/types/ink/termio/types.js +68 -0
- package/lib/types/ink/termio.d.ts +25 -0
- package/lib/types/ink/termio.d.ts.map +1 -0
- package/lib/types/ink/termio.js +24 -0
- package/lib/types/ink/truncateToWidth.d.ts +7 -0
- package/lib/types/ink/truncateToWidth.d.ts.map +1 -0
- package/lib/types/ink/truncateToWidth.js +18 -0
- package/lib/types/ink/useTerminalNotification.d.ts +45 -0
- package/lib/types/ink/useTerminalNotification.d.ts.map +1 -0
- package/lib/types/ink/useTerminalNotification.js +70 -0
- package/lib/types/ink/warn.d.ts +7 -0
- package/lib/types/ink/warn.d.ts.map +1 -0
- package/lib/types/ink/warn.js +15 -0
- package/lib/types/ink/widest-line.d.ts +7 -0
- package/lib/types/ink/widest-line.d.ts.map +1 -0
- package/lib/types/ink/widest-line.js +19 -0
- package/lib/types/ink/wrap-text.d.ts +10 -0
- package/lib/types/ink/wrap-text.d.ts.map +1 -0
- package/lib/types/ink/wrap-text.js +61 -0
- package/lib/types/ink/wrapAnsi.d.ts +18 -0
- package/lib/types/ink/wrapAnsi.d.ts.map +1 -0
- package/lib/types/ink/wrapAnsi.js +16 -0
- package/lib/types/invariant.d.ts +20 -0
- package/lib/types/invariant.d.ts.map +1 -0
- package/lib/types/invariant.js +26 -0
- package/lib/types/modelPrefs.d.ts +37 -0
- package/lib/types/modelPrefs.d.ts.map +1 -0
- package/lib/types/modelPrefs.js +66 -0
- package/lib/types/modelRoute.d.ts +79 -0
- package/lib/types/modelRoute.d.ts.map +1 -0
- package/lib/types/modelRoute.js +96 -0
- package/lib/types/native-ts/yoga-layout/enums.d.ts +183 -0
- package/lib/types/native-ts/yoga-layout/enums.d.ts.map +1 -0
- package/lib/types/native-ts/yoga-layout/enums.js +150 -0
- package/lib/types/native-ts/yoga-layout/index.d.ts +788 -0
- package/lib/types/native-ts/yoga-layout/index.d.ts.map +1 -0
- package/lib/types/native-ts/yoga-layout/index.js +2571 -0
- package/lib/types/packaged-skills.d.ts +10 -0
- package/lib/types/packaged-skills.d.ts.map +1 -0
- package/lib/types/packaged-skills.js +63 -0
- package/lib/types/plugin.d.ts +33 -0
- package/lib/types/plugin.d.ts.map +1 -0
- package/lib/types/plugin.js +454 -0
- package/lib/types/presetPrefs.d.ts +29 -0
- package/lib/types/presetPrefs.d.ts.map +1 -0
- package/lib/types/presetPrefs.js +61 -0
- package/lib/types/presets.d.ts +110 -0
- package/lib/types/presets.d.ts.map +1 -0
- package/lib/types/presets.js +114 -0
- package/lib/types/questions.d.ts +97 -0
- package/lib/types/questions.d.ts.map +1 -0
- package/lib/types/questions.js +201 -0
- package/lib/types/screens/Chat.d.ts +23 -0
- package/lib/types/screens/Chat.d.ts.map +1 -0
- package/lib/types/screens/Chat.js +1263 -0
- package/lib/types/screens/StatusLine.d.ts +16 -0
- package/lib/types/screens/StatusLine.d.ts.map +1 -0
- package/lib/types/screens/StatusLine.js +105 -0
- package/lib/types/screens/StatusMetrics.d.ts +87 -0
- package/lib/types/screens/StatusMetrics.d.ts.map +1 -0
- package/lib/types/screens/StatusMetrics.js +252 -0
- package/lib/types/sessionHistory.d.ts +32 -0
- package/lib/types/sessionHistory.d.ts.map +1 -0
- package/lib/types/sessionHistory.js +87 -0
- package/lib/types/theme.d.ts +115 -0
- package/lib/types/theme.d.ts.map +1 -0
- package/lib/types/theme.js +300 -0
- package/lib/types/themePrefs.d.ts +28 -0
- package/lib/types/themePrefs.d.ts.map +1 -0
- package/lib/types/themePrefs.js +59 -0
- package/lib/types/ui.d.ts +28 -0
- package/lib/types/ui.d.ts.map +1 -0
- package/lib/types/ui.js +25 -0
- package/lib/types/update.d.ts +76 -0
- package/lib/types/update.d.ts.map +1 -0
- package/lib/types/update.js +203 -0
- package/lib/types/utils/clipboard.d.ts +43 -0
- package/lib/types/utils/clipboard.d.ts.map +1 -0
- package/lib/types/utils/clipboard.js +82 -0
- package/lib/types/utils/debug.d.ts +8 -0
- package/lib/types/utils/debug.d.ts.map +1 -0
- package/lib/types/utils/debug.js +12 -0
- package/lib/types/utils/earlyInput.d.ts +7 -0
- package/lib/types/utils/earlyInput.d.ts.map +1 -0
- package/lib/types/utils/earlyInput.js +6 -0
- package/lib/types/utils/env.d.ts +10 -0
- package/lib/types/utils/env.d.ts.map +1 -0
- package/lib/types/utils/env.js +9 -0
- package/lib/types/utils/envUtils.d.ts +8 -0
- package/lib/types/utils/envUtils.d.ts.map +1 -0
- package/lib/types/utils/envUtils.js +13 -0
- package/lib/types/utils/execFileNoThrow.d.ts +34 -0
- package/lib/types/utils/execFileNoThrow.d.ts.map +1 -0
- package/lib/types/utils/execFileNoThrow.js +31 -0
- package/lib/types/utils/fullscreen.d.ts +8 -0
- package/lib/types/utils/fullscreen.d.ts.map +1 -0
- package/lib/types/utils/fullscreen.js +10 -0
- package/lib/types/utils/intl.d.ts +7 -0
- package/lib/types/utils/intl.d.ts.map +1 -0
- package/lib/types/utils/intl.js +9 -0
- package/lib/types/utils/loaded-context.d.ts +20 -0
- package/lib/types/utils/loaded-context.d.ts.map +1 -0
- package/lib/types/utils/loaded-context.js +36 -0
- package/lib/types/utils/log.d.ts +7 -0
- package/lib/types/utils/log.d.ts.map +1 -0
- package/lib/types/utils/log.js +9 -0
- package/lib/types/utils/mentions.d.ts +30 -0
- package/lib/types/utils/mentions.d.ts.map +1 -0
- package/lib/types/utils/mentions.js +72 -0
- package/lib/types/utils/narration.d.ts +11 -0
- package/lib/types/utils/narration.d.ts.map +1 -0
- package/lib/types/utils/narration.js +16 -0
- package/lib/types/utils/semver.d.ts +9 -0
- package/lib/types/utils/semver.d.ts.map +1 -0
- package/lib/types/utils/semver.js +24 -0
- package/lib/types/utils/sliceAnsi.d.ts +12 -0
- package/lib/types/utils/sliceAnsi.d.ts.map +1 -0
- package/lib/types/utils/sliceAnsi.js +79 -0
- package/lib/types/working-activity.d.ts +19 -0
- package/lib/types/working-activity.d.ts.map +1 -0
- package/lib/types/working-activity.js +18 -0
- package/package.json +141 -0
- package/skills/audit/SKILL.md +24 -0
- package/skills/bug/SKILL.md +27 -0
- package/skills/pr-comments/SKILL.md +20 -0
- package/skills/practice/SKILL.md +22 -0
- package/skills/release-notes/SKILL.md +25 -0
- package/skills/review/SKILL.md +25 -0
- package/skills/vuln-check/SKILL.md +25 -0
|
@@ -0,0 +1,710 @@
|
|
|
1
|
+
import { ansiCodesToString, diffAnsiCodes, } from '@alcalzone/ansi-tokenize';
|
|
2
|
+
import { logForDebugging } from '../utils/debug.js';
|
|
3
|
+
import { cellAt, charInCellAt, diffEach, isEmptyCellAt, shiftRows, visibleCellAtIndex, } from './screen.js';
|
|
4
|
+
import { CURSOR_HOME, cursorUp, eraseToEndOfScreen, scrollDown as csiScrollDown, scrollUp as csiScrollUp, RESET_SCROLL_REGION, setScrollRegion, } from './termio/csi.js';
|
|
5
|
+
import { LINK_END, link as oscLink } from './termio/osc.js';
|
|
6
|
+
const CARRIAGE_RETURN = { type: 'carriageReturn' };
|
|
7
|
+
const NEWLINE = { type: 'stdout', content: '\n' };
|
|
8
|
+
/**
|
|
9
|
+
* Converts frame diffs into terminal write patches. Holds per-instance
|
|
10
|
+
* state (previous output, style pool, TTY mode) across frames.
|
|
11
|
+
*/
|
|
12
|
+
export class LogUpdate {
|
|
13
|
+
options;
|
|
14
|
+
state;
|
|
15
|
+
constructor(options) {
|
|
16
|
+
this.options = options;
|
|
17
|
+
this.state = {
|
|
18
|
+
previousOutput: '',
|
|
19
|
+
reanchorPending: false,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Request a one-shot viewport re-anchor on the next main-screen frame.
|
|
24
|
+
*
|
|
25
|
+
* The main-screen diff engine addresses rows purely relative to where it
|
|
26
|
+
* left the cursor — it has no absolute anchor and no way to notice when a
|
|
27
|
+
* third party moved it. A subprocess writing directly to the tty (an MCP
|
|
28
|
+
* server's stderr, a stray native log line — issue #17) advances the
|
|
29
|
+
* cursor and scrolls the terminal; every subsequent diff then lands N
|
|
30
|
+
* rows off, garbling the UI (missing labels, shifted rows — issue #16)
|
|
31
|
+
* until some full repaint happens to run. There is nothing to detect
|
|
32
|
+
* after the fact (a newline-terminated write parks the cursor back at
|
|
33
|
+
* the bottom column 0, exactly where the engine expects it), so the
|
|
34
|
+
* recovery is a blind idempotent repaint: rebuild the viewport from the
|
|
35
|
+
* physical cursor position, which re-syncs the virtual↔physical mapping
|
|
36
|
+
* no matter how far they had drifted. Wired to the stdin-gap reassert
|
|
37
|
+
* (>5s idle then a keypress) — the same trigger that re-asserts DEC
|
|
38
|
+
* modes after tmux attach / ssh reconnect.
|
|
39
|
+
*/
|
|
40
|
+
requestViewportReanchor() {
|
|
41
|
+
this.state.reanchorPending = true;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Render the terminal state for a finished run, for streams that no
|
|
45
|
+
* longer support string output.
|
|
46
|
+
* @param prevFrame - the previously rendered frame.
|
|
47
|
+
* @returns the patches that restore the terminal to the previous frame's state.
|
|
48
|
+
*/
|
|
49
|
+
renderPreviousOutput_DEPRECATED(prevFrame) {
|
|
50
|
+
if (!this.options.isTTY) {
|
|
51
|
+
// Non-TTY output is no longer supported (string output was removed)
|
|
52
|
+
return [NEWLINE];
|
|
53
|
+
}
|
|
54
|
+
return this.getRenderOpsForDone(prevFrame);
|
|
55
|
+
}
|
|
56
|
+
// Called when process resumes from suspension (SIGCONT) to prevent clobbering terminal content
|
|
57
|
+
/** Drop the previous-output state after the process resumes from suspension (SIGCONT) so terminal content is not clobbered. */
|
|
58
|
+
reset() {
|
|
59
|
+
this.state.previousOutput = '';
|
|
60
|
+
}
|
|
61
|
+
renderFullFrame(frame) {
|
|
62
|
+
const { screen } = frame;
|
|
63
|
+
const lines = [];
|
|
64
|
+
let currentStyles = [];
|
|
65
|
+
let currentHyperlink = undefined;
|
|
66
|
+
for (let y = 0; y < screen.height; y++) {
|
|
67
|
+
let line = '';
|
|
68
|
+
for (let x = 0; x < screen.width; x++) {
|
|
69
|
+
const cell = cellAt(screen, x, y);
|
|
70
|
+
if (cell && cell.width !== 2 /* CellWidth.SpacerTail */) {
|
|
71
|
+
// Handle hyperlink transitions
|
|
72
|
+
if (cell.hyperlink !== currentHyperlink) {
|
|
73
|
+
if (currentHyperlink !== undefined) {
|
|
74
|
+
line += LINK_END;
|
|
75
|
+
}
|
|
76
|
+
if (cell.hyperlink !== undefined) {
|
|
77
|
+
line += oscLink(cell.hyperlink);
|
|
78
|
+
}
|
|
79
|
+
currentHyperlink = cell.hyperlink;
|
|
80
|
+
}
|
|
81
|
+
const cellStyles = this.options.stylePool.get(cell.styleId);
|
|
82
|
+
const styleDiff = diffAnsiCodes(currentStyles, cellStyles);
|
|
83
|
+
if (styleDiff.length > 0) {
|
|
84
|
+
line += ansiCodesToString(styleDiff);
|
|
85
|
+
currentStyles = cellStyles;
|
|
86
|
+
}
|
|
87
|
+
line += cell.char;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Close any open hyperlink before resetting styles
|
|
91
|
+
if (currentHyperlink !== undefined) {
|
|
92
|
+
line += LINK_END;
|
|
93
|
+
currentHyperlink = undefined;
|
|
94
|
+
}
|
|
95
|
+
// Reset styles at end of line so trimEnd doesn't leave dangling codes
|
|
96
|
+
const resetCodes = diffAnsiCodes(currentStyles, []);
|
|
97
|
+
if (resetCodes.length > 0) {
|
|
98
|
+
line += ansiCodesToString(resetCodes);
|
|
99
|
+
currentStyles = [];
|
|
100
|
+
}
|
|
101
|
+
lines.push(line.trimEnd());
|
|
102
|
+
}
|
|
103
|
+
if (lines.length === 0) {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
return [{ type: 'stdout', content: lines.join('\n') }];
|
|
107
|
+
}
|
|
108
|
+
getRenderOpsForDone(prev) {
|
|
109
|
+
this.state.previousOutput = '';
|
|
110
|
+
if (!prev.cursor.visible) {
|
|
111
|
+
return [{ type: 'cursorShow' }];
|
|
112
|
+
}
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Diff the previous and next frames and produce the patches that update
|
|
117
|
+
* the terminal from one to the other.
|
|
118
|
+
* @param prev - the previously rendered frame.
|
|
119
|
+
* @param next - the frame to render.
|
|
120
|
+
* @param altScreen - whether the frame renders to the alternate screen.
|
|
121
|
+
* @param decstbmSafe - whether the DECSTBM scroll sequence can be made atomic (DEC 2026 / BSU/ESU).
|
|
122
|
+
* @returns the terminal write patches.
|
|
123
|
+
*/
|
|
124
|
+
render(prev, next, altScreen = false, decstbmSafe = true) {
|
|
125
|
+
if (!this.options.isTTY) {
|
|
126
|
+
return this.renderFullFrame(next);
|
|
127
|
+
}
|
|
128
|
+
const startTime = performance.now();
|
|
129
|
+
const stylePool = this.options.stylePool;
|
|
130
|
+
// Since we assume the cursor is at the bottom on the screen, we only need
|
|
131
|
+
// to clear when the viewport gets shorter (i.e. the cursor position drifts)
|
|
132
|
+
// or when it gets thinner (and text wraps). We _could_ figure out how to
|
|
133
|
+
// not reset here but that would involve predicting the current layout
|
|
134
|
+
// _after_ the viewport change which means calcuating text wrapping.
|
|
135
|
+
// Resizing is a rare enough event that it's not practically a big issue.
|
|
136
|
+
if (next.viewport.height < prev.viewport.height ||
|
|
137
|
+
(prev.viewport.width !== 0 && next.viewport.width !== prev.viewport.width)) {
|
|
138
|
+
return fullResetSequence_CAUSES_FLICKER(next, 'resize', stylePool);
|
|
139
|
+
}
|
|
140
|
+
// One-shot viewport re-anchor (see requestViewportReanchor): repaint
|
|
141
|
+
// the whole visible window from the physical cursor position, blind to
|
|
142
|
+
// whatever a third-party tty write did to it. Main-screen only — the
|
|
143
|
+
// alt-screen path already self-heals with CSI H every frame. Checked
|
|
144
|
+
// after the resize reset (which supersedes it; the flag survives to
|
|
145
|
+
// the next frame) and before the DECSTBM path (alt-screen only, so
|
|
146
|
+
// mutually exclusive anyway).
|
|
147
|
+
if (this.state.reanchorPending && !altScreen) {
|
|
148
|
+
this.state.reanchorPending = false;
|
|
149
|
+
return repaintViewportInPlace(prev, next, stylePool);
|
|
150
|
+
}
|
|
151
|
+
// DECSTBM scroll optimization: when a ScrollBox's scrollTop changed,
|
|
152
|
+
// shift content with a hardware scroll (CSI top;bot r + CSI n S/T)
|
|
153
|
+
// instead of rewriting the whole scroll region. The shiftRows on
|
|
154
|
+
// prev.screen simulates the shift so the diff loop below naturally
|
|
155
|
+
// finds only the rows that scrolled IN as diffs. prev.screen is
|
|
156
|
+
// about to become backFrame (reused next render) so mutation is safe.
|
|
157
|
+
// CURSOR_HOME after RESET_SCROLL_REGION is defensive — DECSTBM reset
|
|
158
|
+
// homes cursor per spec but terminal implementations vary.
|
|
159
|
+
//
|
|
160
|
+
// decstbmSafe: caller passes false when the DECSTBM→diff sequence
|
|
161
|
+
// can't be made atomic (no DEC 2026 / BSU/ESU). Without atomicity the
|
|
162
|
+
// outer terminal renders the intermediate state — region scrolled,
|
|
163
|
+
// edge rows not yet painted — a visible vertical jump on every frame
|
|
164
|
+
// where scrollTop moves. Falling through to the diff loop writes all
|
|
165
|
+
// shifted rows: more bytes, no intermediate state. next.screen from
|
|
166
|
+
// render-node-to-output's blit+shift is correct either way.
|
|
167
|
+
let scrollPatch = [];
|
|
168
|
+
if (altScreen && next.scrollHint && decstbmSafe) {
|
|
169
|
+
const { top, bottom, delta } = next.scrollHint;
|
|
170
|
+
if (top >= 0 &&
|
|
171
|
+
bottom < prev.screen.height &&
|
|
172
|
+
bottom < next.screen.height) {
|
|
173
|
+
shiftRows(prev.screen, top, bottom, delta);
|
|
174
|
+
// The hardware scroll's blank fill uses the terminal's CURRENT
|
|
175
|
+
// background (BCE); the SGR reset at the head of every frame buffer
|
|
176
|
+
// (writeDiffToTerminal) guarantees the default background here even
|
|
177
|
+
// after a truncated previous frame left a colored SGR stuck.
|
|
178
|
+
scrollPatch = [
|
|
179
|
+
{
|
|
180
|
+
type: 'stdout',
|
|
181
|
+
content: setScrollRegion(top + 1, bottom + 1) +
|
|
182
|
+
(delta > 0 ? csiScrollUp(delta) : csiScrollDown(-delta)) +
|
|
183
|
+
RESET_SCROLL_REGION +
|
|
184
|
+
CURSOR_HOME,
|
|
185
|
+
},
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// We have to use purely relative operations to manipulate the cursor since
|
|
190
|
+
// we don't know its starting point.
|
|
191
|
+
//
|
|
192
|
+
// When content height >= viewport height AND cursor is at the bottom,
|
|
193
|
+
// the cursor restore at the end of the previous frame caused terminal scroll.
|
|
194
|
+
// viewportY tells us how many rows are in scrollback from content overflow.
|
|
195
|
+
// Additionally, the cursor-restore scroll pushes 1 more row into scrollback.
|
|
196
|
+
// We need fullReset if any changes are to rows that are now in scrollback.
|
|
197
|
+
//
|
|
198
|
+
// This early full-reset check only applies in "steady state" (not growing).
|
|
199
|
+
// For growing, the viewportY calculation below (with cursorRestoreScroll)
|
|
200
|
+
// catches unreachable scrollback rows in the diff loop instead.
|
|
201
|
+
const cursorAtBottom = prev.cursor.y >= prev.screen.height;
|
|
202
|
+
const isGrowing = next.screen.height > prev.screen.height;
|
|
203
|
+
// When content fills the viewport exactly (height == viewport) and the
|
|
204
|
+
// cursor is at the bottom, the cursor-restore LF at the end of the
|
|
205
|
+
// previous frame scrolled 1 row into scrollback. Use >= to catch this.
|
|
206
|
+
const prevHadScrollback = cursorAtBottom && prev.screen.height >= prev.viewport.height;
|
|
207
|
+
const isShrinking = next.screen.height < prev.screen.height;
|
|
208
|
+
const nextFitsViewport = next.screen.height <= prev.viewport.height;
|
|
209
|
+
// When shrinking from above-viewport to at-or-below-viewport, content
|
|
210
|
+
// that was in scrollback stays there — terminal clears can't pull it
|
|
211
|
+
// back — but the viewport itself can be rebuilt in place: the cursor is
|
|
212
|
+
// parked at the physical bottom (prevHadScrollback implies it), so the
|
|
213
|
+
// viewport rows are all reachable. Repainting them directly avoids the
|
|
214
|
+
// former full reset here, whose clearTerminal + whole-frame reprint
|
|
215
|
+
// deposited one stale UI copy into the scrollback per shrink.
|
|
216
|
+
// Use <= (not <) because even when next height equals viewport height,
|
|
217
|
+
// the scrollback depth from the previous render differs from a fresh
|
|
218
|
+
// render.
|
|
219
|
+
if (prevHadScrollback && nextFitsViewport && isShrinking) {
|
|
220
|
+
logForDebugging(`Viewport repaint (shrink->below): prevHeight=${prev.screen.height}, nextHeight=${next.screen.height}, viewport=${prev.viewport.height}`);
|
|
221
|
+
return repaintViewportInPlace(prev, next, stylePool);
|
|
222
|
+
}
|
|
223
|
+
// Steady-state scrollback check removed: rows above the viewport used
|
|
224
|
+
// to force a full reset (ESC[2J+ESC[3J) whenever they changed, which
|
|
225
|
+
// wipes terminal scrollback and snaps the viewport to the top — firing
|
|
226
|
+
// on every streaming pause frame. The diff loop below now skips those
|
|
227
|
+
// rows instead (y < viewportY → skip), repainting them when they
|
|
228
|
+
// scroll back into view. Shrink and resize resets below are kept.
|
|
229
|
+
const screen = new VirtualScreen(prev.cursor, next.viewport.width);
|
|
230
|
+
// Treat empty screen as height 1 to avoid spurious adjustments on first render
|
|
231
|
+
const heightDelta = Math.max(next.screen.height, 1) - Math.max(prev.screen.height, 1);
|
|
232
|
+
const shrinking = heightDelta < 0;
|
|
233
|
+
const growing = heightDelta > 0;
|
|
234
|
+
// Handle shrinking: clear lines from the bottom
|
|
235
|
+
// When prevHadScrollback, add 1 for the cursor-restore LF that scrolled
|
|
236
|
+
// an additional row out of view at the end of the previous frame.
|
|
237
|
+
const cursorRestoreScroll = prevHadScrollback ? 1 : 0;
|
|
238
|
+
if (shrinking) {
|
|
239
|
+
const linesToClear = prev.screen.height - next.screen.height;
|
|
240
|
+
// Main-screen mode + content taller than the viewport: the terminal
|
|
241
|
+
// viewport does NOT follow the content bottom when content shrinks —
|
|
242
|
+
// a diff-loop path would write rows at stale physical offsets. But
|
|
243
|
+
// when the cursor sits on its park row (the invariant the renderer
|
|
244
|
+
// maintains every main-screen frame), the whole viewport is directly
|
|
245
|
+
// addressable: repaint it in place. This branch fires on EVERY turn
|
|
246
|
+
// (thinking fold, spinner/esc-hint unmount, markdown reflow shrink
|
|
247
|
+
// the frame by a row or two while it is taller than the viewport) —
|
|
248
|
+
// the former full reset here was the copy machine behind the
|
|
249
|
+
// duplicated-UI scrollback reports (#38 #39 #19). Fall back to the
|
|
250
|
+
// full reset only if the cursor is somewhere unexpected.
|
|
251
|
+
if (!altScreen && prev.screen.height > prev.viewport.height) {
|
|
252
|
+
if (cursorAtBottom) {
|
|
253
|
+
logForDebugging(`Viewport repaint (shrink tall): prevHeight=${prev.screen.height}, nextHeight=${next.screen.height}, viewport=${prev.viewport.height}`);
|
|
254
|
+
return repaintViewportInPlace(prev, next, this.options.stylePool);
|
|
255
|
+
}
|
|
256
|
+
return fullResetSequence_CAUSES_FLICKER(next, 'offscreen', this.options.stylePool);
|
|
257
|
+
}
|
|
258
|
+
// eraseLines only works within the viewport - it can't clear scrollback.
|
|
259
|
+
// If we need to clear more lines than fit in the viewport, some are in
|
|
260
|
+
// scrollback, so we need a full reset.
|
|
261
|
+
if (linesToClear > prev.viewport.height) {
|
|
262
|
+
return fullResetSequence_CAUSES_FLICKER(next, 'offscreen', this.options.stylePool);
|
|
263
|
+
}
|
|
264
|
+
// clear(N) moves cursor UP by N-1 lines and to column 0
|
|
265
|
+
// This puts us at line prev.screen.height - N = next.screen.height
|
|
266
|
+
// But we want to be at next.screen.height - 1 (bottom of new screen)
|
|
267
|
+
screen.txn(prev2 => [
|
|
268
|
+
[
|
|
269
|
+
{ type: 'clear', count: linesToClear },
|
|
270
|
+
{ type: 'cursorMove', x: 0, y: -1 },
|
|
271
|
+
],
|
|
272
|
+
{ dx: -prev2.x, dy: -linesToClear },
|
|
273
|
+
]);
|
|
274
|
+
}
|
|
275
|
+
// viewportY = number of rows in scrollback (not visible on terminal).
|
|
276
|
+
// For shrinking: use max(prev, next) because terminal clears don't scroll.
|
|
277
|
+
// For growing: use prev state because new rows haven't scrolled old ones yet.
|
|
278
|
+
// When prevHadScrollback, add 1 for the cursor-restore LF that scrolled
|
|
279
|
+
// an additional row out of view at the end of the previous frame. Without
|
|
280
|
+
// this, the diff loop treats that row as reachable — but the cursor clamps
|
|
281
|
+
// at viewport top, causing writes to land 1 row off and garbling the output.
|
|
282
|
+
const viewportY = growing
|
|
283
|
+
? Math.max(0, prev.screen.height - prev.viewport.height + cursorRestoreScroll)
|
|
284
|
+
: Math.max(prev.screen.height, next.screen.height) -
|
|
285
|
+
next.viewport.height +
|
|
286
|
+
cursorRestoreScroll;
|
|
287
|
+
// Rows above viewportY live in terminal scrollback and are skipped by the
|
|
288
|
+
// diff loop (see below). Clip the damage region to the visible area so the
|
|
289
|
+
// loop doesn't scan scrollback rows cell-by-cell every frame — with a tall
|
|
290
|
+
// conversation that's a per-frame O(full screen) cost and stalls rendering.
|
|
291
|
+
// prev.damage participates in diffEach's region union, so clip it too
|
|
292
|
+
// (blit doesn't read damage — renderer.ts uses it only in comments).
|
|
293
|
+
if (viewportY > 0) {
|
|
294
|
+
for (const src of [next.screen, prev.screen]) {
|
|
295
|
+
const dmg = src.damage;
|
|
296
|
+
if (dmg && dmg.y < viewportY) {
|
|
297
|
+
const overhang = viewportY - dmg.y;
|
|
298
|
+
src.damage = {
|
|
299
|
+
x: dmg.x,
|
|
300
|
+
y: viewportY,
|
|
301
|
+
width: dmg.width,
|
|
302
|
+
height: Math.max(0, dmg.height - overhang),
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
let currentStyleId = stylePool.none;
|
|
308
|
+
let currentHyperlink = undefined;
|
|
309
|
+
// First pass: render changes to existing rows (rows < prev.screen.height)
|
|
310
|
+
diffEach(prev.screen, next.screen, (x, y, removed, added) => {
|
|
311
|
+
// Skip new rows - we'll render them directly after
|
|
312
|
+
if (growing && y >= prev.screen.height) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
// Skip spacers during rendering because the terminal will automatically
|
|
316
|
+
// advance 2 columns when we write the wide character itself.
|
|
317
|
+
// SpacerTail: Second cell of a wide character
|
|
318
|
+
// SpacerHead: Marks line-end position where wide char wraps to next line
|
|
319
|
+
if (added &&
|
|
320
|
+
(added.width === 2 /* CellWidth.SpacerTail */ ||
|
|
321
|
+
added.width === 3 /* CellWidth.SpacerHead */)) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (removed &&
|
|
325
|
+
(removed.width === 2 /* CellWidth.SpacerTail */ ||
|
|
326
|
+
removed.width === 3 /* CellWidth.SpacerHead */) &&
|
|
327
|
+
!added) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
// Skip empty cells that don't need to overwrite existing content.
|
|
331
|
+
// This prevents writing trailing spaces that would cause unnecessary
|
|
332
|
+
// line wrapping at the edge of the screen.
|
|
333
|
+
// Uses isEmptyCellAt to check if both packed words are zero (empty cell).
|
|
334
|
+
if (added && isEmptyCellAt(next.screen, x, y) && !removed) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
// Rows above the viewport live in terminal scrollback — the cursor
|
|
338
|
+
// can't reach them, and the only way to repaint them is a full reset
|
|
339
|
+
// (ESC[2J+ESC[3J), which wipes the scrollback and snaps the terminal
|
|
340
|
+
// viewport back to the top (user scrolled up → jumps to the very
|
|
341
|
+
// first line). Skip updating them; they repaint normally when they
|
|
342
|
+
// scroll back into the viewport. Chat history is static content, so
|
|
343
|
+
// nothing visible is lost by leaving scrollback rows stale.
|
|
344
|
+
if (y < viewportY) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
moveCursorTo(screen, x, y);
|
|
348
|
+
if (added) {
|
|
349
|
+
const targetHyperlink = added.hyperlink;
|
|
350
|
+
currentHyperlink = transitionHyperlink(screen.diff, currentHyperlink, targetHyperlink);
|
|
351
|
+
const styleStr = stylePool.transition(currentStyleId, added.styleId);
|
|
352
|
+
if (writeCellWithStyleStr(screen, added, styleStr)) {
|
|
353
|
+
currentStyleId = added.styleId;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
else if (removed) {
|
|
357
|
+
// Cell was removed - clear it with a space
|
|
358
|
+
// (This handles shrinking content)
|
|
359
|
+
// Reset any active styles/hyperlinks first to avoid leaking into cleared cells
|
|
360
|
+
const styleIdToReset = currentStyleId;
|
|
361
|
+
const hyperlinkToReset = currentHyperlink;
|
|
362
|
+
currentStyleId = stylePool.none;
|
|
363
|
+
currentHyperlink = undefined;
|
|
364
|
+
screen.txn(() => {
|
|
365
|
+
const patches = [];
|
|
366
|
+
transitionStyle(patches, stylePool, styleIdToReset, stylePool.none);
|
|
367
|
+
transitionHyperlink(patches, hyperlinkToReset, undefined);
|
|
368
|
+
patches.push({ type: 'stdout', content: ' ' });
|
|
369
|
+
return [patches, { dx: 1, dy: 0 }];
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
// Reset styles before rendering new rows (they'll set their own styles)
|
|
374
|
+
currentStyleId = transitionStyle(screen.diff, stylePool, currentStyleId, stylePool.none);
|
|
375
|
+
currentHyperlink = transitionHyperlink(screen.diff, currentHyperlink, undefined);
|
|
376
|
+
// Handle growth: render new rows directly (they naturally scroll the terminal)
|
|
377
|
+
if (growing) {
|
|
378
|
+
renderFrameSlice(screen, next, prev.screen.height, next.screen.height, stylePool);
|
|
379
|
+
}
|
|
380
|
+
// Restore cursor. Skipped in alt-screen: the cursor is hidden, its
|
|
381
|
+
// position only matters as the starting point for the NEXT frame's
|
|
382
|
+
// relative moves, and in alt-screen the next frame always begins with
|
|
383
|
+
// CSI H (see ink.tsx onRender) which resets to (0,0) regardless. This
|
|
384
|
+
// saves a CR + cursorMove round-trip (~6-10 bytes) every frame.
|
|
385
|
+
//
|
|
386
|
+
// Main screen: if cursor needs to be past the last line of content
|
|
387
|
+
// (typical: cursor.y = screen.height), emit \n to create that line
|
|
388
|
+
// since cursor movement can't create new lines.
|
|
389
|
+
if (altScreen) {
|
|
390
|
+
// no-op; next frame's CSI H anchors cursor
|
|
391
|
+
}
|
|
392
|
+
else if (next.cursor.y >= next.screen.height) {
|
|
393
|
+
// Move to column 0 of current line, then emit newlines to reach target row
|
|
394
|
+
screen.txn(prev => {
|
|
395
|
+
const rowsToCreate = next.cursor.y - prev.y;
|
|
396
|
+
if (rowsToCreate > 0) {
|
|
397
|
+
// Use CR to resolve pending wrap (if any) without advancing
|
|
398
|
+
// to the next line, then LF to create each new row.
|
|
399
|
+
const patches = new Array(1 + rowsToCreate);
|
|
400
|
+
patches[0] = CARRIAGE_RETURN;
|
|
401
|
+
for (let i = 0; i < rowsToCreate; i++) {
|
|
402
|
+
patches[1 + i] = NEWLINE;
|
|
403
|
+
}
|
|
404
|
+
return [patches, { dx: -prev.x, dy: rowsToCreate }];
|
|
405
|
+
}
|
|
406
|
+
// At or past target row - need to move cursor to correct position
|
|
407
|
+
const dy = next.cursor.y - prev.y;
|
|
408
|
+
if (dy !== 0 || prev.x !== next.cursor.x) {
|
|
409
|
+
// Use CR to clear pending wrap (if any), then cursor move
|
|
410
|
+
const patches = [CARRIAGE_RETURN];
|
|
411
|
+
patches.push({ type: 'cursorMove', x: next.cursor.x, y: dy });
|
|
412
|
+
return [patches, { dx: next.cursor.x - prev.x, dy }];
|
|
413
|
+
}
|
|
414
|
+
return [[], { dx: 0, dy: 0 }];
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
moveCursorTo(screen, next.cursor.x, next.cursor.y);
|
|
419
|
+
}
|
|
420
|
+
const elapsed = performance.now() - startTime;
|
|
421
|
+
if (elapsed > 50) {
|
|
422
|
+
const damage = next.screen.damage;
|
|
423
|
+
const damageInfo = damage
|
|
424
|
+
? `${damage.width}x${damage.height} at (${damage.x},${damage.y})`
|
|
425
|
+
: 'none';
|
|
426
|
+
logForDebugging(`Slow render: ${elapsed.toFixed(1)}ms, screen: ${next.screen.height}x${next.screen.width}, damage: ${damageInfo}, changes: ${screen.diff.length}`);
|
|
427
|
+
}
|
|
428
|
+
return scrollPatch.length > 0
|
|
429
|
+
? [...scrollPatch, ...screen.diff]
|
|
430
|
+
: screen.diff;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
function transitionHyperlink(diff, current, target) {
|
|
434
|
+
if (current !== target) {
|
|
435
|
+
diff.push({ type: 'hyperlink', uri: target ?? '' });
|
|
436
|
+
return target;
|
|
437
|
+
}
|
|
438
|
+
return current;
|
|
439
|
+
}
|
|
440
|
+
function transitionStyle(diff, stylePool, currentId, targetId) {
|
|
441
|
+
const str = stylePool.transition(currentId, targetId);
|
|
442
|
+
if (str.length > 0) {
|
|
443
|
+
diff.push({ type: 'styleStr', str });
|
|
444
|
+
}
|
|
445
|
+
return targetId;
|
|
446
|
+
}
|
|
447
|
+
function readLine(screen, y) {
|
|
448
|
+
let line = '';
|
|
449
|
+
for (let x = 0; x < screen.width; x++) {
|
|
450
|
+
line += charInCellAt(screen, x, y) ?? ' ';
|
|
451
|
+
}
|
|
452
|
+
return line.trimEnd();
|
|
453
|
+
}
|
|
454
|
+
function fullResetSequence_CAUSES_FLICKER(frame, reason, stylePool, debug) {
|
|
455
|
+
// After clearTerminal, cursor is at (0, 0)
|
|
456
|
+
const screen = new VirtualScreen({ x: 0, y: 0 }, frame.viewport.width);
|
|
457
|
+
renderFrame(screen, frame, stylePool);
|
|
458
|
+
return [{ type: 'clearTerminal', reason, debug }, ...screen.diff];
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Repaint the visible viewport in place — the main-screen shrink recovery
|
|
462
|
+
* that replaces fullResetSequence's clearTerminal + whole-frame reprint.
|
|
463
|
+
*
|
|
464
|
+
* Precondition (caller-guarded): the cursor is parked on the physical
|
|
465
|
+
* bottom row (the renderer pins cursor.y = screen.height every main-screen
|
|
466
|
+
* frame), so the viewport top is exactly viewportHeight-1 rows up. Walk
|
|
467
|
+
* there, erase to the end of the screen, and repaint the frame's tail
|
|
468
|
+
* directly into the viewport. Nothing scrolls: no rows are pushed into
|
|
469
|
+
* (WT semantics) or spliced out of (xterm.js semantics) the terminal
|
|
470
|
+
* scrollback, so the shrink frames that fire on EVERY turn — thinking
|
|
471
|
+
* fold, spinner/esc-hint rows unmounting at end of turn, streaming
|
|
472
|
+
* markdown reflow — stop depositing a full stale UI copy per turn into
|
|
473
|
+
* the user's scroll history (issues #38 #39 #19).
|
|
474
|
+
*
|
|
475
|
+
* Frame-row bookkeeping stays on the steady-state formulas: the repaint
|
|
476
|
+
* leaves frame rows [H-min(H,V-1), H) on the viewport with the cursor at
|
|
477
|
+
* frame row H on the physical bottom row — exactly the mapping viewportY
|
|
478
|
+
* derives (viewport top = H-V+1 when H >= V), so the next frame needs no
|
|
479
|
+
* special casing. Cost is O(viewport) cells once per shrink frame, well
|
|
480
|
+
* under the fullReset path it replaces (whole frame + 10000-row scroll).
|
|
481
|
+
*
|
|
482
|
+
* Also reused by the viewport re-anchor (requestViewportReanchor), where
|
|
483
|
+
* the cursor may NOT be exactly on the park row — a third-party write
|
|
484
|
+
* left it somewhere in the bottom region. The CR + cursorUp(V-1) still
|
|
485
|
+
* lands on the viewport top because CUU clamps at the top margin, so the
|
|
486
|
+
* repaint re-syncs the mapping from any bottom-region start. (On legacy
|
|
487
|
+
* conhost the clamp can drag the viewport instead — see
|
|
488
|
+
* hasCursorUpViewportYankBug — but only when the cursor starts above the
|
|
489
|
+
* bottom row, which no known writer produces.)
|
|
490
|
+
*/
|
|
491
|
+
function repaintViewportInPlace(prev, next, stylePool) {
|
|
492
|
+
const viewportHeight = prev.viewport.height;
|
|
493
|
+
const height = next.screen.height;
|
|
494
|
+
// The bottom viewport row stays reserved for the cursor park; content
|
|
495
|
+
// occupies at most viewportHeight-1 rows above it (same split as the
|
|
496
|
+
// steady state, where the park LF materializes one row below the frame).
|
|
497
|
+
const contentRows = Math.min(height, viewportHeight - 1);
|
|
498
|
+
const startY = height - contentRows;
|
|
499
|
+
// CR + up(V-1): from the parked bottom row to the viewport top — stays
|
|
500
|
+
// inside the viewport, so conhost's CUU-into-scrollback yank bug can't
|
|
501
|
+
// trigger. Erase down from there (BCE fill — the SGR reset at the head
|
|
502
|
+
// of every frame buffer guarantees the default background). The erase
|
|
503
|
+
// also blanks the park row, so no stale prompt/status pixels survive
|
|
504
|
+
// below short content.
|
|
505
|
+
const anchor = '\r' + cursorUp(viewportHeight - 1) + eraseToEndOfScreen();
|
|
506
|
+
const screen = new VirtualScreen({ x: 0, y: startY }, next.viewport.width);
|
|
507
|
+
renderFrameSlice(screen, next, startY, height, stylePool);
|
|
508
|
+
return [{ type: 'stdout', content: anchor }, ...screen.diff];
|
|
509
|
+
}
|
|
510
|
+
function renderFrame(screen, frame, stylePool) {
|
|
511
|
+
renderFrameSlice(screen, frame, 0, frame.screen.height, stylePool);
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Render a slice of rows from the frame's screen.
|
|
515
|
+
* Each row is rendered followed by a newline. Cursor ends at (0, endY).
|
|
516
|
+
*/
|
|
517
|
+
function renderFrameSlice(screen, frame, startY, endY, stylePool) {
|
|
518
|
+
let currentStyleId = stylePool.none;
|
|
519
|
+
let currentHyperlink = undefined;
|
|
520
|
+
// Track the styleId of the last rendered cell on this line (-1 if none).
|
|
521
|
+
// Passed to visibleCellAtIndex to enable fg-only space optimization.
|
|
522
|
+
let lastRenderedStyleId = -1;
|
|
523
|
+
const { width: screenWidth, cells, charPool, hyperlinkPool } = frame.screen;
|
|
524
|
+
let index = startY * screenWidth;
|
|
525
|
+
for (let y = startY; y < endY; y += 1) {
|
|
526
|
+
// Advance cursor to this row using LF (not CSI CUD / cursor-down).
|
|
527
|
+
// CSI CUD stops at the viewport bottom margin and cannot scroll,
|
|
528
|
+
// but LF scrolls the viewport to create new lines. Without this,
|
|
529
|
+
// when the cursor is at the viewport bottom, moveCursorTo's
|
|
530
|
+
// cursor-down silently fails, creating a permanent off-by-one
|
|
531
|
+
// between the virtual cursor and the real terminal cursor.
|
|
532
|
+
if (screen.cursor.y < y) {
|
|
533
|
+
const rowsToAdvance = y - screen.cursor.y;
|
|
534
|
+
screen.txn(prev => {
|
|
535
|
+
const patches = new Array(1 + rowsToAdvance);
|
|
536
|
+
patches[0] = CARRIAGE_RETURN;
|
|
537
|
+
for (let i = 0; i < rowsToAdvance; i++) {
|
|
538
|
+
patches[1 + i] = NEWLINE;
|
|
539
|
+
}
|
|
540
|
+
return [patches, { dx: -prev.x, dy: rowsToAdvance }];
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
// Reset at start of each line — no cell rendered yet
|
|
544
|
+
lastRenderedStyleId = -1;
|
|
545
|
+
for (let x = 0; x < screenWidth; x += 1, index += 1) {
|
|
546
|
+
// Skip spacers, unstyled empty cells, and fg-only styled spaces that
|
|
547
|
+
// match the last rendered style (since cursor-forward produces identical
|
|
548
|
+
// visual result). visibleCellAtIndex handles the optimization internally
|
|
549
|
+
// to avoid allocating Cell objects for skipped cells.
|
|
550
|
+
const cell = visibleCellAtIndex(cells, charPool, hyperlinkPool, index, lastRenderedStyleId);
|
|
551
|
+
if (!cell) {
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
moveCursorTo(screen, x, y);
|
|
555
|
+
// Handle hyperlink
|
|
556
|
+
const targetHyperlink = cell.hyperlink;
|
|
557
|
+
currentHyperlink = transitionHyperlink(screen.diff, currentHyperlink, targetHyperlink);
|
|
558
|
+
// Style transition — cached string, zero allocations after warmup
|
|
559
|
+
const styleStr = stylePool.transition(currentStyleId, cell.styleId);
|
|
560
|
+
if (writeCellWithStyleStr(screen, cell, styleStr)) {
|
|
561
|
+
currentStyleId = cell.styleId;
|
|
562
|
+
lastRenderedStyleId = cell.styleId;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
// Reset styles/hyperlinks before newline so background color doesn't
|
|
566
|
+
// bleed into the next line when the terminal scrolls. The old code
|
|
567
|
+
// reset implicitly by writing trailing unstyled spaces; now that we
|
|
568
|
+
// skip empty cells, we must reset explicitly.
|
|
569
|
+
currentStyleId = transitionStyle(screen.diff, stylePool, currentStyleId, stylePool.none);
|
|
570
|
+
currentHyperlink = transitionHyperlink(screen.diff, currentHyperlink, undefined);
|
|
571
|
+
// CR+LF at end of row — \r resets to column 0, \n moves to next line.
|
|
572
|
+
// Without \r, the terminal cursor stays at whatever column content ended
|
|
573
|
+
// (since we skip trailing spaces, this can be mid-row).
|
|
574
|
+
screen.txn(prev => [[CARRIAGE_RETURN, NEWLINE], { dx: -prev.x, dy: 1 }]);
|
|
575
|
+
}
|
|
576
|
+
// Reset any open style/hyperlink at end of slice
|
|
577
|
+
transitionStyle(screen.diff, stylePool, currentStyleId, stylePool.none);
|
|
578
|
+
transitionHyperlink(screen.diff, currentHyperlink, undefined);
|
|
579
|
+
return screen;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Write a cell with a pre-serialized style transition string (from
|
|
583
|
+
* StylePool.transition). Inlines the txn logic to avoid closure/tuple/delta
|
|
584
|
+
* allocations on every cell.
|
|
585
|
+
*
|
|
586
|
+
* Returns true if the cell was written, false if skipped (wide char at
|
|
587
|
+
* viewport edge). Callers MUST gate currentStyleId updates on this — when
|
|
588
|
+
* skipped, styleStr is never pushed and the terminal's style state is
|
|
589
|
+
* unchanged. Updating the virtual tracker anyway desyncs it from the
|
|
590
|
+
* terminal, and the next transition is computed from phantom state.
|
|
591
|
+
*/
|
|
592
|
+
function writeCellWithStyleStr(screen, cell, styleStr) {
|
|
593
|
+
const cellWidth = cell.width === 1 /* CellWidth.Wide */ ? 2 : 1;
|
|
594
|
+
const px = screen.cursor.x;
|
|
595
|
+
const vw = screen.viewportWidth;
|
|
596
|
+
// Don't write wide chars that would cross the viewport edge.
|
|
597
|
+
// Single-codepoint chars (CJK) at vw-2 are safe; multi-codepoint
|
|
598
|
+
// graphemes (flags, ZWJ emoji) need stricter threshold.
|
|
599
|
+
if (cellWidth === 2 && px < vw) {
|
|
600
|
+
const threshold = cell.char.length > 2 ? vw : vw + 1;
|
|
601
|
+
if (px + 2 >= threshold) {
|
|
602
|
+
return false;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
const diff = screen.diff;
|
|
606
|
+
if (styleStr.length > 0) {
|
|
607
|
+
diff.push({ type: 'styleStr', str: styleStr });
|
|
608
|
+
}
|
|
609
|
+
const needsCompensation = cellWidth === 2 && needsWidthCompensation(cell.char);
|
|
610
|
+
// On terminals with old wcwidth tables, a compensated emoji only advances
|
|
611
|
+
// the cursor 1 column, so the CHA below skips column x+1 without painting
|
|
612
|
+
// it. Write a styled space there first — on correct terminals the emoji
|
|
613
|
+
// glyph (width 2) overwrites it harmlessly; on old terminals it fills the
|
|
614
|
+
// gap with the emoji's background. Also clears any stale content at x+1.
|
|
615
|
+
// CHA is 1-based, so column px+1 (0-based) is CHA target px+2.
|
|
616
|
+
if (needsCompensation && px + 1 < vw) {
|
|
617
|
+
diff.push({ type: 'cursorTo', col: px + 2 });
|
|
618
|
+
diff.push({ type: 'stdout', content: ' ' });
|
|
619
|
+
diff.push({ type: 'cursorTo', col: px + 1 });
|
|
620
|
+
}
|
|
621
|
+
diff.push({ type: 'stdout', content: cell.char });
|
|
622
|
+
// Force terminal cursor to correct column after the emoji.
|
|
623
|
+
if (needsCompensation) {
|
|
624
|
+
diff.push({ type: 'cursorTo', col: px + cellWidth + 1 });
|
|
625
|
+
}
|
|
626
|
+
// Update cursor — mutate in place to avoid Point allocation
|
|
627
|
+
if (px >= vw) {
|
|
628
|
+
screen.cursor.x = cellWidth;
|
|
629
|
+
screen.cursor.y++;
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
screen.cursor.x = px + cellWidth;
|
|
633
|
+
}
|
|
634
|
+
return true;
|
|
635
|
+
}
|
|
636
|
+
function moveCursorTo(screen, targetX, targetY) {
|
|
637
|
+
screen.txn(prev => {
|
|
638
|
+
const dx = targetX - prev.x;
|
|
639
|
+
const dy = targetY - prev.y;
|
|
640
|
+
const inPendingWrap = prev.x >= screen.viewportWidth;
|
|
641
|
+
// If we're in pending wrap state (cursor.x >= width), use CR
|
|
642
|
+
// to reset to column 0 on the current line without advancing
|
|
643
|
+
// to the next line, then issue the cursor movement.
|
|
644
|
+
if (inPendingWrap) {
|
|
645
|
+
return [
|
|
646
|
+
[CARRIAGE_RETURN, { type: 'cursorMove', x: targetX, y: dy }],
|
|
647
|
+
{ dx, dy },
|
|
648
|
+
];
|
|
649
|
+
}
|
|
650
|
+
// When moving to a different line, use carriage return (\r) to reset to
|
|
651
|
+
// column 0 first, then cursor move.
|
|
652
|
+
if (dy !== 0) {
|
|
653
|
+
return [
|
|
654
|
+
[CARRIAGE_RETURN, { type: 'cursorMove', x: targetX, y: dy }],
|
|
655
|
+
{ dx, dy },
|
|
656
|
+
];
|
|
657
|
+
}
|
|
658
|
+
// Standard same-line cursor move
|
|
659
|
+
return [[{ type: 'cursorMove', x: dx, y: dy }], { dx, dy }];
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Identify emoji where the terminal's wcwidth may disagree with Unicode.
|
|
664
|
+
* On terminals with correct tables, the CHA we emit is a harmless no-op.
|
|
665
|
+
*
|
|
666
|
+
* Two categories:
|
|
667
|
+
* 1. Newer emoji (Unicode 12.0+) missing from terminal wcwidth tables.
|
|
668
|
+
* 2. Text-by-default emoji + VS16 (U+FE0F): the base codepoint is width 1
|
|
669
|
+
* in wcwidth, but VS16 triggers emoji presentation making it width 2.
|
|
670
|
+
* Examples: ⚔️ (U+2694), ☠️ (U+2620), ❤️ (U+2764).
|
|
671
|
+
*/
|
|
672
|
+
function needsWidthCompensation(char) {
|
|
673
|
+
const cp = char.codePointAt(0);
|
|
674
|
+
if (cp === undefined)
|
|
675
|
+
return false;
|
|
676
|
+
// U+1FA70-U+1FAFF: Symbols and Pictographs Extended-A (Unicode 12.0-15.0)
|
|
677
|
+
// U+1FB00-U+1FBFF: Symbols for Legacy Computing (Unicode 13.0)
|
|
678
|
+
if ((cp >= 0x1fa70 && cp <= 0x1faff) || (cp >= 0x1fb00 && cp <= 0x1fbff)) {
|
|
679
|
+
return true;
|
|
680
|
+
}
|
|
681
|
+
// Text-by-default emoji with VS16: scan for U+FE0F in multi-codepoint
|
|
682
|
+
// graphemes. Single BMP chars (length 1) and surrogate pairs without VS16
|
|
683
|
+
// skip this check. VS16 (0xFE0F) can't collide with surrogates (0xD800-0xDFFF).
|
|
684
|
+
if (char.length >= 2) {
|
|
685
|
+
for (let i = 0; i < char.length; i++) {
|
|
686
|
+
if (char.charCodeAt(i) === 0xfe0f)
|
|
687
|
+
return true;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
return false;
|
|
691
|
+
}
|
|
692
|
+
class VirtualScreen {
|
|
693
|
+
viewportWidth;
|
|
694
|
+
// Public for direct mutation by writeCellWithStyleStr (avoids txn overhead).
|
|
695
|
+
// File-private class — not exposed outside log-update.ts.
|
|
696
|
+
cursor;
|
|
697
|
+
diff = [];
|
|
698
|
+
constructor(origin, viewportWidth) {
|
|
699
|
+
this.viewportWidth = viewportWidth;
|
|
700
|
+
this.cursor = { ...origin };
|
|
701
|
+
}
|
|
702
|
+
txn(fn) {
|
|
703
|
+
const [patches, next] = fn(this.cursor);
|
|
704
|
+
for (const patch of patches) {
|
|
705
|
+
this.diff.push(patch);
|
|
706
|
+
}
|
|
707
|
+
this.cursor.x += next.dx;
|
|
708
|
+
this.cursor.y += next.dy;
|
|
709
|
+
}
|
|
710
|
+
}
|