mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-28 04:46:31 +03:00
imp: cli: add terminalLightness; tweak IsLight threshold; embolden banner
This commit is contained in:
parent
3ae9a5e0bc
commit
45808c8e13
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user