irb icon indicating copy to clipboard operation
irb copied to clipboard

JRuby issues with irb and reline

Open headius opened this issue 3 years ago • 4 comments

Description

I have been working to switch JRuby to reline+irb gems and things are close but I have seen two issues testing it today.

  1. Backspace does not work. It seems to be ignored. ^H works, but shows the ^H character briefly before backspacing.
  2. The prompt line seems to print out again before running whatever code you entered:
$ irb
irb(main):001:0> puts
irb(main):001:0> puts

=> nil
irb(main):002:0> exit
irb(main):002:0> exit

I am not sure if these are IRB issues or Reline issues, and I need help figuring out what is wrong!

Note: JRuby uses an FFI-based version of io-console that we recently upstreamed to the gem. The io-console tests can't run green on JRuby due to our broken PTY library, but they run green on CRuby. There may still be bugs. See https://github.com/ruby/io-console/pull/22 for the work I did to get it working.

To investigate this it would be best to use the irb+reline branch I have pushed here: https://github.com/jruby/jruby/pull/5803

Note another issue we thought might be fixed by this move still seems broken under new IRB + reline: https://github.com/jruby/jruby/issues/1372

Result of irb_info

irb(main):001:0> irb_info
=> 
Ruby version: 2.6.5
IRB version: irb 1.3.4 (2021-02-25)
InputMethod: ReidlineInputMethod with Reline 0.2.4
RUBY_PLATFORM: java

Terminal Emulator

I am using MacOS Terminal.

Setting Files

No setting files.

headius avatar Mar 05 '21 22:03 headius

Still having issues with backspace. Now also noticing that the escape sequence for arrow keys sometimes shows up in the console:

Did not get cleared:

irb(main):005:0> puts "hello"^[[A

Shows up when up-arrowing through multiline history:

irb(main):010:1> def foo
irb(main):011:1>   p^[[A"hello"
irb(main):012:0> end^[[A

headius avatar May 26 '21 14:05 headius

STDIN.raw(intr: true, &:getbyte) returns the same value in CRuby and JRuby if it's alone (the example below), but Reline internal code returns a different value. Specifically, Enter and Ctrl+d return "\r" and 0x04 on CRuby, but "\n" and 0x00 on JRuby.

require 'io/console'

loop do
  until c = STDIN.raw(intr: true, &:getbyte)
    sleep 0.1
  end
  puts "#{c.inspect}"
  break if c == 'q'.ord or c == 0x04 or c == 0x00
end

Also, the code in the Reline is echoed back on JRuby.

aycabta avatar May 28 '21 12:05 aycabta

@aycabta Ok thank you. I will look into why the FFI io-console doesn't behave properly on JRuby.

headius avatar Jun 02 '21 19:06 headius

I can't reproduce that locally on Darwin:

$ ruby -v console_bug.rb 
jruby 9.3.0.0-SNAPSHOT (2.6.5) 2021-06-01 f960869395 OpenJDK 64-Bit Server VM 11.0.4+11 on 11.0.4+11 +jit [darwin-x86_64]
13
4

Still hunting for a minimal reproduction of the issue.

headius avatar Jun 02 '21 19:06 headius