Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing support for bracketed paste #404

Closed
3 tasks done
knz opened this issue Aug 18, 2022 · 4 comments
Closed
3 tasks done

Missing support for bracketed paste #404

knz opened this issue Aug 18, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@knz
Copy link
Contributor

knz commented Aug 18, 2022

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:

image

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:

Terminal support

Terminal Bracketed Paste
alacritty
foot
kitty
Konsole
rxvt
screen 1
st
tmux
vte-based
wezterm
xterm
Linux Console
Apple Terminal
iTerm
Windows cmd
Windows Terminal

Footnotes

  1. A patch is available here https://gist.github.com/saitoha/2977889

@knz
Copy link
Contributor Author

knz commented Aug 18, 2022

See public slack discussion here: https://charmbracelet.slack.com/archives/CQ2E9CGTV/p1660812723955889

@knz
Copy link
Contributor Author

knz commented Aug 18, 2022

There's a couple implementation questions here:

  1. 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.
  2. 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)

@knz
Copy link
Contributor Author

knz commented Dec 28, 2022

More: cockroachdb/cockroach#94341

@muesli muesli closed this as completed Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants