Psreadline: Support "Paste Bracketing"

Created on 16 Apr 2020  路  4Comments  路  Source: PowerShell/PSReadLine

Description of the new feature/enhancement

For some readline experiences, they support this concept of paste bracketing.

The idea is simple:

  • First, the shell emits esc[?2004h
  • This tells the terminal that this shell wants to use paste bracketing
  • When paste bracketing is on, pasted text is prefixed by esc[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):

MicrosoftTeams-image

  • first command tells the terminal to deactivate bracketed pasting
  • second is a paste from the clipboard
  • 3rd activates bracketed pasting
  • 4th is the same paste from the clipboard but now it has \e[200~ and \e[201~ around it

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: https://github.com/microsoft/terminal/issues/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 bracketing

When we get \e[200~ we can wait until \e[201~ before actually executing anything. (or we can wait for the ENTER _after_ \e[201~)

Issue-Enhancement Triaged

All 4 comments

This would resolve this longstanding issue too: https://github.com/PowerShell/PSReadLine/issues/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

Was this page helpful?
0 / 5 - 0 ratings