File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change 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.
179177func 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 )
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments