Exploring terminfo

Alan Gauld alan.gauld at yahoo.co.uk
Fri Jan 15 13:36:20 EST 2021


On 15/01/2021 17:31, Grant Edwards wrote:

>>> cur.putp(cls)
>>> name = input("Hello, what's your name? ")
>>>
>>> cur.putp(bold)
>>> print("Nice to meet you ", name)


>>     putp(clr);
>>     putp(bold);
>>     printf("Enter a name: ");
>>     fgets(line, sizeof(line),stdin);
>>
>>     printf("Hello %s\n", line);
>>     exit(0);

> One difference is that the name prompt is being written to stdout in
> the C version and stderr in the Python version. But I don't see why
> that would matter.

That could make a big difference, the putp() function specifically
states that it writes to stdout.

> I suspect that the problem is that putp is writing to the libc
> "stdout" FILE stream that's declaredin <stdio.h>. That stream
> layer/object has buffering that is invisible to Python. 

That would indeed explain it.

> Now the question: is there a way to tell the curses module to flush
> its stdout FILE stream?

Indeed. But unless it's trivial it rather defeats the concept of
using the terminfo functions to create text effects without
diving into full curses screen control! And that was what I
was hoping to uncover.

I wonder if I can use the os module to mess with the
file descriptors.... hmmm.

Thanks for that snippet, I had no idea that input() wrote
to stderr nor that Python added a stdout layer on top of libc.
Do you know where that is documented? I'd be interested in
reading more.

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