Skip to content

Commit b67d014

Browse files
Render by default to stderr if stdout is redirected.
1 parent 795d866 commit b67d014

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

prompt_toolkit/output/defaults.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ def create_output(stdout: Optional[TextIO] = None) -> Output:
2121
2222
:param stdout: The stdout object
2323
"""
24-
stdout = stdout or sys.__stdout__
24+
if stdout is None:
25+
# By default, render to stdout. If the output is piped somewhere else,
26+
# render to stderr. The prompt_toolkit render output is not meant to be
27+
# consumed by something other then a terminal, so this is a reasonable
28+
# default.
29+
if sys.stdout.isatty():
30+
stdout = sys.stdout
31+
else:
32+
stdout = sys.stderr
2533

2634
if is_windows():
2735
from .conemu import ConEmuOutput

0 commit comments

Comments
 (0)