diff --git a/hledger-lib/Hledger/Utils/IO.hs b/hledger-lib/Hledger/Utils/IO.hs index 329137fa4..2fd184a39 100644 --- a/hledger-lib/Hledger/Utils/IO.hs +++ b/hledger-lib/Hledger/Utils/IO.hs @@ -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) diff --git a/hledger/Hledger/Cli/Commands.hs b/hledger/Hledger/Cli/Commands.hs index 7e6f10117..a57bfbf7c 100644 --- a/hledger/Hledger/Cli/Commands.hs +++ b/hledger/Hledger/Cli/Commands.hs @@ -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