Skip to content

feat(console): add mouse selection and scrolling support, with optional onCopy callback to use clipboard in applications - #411

Merged
kommander merged 11 commits into
anomalyco:mainfrom
edlsh:feat/console-copy-selection
Dec 15, 2025
Merged

kommander merged 11 commits into
anomalyco:mainfrom
edlsh:feat/console-copy-selection

Conversation

@edlsh

@edlsh edlsh commented Dec 13, 2025 •

Copy link
Copy Markdown
Contributor

Add copy-to-clipboard support for TerminalConsole

Adds text selection and copy functionality to the console:

  • Mouse selection: Click and drag in the log area to select text
  • [Copy] button: Clickable button in title bar
  • Keyboard shortcut: Configurable, defaults to Ctrl+Shift+C
  • Callback API: onCopySelection?: (text: string) => void in ConsoleOptions

Motivation

Requested in sst/opencode#5239 — rather than having consumers intercept mouse events, this implements the feature properly in opentui.

New options

interface ConsoleOptions {
  onCopySelection?: (text: string) => void
  copyShortcut?: { key: string; ctrl?: boolean; shift?: boolean }
  selectionColor?: ColorInput
  copyButtonColor?: ColorInput
}

Usage

const renderer = await createCliRenderer({
  consoleOptions: {
    onCopySelection: (text) => Clipboard.copy(text)
  }
})

- Add mouse drag selection in console log area
- Add [Copy] button in title bar
- Add configurable keyboard shortcut (default Ctrl+Shift+C)
- Add onCopySelection callback in ConsoleOptions
- Add selectionColor and copyButtonColor options
- Route mouse events from renderer to console when in bounds

Related: anomalyco/opencode#5239
Amp-Thread-ID: https://ampcode.com/threads/T-019b1749-4adb-758e-8d91-735fbab1a13f
@edlsh

edlsh commented Dec 13, 2025

Copy link
Copy Markdown
Contributor Author

CleanShot 2025-12-13 at 06 37 04

edlsh and others added 10 commits December 13, 2025 08:18
- Wrap onCopySelection callback in try-catch for robustness
- Add cross-platform clipboard comment to demo example
- Add tests for indented line selection, out-of-bounds selection,
  missing callback safety, and right-click rejection
@kommander kommander changed the title feat(console): add copy-to-clipboard support feat(console): add mouse selection and scrolling support, with optional onCopy callback to use clipboard in applications Dec 15, 2025
@kommander
kommander merged commit bd159ef into anomalyco:main Dec 15, 2025
4 checks passed
msmps pushed a commit that referenced this pull request Jan 8, 2026
…al onCopy callback to use clipboard in applications (#411)

---------

Co-authored-by: Sebastian Herrlinger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants