Show More
@@ -52,8 +52,9 b' class TestFileToRun(unittest.TestCase, tt.TempFileMixin):' | |||||
52 | src = "True\n" |
|
52 | src = "True\n" | |
53 | self.mktmp(src) |
|
53 | self.mktmp(src) | |
54 |
|
54 | |||
|
55 | out = 'In [1]: False\n\nIn [2]:' | |||
55 | err = SQLITE_NOT_AVAILABLE_ERROR if sqlite_err_maybe else None |
|
56 | err = SQLITE_NOT_AVAILABLE_ERROR if sqlite_err_maybe else None | |
56 |
tt.ipexec_validate(self.fname, |
|
57 | tt.ipexec_validate(self.fname, out, err, options=['-i'], | |
57 | commands=['"__file__" in globals()', 'exit()']) |
|
58 | commands=['"__file__" in globals()', 'exit()']) | |
58 |
|
59 | |||
59 | @dec.skip_win32 |
|
60 | @dec.skip_win32 | |
@@ -63,6 +64,7 b' class TestFileToRun(unittest.TestCase, tt.TempFileMixin):' | |||||
63 | src = "from __future__ import division\n" |
|
64 | src = "from __future__ import division\n" | |
64 | self.mktmp(src) |
|
65 | self.mktmp(src) | |
65 |
|
66 | |||
|
67 | out = 'In [1]: float\n\nIn [2]:' | |||
66 | err = SQLITE_NOT_AVAILABLE_ERROR if sqlite_err_maybe else None |
|
68 | err = SQLITE_NOT_AVAILABLE_ERROR if sqlite_err_maybe else None | |
67 |
tt.ipexec_validate(self.fname, |
|
69 | tt.ipexec_validate(self.fname, out, err, options=['-i'], | |
68 | commands=['type(1/2)', 'exit()']) |
|
70 | commands=['type(1/2)', 'exit()']) |
@@ -4,7 +4,7 b' from __future__ import print_function' | |||||
4 | import sys |
|
4 | import sys | |
5 |
|
5 | |||
6 | from IPython.core.interactiveshell import InteractiveShell |
|
6 | from IPython.core.interactiveshell import InteractiveShell | |
7 | from IPython.utils.py3compat import PY3, cast_unicode_py2 |
|
7 | from IPython.utils.py3compat import PY3, cast_unicode_py2, input | |
8 | from traitlets import Bool, Unicode, Dict |
|
8 | from traitlets import Bool, Unicode, Dict | |
9 |
|
9 | |||
10 | from prompt_toolkit.completion import Completer, Completion |
|
10 | from prompt_toolkit.completion import Completer, Completion | |
@@ -83,6 +83,14 b' class PTInteractiveShell(InteractiveShell):' | |||||
83 | ] |
|
83 | ] | |
84 |
|
84 | |||
85 | def init_prompt_toolkit_cli(self): |
|
85 | def init_prompt_toolkit_cli(self): | |
|
86 | if not sys.stdin.isatty(): | |||
|
87 | # Piped input - e.g. for tests. Fall back to plain non-interactive | |||
|
88 | # output. This is very limited, and only accepts a single line. | |||
|
89 | def prompt(): | |||
|
90 | return cast_unicode_py2(input('In [%d]: ' % self.execution_count)) | |||
|
91 | self.prompt_for_code = prompt | |||
|
92 | return | |||
|
93 | ||||
86 | kbmanager = KeyBindingManager.for_prompt(enable_vi_mode=self.vi_mode) |
|
94 | kbmanager = KeyBindingManager.for_prompt(enable_vi_mode=self.vi_mode) | |
87 | insert_mode = ViStateFilter(kbmanager.get_vi_state, InputMode.INSERT) |
|
95 | insert_mode = ViStateFilter(kbmanager.get_vi_state, InputMode.INSERT) | |
88 | # Ctrl+J == Enter, seemingly |
|
96 | # Ctrl+J == Enter, seemingly | |
@@ -160,6 +168,10 b' class PTInteractiveShell(InteractiveShell):' | |||||
160 | self.pt_cli = CommandLineInterface(app, |
|
168 | self.pt_cli = CommandLineInterface(app, | |
161 | eventloop=create_eventloop(self.inputhook)) |
|
169 | eventloop=create_eventloop(self.inputhook)) | |
162 |
|
170 | |||
|
171 | def prompt_for_code(self): | |||
|
172 | document = self.pt_cli.run(pre_run=self.pre_prompt) | |||
|
173 | return document.text | |||
|
174 | ||||
163 | def init_io(self): |
|
175 | def init_io(self): | |
164 | if sys.platform not in {'win32', 'cli'}: |
|
176 | if sys.platform not in {'win32', 'cli'}: | |
165 | return |
|
177 | return | |
@@ -194,14 +206,14 b' class PTInteractiveShell(InteractiveShell):' | |||||
194 | print(self.separate_in, end='') |
|
206 | print(self.separate_in, end='') | |
195 |
|
207 | |||
196 | try: |
|
208 | try: | |
197 | document = self.pt_cli.run(pre_run=self.pre_prompt) |
|
209 | code = self.prompt_for_code() | |
198 | except EOFError: |
|
210 | except EOFError: | |
199 | if self.ask_yes_no('Do you really want to exit ([y]/n)?','y','n'): |
|
211 | if self.ask_yes_no('Do you really want to exit ([y]/n)?','y','n'): | |
200 | self.ask_exit() |
|
212 | self.ask_exit() | |
201 |
|
213 | |||
202 | else: |
|
214 | else: | |
203 |
if |
|
215 | if code: | |
204 |
self.run_cell( |
|
216 | self.run_cell(code, store_history=True) | |
205 |
|
217 | |||
206 | def mainloop(self): |
|
218 | def mainloop(self): | |
207 | # An extra layer of protection in case someone mashing Ctrl-C breaks |
|
219 | # An extra layer of protection in case someone mashing Ctrl-C breaks |
General Comments 0
You need to be logged in to leave comments.
Login now