Move one character to the left in the console

In the console, you can print "\b"to erase the character to the 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 easy is it to move one position to the left instead of erasing (left arrow)?

+5
source share
1 answer

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

print "The cursor should be here:> <\e[D\e[D"
readline

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

+9
source

All Articles