@@ -79,6 +79,7 @@ import Hledger.Cli.Conf
7979import Hledger.Cli.Version
8080import System.IO (localeEncoding , hFlush , stdout )
8181import Data.Either (isLeft , isRight )
82+ import Control.Arrow ((>>>) )
8283
8384
8485setupmode = hledgerCommandMode
@@ -112,10 +113,10 @@ setup _opts@CliOpts{rawopts_=_rawopts, reportspec_=_rspec} _ignoredj = do
112113 color <- useColorOnStdout
113114 when color $
114115 putStrLn $ " Legend: " <> intercalate " , " [
115- ansiGood " good"
116- ,ansiInfo " info"
117- ,ansiWarning " warning"
118- ,ansiProblem " problem"
116+ styleGood " good"
117+ ,styleInfo " info"
118+ ,styleWarning " warning"
119+ ,styleBad " problem"
119120 ]
120121 meconf <- setupHledger
121122 setupTerminal meconf
@@ -476,34 +477,43 @@ instance Show YNU where
476477p :: YNU -> String -> IO ()
477478p status msg = putStrLn $ unwords [" " , showGoodBad status, " " , msg]
478479 where
479- showGoodBad Y = ansiGood $ " yes" `andIfColour` checkmarkInGreenBoxEmoji
480- showGoodBad N = ansiProblem $ " no" `andIfColour` redExclamationMarkEmoji
481- showGoodBad U = ansiWarning $ " ?" `andIfColour` yellowDiamondEmoji
480+ showGoodBad Y = styleGood " yes"
481+ showGoodBad N = styleBad " no"
482+ showGoodBad U = styleWarning " ?"
482483
483- -- | Print a status, ANSI-styled and emoji-decorated when permitted, using the good/warning styles for Y/N;
484- -- and the (possibly empty) provided message.
484+ -- | Print a status, ANSI-styled and emoji-decorated when permitted,
485+ -- using the good/warning styles for Y/N; and the (possibly empty) provided message.
485486w :: YNU -> String -> IO ()
486487w status msg = putStrLn $ unwords [" " , showGoodWarn status, " " , msg]
487488 where
488- showGoodWarn Y = ansiGood $ " yes" `andIfColour` iInBlueBoxEmoji
489- showGoodWarn N = ansiWarning $ " no" `andIfColour` yellowDiamondEmoji
490- showGoodWarn U = ansiWarning $ " ?" `andIfColour` yellowDiamondEmoji
489+ showGoodWarn Y = styleGood " yes"
490+ showGoodWarn N = styleWarning " no"
491+ showGoodWarn U = styleWarning " ?"
491492
492- -- | Print a status, ANSI-styled and emoji-decorated when permitted, using the neutral style for Y/N;
493- -- and the (possibly empty) provided message.
493+ -- | Print a status, ANSI-styled and emoji-decorated when permitted,
494+ -- using the info style for Y/N; and the (possibly empty) provided message.
494495i :: YNU -> String -> IO ()
495496i status msg = putStrLn $ unwords [" " , showInfo status, " " , msg]
496497 where
497- showInfo Y = ansiInfo $ " yes" `andIfColour` iInBlueBoxEmoji
498- showInfo N = ansiInfo $ " no" `andIfColour` iInBlueBoxEmoji
499- showInfo U = ansiWarning $ " ?" `andIfColour` yellowDiamondEmoji
498+ showInfo Y = styleInfo " yes"
499+ showInfo N = styleInfo " no"
500+ showInfo U = styleWarning " ?"
501+
502+ styleGood = ansiGood >>> appendIfColor checkmarkInGreenBoxEmoji
503+ styleInfo = ansiInfo >>> appendIfColor iInBlueBoxEmoji
504+ styleWarning = ansiWarning >>> appendIfColor yellowDiamondEmoji
505+ styleBad = ansiProblem >>> appendIfColor redExclamationMarkEmoji
500506
501507-- Apply setup-status-related ANSI styles to text.
502508ansiGood = bold' . brightGreen'
503509ansiInfo = bold' . brightBlue'
504510ansiWarning = bold' . brightYellow'
505511ansiProblem = bold' . brightRed'
506512
513+ -- Append a space and the given text to the second text,
514+ -- if colour is permitted on stdout (using 'useColorOnStdoutUnsafe').
515+ appendIfColor suffix t = t <> if useColorOnStdoutUnsafe then " " <> suffix else " "
516+
507517-- Use only reasonably well-supported emojis here.
508518checkmarkInGreenBoxEmoji = " ✅"
509519-- This one may render as monochrome in some terminals ?
@@ -513,9 +523,6 @@ yellowDiamondEmoji = "🔸"
513523largeYellowDiamondEmoji = " 🔶"
514524redExclamationMarkEmoji = " ❗"
515525
516- -- Append a space and the second text, if colour is permitted on stdout (using 'useColorOnStdoutUnsafe').
517- andIfColour a b = a <> if useColorOnStdoutUnsafe then " " <> b else " "
518-
519526-- | Print a setup test group's heading.
520527pgroup :: String -> IO ()
521528pgroup s = putStrLn $ " \n " <> bold' s
0 commit comments