0

Expected behavior: Keyboard shortcuts using readline shortcuts like this answer.

What actually happens: Ctrl+l is pressed to clear the screen

irb
2023-08-08 20:31:17 -0600
Loaded Profile methods
irb.main{
irb.m${ ^Ltyping stuff^E^A

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

I thought my ~/.irbrc may have been disrupting shortcuts, inadvertently. I've renamed it so it isn't sourced but the behavior remains the same irb writes "^#{letter_I_pressed}" to screen instead of readline behaviors.

I noticed <esc> enables Ctrl-l to clear and some vi-like behavior (0 moves to beginning of line, Shift-c does nothing). So, maybe setting my bash modes to vi is breaking this? in my /etc/profile I have:

set -o vi
set editing-mode vi
set keymap vi
set show-mode-in-prompt on

so I tried: set -o emacs ; set editing-mode emacs ; set keymap emacs ; irb

Oddly, this does not enable emacs like readline behavior, nor does it change what I've described above.

1 Answers1

0

The Likely Problem and Wrapper Work-Around

Your Ruby may have been compiled without readline support. This is most often due to recent changes in either Ruby or pkgconfig where various compilation flags aren't properly being handled because pkgconfig can't find the right libraries.

Make sure you have the prerequisites installed and enable the feature flag during compilation. On some platforms or particular builds where I've encountered this issue, I've also found it useful to install rlwrap into addition to readline, which is a readline wrapper that provides GNU readline and BSD libedit support for applications that are missing it. For example:

brew install rlwrap
rlwrap irb

has fixed that problem for me when readline or libedit aren't properly compiled into irb or icr, the latter being Crystal's REPL where I've recently found readline and libedit support to be hit-or-miss because of this issue.

Environment Variables for Compiling Against GNU Readline

Alternatively, you can try setting the following environment values and try recompiling:

export LDFLAGS="-L/opt/homebrew/opt/readline/lib"
export CPPFLAGS="-I/opt/homebrew/opt/readline/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/readline/lib/pkgconfig"

Similar issues related to OpenSSL have also been reported, so you may need to do something similar there as well.

Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199