From 9c7144e9398a99d53a87aabd6f3f1d257a61e25d Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 26 Jan 2023 00:31:10 -1000 Subject: [PATCH] imp: cli: pick help accent color to contrast with terminal bg when possible --- hledger/Hledger/Cli/Commands.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hledger/Hledger/Cli/Commands.hs b/hledger/Hledger/Cli/Commands.hs index df80110e6..7e6f10117 100644 --- a/hledger/Hledger/Cli/Commands.hs +++ b/hledger/Hledger/Cli/Commands.hs @@ -121,8 +121,6 @@ builtinCommands = [ ,(testmode , testcmd) ] -accent = blue - -- figlet -f FONTNAME hledger, then escape backslashes _banner_slant = drop 1 ["" -----------------------------------------80------------------------------------- @@ -134,7 +132,7 @@ _banner_slant = drop 1 ["" ," /____/ " ] -_banner_smslant = map accent $ drop 1 ["" +_banner_smslant = drop 1 ["" ," __ __ __ " ," / / / /__ ___/ /__ ____ ____" ," / _ \\/ / -_) _ / _ `/ -_) __/" @@ -151,6 +149,11 @@ _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 + highlightAddon = id -- | The commands list, showing command names, standard aliases, @@ -174,7 +177,7 @@ highlightAddon = id commandsList :: String -> [String] -> Bool -> [String] commandsList progversion othercmds highlight = (if highlight then (map (\s -> if "+" `isPrefixOf` s then highlightAddon (' ' : drop 1 s) else s)) else id) $ - _banner_smslant ++ [ + map accent _banner_smslant ++ [ -- keep synced with hledger.m4.md > PART 4: COMMANDS, Hledger/Cli/Commands > commands.m4 --> -----------------------------------------80------------------------------------- ""