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

re-enable bracketed paste on not(windows) (fixes #9944) (fixes #648) #657

Merged

Conversation

LevitatingBusinessMan
Copy link
Contributor

@LevitatingBusinessMan LevitatingBusinessMan commented Nov 5, 2023

Due to a supposed issue (nushell/nushell#9218) in nushell regarding commands that read standard input, a fix (nushell/nushell#9399) was proposed that temporarily disables bracketed_paste during the execution of eval_source.

Instead, this issue was moved over to reedline and a new PR was created (#598). In this version of the "fix", bracketed_paste is disabled completely after the first execution of reedline. This has led to issue #648, where multiline paste is now being disabled on non-windows environments.

This PR effectively reverts #598. This might cause nushell/nushell#9218 to reappear in nushell.

I have personally not been able to reproduce nushell/nushell#9218, modern versions of gpg use a GUI prompt for the password, or alternatively a curses window. I did try to replicate the issue using GNU readline and other prompting methods but I wasn't succesful.

If nushell/nushell#9218 is a reproducible issue, I think the best course of action is to merge nushell/nushell#9399, which supposedly fixes the issue, but on the nushell side. It seems like this issue might be specific to nushell, and thus it should be fixed in that repository. No need to affect all other reedline dependent packages with it.

@LevitatingBusinessMan LevitatingBusinessMan changed the title re-enable bracketed past on not(windows) re-enable bracketed paste on not(windows) Nov 5, 2023
Copy link

codecov bot commented Nov 5, 2023

Codecov Report

Merging #657 (5e0892b) into main (60b3b62) will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #657      +/-   ##
==========================================
+ Coverage   49.21%   49.22%   +0.01%     
==========================================
  Files          43       43              
  Lines        7914     7912       -2     
==========================================
  Hits         3895     3895              
+ Misses       4019     4017       -2     
Files Coverage Δ
src/engine.rs 5.15% <ø> (+<0.01%) ⬆️

@@ -630,9 +630,6 @@ impl Reedline {

let result = self.read_line_helper(prompt);

#[cfg(not(target_os = "windows"))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of wonder if this was originally just a typo and should've really been #[cfg(target_os = "windows"))] because bracketed paste doesn't work in windows since crossterm doesn't support it yet.

Copy link
Contributor Author

@LevitatingBusinessMan LevitatingBusinessMan Nov 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The author of the original issue was using Linux. Though he was using the Windows Terminal (using debian via WSL2).

Thus it might be a Windows Terminal issue? I don't think anyone tried it to reproduce it with Windows Terminal specifically. And it seems nobody was actually able to reproduce it except @theAkito himself.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try to reproduce with WezTerm on Windows. Just tell me which commits to try & any additional useful information...

@LevitatingBusinessMan
Copy link
Contributor Author

LevitatingBusinessMan commented Nov 5, 2023

@theAkito

I can try to reproduce with WezTerm on Windows. Just tell me which commits to try & any additional useful information...

I think the easiest way to test it would be to compile nushell with:

[patch.crates-io]
reedline = { git = "https://github.com/LevitatingBusinessMan/reedline.git", branch = "re-enable-bracketed-paste" }

And then try to reproduce the error (first in Windows Terminal like before, if that works in WezTerm). Have you seen this error only with gpg or also other commands that take input?

@theAkito
Copy link

theAkito commented Nov 5, 2023

And then try to reproduce the error.

What's the point of trying to reproduce it in Windows Terminal? If it's gonna happen again, it still could be due to this terminal.

@LevitatingBusinessMan
Copy link
Contributor Author

If it's gonna happen again, it still could be due to this terminal.

Exactly. You can first verify the bug is still present on Windows Terminal. And then you can remove variables to find the root cause. Like if it is related to the terminal by switching to another.

You can also test for the bug in WezTerm first, but if that fails you'd have to test it in Windows Terminal anyway.

I am curious if the bug is specific to gpg somehow. If it isn't than I think more people would experience it. If the bug does appear in gpg try using passwd.

If it is specific to gpg than it must be related to pinentry.

@fdncred
Copy link
Collaborator

fdncred commented Nov 5, 2023

also related nushell/nushell#9944

@LevitatingBusinessMan
Copy link
Contributor Author

LevitatingBusinessMan commented Nov 5, 2023

I tested it and believe nushell/nushell#9944 is actually fixed by this PR.

@amtoine is on Linux so it makes sense.

@theAkito
Copy link

theAkito commented Nov 5, 2023

Exactly. You can first verify the bug is still present on Windows Terminal. And then you can remove variables to find the root cause. Like if it is related to the terminal by switching to another.

You can also test for the bug in WezTerm first, but if that fails you'd have to test it in Windows Terminal anyway.

Makes sense. Will try, when I get the time.

Am following this pull request.

@WindSoilder
Copy link
Contributor

Thanks, generally I'm ok with your point.

I believe it will cause nushell/nushell#9218 to reappear. But we can bring nushell/nushell#9399 back, so both reedline and nushell are useful to us again.

@theAkito
Copy link

theAkito commented Nov 6, 2023

You can also test for the bug in WezTerm first, but if that fails you'd have to test it in Windows Terminal anyway.

Done, did it.

Here is what I did, so there are no misunderstandings.

  1. Compiled Nushell master branch on WSL: cargo build --release --workspace; cargo run --release
  2. Testing GPG signing, which requires the passphrase. gpg --yes -s s.txt
  3. Same issue, as in Pasting into Terminal entirely broken since 0.80.0 (Example: GPG Passphrase Paste) nushell#9218.
  4. Connected to WSL via WezTerm.
  5. Same issue, once again.

I am curious if the bug is specific to gpg somehow. If it isn't than I think more people would experience it. If the bug does appear in gpg try using passwd.

If it is specific to gpg than it must be related to pinentry.

There are probably tons of other programs requiring password entry in a similar fashion, but right now none come to my mind. If you can tell me an example program, I can test, I will test the password entry there.

@LevitatingBusinessMan
Copy link
Contributor Author

There are probably tons of other programs requiring password entry in a similar fashion, but right now none come to my mind. If you can tell me an example program, I can test, I will test the password entry there.

Passwd maybe? Modern GPG uses its own pinentry tool, which will prompt using curses (those terminal user interfaces).

Does the prompt you get look like this?
image

If it happens in wezterm, it could be specific to WSL2? More likely would be that it is specific to GPG I'd think.

@theAkito
Copy link

theAkito commented Nov 6, 2023

Tried passwd & works perfectly fine without issues.

These are the literal characters presented to me on pinentry.

                           ┌────────────────────────────────────────────────────────────────┐
                           │ Please enter the passphrase to unlock the OpenPGP secret key:  │
                           │ "Name <[email protected]>"                                         │
                           │ 4096-bit RSA key, ID HEXHEXHEXHEXHEHX,                         │
                           │ created 2001-11-11.                                            │
                           │                                                                │
                           │                                                                │
                           │ Passphrase: __________________________________________________ │
                           │                                                                │
                           │         <OK>                                    <Cancel>       │
                           └────────────────────────────────────────────────────────────────┘

GPG version

gpg (GnuPG) 2.2.27
libgcrypt 1.8.8
Copyright (C) 2021 Free Software Foundation, Inc.
License GNU GPL-3.0-or-later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

@fdncred
Copy link
Collaborator

fdncred commented Nov 6, 2023

Are we saying this PR is ready to land or is it going to create other problems?

@LevitatingBusinessMan LevitatingBusinessMan changed the title re-enable bracketed paste on not(windows) re-enable bracketed paste on not(windows) (fixes #9944) (fixes #648) Nov 6, 2023
@LevitatingBusinessMan
Copy link
Contributor Author

Thanks to @theAkito I can now confirm that this issue is specific to curses.

I was able to replicate it with a password prompt written in python (with curses).

import curses

def main():
    # Initialize curses
    stdscr = curses.initscr()

    # Prompt for password
    stdscr.addstr("Paste text using bracketed_paste: ")
    password = ""
    while True:
        key = stdscr.getch()

        password += chr(key)

        stdscr.clear()  # Clear screen
        stdscr.addstr("Paste text using bracketed_paste: " + password)

if __name__ == "__main__":
    main()

Escape characters 200 and 201 are prefixed and suffixed respectively. Curses captures the key and converts it to a character, and apparently nushell is sending some escape characters that get converted like this.

@LevitatingBusinessMan
Copy link
Contributor Author

LevitatingBusinessMan commented Nov 6, 2023

I personally think this PR should be merged, so nushell/nushell#9944 and #648 can be closed.

After this is merged, I will open a new issue at nushell, covering this issue with bracketed paste and curses.

@fdncred
Copy link
Collaborator

fdncred commented Nov 6, 2023

ok @LevitatingBusinessMan let's try your solution. I'll be looking for that nushell PR. Appreciate it.

@fdncred fdncred merged commit c853d71 into nushell:main Nov 6, 2023
8 checks passed
@LevitatingBusinessMan LevitatingBusinessMan deleted the re-enable-bracketed-paste branch November 6, 2023 20:37
@theAkito
Copy link

theAkito commented Nov 6, 2023

I was able to replicate it with a password prompt written in python (with curses).

Weird. Cannot reproduce it in Nim.

##[
  Works on Nim 2.0.0

  nimble install ncurses # https://github.com/walkre-niboshi/nim-ncurses
  nim c -r reedline_657.nim ; rm reedline_657
]##

import pkg/ncurses

when isMainModule:
  let stdscr = initscr()
  stdscr.waddstr("Paste text using bracketed_paste: ")
  var password = ""
  while true:
    var key = stdscr.wgetch()

    if key == 0: break

    password &= key.chr

    stdscr.werase
    stdscr.waddstr(cstring("Paste text using bracketed_paste: " & password.repr))

Output just shows the characters I entered, which is, I suppose, the correct behaviour.

This program's ncurses library uses libncursesw.so(.5|.6|) in the background, so it's the behaviour I get from my system's ncurses library.


Same with this Python program. No incorrect characters echoed.

@LevitatingBusinessMan
Copy link
Contributor Author

LevitatingBusinessMan commented Nov 6, 2023

@theAkito Did you test it using reedline compiled from git? Including this merge?

@theAkito
Copy link

theAkito commented Nov 6, 2023

@theAkito Did you test it using reedline compiled from git? Including this merge?

I tested with the product of yesterday's compilation, where I did reproduce it with GPG, earlier.

@LevitatingBusinessMan
Copy link
Contributor Author

I can reproduce it just fine, by having reedline pointed to the git's main branch. And doing cargo update to update the dependencies.

@theAkito
Copy link

theAkito commented Nov 6, 2023

@LevitatingBusinessMan

Well, turns out, I had a user error, when trying to reproduce. Can reproduce now.

Confirmed. 👍🏻

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

Successfully merging this pull request may close these issues.

4 participants