tags:

views:

112

answers:

1

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.

+6  A: 

Using Ruby's Readline Library:

require 'readline'
foo = Readline::readline
jleedev