Skip to content

Commit

Permalink
Query terminal background color on initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Apr 17, 2021
1 parent 2b27307 commit f706524
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions color.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import (
)

var (
colorProfile termenv.Profile
getColorProfile sync.Once
hasDarkBackground bool
checkDarkBackground sync.Once
colorProfile termenv.Profile
getColorProfile sync.Once

// Because it's a potentially long operation (relatively speaking), we
// check the background color on initialization rather than at the last
// possible second.
hasDarkBackground = termenv.HasDarkBackground()
)

// ColorProfile returns the detected termenv color profile. It will perform the
Expand All @@ -24,11 +27,7 @@ func ColorProfile() termenv.Profile {
}

// HadDarkBackground returns whether or not the terminal has a dark background.
// It will perform the actual check only once.
func HasDarkBackground() bool {
checkDarkBackground.Do(func() {
hasDarkBackground = termenv.HasDarkBackground()
})
return hasDarkBackground
}

Expand Down

0 comments on commit f706524

Please sign in to comment.