summaryrefslogtreecommitdiffstats
path: root/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/defaults.py
diff options
context:
space:
mode:
authorshadchin <[email protected]>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/python/prompt-toolkit/py3/prompt_toolkit/output/defaults.py
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
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.py152
1 files changed, 76 insertions, 76 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 e2a1ef95e99..bd4bf950c43 100644
--- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/defaults.py
+++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/defaults.py
@@ -1,31 +1,31 @@
-import sys
-from typing import Optional, TextIO, cast
-
-from prompt_toolkit.utils import (
- get_bell_environment_variable,
- get_term_environment_variable,
- is_conemu_ansi,
- is_windows,
-)
-
+import sys
+from typing import Optional, TextIO, cast
+
+from prompt_toolkit.utils import (
+ get_bell_environment_variable,
+ get_term_environment_variable,
+ is_conemu_ansi,
+ is_windows,
+)
+
from .base import DummyOutput, Output
-from .color_depth import ColorDepth
+from .color_depth import ColorDepth
from .plain_text import PlainTextOutput
-
-__all__ = [
- "create_output",
-]
-
-
-def create_output(
+
+__all__ = [
+ "create_output",
+]
+
+
+def create_output(
stdout: Optional[TextIO] = None, always_prefer_tty: bool = False
-) -> Output:
- """
- Return an :class:`~prompt_toolkit.output.Output` instance for the command
- line.
-
- :param stdout: The stdout object
- :param always_prefer_tty: When set, look for `sys.stderr` if `sys.stdout`
+) -> Output:
+ """
+ Return an :class:`~prompt_toolkit.output.Output` instance for the command
+ line.
+
+ :param stdout: The stdout object
+ :param always_prefer_tty: When set, look for `sys.stderr` if `sys.stdout`
is not a TTY. Useful if `sys.stdout` is redirected to a file, but we
still want user input and output on the terminal.
@@ -33,26 +33,26 @@ def create_output(
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
- # the default that's used if the Application doesn't override it.
- term_from_env = get_term_environment_variable()
- bell_from_env = get_bell_environment_variable()
- color_depth_from_env = ColorDepth.from_env()
-
- if stdout is None:
- # By default, render to stdout. If the output is piped somewhere else,
- # render to stderr.
- stdout = sys.stdout
-
- if always_prefer_tty:
- for io in [sys.stdout, sys.stderr]:
+ """
+ # Consider TERM, PROMPT_TOOLKIT_BELL, and PROMPT_TOOLKIT_COLOR_DEPTH
+ # environment variables. Notice that PROMPT_TOOLKIT_COLOR_DEPTH value is
+ # the default that's used if the Application doesn't override it.
+ term_from_env = get_term_environment_variable()
+ bell_from_env = get_bell_environment_variable()
+ color_depth_from_env = ColorDepth.from_env()
+
+ if stdout is None:
+ # By default, render to stdout. If the output is piped somewhere else,
+ # render to stderr.
+ stdout = sys.stdout
+
+ if always_prefer_tty:
+ for io in [sys.stdout, sys.stderr]:
if io is not None and io.isatty():
# (This is `None` when using `pythonw.exe` on Windows.)
- stdout = io
- break
-
+ 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
@@ -60,42 +60,42 @@ def create_output(
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.
- from prompt_toolkit.patch_stdout import StdoutProxy
-
- while isinstance(stdout, StdoutProxy):
- stdout = stdout.original_stdout
-
- if is_windows():
- from .conemu import ConEmuOutput
- from .win32 import Win32Output
- from .windows10 import Windows10_Output, is_win_vt100_enabled
-
- if is_win_vt100_enabled():
- return cast(
- Output,
- Windows10_Output(stdout, default_color_depth=color_depth_from_env),
- )
- if is_conemu_ansi():
- return cast(
- Output, ConEmuOutput(stdout, default_color_depth=color_depth_from_env)
- )
- else:
- return Win32Output(stdout, default_color_depth=color_depth_from_env)
- else:
- from .vt100 import Vt100_Output
-
+ # 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.
+ from prompt_toolkit.patch_stdout import StdoutProxy
+
+ while isinstance(stdout, StdoutProxy):
+ stdout = stdout.original_stdout
+
+ if is_windows():
+ from .conemu import ConEmuOutput
+ from .win32 import Win32Output
+ from .windows10 import Windows10_Output, is_win_vt100_enabled
+
+ if is_win_vt100_enabled():
+ return cast(
+ Output,
+ Windows10_Output(stdout, default_color_depth=color_depth_from_env),
+ )
+ if is_conemu_ansi():
+ return cast(
+ Output, ConEmuOutput(stdout, default_color_depth=color_depth_from_env)
+ )
+ else:
+ return Win32Output(stdout, default_color_depth=color_depth_from_env)
+ 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,
- default_color_depth=color_depth_from_env,
- enable_bell=bell_from_env,
- )
+ return Vt100_Output.from_pty(
+ stdout,
+ term=term_from_env,
+ default_color_depth=color_depth_from_env,
+ enable_bell=bell_from_env,
+ )