Show More
@@ -12,8 +12,19 b' from IPython.utils.py3compat import input' | |||
|
12 | 12 | from IPython.utils.terminal import toggle_set_term_title, set_term_title, restore_term_title |
|
13 | 13 | from IPython.utils.process import abbrev_cwd |
|
14 | 14 | from traitlets import ( |
|
15 | Bool, Unicode, Dict, Integer, observe, Instance, Type, default, Enum, Union, | |
|
16 | Any, validate | |
|
15 | Bool, | |
|
16 | Unicode, | |
|
17 | Dict, | |
|
18 | Integer, | |
|
19 | observe, | |
|
20 | Instance, | |
|
21 | Type, | |
|
22 | default, | |
|
23 | Enum, | |
|
24 | Union, | |
|
25 | Any, | |
|
26 | validate, | |
|
27 | Float, | |
|
17 | 28 | ) |
|
18 | 29 | |
|
19 | 30 | from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode |
@@ -142,6 +153,25 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
142 | 153 | help="Add shortcuts from 'emacs' insert mode to 'vi' insert mode.", |
|
143 | 154 | ).tag(config=True) |
|
144 | 155 | |
|
156 | modal_cursor = Bool( | |
|
157 | True, | |
|
158 | help=""" | |
|
159 | Cursor shape changes depending on vi mode: beam in vi insert mode, | |
|
160 | block in nav mode, underscore in replace mode.""", | |
|
161 | ).tag(config=True) | |
|
162 | ||
|
163 | ttimeoutlen = Float( | |
|
164 | 0.01, | |
|
165 | help="""The time in milliseconds that is waited for a key code | |
|
166 | to complete.""", | |
|
167 | ).tag(config=True) | |
|
168 | ||
|
169 | timeoutlen = Float( | |
|
170 | 0.5, | |
|
171 | help="""The time in milliseconds that is waited for a mapped key | |
|
172 | sequence to complete.""", | |
|
173 | ).tag(config=True) | |
|
174 | ||
|
145 | 175 | autoformatter = Unicode(None, |
|
146 | 176 | help="Autoformatter to reformat Terminal code. Can be `'black'` or `None`", |
|
147 | 177 | allow_none=True |
@@ -19,6 +19,7 b' from prompt_toolkit.filters import (has_focus, has_selection, Condition,' | |||
|
19 | 19 | from prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline |
|
20 | 20 | from prompt_toolkit.key_binding import KeyBindings |
|
21 | 21 | from prompt_toolkit.key_binding.bindings import named_commands as nc |
|
22 | from prompt_toolkit.key_binding.vi_state import InputMode, ViState | |
|
22 | 23 | |
|
23 | 24 | from IPython.utils.decorators import undoc |
|
24 | 25 | |
@@ -160,6 +161,32 b' def create_ipython_shortcuts(shell):' | |||
|
160 | 161 | for keys, cmd in keys_cmd_dict.items(): |
|
161 | 162 | kb.add(*keys, filter=focused_insert & ebivim)(cmd) |
|
162 | 163 | |
|
164 | def get_input_mode(self): | |
|
165 | if sys.version_info[0] == 3: | |
|
166 | app = get_app() | |
|
167 | app.ttimeoutlen = shell.ttimeoutlen | |
|
168 | app.timeoutlen = shell.timeoutlen | |
|
169 | ||
|
170 | return self._input_mode | |
|
171 | ||
|
172 | def set_input_mode(self, mode): | |
|
173 | shape = {InputMode.NAVIGATION: 2, InputMode.REPLACE: 4}.get(mode, 6) | |
|
174 | cursor = "\x1b[{} q".format(shape) | |
|
175 | ||
|
176 | if hasattr(sys.stdout, "_cli"): | |
|
177 | write = sys.stdout._cli.output.write_raw | |
|
178 | else: | |
|
179 | write = sys.stdout.write | |
|
180 | ||
|
181 | write(cursor) | |
|
182 | sys.stdout.flush() | |
|
183 | ||
|
184 | self._input_mode = mode | |
|
185 | ||
|
186 | if shell.editing_mode == "vi" and shell.modal_cursor: | |
|
187 | ViState._input_mode = InputMode.INSERT | |
|
188 | ViState.input_mode = property(get_input_mode, set_input_mode) | |
|
189 | ||
|
163 | 190 | return kb |
|
164 | 191 | |
|
165 | 192 | |
@@ -341,4 +368,4 b" if sys.platform == 'win32':" | |||
|
341 | 368 | return |
|
342 | 369 | except ClipboardEmpty: |
|
343 | 370 | return |
|
344 |
event.current_buffer.insert_text(text.replace( |
|
|
371 | event.current_buffer.insert_text(text.replace("\t", " " * 4)) |
@@ -41,12 +41,14 b' def multi_filter_str(flt):' | |||
|
41 | 41 | log_filters = {'_AndList': 'And', '_OrList': 'Or'} |
|
42 | 42 | log_invert = {'_Invert'} |
|
43 | 43 | |
|
44 |
class _DummyTerminal |
|
|
44 | class _DummyTerminal: | |
|
45 | 45 | """Used as a buffer to get prompt_toolkit bindings |
|
46 | 46 | """ |
|
47 | 47 | handle_return = None |
|
48 | 48 | input_transformer_manager = None |
|
49 | 49 | display_completions = None |
|
50 | editing_mode = "emacs" | |
|
51 | ||
|
50 | 52 | |
|
51 | 53 | ipy_bindings = create_ipython_shortcuts(_DummyTerminal()).bindings |
|
52 | 54 |
General Comments 0
You need to be logged in to leave comments.
Login now