Skip to content

Commit 7325030

Browse files
Fix: make print_container utility work if the input is not a pty.
1 parent 03fbae4 commit 7325030

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

prompt_toolkit/input/base.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from __future__ import unicode_literals
55

66
from abc import ABCMeta, abstractmethod, abstractproperty
7+
from contextlib import contextmanager
78
from six import with_metaclass
89

910
__all__ = [
@@ -111,13 +112,18 @@ def closed(self):
111112
return True
112113

113114
def raw_mode(self):
114-
raise NotImplementedError
115+
return _dummy_context_manager()
115116

116117
def cooked_mode(self):
117-
raise NotImplementedError
118+
return _dummy_context_manager()
118119

119120
def attach(self, input_ready_callback):
120-
raise NotImplementedError
121+
return _dummy_context_manager()
121122

122123
def detach(self):
123-
raise NotImplementedError
124+
return _dummy_context_manager()
125+
126+
127+
@contextmanager
128+
def _dummy_context_manager():
129+
yield

prompt_toolkit/shortcuts/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from prompt_toolkit.application import Application
33
from prompt_toolkit.eventloop import get_event_loop
44
from prompt_toolkit.formatted_text import to_formatted_text, FormattedText
5+
from prompt_toolkit.input import DummyInput
56
from prompt_toolkit.layout import Layout
67
from prompt_toolkit.output import Output, ColorDepth
78
from prompt_toolkit.output.defaults import create_output, get_default_output
@@ -150,7 +151,8 @@ def exit_immediately():
150151

151152
app = Application(
152153
layout=Layout(container=container),
153-
output=output)
154+
output=output,
155+
input=DummyInput())
154156
app.run(pre_run=exit_immediately)
155157

156158

0 commit comments

Comments
 (0)