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

When used inside Emacs with Reline, input is echoed #2303

Open
dgutov opened this issue Mar 14, 2024 · 2 comments · May be fixed by #2304
Open

When used inside Emacs with Reline, input is echoed #2303

dgutov opened this issue Mar 14, 2024 · 2 comments · May be fixed by #2304

Comments

@dgutov
Copy link
Contributor

dgutov commented Mar 14, 2024

Description

This issue is about using Pry as a Ruby REPL inside Emacs.

The effect looks very much like ruby/reline#616:

[1] pry(main)> [1] pry(main)> 2
[1] pry(main)> 2[1] pry(main)> 2=> 2
[2] pry(main)> [2] pry(main)> 3
[2] pry(main)> 3[2] pry(main)> 3=> 3
[3] pry(main)> [3] pry(main)> 

But there doesn't seem to be any interest in having this solved inside Reline (i.e. providing a "simple" io driver).

What are your expected behavior and actual behavior of your environment?

The expected behavior is that the input is not copied or otherwise reproduced in the output.

This problem will come up more often now than Ruby 3.3 defaults to Reline.

Terminal Emulator

Comint inside Emacs.

IRB has a workaround: when launched with --nosingleline --nomultiline, it switches to a different I/O implementation, which it calls StdioInputMethod.

Should Pry carry its own solution like that as well? The hackish patch below seems to do the trick. It can be a configuration option, a separate wrapper class, etc.

@@ -179,7 +179,10 @@
diff --git a/lib/pry/repl.rb b/lib/pry/repl.rb
index 9a58b827..2bfcad35 100644
--- a/lib/pry/repl.rb
+++ b/lib/pry/repl.rb
@@ -179,7 +179,10 @@ class Pry
           end
         end
 
-        if readline_available?
+        if ENV['TERM'] == 'dumb'
+          STDOUT.print(current_prompt)
+          STDIN.gets
+        elsif readline_available?
           set_readline_output
           input_readline(current_prompt, false) # false since we'll add it manually
         elsif coolline_available?

Downstream report: dgutov/robe#147 (comment)

@andrehjr
Copy link
Member

Hi, thanks for the issue!

I'm trying to add proper support for reline on #2298, wondering if this also fixes the issue?

If not, I think pry should have a workaround for TERM/dumb too. I will investigate a bit more

@dgutov
Copy link
Contributor Author

dgutov commented Mar 14, 2024

@andrehjr Hi! I've tried your branch (and also the nearby one-liner PR with "basic Readline support") - no difference.

It does seem like there needs to be a fix inside Reline, or special handling in consumers.

I'm currently preparing a small PR that uses the approach from my patch, I think it will be orthogonal to your work, comments welcome. But if you manage to find a more organic solution, that'd be even better.

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 a pull request may close this issue.

2 participants