Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move one character to the left in the console

Tags:

ruby

console

In the console you can print "\b" to erase the character left of the cursor (backspace) like this

print "the last char is going to be erased\b" # the last char is going to be erased

How to just move one position to the left instead of erasing (left arrow)?

like image 875
peter Avatar asked Apr 22 '12 00:04

peter


1 Answers

It depends on the terminal type and connection, but you can usually assume ANSI cursor movement, so cursor-left is ESC + '[' + 'D':

print "The cursor should be between the arrows: -> <-\e[D\e[D\e[D"
readline

See http://ascii-table.com/ansi-escape-sequences.php for more information.

like image 196
Mark Reed Avatar answered Sep 27 '22 22:09

Mark Reed