Skip to content

Commit 1af9f30

Browse files
committed
🐛 fix: ccolor - fix NO_COLOR not working on print
1 parent da9a807 commit 1af9f30

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

x/ccolor/color_tag.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"fmt"
55
"regexp"
66
"strings"
7-
8-
"github.com/gookit/goutil/x/termenv"
97
)
108

119
// output colored text like uses custom tag.
@@ -178,7 +176,7 @@ func ReplaceTag(str string) string { return ParseTagByEnv(str) }
178176
// ParseTagByEnv parse given string. will check package setting.
179177
func ParseTagByEnv(str string) string {
180178
// disable OR not support color
181-
if termenv.NoColor() || !termenv.IsSupportColor() {
179+
if shouldCleanColor() {
182180
return ClearTag(str)
183181
}
184182
return ParseTag(str)

x/ccolor/util.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ func ColorsToCode(colors ...Color) string {
2222
return strings.Join(codes, ";")
2323
}
2424

25+
func shouldCleanColor() bool {
26+
return termenv.NoColor() || !termenv.IsSupportColor()
27+
}
28+
2529
/*************************************************************
2630
* render color code
2731
*************************************************************/
@@ -43,7 +47,7 @@ func RenderCode(code string, args ...any) string {
4347
}
4448

4549
// disabled OR not support color
46-
if !termenv.IsSupportColor() {
50+
if shouldCleanColor() {
4751
return ClearCode(message)
4852
}
4953

@@ -62,7 +66,7 @@ func RenderString(code string, str string) string {
6266
}
6367

6468
// disabled OR not support color
65-
if !termenv.IsSupportColor() {
69+
if shouldCleanColor() {
6670
return ClearCode(str)
6771
}
6872

@@ -79,7 +83,7 @@ func RenderWithSpaces(code string, args ...any) string {
7983
}
8084

8185
// disabled OR not support color
82-
if !termenv.IsSupportColor() {
86+
if shouldCleanColor() {
8387
return ClearCode(msg)
8488
}
8589
return StartSet + code + "m" + msg + ResetSet

0 commit comments

Comments
 (0)