diff options
author | arcadia-devtools <[email protected]> | 2022-02-08 15:26:58 +0300 |
---|---|---|
committer | arcadia-devtools <[email protected]> | 2022-02-08 15:26:58 +0300 |
commit | 2efaaefec2cb2a55d55c01753d1eed2a3296adb5 (patch) | |
tree | 27ec5258b325565c3963b91b36d64e84084fdb04 /contrib/python/prompt-toolkit/py3/prompt_toolkit/output/defaults.py | |
parent | 23793c5d0827a08b5ff9242d2123eff92b681912 (diff) |
intermediate changes
ref:0bfa27bb6c38df8c510497e54e4ebf0b4fb84503
Diffstat (limited to 'contrib/python/prompt-toolkit/py3/prompt_toolkit/output/defaults.py')
-rw-r--r-- | contrib/python/prompt-toolkit/py3/prompt_toolkit/output/defaults.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/defaults.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/defaults.py index fc107a4d6ed..bd4bf950c43 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/defaults.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/defaults.py @@ -10,6 +10,7 @@ from prompt_toolkit.utils import ( from .base import DummyOutput, Output from .color_depth import ColorDepth +from .plain_text import PlainTextOutput __all__ = [ "create_output", @@ -17,7 +18,7 @@ __all__ = [ def create_output( - stdout: Optional[TextIO] = None, always_prefer_tty: bool = True + stdout: Optional[TextIO] = None, always_prefer_tty: bool = False ) -> Output: """ Return an :class:`~prompt_toolkit.output.Output` instance for the command @@ -25,9 +26,13 @@ def create_output( :param stdout: The stdout object :param always_prefer_tty: When set, look for `sys.stderr` if `sys.stdout` - is not a TTY. (The prompt_toolkit render output is not meant to be - consumed by something other then a terminal, so this is a reasonable - default.) + is not a TTY. Useful if `sys.stdout` is redirected to a file, but we + still want user input and output on the terminal. + + By default, this is `False`. If `sys.stdout` is not a terminal (maybe + it's redirected to a file), then a `PlainTextOutput` will be returned. + That way, tools like `print_formatted_text` will write plain text into + that file. """ # Consider TERM, PROMPT_TOOLKIT_BELL, and PROMPT_TOOLKIT_COLOR_DEPTH # environment variables. Notice that PROMPT_TOOLKIT_COLOR_DEPTH value is @@ -82,6 +87,12 @@ def create_output( else: from .vt100 import Vt100_Output + # Stdout is not a TTY? Render as plain text. + # This is mostly useful if stdout is redirected to a file, and + # `print_formatted_text` is used. + if not stdout.isatty(): + return PlainTextOutput(stdout) + return Vt100_Output.from_pty( stdout, term=term_from_env, |