41
41
)
42
42
43
43
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
45
45
from prompt_toolkit .auto_suggest import AutoSuggest , DynamicAutoSuggest
46
46
from prompt_toolkit .buffer import Buffer
47
47
from prompt_toolkit .clipboard import (
@@ -316,6 +316,9 @@ class PromptSession:
316
316
to enable mouse support.
317
317
:param refresh_interval: (number; in seconds) When given, refresh the UI
318
318
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.
319
322
"""
320
323
_fields = (
321
324
'message' , 'lexer' , 'completer' , 'complete_in_thread' , 'is_password' ,
@@ -367,7 +370,10 @@ def __init__(
367
370
erase_when_done : bool = False ,
368
371
tempfile_suffix : str = '.txt' ,
369
372
370
- refresh_interval : float = 0 ) -> None :
373
+ refresh_interval : float = 0 ,
374
+
375
+ input : Optional [Input ] = None ,
376
+ output : Optional [Output ] = None ) -> None :
371
377
372
378
history = history or InMemoryHistory ()
373
379
clipboard = clipboard or InMemoryClipboard ()
@@ -377,6 +383,8 @@ def __init__(
377
383
editing_mode = EditingMode .VI
378
384
379
385
# Store all settings in this class.
386
+ self ._input = input
387
+ self ._output = output
380
388
381
389
# Store attributes.
382
390
# (All except 'editing_mode'.)
@@ -654,6 +662,8 @@ def _create_application(
654
662
erase_when_done = erase_when_done ,
655
663
reverse_vi_search_direction = True ,
656
664
color_depth = lambda : self .color_depth ,
665
+ input = self ._input ,
666
+ output = self ._output
657
667
)
658
668
659
669
# During render time, make sure that we focus the right search control
@@ -948,11 +958,11 @@ def _inline_arg(self) -> StyleAndTextTuples:
948
958
949
959
@property
950
960
def input (self ) -> Input :
951
- return get_app_session () .input
961
+ return self . app .input
952
962
953
963
@property
954
964
def output (self ) -> Output :
955
- return get_app_session () .output
965
+ return self . app .output
956
966
957
967
958
968
def prompt (* a , ** kw ):
0 commit comments