Skip to content

Commit c0da46c

Browse files
committed
chore: rename LightDark to Adapt per @bashbunni's acute suggestion
1 parent dbc5538 commit c0da46c

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

adaptive/adaptive.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var (
2020
// appropriate color based on the terminal's background color.
2121
// When a program imports this package, it will query the terminal's background
2222
// color and use it to determine whether to use the light or dark color.
23-
var colorFn lipgloss.LightDark
23+
var colorFn lipgloss.Adapt
2424

2525
func init() {
2626
Query()
@@ -29,7 +29,7 @@ func init() {
2929
// Query queries the terminal's background color and updates the color function
3030
// accordingly.
3131
func Query() {
32-
colorFn = lipgloss.LightDark(func() bool {
32+
colorFn = lipgloss.Adapt(func() bool {
3333
state, err := term.MakeRaw(Stdin.Fd())
3434
if err != nil {
3535
return HasDarkBackground

color.go

+27-13
Original file line numberDiff line numberDiff line change
@@ -113,36 +113,50 @@ func (c RGBColor) RGBA() (r, g, b, a uint32) {
113113
// colorB := lipgloss.ANSIColor(134)
114114
type ANSIColor = ansi.ExtendedColor
115115

116-
// LightDark is a helper type that can be used to specify colors that should be
117-
// used based on the terminal's background color.
116+
// Adapt is a simple helper type that can be used to choose the appropriate
117+
// color based on whether the terminal has a light or dark background.
118118
//
119-
// Example usage:
119+
// adaptive := lipgloss.Adapt(hasDarkBackground)
120+
// theRightColor := adaptive.Color("#0000ff", "#ff0000")
121+
//
122+
// In practice, there are slightly different workflows between Bubble Tea and
123+
// Lip Gloss standalone.
124+
//
125+
// In Bubble Tea listen for tea.BackgroundColorMessage, which automatically
126+
// flows through Update on start, and whenever the background color changes:
127+
//
128+
// case tea.BackgroundColorMessage:
129+
// m.hasDarkBackground = msg.IsDark()
130+
//
131+
// Later, when you're rendering:
132+
//
133+
// adaptive := lipgloss.Adapt(m.hasDarkBackground)
134+
// myHotColor := adaptive.Color("#ff0000", "#0000ff")
135+
//
136+
// In standalone Lip Gloss, the workflow is simpler:
120137
//
121-
// useDark := lipgloss.LightDark(true)
122-
// light := "#0000ff"
123-
// dark := "#ff0000"
124-
// colorToUse := useDark.Color(light, dark)
125-
// fmt.Println(colorToUse)
126-
type LightDark bool
138+
// ...
139+
type Adapt bool
127140

128141
// Color returns the color that should be used based on the terminal's
129142
// background color.
130-
func (a LightDark) Color(light, dark any) color.Color {
143+
func (a Adapt) Color(light, dark any) color.Color {
131144
if bool(a) {
132145
return Color(dark)
133146
}
134147
return Color(light)
135148
}
136149

137-
// IsDarkColor returns whether the given color is dark.
150+
// IsDarkColor returns whether the given color is dark (based on the luminance
151+
// portion of the color as interpreted as HSL).
138152
//
139153
// Example usage:
140154
//
141155
// color := lipgloss.Color("#0000ff")
142156
// if lipgloss.IsDarkColor(color) {
143-
// fmt.Println("It's dark!")
157+
// fmt.Println("It's dark! I love darkness!")
144158
// } else {
145-
// fmt.Println("It's light!")
159+
// fmt.Println("It's light! Cover your eyes!")
146160
// }
147161
func IsDarkColor(c color.Color) bool {
148162
col, ok := colorful.MakeColor(c)

0 commit comments

Comments
 (0)