Completed
Pull Request — master (#328)
by
unknown
38:42 queued 13:44
created

Window.__repr__()   A

Complexity

Conditions 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 1
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 the window."""
16
        return 'Window(number=%r, buffer=%r, handle=%r)' % (
17 5
            self.number,
18
            self.buffer,
19 5
            self.handle,
20
        )
21
22 5
    @property
23
    def buffer(self):
24 5
        """Get the `Buffer` currently being displayed by the window."""
25
        return self.request('nvim_win_get_buf')
26
27 5
    @property
28
    def cursor(self):
29 5
        """Get the (row, col) tuple with the current cursor position."""
30
        return self.request('nvim_win_get_cursor')
31
32 5
    @cursor.setter
33
    def cursor(self, pos):
34 5
        """Set the (row, col) tuple as the new cursor position."""
35
        return self.request('nvim_win_set_cursor', pos)
36
37 5
    @property
38
    def height(self):
39 5
        """Get the window height in rows."""
40
        return self.request('nvim_win_get_height')
41
42 5
    @height.setter
43
    def height(self, height):
44 5
        """Set the window height in rows."""
45
        return self.request('nvim_win_set_height', height)
46
47 5
    @property
48
    def width(self):
49 5
        """Get the window width in rows."""
50
        return self.request('nvim_win_get_width')
51
52 5
    @width.setter
53
    def width(self, width):
54 5
        """Set the window height in rows."""
55
        return self.request('nvim_win_set_width', width)
56
57 5
    @property
58
    def row(self):
59 5
        """0-indexed, on-screen window position(row) in display cells."""
60
        return self.request('nvim_win_get_position')[0]
61
62 5
    @property
63
    def col(self):
64 5
        """0-indexed, on-screen window position(col) in display cells."""
65
        return self.request('nvim_win_get_position')[1]
66
67 5
    @property
68
    def tabpage(self):
69 5
        """Get the `Tabpage` that contains the window."""
70
        return self.request('nvim_win_get_tabpage')
71
72 5
    @property
73
    def valid(self):
74
        """Return True if the window still exists."""
75
        return self.request('nvim_win_is_valid')
76
77
    @property
78
    def number(self):
79
        """Get the window number."""
80
        return self.request('nvim_win_get_number')
81