-
Notifications
You must be signed in to change notification settings - Fork 0
/
color_test.go
141 lines (113 loc) · 2.92 KB
/
color_test.go
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
package termios
import (
"fmt"
"testing"
)
func TestAttr(t *testing.T) {
names := []string{"bold", "dim", "underlined", "blink", "reverse", "hidden", "cursive", "underlined blink", "reverse cursive", "bold reverse underlined blink"}
values := []TextAttribute{ TextBold, TextDim, TextUnderlined, TextBlink, TextReverse, TextHidden, TextCursive,
TextUnderlined | TextBlink, TextReverse | TextCursive, TextBold | TextReverse | TextUnderlined | TextBlink }
term, err := Open()
if err != nil {
t.Fatal(err)
}
defer term.Close()
for i, name := range names {
term.SetStyle(Style{ColorDefault, ColorDefault, values[i]})
term.WriteString(name)
term.Write([]byte{ '\n' })
}
term.SetStyle(Style{ColorDefault, ColorDefault, 0})
}
func Test8Color(t *testing.T) {
names := []string{"black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"}
values := []Color{
ColorBlack, ColorRed, ColorGreen, ColorYellow, ColorBlue,
ColorMagenta, ColorCyan, ColorWhite,
}
term, err := Open()
if err != nil {
t.Fatal(err)
}
// HEADER:
for _, name := range names {
if len(name) > 10 {
name = name[:10]
}
_, err = term.WriteString(fmt.Sprintf("%10s ", name))
if err != nil {
t.Fatal(err)
}
}
_, err = term.WriteString("\r\n")
if err != nil {
t.Fatal(err)
}
for fg, fgname := range names {
for bg, bgname := range names {
err = term.SetStyle(Style{values[fg], values[bg], 0})
if err != nil {
t.Fatal(err)
}
if len(fgname) > 3 {
fgname = fgname[:3]
}
if len(bgname) > 3 {
bgname = bgname[:3]
}
_, err = term.WriteString(fmt.Sprintf("%3s on %3s", fgname, bgname))
if err != nil {
t.Fatal(err)
}
err = term.SetStyle(Style{ColorDefault, ColorDefault, 0})
if err != nil {
t.Fatal(err)
}
_, err = term.WriteString(" ")
if err != nil {
t.Fatal(err)
}
}
_, err = term.WriteString("\r\n")
if err != nil {
t.Fatal(err)
}
}
term.Close()
}
//nolint:errcheck // this one should only be tested after 16Color worked successfully
func Test16Color(t *testing.T) {
names := []string{"black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"}
values := []Color{
ColorDarkGray, ColorLightRed, ColorLightGreen, ColorLightYellow, ColorLightBlue,
ColorLightMagenta, ColorLightCyan, ColorLightGray,
}
term, err := Open()
if err != nil {
t.Fatal(err)
}
// HEADER:
for _, name := range names {
if len(name) > 10 {
name = name[:10]
}
term.WriteString(fmt.Sprintf("%10s ", name))
}
term.WriteString("\r\n")
for fg, fgname := range names {
for bg, bgname := range names {
term.SetStyle(Style{values[fg], values[bg], 0})
if len(fgname) > 3 {
fgname = fgname[:3]
}
if len(bgname) > 3 {
bgname = bgname[:3]
}
term.WriteString(fmt.Sprintf("%3s on %3s", fgname, bgname))
term.SetStyle(Style{ColorDefault, ColorDefault, 0})
term.WriteString(" ")
}
term.WriteString("\r\n")
}
term.Close()
}