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

Reline behaves oddly with redirect (nontty output) #616

Open
mtasaka opened this issue Dec 10, 2023 · 1 comment
Open

Reline behaves oddly with redirect (nontty output) #616

mtasaka opened this issue Dec 10, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@mtasaka
Copy link

mtasaka commented Dec 10, 2023

Forwarded from cucumber/aruba testsute issue cucumber/aruba#910 , then from https://bugs.ruby-lang.org/issues/20052

Looks line reline behaves oddly with redirect (non tty)

With ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux] and Readline (version 8.2):

$ echo 'foo' | ruby -e 'require "readline"; puts Readline.readline(">")' > bar.log ; cat bar.log 
> foo
foo

With ruby 3.3.0dev (2023-12-09 master 1cbe114d1c) [x86_64-linux] and Reline (version 4.1): (Reline installed from gem install)

$ echo 'foo' | ruby -e 'require "reline"; puts Reline.readline(">")' > bar.log ; cat bar.log 
>>> f>f>fo>fo>foo>foofoo
@ima1zumi ima1zumi added the bug Something isn't working label Dec 11, 2023
@tompng
Copy link
Member

tompng commented Dec 11, 2023

I think it is Reline's bug. Reline's output should make the terminal screen to show:

>foo
foo

My understanding is that Reline does not aim to output exactly the same byte sequence as Readline. Reline's output can contain escape sequences or control characters like "\r>\r>f\r>foo\nfoo\n". Fixing this bug might not make the mentioned test pass.

Note that Readline's output sometimes contains different escape sequence depending on version or environment.

printf "ruby\x01\x04R\n" | ruby -rreadline -e 'puts Readline.readline(">")'
# output(readline 8.2): ">ruby\r\e[C\e[1Puby\r\e[CRuby\b\b\b\nRuby\n"
# output(readline 8.1): ">ruby\r>\e[1P\e[1@R\nRuby\n"
# terminal screen: ">Ruby\nRuby\n"

mvz added a commit to cucumber/aruba that referenced this issue Dec 17, 2023
In ruby 3.3, readline falls back to reline by default. This creates odd
output when the terminal is not a real TTY. See
ruby/reline#616.
mvz added a commit to cucumber/aruba that referenced this issue Dec 23, 2023
In ruby 3.3, requiring readline does not load the real readline library
but falls back to reline by default. This creates odd output when the
terminal is not a real TTY, making the interactive debugging scenario
fail.

See #910 for details. Also, see
ruby/reline#616 for the resulting reline
issue.

As a workaround, add the readline-ext gem which tries to use the real
readline as was the default in Ruby 3.2 and earlier.
mvz added a commit to cucumber/aruba that referenced this issue Dec 23, 2023
In Ruby 3.3, requiring readline does not load the real readline library
but falls back to reline by default. This creates odd output when the
terminal is not a real TTY and a prompt is used when getting input.
Because pry uses a prompt, this makes the interactive debugging scenario
fail.

This change works around this issue by switching to irb. Irb will not
use a prompt, possibly because the output is not a TTY.

See #910. Also, see
ruby/reline#616 for the resulting reline
issue.
dgutov added a commit to dgutov/irb that referenced this issue Mar 22, 2024
This works around Reline's misbehavior on low-capability terminals,
such as when IRB is launched inside Emacs (ruby/reline#616).

It should also resolve ruby#68 and resolve ruby#113 which were filed out of
similar need.
tompng added a commit to ruby/irb that referenced this issue May 1, 2024
* Switch to StdioInputMethod when TERM is 'dumb'

This works around Reline's misbehavior on low-capability terminals,
such as when IRB is launched inside Emacs (ruby/reline#616).

It should also resolve #68 and resolve #113 which were filed out of
similar need.

* Add special env for testing

See discussion in #907.

---------

Co-authored-by: tomoya ishida <tomoyapenguin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants