Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/prompt_toolkit/selection.py: 76%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

21 statements  

1""" 

2Data structures for the selection. 

3""" 

4 

5from __future__ import annotations 

6 

7from enum import Enum 

8 

9__all__ = [ 

10 "SelectionType", 

11 "PasteMode", 

12 "SelectionState", 

13] 

14 

15 

16class SelectionType(Enum): 

17 """ 

18 Type of selection. 

19 """ 

20 

21 #: Characters. (Visual in Vi.) 

22 CHARACTERS = "CHARACTERS" 

23 

24 #: Whole lines. (Visual-Line in Vi.) 

25 LINES = "LINES" 

26 

27 #: A block selection. (Visual-Block in Vi.) 

28 BLOCK = "BLOCK" 

29 

30 

31class PasteMode(Enum): 

32 EMACS = "EMACS" # Yank like emacs. 

33 VI_AFTER = "VI_AFTER" # When pressing 'p' in Vi. 

34 VI_BEFORE = "VI_BEFORE" # When pressing 'P' in Vi. 

35 

36 

37class SelectionState: 

38 """ 

39 State of the current selection. 

40 

41 :param original_cursor_position: int 

42 :param type: :class:`~.SelectionType` 

43 """ 

44 

45 def __init__( 

46 self, 

47 original_cursor_position: int = 0, 

48 type: SelectionType = SelectionType.CHARACTERS, 

49 ) -> None: 

50 self.original_cursor_position = original_cursor_position 

51 self.type = type 

52 self.shift_mode = False 

53 

54 def enter_shift_mode(self) -> None: 

55 self.shift_mode = True 

56 

57 def __repr__(self) -> str: 

58 return f"{self.__class__.__name__}(original_cursor_position={self.original_cursor_position!r}, type={self.type!r})"