Skip to content
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

bracketed paste in conhost #395

Closed
davidanthoff opened this issue Mar 27, 2019 · 22 comments · Fixed by #15155
Closed

bracketed paste in conhost #395

davidanthoff opened this issue Mar 27, 2019 · 22 comments · Fixed by #15155
Labels
Area-VT Virtual Terminal sequence support In-PR This issue has a related PR Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Needs-Tag-Fix Doesn't match tag requirements Product-Conhost For issues in the Console codebase Work-Item It's being tracked by an actual work item internally. (to be removed soon)
Milestone

Comments

@davidanthoff
Copy link

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

@DHowett-MSFT
Copy link
Contributor

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.

@DHowett-MSFT DHowett-MSFT self-assigned this Mar 27, 2019
@DHowett-MSFT DHowett-MSFT added Work-Item It's being tracked by an actual work item internally. (to be removed soon) Product-Conhost For issues in the Console codebase labels Mar 27, 2019
@vapier
Copy link

vapier commented Mar 27, 2019

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

@oising
Copy link
Collaborator

oising commented Mar 27, 2019

@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

@miniksa miniksa added the Area-VT Virtual Terminal sequence support label Mar 27, 2019
@miniksa
Copy link
Member

miniksa commented Mar 27, 2019

@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.

@ghost ghost added the Needs-Tag-Fix Doesn't match tag requirements label May 17, 2019
@DHowett-MSFT DHowett-MSFT added the Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. label May 17, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label May 17, 2019
@DHowett-MSFT DHowett-MSFT added this to the Console Backlog milestone Sep 24, 2019
@chris-morgan
Copy link

chris-morgan commented Nov 10, 2019

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.)

@FlipperPA
Copy link

@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?

@DHowett-MSFT
Copy link
Contributor

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

@FlipperPA
Copy link

FlipperPA commented Mar 22, 2020

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!

@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Mar 4, 2021
@davidanthoff davidanthoff changed the title bracketed paste mode bracketed paste in conhost Mar 4, 2021
@davidanthoff
Copy link
Author

Done!

@FlipperPA
Copy link

Just a big THANK YOU to everyone involved - this is a huge time saver and help for my workflow.

@blayz3r
Copy link

blayz3r commented Mar 9, 2021

@davidanthoff my work is to bring bracketed paste into Windows Terminal. The support for bracketed paste in Conhost is yet to be done. I understand this issue is probably opened when Windows Terminal wasn’t really a thing, but here it is.

We may want to reopen this and change the title to just “bracketed paste in conhost”.

So bracketed paste will not work in ConPTY atm? correct?

@zadjii-msft
Copy link
Member

No it should work just fine in conpty (the Terminal uses conpty too 😉). Conhost (the vintage console) still needs to implement support for this itself, but that should be much simpler now.

@blayz3r
Copy link

blayz3r commented Mar 9, 2021

No it should work just fine in conpty (the Terminal uses conpty too 😉). Conhost (the vintage console) still needs to implement support for this itself, but that should be much simpler now.

Ok great, is there a preview version on ConPty. or do we have to wait for the new release:
Context using conpty in Gvim:
image

@zadjii-msft zadjii-msft modified the milestones: Console Backlog, Backlog Jan 4, 2022
@dashesy
Copy link

dashesy commented Oct 22, 2022

I have 1.15.2875.0 but this seems to be unsupported still.

@DHowett
Copy link
Member

DHowett commented Oct 22, 2022

I have 1.15.2875.0 but this seems to be unsupported still.

@dashesy i would encourage you to file a new issue and fill out the issue template. As far as we are aware, paste bracketing works fine for every client application that requests it. Filing a new issue would be the best way to draw attention to, and provide specific information about, the problem you're facing.

@microsoft microsoft locked and limited conversation to collaborators Oct 22, 2022
@microsoft-github-policy-service microsoft-github-policy-service bot added the In-PR This issue has a related PR label Apr 10, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Tag-Fix Doesn't match tag requirements label Apr 26, 2023
DHowett pushed a commit that referenced this issue Apr 26, 2023
This adds support for XTerm's "bracketed paste" mode in ConHost. When
enabled, any pasted text is bracketed with a pair of escape sequences,
which lets the receiving application know that the content was pasted
rather than typed.

## References and Relevant Issues

Bracketed paste mode was added to Windows Terminal in PR #9034.
Adding it to ConHost ticks one more item off the list in #13408. 

## Detailed Description of the Pull Request / Additional comments

This only applies when VT input mode is enabled, since that is the way
Windows Terminal currently works.

When it comes to filtering, though, the only change I've made is to
filter out the escape character, and only when bracketed mode is
enabled. That's necessary to prevent any attempts to bypass the
bracketing, but I didn't want to mess with the expected behavior for
legacy apps if bracketed mode is disabled.

## Validation Steps Performed

Manually tested in bash with `bind 'set enable-bracketed-paste on'` and
confirmed that pasted content is now buffered, instead of being executed
immediately.

Also tested in VIM, and confirmed that you can now paste preformatted
code without the autoindent breaking the formatting.

Closes #395
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area-VT Virtual Terminal sequence support In-PR This issue has a related PR Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Needs-Tag-Fix Doesn't match tag requirements Product-Conhost For issues in the Console codebase Work-Item It's being tracked by an actual work item internally. (to be removed soon)
Projects
None yet
14 participants