def create_pipe_input(): """ Create an input pipe. This is mostly useful for unit testing. """ if is_windows(): from .win32_pipe import Win32PipeInput return Win32PipeInput() else: from .posix_pipe import PosixPipeInput return PosixPipeInput() _default_input = TaskLocal() def get_default_input(): """ Get the input class to be used by default. Called when creating a new Application(), when no `Input` has been passed. """ # Other create/return the default input. try: value = _default_input.get() except TaskLocalNotSetError: # If an application is already running, take the input from there. # (This is important for the "ENTER for continue" prompts after # executing system commands and displaying readline-style completions.)
from __future__ import unicode_literals from contextlib import contextmanager from prompt_toolkit.eventloop.context import TaskLocal, TaskLocalNotSetError __all__ = [ 'get_app', 'set_app', 'NoRunningApplicationError', ] _current_app = TaskLocal() def get_app(raise_exception=False, return_none=False): """ Get the current active (running) Application. An :class:`.Application` is active during the :meth:`.Application.run_async` call. We assume that there can only be one :class:`.Application` active at the same time. There is only one terminal window, with only one stdin and stdout. This makes the code significantly easier than passing around the :class:`.Application` everywhere. If no :class:`.Application` is running, then return by default a :class:`.DummyApplication`. For practical reasons, we prefer to not raise an exception. This way, we don't have to check all over the place whether an actual `Application` was returned.
return ConEmuOutput(stdout) else: return Win32Output(stdout) else: from .vt100 import Vt100_Output term = os.environ.get('TERM', '') if PY2: term = term.decode('utf-8') return Vt100_Output.from_pty(stdout, true_color=true_color, ansi_colors_only=ansi_colors_only, term=term) _default_output = TaskLocal() def get_default_output(): """ Get the output class to be used by default. Called when creating a new Application(), when no `Output` has been passed. """ try: value = _default_output.get() except TaskLocalNotSetError: return create_output() else: return value