-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Support bracketed paste mode #1097
Conversation
c7f4855
to
5986c09
Compare
- As described in https://cirw.in/blog/bracketed-paste - Example support in vim: - https://github.com/ConradIrwin/vim-bracketed-paste/blob/master/plugin/bracketed-paste.vim - http://vimdoc.sourceforge.net/htmldoc/term.html#raw-terminal-mode - Required for e.g. ipython, via python-prompt-toolkit: - https://github.com/ipython/ipython - https://github.com/jonathanslenders/python-prompt-toolkit Repro: - Run `ipython` (version 6.2.1) - Copy multiple lines of text and paste into ipython prompt, e.g. ```py print(1) print(2) print(3) ``` - Before: first line would paste and run, and subsequent lines are lost - After: all lines paste into single prompt
5986c09
to
1dbcf70
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really well put together PR! Just some minor comments
@@ -52,6 +63,7 @@ export function pasteHandler(ev: ClipboardEvent, term: ITerminal): void { | |||
|
|||
let dispatchPaste = function(text: string): void { | |||
text = prepareTextForTerminal(text, term.browser.isMSWindows); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge bracketTextForPaste
into prepareTextForTerminal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Will do, but I might not have time to get to it before the weekend, so feel free to take it over in the meantime.
* Bracket text for paste, if necessary, as per https://cirw.in/blog/bracketed-paste | ||
* @param text The pasted text to bracket | ||
*/ | ||
export function bracketTextForPaste(text: string, bracketedPasteMode: boolean): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test in Clipboard.test.ts that tests either this function of pasteHandler
would be great
Very nice contribution. One general question that comes to my mind: Shouldn't this mode be specific to the buffer (normal / alt) that activated it? Say we open |
@mofux Generally yes, but afaik there's not a good solution to that problem. Terminal processes that set bracketed paste mode do make efforts to unset it on exit—so actually |
@mofux you bring up a good point, I'm not sure we unset all the mode-related stuff when switching away from the alt buffer though. Only |
@Tyriar Do you think the modes (like the mouse modes) should actually depend on the buffer? Didn't find anything meaningful about it on the web, but if they do, we should probably stores these modes with the buffer instead of setting them on the terminal instance... |
@mofux we should test how other terminals handle this (or how xterm does) before changing anything. |
Yeah, so it looks like the only stuff that should be stored on a per-buffer basis is the cursor position (which can be saved & restored). I've checked the xterm, libvte and iterm2 sources as well as this xterm sequences guide, and couldn't find any hint to store / reset the mode settings with the buffer. Seems that one has to rely on the terminal application to correctly reset modes that have previously been set (as already stated above by @jdanbrown). |
In case another example terminal is helpful, iTerm2 on OSX has handled bracketed paste mode very well for me in practice. |
- Requires xtermjs/xterm.js#1097
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, should land in v3.0.0 😃
Thanks! Looking forward to v3! |
@jdanbrown you can track progress on the release here #1116 It's our biggest release ever so it's getting delayed a little 😄 |
Repro:
ipython
(version 6.2.1)