summaryrefslogtreecommitdiffstats
path: root/src/prompt_toolkit/selection.py
blob: a02aa8708cb88a9a62465a37a528ef68a5eac2dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
Data structures for the selection.
"""
from enum import Enum

__all__ = [
    "SelectionType",
    "PasteMode",
    "SelectionState",
]


class SelectionType(Enum):
    """
    Type of selection.
    """

    #: Characters. (Visual in Vi.)
    CHARACTERS = "CHARACTERS"

    #: Whole lines. (Visual-Line in Vi.)
    LINES = "LINES"

    #: A block selection. (Visual-Block in Vi.)
    BLOCK = "BLOCK"


class PasteMode(Enum):
    EMACS = "EMACS"  # Yank like emacs.
    VI_AFTER = "VI_AFTER"  # When pressing 'p' in Vi.
    VI_BEFORE = "VI_BEFORE"  # When pressing 'P' in Vi.


class SelectionState:
    """
    State of the current selection.

    :param original_cursor_position: int
    :param type: :class:`~.SelectionType`
    """

    def __init__(
        self,
        original_cursor_position: int = 0,
        type: SelectionType = SelectionType.CHARACTERS,
    ) -> None:

        self.original_cursor_position = original_cursor_position
        self.type = type
        self.shift_mode = False

    def enter_shift_mode(self) -> None:
        self.shift_mode = True

    def __repr__(self) -> str:
        return "{}(original_cursor_position={!r}, type={!r})".format(
            self.__class__.__name__,
            self.original_cursor_position,
            self.type,
        )