|
34 | 34 | ThreadedCompleter, |
35 | 35 | merge_completers, |
36 | 36 | ) |
| 37 | +from prompt_toolkit.cursor_shapes import ( |
| 38 | + AnyCursorShapeConfig, |
| 39 | + CursorShape, |
| 40 | + DynamicCursorShapeConfig, |
| 41 | + ModalCursorShapeConfig, |
| 42 | +) |
37 | 43 | from prompt_toolkit.document import Document |
38 | 44 | from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode |
39 | 45 | from prompt_toolkit.filters import Condition |
@@ -325,6 +331,18 @@ def __init__( |
325 | 331 | self.search_buffer: Buffer = Buffer() |
326 | 332 | self.docstring_buffer: Buffer = Buffer(read_only=True) |
327 | 333 |
|
| 334 | + # Cursor shapes. |
| 335 | + self.cursor_shape_config = "Block" |
| 336 | + self.all_cursor_shape_configs: Dict[str, AnyCursorShapeConfig] = { |
| 337 | + "Block": CursorShape.BLOCK, |
| 338 | + "Underline": CursorShape.UNDERLINE, |
| 339 | + "Beam": CursorShape.BEAM, |
| 340 | + "Modal (vi)": ModalCursorShapeConfig(), |
| 341 | + "Blink block": CursorShape.BLINKING_BLOCK, |
| 342 | + "Blink under": CursorShape.BLINKING_UNDERLINE, |
| 343 | + "Blink beam": CursorShape.BLINKING_BEAM, |
| 344 | + } |
| 345 | + |
328 | 346 | # Tokens to be shown at the prompt. |
329 | 347 | self.prompt_style: str = "classic" # The currently active style. |
330 | 348 |
|
@@ -584,6 +602,16 @@ def get_values() -> dict[str, Callable[[], bool]]: |
584 | 602 | "Vi": lambda: enable("vi_mode"), |
585 | 603 | }, |
586 | 604 | ), |
| 605 | + Option( |
| 606 | + title="Cursor shape", |
| 607 | + description="Change the cursor style, possibly according " |
| 608 | + "to the Vi input mode.", |
| 609 | + get_current_value=lambda: self.cursor_shape_config, |
| 610 | + get_values=lambda: dict( |
| 611 | + (s, partial(enable, "cursor_shape_config", s)) |
| 612 | + for s in self.all_cursor_shape_configs |
| 613 | + ), |
| 614 | + ), |
587 | 615 | simple_option( |
588 | 616 | title="Paste mode", |
589 | 617 | description="When enabled, don't indent automatically.", |
@@ -896,6 +924,9 @@ def _create_application( |
896 | 924 | style_transformation=self.style_transformation, |
897 | 925 | include_default_pygments_style=False, |
898 | 926 | reverse_vi_search_direction=True, |
| 927 | + cursor=DynamicCursorShapeConfig( |
| 928 | + lambda: self.all_cursor_shape_configs[self.cursor_shape_config] |
| 929 | + ), |
899 | 930 | input=input, |
900 | 931 | output=output, |
901 | 932 | ) |
|
0 commit comments