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