Skip to content

Commit d8996c0

Browse files
committed
imp:setup: show emojis in the legend also
1 parent 46ad6c0 commit d8996c0

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

hledger/Hledger/Cli/Commands/Setup.hs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import Hledger.Cli.Conf
7979
import Hledger.Cli.Version
8080
import System.IO (localeEncoding, hFlush, stdout)
8181
import Data.Either (isLeft, isRight)
82+
import Control.Arrow ((>>>))
8283

8384

8485
setupmode = 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
476477
p :: YNU -> String -> IO ()
477478
p 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.
485486
w :: YNU -> String -> IO ()
486487
w 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.
494495
i :: YNU -> String -> IO ()
495496
i 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.
502508
ansiGood = bold' . brightGreen'
503509
ansiInfo = bold' . brightBlue'
504510
ansiWarning = bold' . brightYellow'
505511
ansiProblem = 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.
508518
checkmarkInGreenBoxEmoji = ""
509519
-- This one may render as monochrome in some terminals ?
@@ -513,9 +523,6 @@ yellowDiamondEmoji = "🔸"
513523
largeYellowDiamondEmoji = "🔶"
514524
redExclamationMarkEmoji = ""
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.
520527
pgroup :: String -> IO ()
521528
pgroup s = putStrLn $ "\n" <> bold' s

0 commit comments

Comments
 (0)