Arrow keys do not work in irb / ruby ​​command line scripts?

When used getsto receive user input, pressing the arrow keys displays text, presumably character codes. How can I prevent this, and how can I get the arrow keys to move the cursor correctly?

irb(main):001:0> foo = gets
^[[A^[[D^[[B^[[C    
=> "\e[A\e[D\e[B\e[C\n"

Edit: maybe I should mention that I'm using Mac OS X and Terminal.app.

+3
source share
1 answer

Using the Ruby Readline Library :

require 'readline'
foo = Readline::readline
+7
source

Source: https://habr.com/ru/post/1731147/


All Articles