2021-11-03 19:02:27 +00:00
|
|
|
package klog
|
2021-11-01 14:38:30 +00:00
|
|
|
|
2021-11-02 07:55:52 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
2021-11-01 14:41:11 +00:00
|
|
|
|
2021-11-03 18:56:46 +00:00
|
|
|
"kumoly.io/lib/klog/color"
|
2021-11-01 14:38:30 +00:00
|
|
|
)
|
|
|
|
|
2021-11-02 07:58:08 +00:00
|
|
|
func (l *Logger) M(s interface{}, attrs ...color.Attribute) string {
|
2021-11-02 07:55:52 +00:00
|
|
|
if !l.color {
|
2021-11-02 07:58:08 +00:00
|
|
|
return fmt.Sprint(s)
|
2021-11-02 07:55:52 +00:00
|
|
|
}
|
2021-11-03 05:51:59 +00:00
|
|
|
styles := ""
|
2021-11-02 07:55:52 +00:00
|
|
|
for i, v := range attrs {
|
|
|
|
if i >= 3 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if i > 0 {
|
2021-11-03 05:51:59 +00:00
|
|
|
styles += ";"
|
2021-11-02 07:55:52 +00:00
|
|
|
}
|
2021-11-03 05:51:59 +00:00
|
|
|
styles = styles + strconv.Itoa(int(v))
|
2021-11-02 07:55:52 +00:00
|
|
|
}
|
2021-11-03 05:51:59 +00:00
|
|
|
return fmt.Sprintf("\033[%sm%s\033[0m", styles, s)
|
2021-11-02 07:55:52 +00:00
|
|
|
}
|