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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With