Reputation: 16174
I tried to create a simple clock up the top-left corner of the console, updating every second:
def clock():
threading.Timer(1.0, clock).start()
print('\033[0;0H' + time.asctime(time.localtime()))
I've used the colorama
package to enable ANSI escape sequences in Windows, but it seems the escape code would just move the cursor the number of pixels specified, and not to the position.
How can I move the cursor to the position (0, 0)
?
Upvotes: 1
Views: 9044
Reputation: 819
The line and column start at 1 not 0.
print('\033[1;1H' + time.asctime(time.localtime()))
or shorter
print('\033[H' + time.asctime(time.localtime()))
You might also need to save and restore position using ESC-7 and ESC-8.
See http://ascii-table.com/ansi-escape-sequences-vt-100.php for a list of codes.
Barry
Upvotes: 2