Show More
@@ -52,8 +52,9 b' class TestFileToRun(unittest.TestCase, tt.TempFileMixin):' | |||
|
52 | 52 | src = "True\n" |
|
53 | 53 | self.mktmp(src) |
|
54 | 54 | |
|
55 | out = 'In [1]: False\n\nIn [2]:' | |
|
55 | 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 | 58 | commands=['"__file__" in globals()', 'exit()']) |
|
58 | 59 | |
|
59 | 60 | @dec.skip_win32 |
@@ -63,6 +64,7 b' class TestFileToRun(unittest.TestCase, tt.TempFileMixin):' | |||
|
63 | 64 | src = "from __future__ import division\n" |
|
64 | 65 | self.mktmp(src) |
|
65 | 66 | |
|
67 | out = 'In [1]: float\n\nIn [2]:' | |
|
66 | 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 | 70 | commands=['type(1/2)', 'exit()']) |
@@ -4,7 +4,7 b' from __future__ import print_function' | |||
|
4 | 4 | import sys |
|
5 | 5 | |
|
6 | 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 | 8 | from traitlets import Bool, Unicode, Dict |
|
9 | 9 | |
|
10 | 10 | from prompt_toolkit.completion import Completer, Completion |
@@ -83,6 +83,14 b' class PTInteractiveShell(InteractiveShell):' | |||
|
83 | 83 | ] |
|
84 | 84 | |
|
85 | 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 | 94 | kbmanager = KeyBindingManager.for_prompt(enable_vi_mode=self.vi_mode) |
|
87 | 95 | insert_mode = ViStateFilter(kbmanager.get_vi_state, InputMode.INSERT) |
|
88 | 96 | # Ctrl+J == Enter, seemingly |
@@ -160,6 +168,10 b' class PTInteractiveShell(InteractiveShell):' | |||
|
160 | 168 | self.pt_cli = CommandLineInterface(app, |
|
161 | 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 | 175 | def init_io(self): |
|
164 | 176 | if sys.platform not in {'win32', 'cli'}: |
|
165 | 177 | return |
@@ -194,14 +206,14 b' class PTInteractiveShell(InteractiveShell):' | |||
|
194 | 206 | print(self.separate_in, end='') |
|
195 | 207 | |
|
196 | 208 | try: |
|
197 | document = self.pt_cli.run(pre_run=self.pre_prompt) | |
|
209 | code = self.prompt_for_code() | |
|
198 | 210 | except EOFError: |
|
199 | 211 | if self.ask_yes_no('Do you really want to exit ([y]/n)?','y','n'): |
|
200 | 212 | self.ask_exit() |
|
201 | 213 | |
|
202 | 214 | else: |
|
203 |
if |
|
|
204 |
self.run_cell( |
|
|
215 | if code: | |
|
216 | self.run_cell(code, store_history=True) | |
|
205 | 217 | |
|
206 | 218 | def mainloop(self): |
|
207 | 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