Skip to content

Commit 67c4aee

Browse files
A few bug fixes for patch_stdout.
1 parent 3dd5923 commit 67c4aee

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

examples/prompts/asyncio-prompt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def interactive_shell():
4343
# Run echo loop. Read text from stdin, and reply it back.
4444
while True:
4545
try:
46-
result = await session.prompt(async_=True)
46+
result = await session.prompt_async()
4747
print('You said: "{0}"'.format(result))
4848
except (EOFError, KeyboardInterrupt):
4949
return

prompt_toolkit/output/defaults.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
from typing import Optional, TextIO, cast
33

4+
from prompt_toolkit.patch_stdout import StdoutProxy
45
from prompt_toolkit.utils import (
56
get_term_environment_variable,
67
is_conemu_ansi,
@@ -31,6 +32,12 @@ def create_output(stdout: Optional[TextIO] = None) -> Output:
3132
else:
3233
stdout = sys.stderr
3334

35+
# If the patch_stdout context manager has been used, then sys.stdout is
36+
# replaced by this proxy. For prompt_toolkit applications, we want to use
37+
# the real stdout.
38+
while isinstance(stdout, StdoutProxy):
39+
stdout = stdout.original_stdout
40+
3441
if is_windows():
3542
from .conemu import ConEmuOutput
3643
from .win32 import Win32Output

prompt_toolkit/patch_stdout.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def write_and_flush() -> None:
102102
def write_and_flush_in_loop() -> None:
103103
# If an application is running, use `run_in_terminal`, otherwise
104104
# call it directly.
105-
run_in_terminal(write_and_flush, in_executor=False)
105+
run_in_terminal.run_in_terminal(write_and_flush, in_executor=False)
106106

107107
# Make sure `write_and_flush` is executed *in* the event loop, not in
108108
# another thread.
@@ -155,3 +155,6 @@ def fileno(self) -> int:
155155
"""
156156
# This is important for code that expects sys.stdout.fileno() to work.
157157
return self.original_stdout.fileno()
158+
159+
def isatty(self) -> bool:
160+
return self.original_stdout.isatty()

0 commit comments

Comments
 (0)