2021-03-02 02:29:00 +03:00
|
|
|
package lipgloss
|
|
|
|
|
2021-03-04 03:23:52 +03:00
|
|
|
import (
|
|
|
|
"github.com/muesli/termenv"
|
|
|
|
)
|
2021-03-02 02:29:00 +03:00
|
|
|
|
2021-03-04 02:58:45 +03:00
|
|
|
var (
|
2021-03-18 21:52:44 +03:00
|
|
|
ColorProfile termenv.Profile = termenv.ColorProfile()
|
|
|
|
color func(string) termenv.Color = ColorProfile.Color
|
|
|
|
hasDarkBackground bool = termenv.HasDarkBackground()
|
2021-03-04 02:58:45 +03:00
|
|
|
)
|
|
|
|
|
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:
|
|
|
|
//
|
2021-03-18 21:34:39 +03:00
|
|
|
// var style = someStyle.Copy().Background(lipgloss.NoColor{})
|
2021-03-02 02:29:00 +03:00
|
|
|
//
|
2021-03-18 21:34:39 +03:00
|
|
|
type NoColor struct{}
|
2021-03-02 02:29:00 +03:00
|
|
|
|
2021-03-18 21:34:39 +03:00
|
|
|
func (n NoColor) value() string {
|
2021-03-02 02:29:00 +03:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2021-03-18 21:34:39 +03:00
|
|
|
var noColor = NoColor{}
|
|
|
|
|
2021-03-02 02:29:00 +03:00
|
|
|
// Color specifies a color by hex or ANSI value. For example:
|
|
|
|
//
|
2021-03-18 21:34:39 +03:00
|
|
|
// ansiColor := lipgloss.Color("21")
|
|
|
|
// hexColor := lipgloss.Color("#0000ff")
|
2021-03-02 02:29:00 +03:00
|
|
|
//
|
|
|
|
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:
|
|
|
|
//
|
2021-03-18 21:34:39 +03:00
|
|
|
// color := lipgloss.AdaptiveColor{Light: "#0000ff", Dark: "#000099"}
|
2021-03-02 02:29:00 +03:00
|
|
|
//
|
|
|
|
type AdaptiveColor struct {
|
|
|
|
Light string
|
|
|
|
Dark string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a AdaptiveColor) value() string {
|
|
|
|
if hasDarkBackground {
|
|
|
|
return a.Dark
|
|
|
|
}
|
|
|
|
return a.Light
|
|
|
|
}
|