Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 gnawing in my mind for some time now :)

Thanks

like image 710
Riccardo B. Avatar asked Jun 01 '11 09:06

Riccardo B.


People also ask

What is the use of tput command?

The tput command allows shell scripts to do things like clear the screen, underline text, and center text no matter how wide the screen is. To do these things, it translates the terminal-independent name of a terminal capability into its actual value for the terminal type being used.

What does tput command do in Linux?

Description. The tput command uses the terminfo database to make terminal-dependent information available to the shell. The tput command outputs a string if the attribute CapabilityName is of type string. The output string is an integer if the attribute is of type integer.


1 Answers

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.

like image 128
Riccardo B. Avatar answered Oct 24 '22 22:10

Riccardo B.