Missing support for bracketed paste
Bracketed paste is an optional feature that modifies how the terminal handles a "paste from clipboard" action by a user. (e.g. middle mouse click in xterm, ctrl+shift+v in vte, etc)
The feature must first be enabled by sending CSI ? 2004 h to the terminal. After bracketed paste is enabled, each pasted text gets enclosed between CSI 200~ and CSI 201~.
The reason why this feature exist is well explained in the wikipedia page:

Likewise, in the Bubbline library, which we intend to use for CockroachDB's SQL shell, we also want to interpret a manually entered newline as a special "run" command, but we also want to give users the option to paste a SQL text containing newline characters without running them.
Prototype implementation
These 3 PRs:
- [ ] termenv: https://github.com/muesli/termenv/pull/84
- [ ] bubbletea: https://github.com/charmbracelet/bubbletea/pull/397
- [ ] bubbles: https://github.com/charmbracelet/bubbles/pull/214
Terminal support
| Terminal | Bracketed Paste |
|---|---|
| alacritty | ✅ |
| foot | ✅ |
| kitty | ✅ |
| Konsole | ✅ |
| rxvt | ✅ |
| screen | ❌ [^screen] |
| st | ✅ |
| tmux | ✅ |
| vte-based | ✅ |
| wezterm | ✅ |
| xterm | ✅ |
| Linux Console | ❌ |
| Apple Terminal | ✅ |
| iTerm | ✅ |
| Windows cmd | ❌ |
| Windows Terminal | ✅ |
[^screen]: A patch is available here https://gist.github.com/saitoha/2977889
See public slack discussion here: https://charmbracelet.slack.com/archives/CQ2E9CGTV/p1660812723955889
There's a couple implementation questions here:
-
do we try to enable BP always in termenv?
- this seems safe and unlikely to confuse terminals. If a terminal does not support BP, it will ignore the CSI code.
- however, once we do this we must also ensure that all the bubble widgets know how to handle text pasted this way.
-
how to represent bracketed pastes in bubbletea?
- the proposed implementation re-uses the existing KeyRunes message type.
- Pro: this makes it possible to immediately support any widget code that handle rune sequences.
- Con: we need to patch a few widgets to handle newlines inside KeyRunes properly
- we could introduce a new, separate message type.
- Pro: no surprise in widgets unless someone explicitly supports the new message type
- Con 1: pasting text from clipboard will appear to "do nothing" until the developer actually does the work. This might confuse users.
- Con 2: it will likely cause redundant logic with the handling of KeyRunes in input handlers (since both will usually need the same behavior)
- the proposed implementation re-uses the existing KeyRunes message type.
Two real-world consequences:
- https://github.com/cockroachdb/cockroach/issues/93135
- https://github.com/cockroachdb/cockroach/issues/93346
More: https://github.com/cockroachdb/cockroach/issues/94341