crossterm
crossterm copied to clipboard
Bracketed Paste Events
Is your feature request related to a problem? Please describe.
I want to be able to process input that contains line feeds. Allowing the terminal to enter bracketed paste mode allows us to buffer an incoming paste and collect non-Enter line feeds. This is already a standard feature of many terminal emulators.
Describe the solution you'd like
- Add the relevant enable/disable pair:
enable_bracketed_paste(EnableBracketedPaste) anddisable_bracketed_paste(DisableBracketedPaste), either to global scope or to the terminal depending on the unix/windows implementation details. - Here are a few options for formatting the paste:
- [1] Add
Event::Pastevariant that holds the entire pasted string - [2] Add
KeyCode::BracketedPasteStartandKeyCode::BracketedPasteEndvariants and allow the user to access escape codes so that they can implement paste filtering themselves (not very user-friendly) or another part of this library will do the paste filtering.
- [1] Add
- Because both of these options change the enum interfaces, we can probably put this behind an optional feature.
Describe alternatives you've considered in any
An alternative is to use something like rustyline to handle shell-like input, and only use crossterm to handle other kinds of interaction. The problem with something like [rustyline] is that it only allows stdin/stdout as far as I am aware and won't be able to implement something like the following "half-shell":
-----------------------------
| | |
| [shell | |
| output] | [other |
| | widget] |
|-------------| |
| > [prompt] | |
-----------------------------
where the [other widget] can read arrow key and other non-text inputs (i.e. how is [rustyline] supposed to know that the input should wrap only at half the terminal width?). Also, multi-panel input components like tui-rs widgets. See this issue for other compatibility issues with rustyline.
Additional context
- The
termwizcrate has a similar kind ofInputEventas solution [1]. - The
rustylinecrate has a similar kind ofKeyCodeas solution [2]. - The Microsoft terminal just added support for this feature.