Forum: Ruby-core [ruby-trunk - Bug #7859][Open] Readline: Incorrect arrow key behavior in vi_editing_mode insert mode

Posted by davidbalbert (David Albert) (Guest)
on 2013-02-15 20:20
(Received via mailing list)
Issue #7859 has been reported by davidbalbert (David Albert).

----------------------------------------
Bug #7859: Readline: Incorrect arrow key behavior in vi_editing_mode 
insert mode with Readline 6.2
https://bugs.ruby-lang.org/issues/7859

Author: davidbalbert (David Albert)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: 2.0.0-rc2


I've discovered what I think is a bug in the Readline module in the 
standard library. When I am using vi_editing_mode in insert mode (rather 
than command mode), I am unable to use the up arrow to go up through 
history. It seems that I can only go up through history when in command 
mode. Additionally, pressing the down arrow while in insert mode changes 
to command mode, which seems odd.

Perhaps this is intended behavior for the Readline module, but if it is, 
I would propose changing it. I would expect the up and down arrows to 
scroll up and down through history in both command mode and insert mode 
when Readline.vi_editing_mode? is true. You can find examples of the 
expected behavior in bash (`set -o vi` to get into vi mode), the Python 
REPL, and all other that I can remember using.

I've reproduced this with Readline 6.2 on Mac OS X 10.8.2 and Ubuntu 
precise64 with kernel version 3.2.0-37. It is worth noting that on Mac 
OS X with the EditLine wrapper, the Readline module works correctly 
although you must have the proper settings in your .editrc file because 
Readline.vi_editing_mode is not implemented.

Here is the code I used to test:

<pre>
<code class="ruby">
# readlinetest.rb
require 'readline'

trap(:INT) {
  exit 0
}

Readline.vi_editing_mode
puts "Readline::VERSION => #{Readline::VERSION}"

loop do
  puts Readline.readline(">> ", true)
end
</code>
</pre>

Example usage:

<pre>
<code>
$ ruby readlinetest.rb
Readline::VERSION => 6.2
>> 1234
1234
>>
</code>
</pre>

At this point, I would expect that the up arrow would put 1234 after the 
prompt, but instead nothing happens. Pressing the down arrow is the same 
as pressing escape and changes readline into command mode.

Let me know if there's anything else I can provide to help fix this. I 
tried jumping into the Readline module myself, but I'm not particularly 
familiar with how readline works and wasn't able to make much headway.
Posted by Nobuyoshi Nakada (nobu)
on 2013-02-16 05:24
(Received via mailing list)
Issue #7859 has been updated by nobu (Nobuyoshi Nakada).

Description updated
Category set to ext
Status changed from Open to Assigned
Assignee set to kouji (Kouji Takao)
Target version set to next minor


----------------------------------------
Bug #7859: Readline: Incorrect arrow key behavior in vi_editing_mode 
insert mode with Readline 6.2
https://bugs.ruby-lang.org/issues/7859#change-36333

Author: davidbalbert (David Albert)
Status: Assigned
Priority: Normal
Assignee: kouji (Kouji Takao)
Category: ext
Target version: next minor
ruby -v: 2.0.0-rc2


=begin
I've discovered what I think is a bug in the (({Readline})) module in 
the standard library. When I am using (({vi_editing_mode})) in insert 
mode (rather than command mode), I am unable to use the up arrow to go 
up through history. It seems that I can only go up through history when 
in command mode. Additionally, pressing the down arrow while in insert 
mode changes to command mode, which seems odd.

Perhaps this is intended behavior for the (({Readline})) module, but if 
it is, I would propose changing it. I would expect the up and down 
arrows to scroll up and down through history in both command mode and 
insert mode when (({Readline.vi_editing_mode?})) is true. You can find 
examples of the expected behavior in bash (`((%set -o vi%))` to get into 
vi mode), the Python REPL, and all other that I can remember using.

I've reproduced this with (({Readline})) 6.2 on Mac OS X 10.8.2 and 
Ubuntu precise64 with kernel version 3.2.0-37. It is worth noting that 
on Mac OS X with the EditLine wrapper, the (({Readline})) module works 
correctly although you must have the proper settings in your .editrc 
file because (({Readline.vi_editing_mode})) is not implemented.

Here is the code I used to test:

  # readlinetest.rb
  require 'readline'

  trap(:INT) {
    exit 0
  }

  Readline.vi_editing_mode
  puts "Readline::VERSION => #{Readline::VERSION}"

  loop do
    puts Readline.readline(">> ", true)
  end

Example usage:

  $ ruby readlinetest.rb
  Readline::VERSION => 6.2
  >> 1234
  1234
  >>

At this point, I would expect that the up arrow would put 1234 after the 
prompt, but instead nothing happens. Pressing the down arrow is the same 
as pressing escape and changes (({readline})) into command mode.

Let me know if there's anything else I can provide to help fix this. I 
tried jumping into the (({Readline})) module myself, but I'm not 
particularly familiar with how (({readline})) works and wasn't able to 
make much headway.
=end
Posted by rmichael (Richard Michael) (Guest)
on 2013-04-25 10:55
(Received via mailing list)
Issue #7859 has been updated by rmichael (Richard Michael).


I have different, but perhaps related, problems with 
Readline.vi_editing_mode in Ruby 1.9.3p392 with MacPorts' readline 6.2 
on MacOS 10.6.8.  Please let me know if I should open a new 1.9.3 bug 
report instead of commenting here.

Using the `readlinetest.rb` program in the above report, any arrow key 
jumps back to the first line of history and prints it's escape sequence, 
and ESC itself jumps back to the first line of history.  (It seems the 
initial escape sequence, either generated by an arrow-key or ESC itself, 
is printing the first line.)

$ ruby tmp/readlinetest.rb
Readline::VERSION => 6.2
>> one
one
>> two
two
>> three
three
>> one[A     # Up-arrow was pressed here, on the empty line; down-arrow would 
print ">> one[B", right-arrow ">> one[B", etc.

$ ruby tmp/readlinetest.rb
Readline::VERSION => 6.2
>> one
one
>> two
two
>> three
three
>> one     # ESC was pressed here, on the empty line.

$ find $MY_RUBY_HOME -name readline.bundle -exec otool -L {} \;
/Users/testuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/x86_64-darwin10.8.0/readline.bundle:
        /Users/testuser/.rvm/rubies/ruby-1.9.3-p392/lib/libruby.1.9.1.dylib 
(compatibility version 1.9.1, current version 1.9.1)
        /opt/local/lib/libreadline.6.2.dylib (compatibility version 
6.0.0, current version 6.2.0)
        /opt/local/lib/libncurses.5.dylib (compatibility version 5.0.0, 
current version 5.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current 
version 125.2.11)
        /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current 
version 227.0.0)
----------------------------------------
Bug #7859: Readline: Incorrect arrow key behavior in vi_editing_mode 
insert mode with Readline 6.2
https://bugs.ruby-lang.org/issues/7859#change-38906

Author: davidbalbert (David Albert)
Status: Assigned
Priority: Normal
Assignee: kouji (Kouji Takao)
Category: ext
Target version: next minor
ruby -v: 2.0.0-rc2
Backport:


=begin
I've discovered what I think is a bug in the (({Readline})) module in 
the standard library. When I am using (({vi_editing_mode})) in insert 
mode (rather than command mode), I am unable to use the up arrow to go 
up through history. It seems that I can only go up through history when 
in command mode. Additionally, pressing the down arrow while in insert 
mode changes to command mode, which seems odd.

Perhaps this is intended behavior for the (({Readline})) module, but if 
it is, I would propose changing it. I would expect the up and down 
arrows to scroll up and down through history in both command mode and 
insert mode when (({Readline.vi_editing_mode?})) is true. You can find 
examples of the expected behavior in bash (`((%set -o vi%))` to get into 
vi mode), the Python REPL, and all other that I can remember using.

I've reproduced this with (({Readline})) 6.2 on Mac OS X 10.8.2 and 
Ubuntu precise64 with kernel version 3.2.0-37. It is worth noting that 
on Mac OS X with the EditLine wrapper, the (({Readline})) module works 
correctly although you must have the proper settings in your .editrc 
file because (({Readline.vi_editing_mode})) is not implemented.

Here is the code I used to test:

  # readlinetest.rb
  require 'readline'

  trap(:INT) {
    exit 0
  }

  Readline.vi_editing_mode
  puts "Readline::VERSION => #{Readline::VERSION}"

  loop do
    puts Readline.readline(">> ", true)
  end

Example usage:

  $ ruby readlinetest.rb
  Readline::VERSION => 6.2
  >> 1234
  1234
  >>

At this point, I would expect that the up arrow would put 1234 after the 
prompt, but instead nothing happens. Pressing the down arrow is the same 
as pressing escape and changes (({readline})) into command mode.

Let me know if there's anything else I can provide to help fix this. I 
tried jumping into the (({Readline})) module myself, but I'm not 
particularly familiar with how (({readline})) works and wasn't able to 
make much headway.
=end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.