jquast / blessed

Blessed is an easy, practical library for making python terminal apps

Home Page:http://pypi.python.org/pypi/blessed

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

inkey() blocks previous print if it hasn't got a newline

SirRhynus opened this issue · comments

When Terminal.inkey() is called after a print statement without newline, that print statement won't show up until after the key has been pressed.
For example:

print('>>>', end='')
term.inkey()

This will print '>>>' only after enter has been pressed. When '\n' is in the print statement like:

print('\n>>>', end='')
term.inkey()

This will first print '>>>' before getting the inkey().
I'm currently using a temporary fix by calling:

print('\n' + term.move_up(1) + '>>>', end='')
term.inkey()

Use argument, flush=True, to the function call to print without a newline

https://stackoverflow.com/questions/1716296/why-does-printf-not-flush-after-the-call-unless-a-newline-is-in-the-format-strin

From https://linux.die.net/man/3/stderr

The stream stderr is unbuffered. The stream stdout is line-buffered when it points to a terminal. Partial lines will not appear until fflush(3) or exit(3) is called,

I often make a “partial function” for this purpose,

https://github.com/jquast/blessed/blob/master/bin/worms.py#L23