Exploring terminfo

Alan Gauld alan.gauld at yahoo.co.uk
Thu Jan 14 19:56:05 EST 2021


On 14/01/2021 23:08, Grant Edwards wrote:

> Alternatively, I think you can use the ncurses library to retrieve the control
> strings (just don't use any ncurses input/output calls), like this example from
> https://stackoverflow.com/questions/6199285/tput-cup-in-python-on-the-commandline:
> 
>     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

That's exactly what I'm trying to do but with the character
attributes rather than cursor positioning. I can retrieve values and I
can clear the screeeen. But the bold(and inverse and underline etc)
strings don;yt seem to affect print() or stdout.write(). But they do
affect the input() prompt strings.

What is different about the input() prompts? Why are they affected
when print isn't?

I've discovered that I can (sort of) get my code to work if I insert
blank input statements between the various prints. But then I need to
keep hitting return to get the display to show up - not exactly useful.
But the point is that after an input() the subsequent print statements
use the set attributes as desired. What can I insert to get the same
effect without requiring the user to type input between prints?
Or what parameter should I be setting where?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Python-list mailing list