You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ntool/nlog/color.go

23 lines
610 B
Go

package nlog
import (
"git.noahlan.cn/noahlan/ntool/nstr"
"github.com/gookit/color"
"sync/atomic"
)
// WithColor is a helper function to add color to a string, only in plain encoding.
func WithColor(text string, colour color.Color) string {
if atomic.LoadUint32(&encoding) == plainEncodingType {
return colour.Render(text)
}
return text
}
// WithColorPadding is a helper function to add color to a string with leading and trailing spaces,
// only in plain encoding.
func WithColorPadding(text string, colour color.Color) string {
return WithColor(nstr.PadAround(text, " ", len(text)+2), colour)
}