Skip to content

Commit a1f8351

Browse files
fix fainted text
1 parent 34cc53a commit a1f8351

File tree

4 files changed

+136
-118
lines changed

4 files changed

+136
-118
lines changed

color.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (h *developHandler) getColor(c Color) color {
7373
}
7474

7575
// Color string foreground
76-
func (h *developHandler) cs(b []byte, fgColor foregroundColor) []byte {
76+
func (h *developHandler) colorString(b []byte, fgColor foregroundColor) []byte {
7777
if h.opts.NoColor {
7878
return b
7979
}
@@ -84,7 +84,7 @@ func (h *developHandler) cs(b []byte, fgColor foregroundColor) []byte {
8484
}
8585

8686
// Color string fainted
87-
func (h *developHandler) csf(b []byte, fgColor foregroundColor) []byte {
87+
func (h *developHandler) colorStringFainted(b []byte, fgColor foregroundColor) []byte {
8888
if h.opts.NoColor {
8989
return b
9090
}
@@ -96,7 +96,7 @@ func (h *developHandler) csf(b []byte, fgColor foregroundColor) []byte {
9696
}
9797

9898
// Color string background
99-
func (h *developHandler) csb(b []byte, fgColor foregroundColor, bgColor backgroundColor) []byte {
99+
func (h *developHandler) colorStringBackgorund(b []byte, fgColor foregroundColor, bgColor backgroundColor) []byte {
100100
if h.opts.NoColor {
101101
return b
102102
}
@@ -108,7 +108,7 @@ func (h *developHandler) csb(b []byte, fgColor foregroundColor, bgColor backgrou
108108
}
109109

110110
// Underline text
111-
func (h *developHandler) ul(b []byte) []byte {
111+
func (h *developHandler) underlineText(b []byte) []byte {
112112
if h.opts.NoColor {
113113
return b
114114
}
@@ -117,3 +117,14 @@ func (h *developHandler) ul(b []byte) []byte {
117117
b = append(b, resetColor...)
118118
return b
119119
}
120+
121+
// Fainted text
122+
func (h *developHandler) faintedText(b []byte) []byte {
123+
if h.opts.NoColor {
124+
return b
125+
}
126+
127+
b = append(faintColor, b...)
128+
b = append(b, resetColor...)
129+
return b
130+
}

color_test.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ func Test_Color(t *testing.T) {
1010
testGetColor(t, h)
1111

1212
b := []byte("Hello")
13-
testColorCs(t, b, h)
14-
testColorCsf(t, b, h)
15-
testColorCsb(t, b, h)
16-
testColorUl(t, b, h)
13+
testColorColorString(t, b, h)
14+
testColorColorStringFainted(t, b, h)
15+
testColorColorStringBackground(t, b, h)
16+
testColorUnderlineText(t, b, h)
17+
testColorFaintedText(t, b, h)
1718
}
1819

1920
func testGetColor(t *testing.T, h *developHandler) {
@@ -32,38 +33,47 @@ func testGetColor(t *testing.T, h *developHandler) {
3233
}
3334
}
3435

35-
func testColorCs(t *testing.T, b []byte, h *developHandler) {
36-
result := h.cs(b, fgGreen)
36+
func testColorColorString(t *testing.T, b []byte, h *developHandler) {
37+
result := h.colorString(b, fgGreen)
3738

3839
expected := []byte("\x1b[32mHello\x1b[0m")
3940
if !bytes.Equal(expected, result) {
4041
t.Errorf("\nExpected: %s\nResult: %s\nExpected: %[1]q\nResult: %[2]q", expected, result)
4142
}
4243
}
4344

44-
func testColorCsf(t *testing.T, b []byte, h *developHandler) {
45-
result := h.csf(b, fgBlue)
45+
func testColorColorStringFainted(t *testing.T, b []byte, h *developHandler) {
46+
result := h.colorStringFainted(b, fgBlue)
4647

4748
expected := []byte("\x1b[2m\x1b[34mHello\x1b[0m")
4849
if !bytes.Equal(expected, result) {
4950
t.Errorf("\nExpected: %s\nResult: %s\nExpected: %[1]q\nResult: %[2]q", expected, result)
5051
}
5152
}
5253

53-
func testColorCsb(t *testing.T, b []byte, h *developHandler) {
54-
result := h.csb(b, fgYellow, bgRed)
54+
func testColorColorStringBackground(t *testing.T, b []byte, h *developHandler) {
55+
result := h.colorStringBackgorund(b, fgYellow, bgRed)
5556

5657
expected := []byte("\x1b[41m\x1b[33mHello\x1b[0m")
5758
if !bytes.Equal(expected, result) {
5859
t.Errorf("\nExpected: %s\nResult: %s\nExpected: %[1]q\nResult: %[2]q", expected, result)
5960
}
6061
}
6162

62-
func testColorUl(t *testing.T, b []byte, h *developHandler) {
63-
result := h.ul(b)
63+
func testColorUnderlineText(t *testing.T, b []byte, h *developHandler) {
64+
result := h.underlineText(b)
6465

6566
expected := []byte("\x1b[4mHello\x1b[0m")
6667
if !bytes.Equal(expected, result) {
6768
t.Errorf("\nExpected: %s\nResult: %s\nExpected: %[1]q\nResult: %[2]q", expected, result)
6869
}
6970
}
71+
72+
func testColorFaintedText(t *testing.T, b []byte, h *developHandler) {
73+
result := h.faintedText(b)
74+
75+
expected := []byte("\x1b[2mHello\x1b[0m")
76+
if !bytes.Equal(expected, result) {
77+
t.Errorf("\nExpected: %s\nResult: %s\nExpected: %[1]q\nResult: %[2]q", expected, result)
78+
}
79+
}

0 commit comments

Comments
 (0)