diff options
| author | robot-piglet <[email protected]> | 2024-10-12 10:39:22 +0300 |
|---|---|---|
| committer | robot-piglet <[email protected]> | 2024-10-12 10:50:34 +0300 |
| commit | b904316f22d889171e7fe39e8c467cbea5c6cdd6 (patch) | |
| tree | 84c870d76f7278ad6a8d1c020a8b950edb7d531e /contrib/python/prompt-toolkit/py3/prompt_toolkit/output/defaults.py | |
| parent | e493167a2cecbdc68258d70ddb044e7a0f56aa7f (diff) | |
Intermediate changes
commit_hash:3ed72e620c7eace6c8edd510ac2324e8acfcfafb
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 | 22 |
1 files changed, 13 insertions, 9 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 ed114e32af5..6b06ed43c88 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/defaults.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/defaults.py @@ -1,7 +1,7 @@ from __future__ import annotations import sys -from typing import TextIO, cast +from typing import TYPE_CHECKING, TextIO, cast from prompt_toolkit.utils import ( get_bell_environment_variable, @@ -13,13 +13,17 @@ from .base import DummyOutput, Output from .color_depth import ColorDepth from .plain_text import PlainTextOutput +if TYPE_CHECKING: + from prompt_toolkit.patch_stdout import StdoutProxy + + __all__ = [ "create_output", ] def create_output( - stdout: TextIO | None = None, always_prefer_tty: bool = False + stdout: TextIO | StdoutProxy | None = None, always_prefer_tty: bool = False ) -> Output: """ Return an :class:`~prompt_toolkit.output.Output` instance for the command @@ -54,13 +58,6 @@ def create_output( stdout = io break - # If the output is still `None`, use a DummyOutput. - # This happens for instance on Windows, when running the application under - # `pythonw.exe`. In that case, there won't be a terminal Window, and - # stdin/stdout/stderr are `None`. - if stdout is None: - return DummyOutput() - # If the patch_stdout context manager has been used, then sys.stdout is # replaced by this proxy. For prompt_toolkit applications, we want to use # the real stdout. @@ -69,6 +66,13 @@ def create_output( while isinstance(stdout, StdoutProxy): stdout = stdout.original_stdout + # If the output is still `None`, use a DummyOutput. + # This happens for instance on Windows, when running the application under + # `pythonw.exe`. In that case, there won't be a terminal Window, and + # stdin/stdout/stderr are `None`. + if stdout is None: + return DummyOutput() + if sys.platform == "win32": from .conemu import ConEmuOutput from .win32 import Win32Output |
