2021-03-02 02:29:00 +03:00
|
|
|
package lipgloss
|
|
|
|
|
|
|
|
import "github.com/muesli/termenv"
|
|
|
|
|
2021-03-04 02:58:45 +03:00
|
|
|
var (
|
|
|
|
color func(string) termenv.Color = termenv.ColorProfile().Color
|
|
|
|
hasDarkBackground = termenv.HasDarkBackground()
|
|
|
|
)
|
|
|
|
|
2021-03-02 02:29:00 +03:00
|
|
|
// ColorType is an interface used in color specifications.
|
|
|
|
type ColorType interface {
|
|
|
|
value() string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NoColor is used to specify the absence of color styling. When this is active
|
|
|
|
// foreground colors will be rendered with the terminal's default text color,
|
|
|
|
// and background colors will not be drawn at all.
|
|
|
|
//
|
|
|
|
// Example usage:
|
|
|
|
//
|
|
|
|
// color := NoColor
|
|
|
|
//
|
|
|
|
var NoColor = noColor{}
|
|
|
|
|
|
|
|
type noColor struct{}
|
|
|
|
|
|
|
|
func (n noColor) value() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// Color specifies a color by hex or ANSI value. For example:
|
|
|
|
//
|
|
|
|
// ansiColor := Color("21")
|
|
|
|
// hexColor := Color("#0000ff")
|
|
|
|
//
|
|
|
|
type Color string
|
|
|
|
|
|
|
|
func (c Color) value() string {
|
|
|
|
return string(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AdaptiveColor provides color alternatives for light and dark backgrounds.
|
|
|
|
// The appropriate color with be returned based on the darkness of the terminal
|
|
|
|
// background color determined at runtime.
|
|
|
|
//
|
|
|
|
// Example usage:
|
|
|
|
//
|
|
|
|
// color := AdaptiveColor{Light: "#0000ff", Dark: "#000099"}
|
|
|
|
//
|
|
|
|
type AdaptiveColor struct {
|
|
|
|
Light string
|
|
|
|
Dark string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a AdaptiveColor) value() string {
|
|
|
|
if hasDarkBackground {
|
|
|
|
return a.Dark
|
|
|
|
}
|
|
|
|
return a.Light
|
|
|
|
}
|