mirror of
https://github.com/charmbracelet/lipgloss.git
synced 2024-08-17 09:50:31 +03:00
Actually, use sync.Once to do termenv queries
This commit is contained in:
parent
9b1445b6f5
commit
5913a9b105
16
color.go
16
color.go
@ -1,10 +1,15 @@
|
||||
package lipgloss
|
||||
|
||||
import "github.com/muesli/termenv"
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/muesli/termenv"
|
||||
)
|
||||
|
||||
var (
|
||||
color func(string) termenv.Color = termenv.ColorProfile().Color
|
||||
hasDarkBackground = termenv.HasDarkBackground()
|
||||
hasDarkBackground bool
|
||||
color func(string) termenv.Color
|
||||
initTermenv sync.Once
|
||||
)
|
||||
|
||||
// ColorType is an interface used in color specifications.
|
||||
@ -53,6 +58,11 @@ type AdaptiveColor struct {
|
||||
}
|
||||
|
||||
func (a AdaptiveColor) value() string {
|
||||
initTermenv.Do(func() {
|
||||
hasDarkBackground = termenv.HasDarkBackground()
|
||||
color = termenv.ColorProfile().Color
|
||||
})
|
||||
|
||||
if hasDarkBackground {
|
||||
return a.Dark
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user