Tput Cup In Python On The Commandline
Is there an elegant solution to do this shell script in Python without importing os ? tput cup 14 15; echo -ne '\033[1;32mtest\033[0m' ; tput cup 50 0 This just has been gnawi
Solution 1:
Thanks Ignacio Vazquez-Abrams for your input, it was a great push in the right direction. In the end i came up with this little code that will help me conquer the world :)
from curses import *
setupterm()#cols = tigetnum("cols")#lines = tigetnum("lines")#print str(cols) + "x" + str(lines)
place_begin = tparm(tigetstr("cup"), 15, 14)
place_end = tparm(tigetstr("cup"), 50, 0)
print place_begin + "-- some text --" + place_end
@TZ.TZIOY, thanks, i think using stdout rather than using print indeed is a better solution.
Solution 2:
All the terminfo capabilities are accessible via curses
. Initialize it and use curses.tiget*()
to get the capabilities you care about.
Solution 3:
Given that
- you assume ANSI escape sequences
tput cup 14 15 | cat -v
displays^[[15;16H
the whole suggested script results in the following Python script:
import sys
sys.stdout.write("\033[15;16H\033[1;32mtest\033[m\033[51;1H")
# and a possible sys.stdout.flush() here, depending on your needs
Post a Comment for "Tput Cup In Python On The Commandline"