Exploring terminfo

Alan Gauld alan.gauld at yahoo.co.uk
Sun Jan 17 09:34:53 EST 2021


On 17/01/2021 00:02, Greg Ewing wrote:
> On 17/01/21 12:40 pm, Chris Angelico wrote:
>> This is true. However, at some point, the boundary is crossed from
>> Python into the C library. Something, at that point, knows. It's very
>> common to have a flush option available, so it should be used.
> 
> I'm wondering whether the problem in this particular case stems
> from trying to use parts of curses without initialising it
> properly.

The problem is terminfo is not really part of curses.
Curses is built on top of terminfo.

> I expect that initialising curses would put stdout
> into some kind of unbuffered mode, 

You can choose the mode, but once in curses all the standard
input/output options cease to be usable, you have to use the
curses functions such as addstr(), getch() etc.

Its precisely because curses is such an all or nothing option
that I wanted to see if I could create some kind of text
attribute control outside of curses - which it seems is
what Cameron has been up to independently!

For example, it is difficult to call a Python function that
has print statements in it (bad practice though it may be!)
from within curses. You need to temporarily turn cures off,
call he function then reinstate curses. It's doable but messy!

If you don't need to create windows and move the cursor
around and respond to mouse clicks etc then curses is a
bit of overkill to just turn some text bold or inverse.
That's where the terminfo functions come in and, as you
saw from the C code, are fairly trivial to use in C.


-- 
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