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 on Windows? #594

Closed
schungx opened this issue Jan 30, 2022 · 16 comments
Closed

Bracketed paste on Windows? #594

schungx opened this issue Jan 30, 2022 · 16 comments

Comments

@schungx
Copy link

schungx commented Jan 30, 2022

Microsoft Terminal now supports bracketed paste.

Can enable_bracketed_paste support be added to Windows targets as well? Right now, support is only for Unix environments.

@gwenn
Copy link
Collaborator

gwenn commented Jan 30, 2022

  1. How do we check / know if bracketed paste is supported ?
  2. What happens if we try to activate bracketed paste on unsupported console / terminal ?

@schungx
Copy link
Author

schungx commented Jan 30, 2022

  1. How do we check / know if bracketed paste is supported ?

Because Microsoft's release announcement said they added support... that's all I can bank on... I haven't actually found a switch to toggle it on/off or something...

https://devblogs.microsoft.com/commandline/windows-terminal-preview-1-7-release/

Seems it starts having it as at version 1.7.

microsoft/terminal#10153 says DECSET 2004 is supported...

2. What happens if we try to activate `bracketed paste` on unsupported console / terminal ?

Then pasted text will be prefixed and postfixed by extra escape codes, I suppose...

@gwenn
Copy link
Collaborator

gwenn commented Feb 1, 2022

I am afraid I will not be able to fix this because I only have limited access (no admin rights, no access to windows store) to a Windows machine at work.

@schungx
Copy link
Author

schungx commented Feb 2, 2022

I am afraid I will not be able to fix this because I only have limited access (no admin rights, no access to windows store) to a Windows machine at work.

Anything I can help? I run a Windows machine. Or maybe I open up a Windows VM on Azure for you?

@gwenn
Copy link
Collaborator

gwenn commented Feb 2, 2022

@schungx If you want, you can checkout https://github.com/gwenn/rustyline/tree/bracketed_paste and then check if you find UnknownEscSeq or Esc in your logs while running RUST_LOG=rustyline=debug cargo run --example example 2> debug.log.
If yes, we will need to catch these escape sequences and handle them properly.

Or maybe there is a way to install microsoft terminal without admin rights ?

@schungx
Copy link
Author

schungx commented Feb 3, 2022

Or maybe there is a way to install microsoft terminal without admin rights ?

I don't think you can install anything on Windows without admin rights unless it is granted via some explicit policy...

I can take some time to try it out and check out the logs...

@gwenn
Copy link
Collaborator

gwenn commented Feb 3, 2022

I can install many apps without admin rights (GVim, Visual Studio Code, Clion, rustc, cargo, MinGW, alacritty, wezterm, ...).

@schungx
Copy link
Author

schungx commented Feb 4, 2022

Hhmmm.... that seem strange. In that case Windows Terminal shouldn't be blocked...

You can install it via an installer instead of from the Microsoft Store and it may work...

@schungx
Copy link
Author

schungx commented Feb 4, 2022

@schungx If you want, you can checkout https://github.com/gwenn/rustyline/tree/bracketed_paste and then check if you find UnknownEscSeq or Esc in your logs while running RUST_LOG=rustyline=debug cargo run --example example 2> debug.log. If yes, we will need to catch these escape sequences and handle them properly.

Tried it, and the example seems to work!!!

No UnknownEscSeq or Esc anywhere in the log. Does that mean that Windows Terminal does not send the bracketed paste escape codes to the app?

debug.log

Log attached.

@schungx
Copy link
Author

schungx commented Feb 4, 2022

Do I need to do any of that MatchingBracketHighlighter::new() stuff in my own app in order for this to work?

Can I just set config.bracketed_paste(true).build()?

Because it doesn't work in my app even when compiled with the local version, but it works just fine with example.

If I take away MatchingBracketHighlighter it no longer takes multiple lines as a whole, but processes them separately line by line.

@gwenn
Copy link
Collaborator

gwenn commented Feb 4, 2022

Tried it, and the example seems to work!!!

No UnknownEscSeq or Esc anywhere in the log. Does that mean that Windows Terminal does not send the bracketed paste escape codes to the app?

If you don't have UnknownEscSeq or Esc anywhere in the log then braketed paste doesn't work...

@gwenn
Copy link
Collaborator

gwenn commented Feb 4, 2022

If I take away MatchingBracketHighlighter it no longer takes multiple lines as a whole, but processes them separately line by line.

It seems related to this optim.
Just send me a minimal example to reproduce the issue.

@schungx
Copy link
Author

schungx commented Feb 5, 2022

As a matter of fact, after scanning through the code, I don't think escape codes are ever implemented for Windows.

Things like color are implemented on Windows via a Highlight Validator, while they are directly implemented on Unix.

So on Windows it is not bracketed paste, but using a validator to continue lines.

I'll experiment some more and post here. It seems that Windows Terminal has never sent the bracketed paste escape codes to the app. Maybe there is a switch or option I need to turn on...

One thing I find strange is that:

  • With crates.io version of rustyline, Windows Terminal pops up a warning when you try to paste multiple lines.

  • WIth your branch version of rustyline, Windows Terminal no longer pops up such a warning. So Windows Terminal must have sensed something different.

EDIT: The warning disappears once it receives a bracketed-paste-on escape sequence ^[[?2004h from the app, so it is expected.

@schungx
Copy link
Author

schungx commented Feb 6, 2022

Taking cue from microsoft/terminal#12385

By setting ENABLE_VIRTUAL_TERMINAL_INPUT for console mode, the escape sequences now properly show up.

However, ENABLE_VIRTUAL_TERMINAL_INPUT in turn disables all Windows meta keys processing (such as Alt, Shift and Ctrl etc.) so it makes it looks like a real VT terminal.

@schungx
Copy link
Author

schungx commented Feb 6, 2022

PR gwenn#1 opened with an implementation that works for me!

@schungx
Copy link
Author

schungx commented Feb 9, 2022

Understand that the implementation is not optimal (which duplicates many of the same escape-code processing for Unix).

It is left in my fork for now: https://github.com/schungx/rustyline

Whoever needs it can pull from my fork, or wait for official support to land here. I can't guarantee that everything works seamlessly, but at least it works for me...

@schungx schungx closed this as completed Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants