|
| 1 | +import sys |
| 2 | + |
1 | 3 | from prompt_toolkit.application import get_app
|
2 | 4 | from prompt_toolkit.document import Document
|
3 | 5 | from prompt_toolkit.enums import DEFAULT_BUFFER
|
|
11 | 13 | )
|
12 | 14 | from prompt_toolkit.key_binding import KeyBindings
|
13 | 15 | from prompt_toolkit.keys import Keys
|
| 16 | +from prompt_toolkit.key_binding.vi_state import InputMode, ViState |
14 | 17 |
|
15 | 18 | from .utils import document_is_multiline_python
|
16 | 19 |
|
@@ -201,6 +204,35 @@ def _(event):
|
201 | 204 | " Abort when Control-C has been pressed. "
|
202 | 205 | event.app.exit(exception=KeyboardInterrupt, style="class:aborting")
|
203 | 206 |
|
| 207 | + |
| 208 | + |
| 209 | + def get_input_mode(self): |
| 210 | + if sys.version_info[0] == 3: |
| 211 | + app = get_app() |
| 212 | + app.ttimeoutlen = python_input.ttimeoutlen |
| 213 | + app.timeoutlen = python_input.timeoutlen |
| 214 | + |
| 215 | + return self._input_mode |
| 216 | + |
| 217 | + |
| 218 | + def set_input_mode(self, mode): |
| 219 | + shape = {InputMode.NAVIGATION: 2, InputMode.REPLACE: 4}.get(mode, 6) |
| 220 | + cursor = "\x1b[{} q".format(shape) |
| 221 | + |
| 222 | + if hasattr(sys.stdout, "_cli"): |
| 223 | + write = sys.stdout._cli.output.write_raw |
| 224 | + else: |
| 225 | + write = sys.stdout.write |
| 226 | + |
| 227 | + write(cursor) |
| 228 | + sys.stdout.flush() |
| 229 | + |
| 230 | + self._input_mode = mode |
| 231 | + |
| 232 | + if python_input.enable_modal_cursor: |
| 233 | + ViState._input_mode = InputMode.INSERT |
| 234 | + ViState.input_mode = property(get_input_mode, set_input_mode) |
| 235 | + |
204 | 236 | return bindings
|
205 | 237 |
|
206 | 238 |
|
|
0 commit comments