##// END OF EJS Templates
cursor shape changes with vi editing mode
Martin Skarzynski -
Show More
@@ -12,8 +12,19 b' from IPython.utils.py3compat import input'
12 from IPython.utils.terminal import toggle_set_term_title, set_term_title, restore_term_title
12 from IPython.utils.terminal import toggle_set_term_title, set_term_title, restore_term_title
13 from IPython.utils.process import abbrev_cwd
13 from IPython.utils.process import abbrev_cwd
14 from traitlets import (
14 from traitlets import (
15 Bool, Unicode, Dict, Integer, observe, Instance, Type, default, Enum, Union,
15 Bool,
16 Any, validate
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 from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode
30 from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode
@@ -142,6 +153,25 b' class TerminalInteractiveShell(InteractiveShell):'
142 help="Add shortcuts from 'emacs' insert mode to 'vi' insert mode.",
153 help="Add shortcuts from 'emacs' insert mode to 'vi' insert mode.",
143 ).tag(config=True)
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 autoformatter = Unicode(None,
175 autoformatter = Unicode(None,
146 help="Autoformatter to reformat Terminal code. Can be `'black'` or `None`",
176 help="Autoformatter to reformat Terminal code. Can be `'black'` or `None`",
147 allow_none=True
177 allow_none=True
@@ -19,6 +19,7 b' from prompt_toolkit.filters import (has_focus, has_selection, Condition,'
19 from prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline
19 from prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline
20 from prompt_toolkit.key_binding import KeyBindings
20 from prompt_toolkit.key_binding import KeyBindings
21 from prompt_toolkit.key_binding.bindings import named_commands as nc
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 from IPython.utils.decorators import undoc
24 from IPython.utils.decorators import undoc
24
25
@@ -160,6 +161,32 b' def create_ipython_shortcuts(shell):'
160 for keys, cmd in keys_cmd_dict.items():
161 for keys, cmd in keys_cmd_dict.items():
161 kb.add(*keys, filter=focused_insert & ebivim)(cmd)
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 return kb
190 return kb
164
191
165
192
@@ -341,4 +368,4 b" if sys.platform == 'win32':"
341 return
368 return
342 except ClipboardEmpty:
369 except ClipboardEmpty:
343 return
370 return
344 event.current_buffer.insert_text(text.replace('\t', ' ' * 4))
371 event.current_buffer.insert_text(text.replace("\t", " " * 4))
General Comments 0
You need to be logged in to leave comments. Login now