how to get ruby 2.7 IRB command history cursor keys

In devel/rubygem-irb as of lang/ruby27, I found that the up/down cursor keys (for accessing recent commands) do not work. Instead, the keys ^P and ^N do work.

The immediate workaround is to invoke irb --singleline. But it also can be properly fixed.

irb knows two line-editing modes: singleline and multiline, where multiline is the default. In singleline mode it seems to use the line-editing from devel/readline (which will usually be installed if you install e.g. shells/bash). This was traditionally configured in ~/.inputrc, but it is not fully clear to me how this all relates nowadays, nor is it clear what happens if devel/readline is not installed - most of the configurations in .inputrc seem no longer to be used, and those that are, do not work everywhere).

In multiline mode ruby brings along it's own line editor, installed as devel/rubygem-reline. This one does also read ~/.inputrc, but it uses different key names. What brought me onto the proper track was this article. So what I actually need in .inputrc is this (with xterm):

"\e[B": ed-next-history
"\e[A": ed-prev-history


Obviousely this may differ according to what terminal you are on, what termcap is used, and what keyboard (and keyboard driver) you have. (With hd you can see what your intended keys do actually send.)
 
lang/ruby27 is built with LIBEDIT by default. You can try building it with READLINE instead. I usually try to set everything to READLINE as much as possible but some ports insist on devel/libedit. This is one of the ports that actually let you choose.

Code:
====> Which line editing lib to use: you have to select exactly one of them
     LIBEDIT=on: Use libedit
     READLINE=off: Use libreadline
 
lang/ruby27 is built with LIBEDIT by default. You can try building it with READLINE instead. I usually try to set everything to READLINE as much as possible but some ports insist on devel/libedit.
Ah, that would explain why it does not behave fully identical to those ports using readline.
And the point here is, that by default irb will nowadays use neither of these, and instead their own ruby-written readline-clone that can do multiline editing.
 
Back
Top