-
Notifications
You must be signed in to change notification settings - Fork 305
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 "Paste Bracketing" #1471
Comments
This would resolve this longstanding issue too: #579. |
Should it be in PowerShell consolehost too? |
Oh vscode has had this support for a long time. I was just suggesting it to use as an alternative as its what most programs do instead of listening for ctrl+v, plus it may work on windows now with conpty. |
For my own reference: https://cirw.in/blog/bracketed-paste |
This issue can be fixed with this |
With microsoft/terminal#9034 merged, bracketed paste is supported in Windows Terminal. I'd love to see it in PSReadLine, too. |
I believe supporting this is non-trivial. PSReadLine currently relies on As I understand bracketed paste - the dotnet runtime would likely ignore the paste begin/end sequences as PSReadLine does have limited support for mapping the VT input escape sequences, but it is currently Windows only and not used by default - but that code might be of use to someone wanting to add support for bracketed paste. |
So it sounds like we need .NET to support understanding this escape sequence and then have a way to inform PSReadLine rather than PSReadLine trying to parse the escape sequence itself. |
Feature requesting issue opened on .NET repo: dotnet/runtime#60107 In summary, the dependencies for fixing this in PowerShell are:
Be noted that, today some key-bindings (e.g. Ctrl+[) work on Windows but not on Unix platforms because on Unix Assuming dotnet/runtime#60107 is addressed in .NET using the same parsing/mapping code that works on Unix, then those key-bindings will stop working on Windows once we switch to the new mode of |
…won't work on cmd or powershell PowerShell/PSReadLine#1471
Since PSReadLine reads the input stream using ReadConsoleInput, could you consider adding a support for "Bracketed Paste" marks (INPUT_RECORD marks) in the following form: Clipboard block (inbound INPUT_RECORD stream): rec_first.EventType == MENU_EVENT;
rec_first.Event.MenuEvent.dwCommandId = 0x8001; // paste_begin
// set of recs with wchar-by-wchar binary copy
// of the block pasted from the clipboard
...
rec_n.EventType == KEY_EVENT;
rec_n.Event.KeyEvent.uChar.UnicodeChar = wchar; // Pasted data set
...
rec_last.EventType == MENU_EVENT;
rec_last.Event.MenuEvent.dwCommandId`= 0x8002; // paste_end Here I mean placing marks on the operating system side (condrv), and not on the application side. In particular, 3p terminal emulator, receiving a clipboard block via SSH, forms on the condrv side a set of INPUT_RECORD records that PSReadLine is waiting for. This approach greatly simplifies the task of cross-platform transferring a clipboard binary immutable block via SSH between hosts. Both from unix to windows to unix, and from windows to unix to windows. Currently, an immutable block of even plain text requires modification before sending to PSReadLine. PSReadLine requires converting '\r' and '\n' into a VK_RETURN keystroke. Also, if there is a requirement for binary immutability of the pasted block, the use of in-text markers
Using INPUT_RECORD marks eliminates these issues. PS: This approach is necessary on Windows hosts to receive binary immutable blocks from the clipboard (e.g. received via ssh from unix/wsl etc) by an arbitrary console application that expects it. |
Description of the new feature/enhancement
For some readline experiences, they support this concept of paste bracketing.
The idea is simple:
esc[?2004h
[200~
and followed by esc[201~
by the terminal before sending the text to the shell.Here's an example screenshot of my version of bash on macOS with readline (which doesn't support this but you can see the effect):
Pretty much any terminal supports this... for example, here's iTerm2's doc:
https://gitlab.com/gnachman/iterm2/-/wikis/Paste-Bracketing#control-sequences
And there's a feature request in Windows Terminal: microsoft/terminal#395
and @Tyriar was considering adding this to VS Code's terminal as well.
What does supporting this mean?
This means that on macOS and Linux (and really crossplat) we can support multi-line pasting - something that has been available on Windows in conhost.exe for a very long time.
Proposed technical implementation details (optional)
At start up, PSReadLine emits
\e[?2004h
to tell the terminal to use paste bracketingWhen we get
\e[200~
we can wait until\e[201~
before actually executing anything. (or we can wait for theENTER
after\e[201~
)The text was updated successfully, but these errors were encountered: