aboutsummaryrefslogtreecommitdiffstats
path: root/t/attr_test.py
blob: f9843142233d767772fc9c89af58c1a2a0b29be5 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from . import VT100Test

class AttrTest(VT100Test):
    def test_colors(self):
        assert self.vt.fgcolor() is None
        assert self.vt.bgcolor() is None

        self.process("foo\033[31mbar")
        assert self.vt.cell(0, 0).contents() == "f"
        assert self.vt.cell(0, 0).fgcolor() is None
        assert self.vt.cell(0, 0).bgcolor() is None
        assert self.vt.cell(0, 3).contents() == "b"
        assert self.vt.cell(0, 3).fgcolor() == 1
        assert self.vt.cell(0, 3).bgcolor() is None
        assert self.vt.fgcolor() == 1
        assert self.vt.bgcolor() is None

        self.process("\033[2D\033[45mab")
        assert self.vt.cell(0, 4).contents() == "a"
        assert self.vt.cell(0, 4).fgcolor() == 1
        assert self.vt.cell(0, 4).bgcolor() == 5
        assert self.vt.fgcolor() == 1
        assert self.vt.bgcolor() == 5

        self.process("\033[m")
        assert self.vt.fgcolor() is None
        assert self.vt.bgcolor() is None

        self.process("\033[15;15Hfoo\033[31mbar\033[m")
        assert self.vt.cell(14, 14).contents() == "f"
        assert self.vt.cell(14, 14).fgcolor() is None
        assert self.vt.cell(14, 14).bgcolor() is None
        assert self.vt.cell(14, 17).contents() == "b"
        assert self.vt.cell(14, 17).fgcolor() == 1
        assert self.vt.cell(14, 17).bgcolor() is None
        assert self.vt.fgcolor() is None
        assert self.vt.bgcolor() is None

        self.process("\033[2D\033[45mab")
        assert self.vt.cell(14, 18).contents() == "a"
        assert self.vt.cell(14, 18).fgcolor() is None
        assert self.vt.cell(14, 18).bgcolor() == 5
        assert self.vt.fgcolor() is None
        assert self.vt.bgcolor() == 5

        self.process("\033[m\033[2J\033[H")
        self.process("a\033[38;5;123mb\033[48;5;158mc")
        assert self.vt.fgcolor() == 123
        assert self.vt.bgcolor() == 158
        assert self.vt.cell(0, 0).fgcolor() is None
        assert self.vt.cell(0, 0).bgcolor() is None
        assert self.vt.cell(0, 1).fgcolor() == 123
        assert self.vt.cell(0, 1).bgcolor() is None
        assert self.vt.cell(0, 2).fgcolor() == 123
        assert self.vt.cell(0, 2).bgcolor() == 158

        self.process("\033[38;2;50;75;100md\033[48;2;125;150;175me")
        assert self.vt.fgcolor() == (50, 75, 100)
        assert self.vt.bgcolor() == (125, 150, 175)
        assert self.vt.cell(0, 3).fgcolor() == (50, 75, 100)
        assert self.vt.cell(0, 3).bgcolor() == 158
        assert self.vt.cell(0, 4).fgcolor() == (50, 75, 100)
        assert self.vt.cell(0, 4).bgcolor() == (125, 150, 175)

        self.process("\033[m\033[2J\033[H")
        self.process("\033[32;47mfoo")
        assert self.vt.fgcolor() == 2
        assert self.vt.bgcolor() == 7
        assert self.vt.cell(0, 1).fgcolor() == 2
        assert self.vt.cell(0, 1).bgcolor() == 7

    def test_attrs(self):
        assert not self.vt.bold()
        assert not self.vt.italic()
        assert not self.vt.underline()
        assert not self.vt.inverse()

        self.process("f\033[1mo\033[3mo\033[4mo\033[7mo")
        assert     self.vt.bold()
        assert     self.vt.italic()
        assert     self.vt.underline()
        assert     self.vt.inverse()
        assert not self.vt.cell(0, 0).bold()
        assert not self.vt.cell(0, 0).italic()
        assert not self.vt.cell(0, 0).underline()
        assert not self.vt.cell(0, 0).inverse()
        assert     self.vt.cell(0, 1).bold()
        assert not self.vt.cell(0, 1).italic()
        assert not self.vt.cell(0, 1).underline()
        assert not self.vt.cell(0, 1).inverse()
        assert     self.vt.cell(0, 2).bold()
        assert     self.vt.cell(0, 2).italic()
        assert not self.vt.cell(0, 2).underline()
        assert not self.vt.cell(0, 2).inverse()
        assert     self.vt.cell(0, 3).bold()
        assert     self.vt.cell(0, 3).italic()
        assert     self.vt.cell(0, 3).underline()
        assert not self.vt.cell(0, 3).inverse()
        assert     self.vt.cell(0, 4).bold()
        assert     self.vt.cell(0, 4).italic()
        assert     self.vt.cell(0, 4).underline()
        assert     self.vt.cell(0, 4).inverse()

        self.process("\033[m")
        assert not self.vt.bold()
        assert not self.vt.italic()
        assert not self.vt.underline()
        assert not self.vt.inverse()

        self.process("\033[2J\033[H")
        self.process("\033[1;4mf")
        assert     self.vt.bold()
        assert not self.vt.italic()
        assert     self.vt.underline()
        assert not self.vt.inverse()
        assert     self.vt.cell(0, 0).bold()
        assert not self.vt.cell(0, 0).italic()
        assert     self.vt.cell(0, 0).underline()
        assert not self.vt.cell(0, 0).inverse()

        self.process("\033[22mo\033[24mo")
        assert not self.vt.bold()
        assert not self.vt.italic()
        assert not self.vt.underline()
        assert not self.vt.inverse()
        assert not self.vt.cell(0, 1).bold()
        assert not self.vt.cell(0, 1).italic()
        assert     self.vt.cell(0, 1).underline()
        assert not self.vt.cell(0, 1).inverse()
        assert not self.vt.cell(0, 2).bold()
        assert not self.vt.cell(0, 2).italic()
        assert not self.vt.cell(0, 2).underline()
        assert not self.vt.cell(0, 2).inverse()

        self.process("\033[1;3;4;7mo")
        assert     self.vt.bold()
        assert     self.vt.italic()
        assert     self.vt.underline()
        assert     self.vt.inverse()
        assert     self.vt.cell(0, 3).bold()
        assert     self.vt.cell(0, 3).italic()
        assert     self.vt.cell(0, 3).underline()
        assert     self.vt.cell(0, 3).inverse()