Terminal: bracketed paste mode

Created on 27 Mar 2019  路  8Comments  路  Source: microsoft/terminal

Does the Windows console support bracket paste mode? I wasn't able to find any information about that.

Area-VT In-PR Issue-Feature Product-Conhost Work-Item

Most helpful comment

Funny you should ask! I've been working on this one myself, as I'd love to see it land.
I'll mark this one with our backlog/tracking tags.

All 8 comments

Funny you should ask! I've been working on this one myself, as I'd love to see it land.
I'll mark this one with our backlog/tracking tags.

one suggestion to keep in mind (as I've seen more than one implementation forget this edge case): make sure to filter out control sequences when pasting. otherwise the buffer could embed the end sequence thus defeating the point of it.

if you want to be compatible with xterm (who invented this feature), you want to filter:
\x00-\x07
\x0b-\x0c
\x0e-\x1f

@DHowett-MSFT -- worth ingesting this page here concerning the security issues various implementations of bracketed paste mode may have: https://lwn.net/Articles/749992/ -- particularly http://thejh.net/misc/website-terminal-copy-paste

@oising, thank you for that read. I think the best thing we could do is write tests for the specific security issues listed there and attempt to mitigate them as we implement the bracketed paste mode.

Would it be possible and/or reasonable for starters to just have ConPTY pass through ESC [ ? 2004 h and ESC [ ? 2004 l on stdout, and ESC [ 200 ~ and ESC [ 201 ~ on stdin, so that other terminals that support bracketed paste (e.g. Alacritty) can support it? (It makes me sad when such terminal emulators are blocked from supporting functionality on Windows because ConPTY filters out the magic.)

@DHowett Dustin, thanks for pointing me to this issue from the one I had opened concerning pasting into IPython / vi. Are there any workarounds in the meantime?

In the meantime, before/after pasting in vim you can :set paste and :set nopaste. I'm not certain what ipy needs here, unfortunately. 鈽癸笍

Several similar workarounds for ipython on Ubuntu for anyone looking:

  • Type %autoindent to turn off automatic indentation, then pasting will work.
  • Type %cpaste and then paste, and then -- to end, and it will work, if you want to leave automatic indentation on.

This will not persist between ipython sessions. To make this change permanent, you can create a configuration file a la vi ~/.ipython/profile_default/ipython_config.py, and put these contents in it:

c = get_config()
c.InteractiveShell.autoindent = False

I hope this helps someone!

Was this page helpful?
0 / 5 - 0 ratings