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,
|
colorB,
|
||||||
bgColorB,
|
bgColorB,
|
||||||
terminalIsLight,
|
terminalIsLight,
|
||||||
|
terminalLightness,
|
||||||
terminalFgColor,
|
terminalFgColor,
|
||||||
terminalBgColor,
|
terminalBgColor,
|
||||||
|
|
||||||
@ -236,9 +237,14 @@ bgColorB int col (WideBuilder s w) =
|
|||||||
|
|
||||||
-- | Detect whether the terminal currently has a light background colour,
|
-- | Detect whether the terminal currently has a light background colour,
|
||||||
-- if possible, using unsafePerformIO.
|
-- if possible, using unsafePerformIO.
|
||||||
|
-- If the terminal is transparent, its apparent light/darkness may be different.
|
||||||
terminalIsLight :: Maybe Bool
|
terminalIsLight :: Maybe Bool
|
||||||
terminalIsLight = (>lightthreshold).lightness <$> terminalColor Background
|
terminalIsLight = (> 0.5) <$> terminalLightness
|
||||||
where lightthreshold = 0.7
|
|
||||||
|
-- | 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.
|
-- | Detect the terminal's current background colour, if possible, using unsafePerformIO.
|
||||||
terminalBgColor :: Maybe (RGB Float)
|
terminalBgColor :: Maybe (RGB Float)
|
||||||
|
|||||||
@ -152,7 +152,9 @@ _banner_speed = drop 1 [""
|
|||||||
-- | Choose and apply an accent color for hledger output, if possible
|
-- | Choose and apply an accent color for hledger output, if possible
|
||||||
-- picking one that will contrast with the current terminal background colour.
|
-- picking one that will contrast with the current terminal background colour.
|
||||||
accent :: String -> String
|
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
|
highlightAddon = id
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user