aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/base.py
blob: 71be6148eb776f893136168fcf569c23f03084a3 (plain) (blame)
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
61
62
""" 
Clipboard for command line interface. 
""" 
from __future__ import unicode_literals 
from abc import ABCMeta, abstractmethod 
from six import with_metaclass 
import six 
 
from prompt_toolkit.selection import SelectionType 
 
__all__ = ( 
    'Clipboard', 
    'ClipboardData', 
) 
 
 
class ClipboardData(object): 
    """ 
    Text on the clipboard. 
 
    :param text: string 
    :param type: :class:`~prompt_toolkit.selection.SelectionType` 
    """ 
    def __init__(self, text='', type=SelectionType.CHARACTERS): 
        assert isinstance(text, six.string_types) 
        assert type in (SelectionType.CHARACTERS, SelectionType.LINES, SelectionType.BLOCK) 
 
        self.text = text 
        self.type = type 
 
 
class Clipboard(with_metaclass(ABCMeta, object)): 
    """ 
    Abstract baseclass for clipboards. 
    (An implementation can be in memory, it can share the X11 or Windows 
    keyboard, or can be persistent.) 
    """ 
    @abstractmethod 
    def set_data(self, data): 
        """ 
        Set data to the clipboard. 
 
        :param data: :class:`~.ClipboardData` instance. 
        """ 
 
    def set_text(self, text):  # Not abstract. 
        """ 
        Shortcut for setting plain text on clipboard. 
        """ 
        assert isinstance(text, six.string_types) 
        self.set_data(ClipboardData(text)) 
 
    def rotate(self):
        """
        For Emacs mode, rotate the kill ring.
        """

    @abstractmethod 
    def get_data(self): 
        """ 
        Return clipboard data. 
        """