I'm using Colorama in Python (32-bit 2.7.2) on Windows 7 (64-bit) and it works great for colouring text in the console, but I'm having problems when getting it to move the cursor.
Specifically, if I use the ANSI code to go up a line, it works when the cursor is far from the bottom of the screen, but when the cursor is near the bottom the cursor doesn't move up correctly and then text starts to be printed further down the page causing it to scroll.
The code I use to move up a line is:
sys.stdout.write('\x1b[4A')
where 4 is moving it four lines up (and something like '\x1b[8A' would move it eight lines up)
I'm not sure if this is a lack of understanding on my part regarding how ANSI codes work or whether it is an issue with Colorama.
To recreate it, run something like this in either the normal Windows Command Prompt (cmd.exe) or in Console2 (it seems to make no difference)
from __future__ import print_function
import colorama
from colorama import Fore, Back, Style
import sys
def main():
print('Blah')
print('Blah')
print('Blah')
print('Blah')
print('Blah')
print('Blah')
print('Blah')
print('Blah')
print('Blah')
print('Blah')
print('Blah')
sys.stdout.write('\x1b[6A')
sys.stdout.write('some text')
if __name__ == '__main__':
main()
If you run the code above near the top of the screen, it'll end up with "some text" written part way through the "Blah" output, but if you start it when already near the bottom of the screen the "some text" will be at the end, with the cursor seemingly not having scrolled back at all.
I specifically need to move the cursor up, so it's placed on a relative basis to other output, rather than give it an absolute screen position (ie move it to position x,y)
Any suggestions on where to start?
You should import "init" from colorama and call "init()" before trying to move up the cursor.