[PR #411] [MERGED] feat(console): add mouse selection and scrolling support, with optional onCopy callback to use clipboard in applications #1299

Closed
opened 2026-03-14 09:29:17 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opentui/pull/411
Author: @edlsh
Created: 12/13/2025
Status: Merged
Merged: 12/15/2025
Merged by: @kommander

Base: mainHead: feat/console-copy-selection


📝 Commits (10+)

📊 Changes

6 files changed (+1170 additions, -95 deletions)

View changed files

📝 packages/core/src/console.test.ts (+537 -21)
📝 packages/core/src/console.ts (+537 -73)
📝 packages/core/src/examples/console-demo.ts (+15 -1)
📝 packages/core/src/lib/keymapping.test.ts (+44 -0)
📝 packages/core/src/lib/keymapping.ts (+23 -0)
📝 packages/core/src/renderer.ts (+14 -0)

📄 Description

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)
  }
})

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opentui/pull/411 **Author:** [@edlsh](https://github.com/edlsh) **Created:** 12/13/2025 **Status:** ✅ Merged **Merged:** 12/15/2025 **Merged by:** [@kommander](https://github.com/kommander) **Base:** `main` ← **Head:** `feat/console-copy-selection` --- ### 📝 Commits (10+) - [`d9b7651`](https://github.com/anomalyco/opentui/commit/d9b7651961b4666ca30ef05d0b36e623fbe8e077) feat(console): add copy-to-clipboard support - [`a79bc0e`](https://github.com/anomalyco/opentui/commit/a79bc0ea2f3486f3f3ece4807905f14825716dbf) fix(console): add defensive error handling and edge case tests - [`63b4e41`](https://github.com/anomalyco/opentui/commit/63b4e4129a611076f74bc5d14cf658b10bae3095) keybindings - [`29d7673`](https://github.com/anomalyco/opentui/commit/29d767393e6948a9cf8f4edb8d1ba7143b0e94a8) setup in run fn - [`583b558`](https://github.com/anomalyco/opentui/commit/583b558062b29d78db1490e0db975037ba088dd8) setup only once - [`b49c1bd`](https://github.com/anomalyco/opentui/commit/b49c1bd72c01838834227b3754ffa9cc0cf9d391) button highlighting - [`5ad9f17`](https://github.com/anomalyco/opentui/commit/5ad9f175f2619b473dbef89ca99b610707f41251) handle full mouse event - [`01dc236`](https://github.com/anomalyco/opentui/commit/01dc23684d47a2fd73812b1127e6696fd742ba0b) stash - [`579cc9d`](https://github.com/anomalyco/opentui/commit/579cc9d33ca3b39473bd55bab66e5ad62f09c697) fix tests and show latest keybind - [`9864997`](https://github.com/anomalyco/opentui/commit/9864997092f0724c090fea52c568bb0d3c636cb0) cleanup ### 📊 Changes **6 files changed** (+1170 additions, -95 deletions) <details> <summary>View changed files</summary> 📝 `packages/core/src/console.test.ts` (+537 -21) 📝 `packages/core/src/console.ts` (+537 -73) 📝 `packages/core/src/examples/console-demo.ts` (+15 -1) 📝 `packages/core/src/lib/keymapping.test.ts` (+44 -0) 📝 `packages/core/src/lib/keymapping.ts` (+23 -0) 📝 `packages/core/src/renderer.ts` (+14 -0) </details> ### 📄 Description ## 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](https://github.com/sst/opencode/pull/5239) — rather than having consumers intercept mouse events, this implements the feature properly in opentui. ### New options ```typescript interface ConsoleOptions { onCopySelection?: (text: string) => void copyShortcut?: { key: string; ctrl?: boolean; shift?: boolean } selectionColor?: ColorInput copyButtonColor?: ColorInput } ``` ### Usage ```typescript const renderer = await createCliRenderer({ consoleOptions: { onCopySelection: (text) => Clipboard.copy(text) } }) ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-14 09:29:17 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/opentui#1299
No description provided.