Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render by default to stderr if stdout is redirected. #899

Merged
merged 1 commit into from
Jun 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion prompt_toolkit/output/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ def create_output(stdout: Optional[TextIO] = None) -> Output:

:param stdout: The stdout object
"""
stdout = stdout or sys.__stdout__
if stdout is None:
# By default, render to stdout. If the output is piped somewhere else,
# render to stderr. The prompt_toolkit render output is not meant to be
# consumed by something other then a terminal, so this is a reasonable
# default.
if sys.stdout.isatty():
stdout = sys.stdout
else:
stdout = sys.stderr

if is_windows():
from .conemu import ConEmuOutput
Expand Down