简体   繁体   中英

Arrow keys don't work in irb/ruby command line scripts?

While using gets to accept user input, pressing the arrow keys outputs text to the screen, presumably the character codes. How can I prevent this from happening, and further how can I get the arrow keys to properly move the cursor around?

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

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

Using Ruby's Readline Library :

require 'readline'
foo = Readline::readline

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM