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

How to make CTRL-V paste on windows (cmd.exe, powershell) #519

Closed
marcbowes opened this issue May 7, 2021 · 8 comments
Closed

How to make CTRL-V paste on windows (cmd.exe, powershell) #519

marcbowes opened this issue May 7, 2021 · 8 comments

Comments

@marcbowes
Copy link
Contributor

When using rustyline on Linux or OSX, system copy-paste works just fine. However, on Windows that's not the case.

Here's a scenario that doesn't work as expected:

  1. Open notepad and type some text. Select it, use CTRL-C to put it on the clipboard.
  2. Open cmd.exe and press CTRL-V. The text should paste.
  3. Open a rustyline application (e.g. the default example will do). Press CTRL-V. The next will not paste.
  4. Use rightclick. The text will paste.

The same thing is true when using Powershell. When using Windows Terminal, CTRL-V works as expected.

I looked through the available keybinds/commands and I don't see a "paste from system clipboard" anywhere. Should this work by default, or is there something I need to enable?

@gwenn
Copy link
Collaborator

gwenn commented May 7, 2021

I only have access to a Windows machine at work.
To check:

  • how does linefeed / termwiz / replxx behave ?
  • For rustyline, by default, CTRL-V does nothing on Windows and there is no command to "paste from system clipboard" so you cannot use bind_sequence.
  • Maybe you should try to tweak Command / Powershell settings.

@marcbowes
Copy link
Contributor Author

marcbowes commented May 7, 2021

how does linefeed / termwiz / replxx behave ?

I only have access to a Windows machine after work, so I'll try the others out later.

For rustyline, by default, CTRL-V does nothing on Windows and there is no command to "paste from system clipboard" so you cannot use bind_sequence.

Is that because rustyline is intercepting the keybinds in some bad way, or is it because the expectation in powershell/cmd.exe is that applications process CTRL-V directly?

Similarly, do you know if it's possible to add "copy/paste clipboard" commands?

Maybe you should try to tweak Command / Powershell settings.

I'd like to make this work by default. My customers (people using the software I'm writing using rustyline) should not have to do this setup (and they won't).

@gwenn
Copy link
Collaborator

gwenn commented May 7, 2021

Is that because rustyline is intercepting the keybinds in some bad way, or is it because the expectation in powershell/cmd.exe is that applications process CTRL-V directly?

rustyline should intercept to key sequence correctly. And rustyline doesn't know / see the difference when text is pasted or typed (see here).

Similarly, do you know if it's possible to add "copy/paste clipboard" commands?

We will need to implement this method and bind it to Ctrl-V on Windows here.

@marcbowes
Copy link
Contributor Author

Well, that's pretty clear! Thanks.

I know literally nothing about the windows API. If you can point me at some method names, I can try implement it.

@marcbowes
Copy link
Contributor Author

https://github.com/marcbowes/rustyline/commit/b0e2669acacf9c259f0f73bc1d9d8f271f8a07c2

I'll test that out later on my Windows machine. If it works, I'll wire up a paste command.

@marcbowes
Copy link
Contributor Author

See the above PR for a fix. Not sure if I did it right. Also had to revert the fd-lock change to get things compiling.

@gwenn gwenn closed this as completed in e1c1d0e May 9, 2021
@gwenn
Copy link
Collaborator

gwenn commented May 18, 2021

Version 8.1.0 released

@marcbowes
Copy link
Contributor Author

Thank you!

marcbowes added a commit to awslabs/amazon-qldb-shell that referenced this issue May 18, 2021
Fixed via kkawakam/rustyline#519

With this upgrade, ctrl-c + ctrl-v should now copy-paste as expected.
Previously, this would only work on Windows Terminal: Powershell or
cmd.exe would ignore the ctrl-v but rightclick would paste.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants