Skip to content

Commit bea6552

Browse files
Take input/output again as attributes in PromptSession.
(Not recommended for applications to use, but useful for tests).
1 parent 0ca201d commit bea6552

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

prompt_toolkit/shortcuts/prompt.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
)
4242

4343
from prompt_toolkit.application import Application
44-
from prompt_toolkit.application.current import get_app, get_app_session
44+
from prompt_toolkit.application.current import get_app
4545
from prompt_toolkit.auto_suggest import AutoSuggest, DynamicAutoSuggest
4646
from prompt_toolkit.buffer import Buffer
4747
from prompt_toolkit.clipboard import (
@@ -316,6 +316,9 @@ class PromptSession:
316316
to enable mouse support.
317317
:param refresh_interval: (number; in seconds) When given, refresh the UI
318318
every so many seconds.
319+
:param input: `Input` object. (Note that the preferred way to change the
320+
input/output is by creating an `AppSession`.)
321+
:param output: `Output` object.
319322
"""
320323
_fields = (
321324
'message', 'lexer', 'completer', 'complete_in_thread', 'is_password',
@@ -367,7 +370,10 @@ def __init__(
367370
erase_when_done: bool = False,
368371
tempfile_suffix: str = '.txt',
369372

370-
refresh_interval: float = 0) -> None:
373+
refresh_interval: float = 0,
374+
375+
input: Optional[Input] = None,
376+
output: Optional[Output] = None) -> None:
371377

372378
history = history or InMemoryHistory()
373379
clipboard = clipboard or InMemoryClipboard()
@@ -377,6 +383,8 @@ def __init__(
377383
editing_mode = EditingMode.VI
378384

379385
# Store all settings in this class.
386+
self._input = input
387+
self._output = output
380388

381389
# Store attributes.
382390
# (All except 'editing_mode'.)
@@ -654,6 +662,8 @@ def _create_application(
654662
erase_when_done=erase_when_done,
655663
reverse_vi_search_direction=True,
656664
color_depth=lambda: self.color_depth,
665+
input=self._input,
666+
output=self._output
657667
)
658668

659669
# During render time, make sure that we focus the right search control
@@ -948,11 +958,11 @@ def _inline_arg(self) -> StyleAndTextTuples:
948958

949959
@property
950960
def input(self) -> Input:
951-
return get_app_session().input
961+
return self.app.input
952962

953963
@property
954964
def output(self) -> Output:
955-
return get_app_session().output
965+
return self.app.output
956966

957967

958968
def prompt(*a, **kw):

0 commit comments

Comments
 (0)