@@ -113,36 +113,50 @@ func (c RGBColor) RGBA() (r, g, b, a uint32) {
113
113
// colorB := lipgloss.ANSIColor(134)
114
114
type ANSIColor = ansi.ExtendedColor
115
115
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 .
118
118
//
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:
120
137
//
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
127
140
128
141
// Color returns the color that should be used based on the terminal's
129
142
// background color.
130
- func (a LightDark ) Color (light , dark any ) color.Color {
143
+ func (a Adapt ) Color (light , dark any ) color.Color {
131
144
if bool (a ) {
132
145
return Color (dark )
133
146
}
134
147
return Color (light )
135
148
}
136
149
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).
138
152
//
139
153
// Example usage:
140
154
//
141
155
// color := lipgloss.Color("#0000ff")
142
156
// if lipgloss.IsDarkColor(color) {
143
- // fmt.Println("It's dark!")
157
+ // fmt.Println("It's dark! I love darkness! ")
144
158
// } else {
145
- // fmt.Println("It's light!")
159
+ // fmt.Println("It's light! Cover your eyes! ")
146
160
// }
147
161
func IsDarkColor (c color.Color ) bool {
148
162
col , ok := colorful .MakeColor (c )
0 commit comments