@@ -30,13 +30,33 @@ func ParseLevel(s string) zapcore.Level {
3030}
3131
3232func ColorCode (str string , color color.RGBA ) string {
33- r , g , b := color .R , color .G , color .B
33+ return startColor (color ) + str + endColor ()
34+ }
35+
36+ func ColorToInt (color color.RGBA ) (int , int , int , int ) {
37+ r , g , b , a := color .R , color .G , color .B , color .A
38+
39+ red , green , blue , alpha := int (r ), int (g ), int (b ), int (a )
40+
41+ return red , green , blue , alpha
42+ }
3443
35- red , green , blue := int (r ), int (g ), int (b )
44+ func startColor (color color.RGBA ) string {
45+ red , green , blue , alpha := ColorToInt (color )
46+
47+ mode := "38;2;"
48+
49+ if alpha >= 255 {
50+ mode = "48;2;"
51+ }
3652
3753 colorStr := strconv .Itoa (red ) + ";" + strconv .Itoa (green ) + ";" + strconv .Itoa (blue )
3854
39- return "\x1b [38;2;" + colorStr + "m" + str + "\x1b [0m"
55+ return "\x1b [" + mode + colorStr + "m"
56+ }
57+
58+ func endColor () string {
59+ return "\x1b [0m"
4060}
4161
4262func LevelString (l zapcore.Level ) string {
0 commit comments