Exploring terminfo

Barry Scott barry at barrys-emacs.org
Thu Jan 14 16:30:11 EST 2021



> On 14 Jan 2021, at 16:12, Alan Gauld via Python-list <python-list at python.org> wrote:
> 
> During lockdown I've been digging deeper into the curses module
> and lately into the tiXXXX family of functions that reside there.
> 
> I've written a short program that is supposed to
> - *clear the screen*,
> - read some input
> - display the result in a message *highlighted in bold*.
> - get input to end the program

It seems that curses does not allow you to mix raw stdin/stdout with its calls.
(got that idea from a quick web search).

If all you want is simple things like bold and clear I'd just use the
ANSI escape sequences directly.

Are there any terminals that do not understand ANSI escape sequences
these days?

Barry

> 
> The parts marked with ** use terminfo, or they should.
> My problem is that while the clear-screen part works the
> bold bit only appears in the final input(), not in the
> output message.
> 
> Here is the code:
> 
> #################
> import curses as cur
> cur.setupterm()
> 
> bold = cur.tigetstr('bold')
> cls = cur.tigetstr('clear')
> 
> cur.putp(cls)
> name = input("Hello, what's your name? ")
> 
> cur.putp(bold)
> print("Nice to meet you ", name)
> 
> input("\nHit enter to exit")
> ###############
> 
> I've tried variations on flush both inside and outside
> the print() - both before and after.
> I've tried writing to stdout instead of print, but nothing is working.
> The Hit enter... message is in bold but the Hello... line isn't.
> 
> Does anyone know what's going on and how to fix it.
> 
> I could, of course, jump into full curses but I wanted to
> see if I could use the terminfo stuff directly to retain
> use of regular input() and print() functions.
> 
> -- 
> 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
> 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 



More information about the Python-list mailing list