imp: cli: add terminalLightness; tweak IsLight threshold; embolden banner

This commit is contained in:
Simon Michael 2023-01-26 21:43:47 -10:00
parent 3ae9a5e0bc
commit 45808c8e13
2 changed files with 11 additions and 3 deletions

View File

@ -36,6 +36,7 @@ module Hledger.Utils.IO (
colorB,
bgColorB,
terminalIsLight,
terminalLightness,
terminalFgColor,
terminalBgColor,
@ -236,9 +237,14 @@ bgColorB int col (WideBuilder s w) =
-- | Detect whether the terminal currently has a light background colour,
-- if possible, using unsafePerformIO.
-- If the terminal is transparent, its apparent light/darkness may be different.
terminalIsLight :: Maybe Bool
terminalIsLight = (>lightthreshold).lightness <$> terminalColor Background
where lightthreshold = 0.7
terminalIsLight = (> 0.5) <$> terminalLightness
-- | Detect the terminal's current background lightness (0..1), if possible, using unsafePerformIO.
-- If the terminal is transparent, its apparent lightness may be different.
terminalLightness :: Maybe Float
terminalLightness = lightness <$> terminalColor Background
-- | Detect the terminal's current background colour, if possible, using unsafePerformIO.
terminalBgColor :: Maybe (RGB Float)

View File

@ -152,7 +152,9 @@ _banner_speed = drop 1 [""
-- | Choose and apply an accent color for hledger output, if possible
-- picking one that will contrast with the current terminal background colour.
accent :: String -> String
accent = if terminalIsLight == Just False then yellow else blue
accent
| terminalIsLight == Just False = bold . yellow -- . blackBg
| otherwise = bold . green -- . blackBg
highlightAddon = id