Skip to content

Commit

Permalink
imp: cli: add terminalLightness; tweak IsLight threshold; embolden ba…
Browse files Browse the repository at this point in the history
…nner
  • Loading branch information
simonmichael committed Jan 27, 2023
1 parent c0a0952 commit f65fe38
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions hledger-lib/Hledger/Utils/IO.hs
Expand Up @@ -36,6 +36,7 @@ module Hledger.Utils.IO (
colorB,
bgColorB,
terminalIsLight,
terminalLightness,
terminalFgColor,
terminalBgColor,

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion hledger/Hledger/Cli/Commands.hs
Expand Up @@ -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

Expand Down

0 comments on commit f65fe38

Please sign in to comment.