Closed jmkd3v closed 3 years ago
I'll try to take a look, but can you send a minimal code sample illustrating the behavior?
Sure.
from blessed import Terminal
from sys import stdout
terminal = Terminal()
# This will not work:
with terminal.cbreak():
stdout.write("ABCDEFG > ")
key = terminal.inkey()
stdout.write(str(key))
# This will work:
with terminal.cbreak():
print("ABCDEFG > ")
key = terminal.inkey()
print(str(key))
Running 3.9.0 (Choco install) on Windows 10.0.19041, this works as expected, no new line needed. Exact same output as on Linux.
ABCDEFG > 3ABCDEFG >
3
I'm still not sure what you're trying to do. There is no difference related to cbreak or inkey in your two examples. The only difference is the way you are outputting to STDOUT, but cbreak operates on STDIN.
Ah, I see. I believe I have misunderstood the documentation. Thank you very much for the help.
If you need to print without newline, empty the "end" argument to print, print("ABCDEFG > ", end='')
(I see this mistake enough it's probably something to clarify in the documentation)
I'm writing a program that has simple yes/no inputs that use
Terminal.inkey()
. It works, however it only updates after a newline is sent. This is an issue, since I'm looking for an output like this:If I try to do this, it only shows the question and the key you entered after a newline character is sent, meaning the only way to get it to work properly was to do something like this:
This is not how it was intended. I looked in the docs and found the context manager
terminal.cbreak()
but it seems to have no effect. I'm still having the same issue where nothing updates until a newline is sent. I'm using it properly, so I don't see why this is happening.I'm on Windows 10
110.0.19042 Build 19042
, usingcmd.exe
with Python 3.9.1 in a venv.