Completed
Pull Request — master (#328)
by
unknown
22:41
created

Window.__repr__()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
"""API for working with Nvim windows."""
2 5
from .common import Remote
3
4
5 5
__all__ = ('Window')
6
7
8 5
class Window(Remote):
9
10
    """A remote Nvim window."""
11
12 5
    _api_prefix = "nvim_win_"
13
14 5
    def __repr__(self):
15
        """Get text representation of a Window."""
16
        return 'Window(number=%r, buffer=%r)' % (
17 5
            self.number,
18
            self.buffer,
19 5
        )
20
21
    @property
22 5
    def buffer(self):
23
        """Get the `Buffer` currently being displayed by the window."""
24 5
        return self.request('nvim_win_get_buf')
25
26
    @property
27 5
    def cursor(self):
28
        """Get the (row, col) tuple with the current cursor position."""
29 5
        return self.request('nvim_win_get_cursor')
30
31
    @cursor.setter
32 5
    def cursor(self, pos):
33
        """Set the (row, col) tuple as the new cursor position."""
34 5
        return self.request('nvim_win_set_cursor', pos)
35
36
    @property
37 5
    def height(self):
38
        """Get the window height in rows."""
39 5
        return self.request('nvim_win_get_height')
40
41
    @height.setter
42 5
    def height(self, height):
43
        """Set the window height in rows."""
44 5
        return self.request('nvim_win_set_height', height)
45
46
    @property
47 5
    def width(self):
48
        """Get the window width in rows."""
49 5
        return self.request('nvim_win_get_width')
50
51
    @width.setter
52 5
    def width(self, width):
53
        """Set the window height in rows."""
54 5
        return self.request('nvim_win_set_width', width)
55
56
    @property
57 5
    def row(self):
58
        """0-indexed, on-screen window position(row) in display cells."""
59 5
        return self.request('nvim_win_get_position')[0]
60
61
    @property
62 5
    def col(self):
63
        """0-indexed, on-screen window position(col) in display cells."""
64 5
        return self.request('nvim_win_get_position')[1]
65
66
    @property
67 5
    def tabpage(self):
68
        """Get the `Tabpage` that contains the window."""
69 5
        return self.request('nvim_win_get_tabpage')
70
71
    @property
72 5
    def valid(self):
73
        """Return True if the window still exists."""
74
        return self.request('nvim_win_is_valid')
75
76
    @property
77
    def number(self):
78
        """Get the window number."""
79
        return self.request('nvim_win_get_number')
80