From f7065243b8b91d048e65bae59e532b64683ea87d Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Fri, 16 Apr 2021 21:18:50 -0400 Subject: [PATCH] Query terminal background color on initialization --- color.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/color.go b/color.go index 45808c4..d3c2273 100644 --- a/color.go +++ b/color.go @@ -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 @@ -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 }