@@ -77,7 +77,7 @@ import Hledger hiding (setupPager)
7777import Hledger.Cli.CliOptions
7878import Hledger.Cli.Conf
7979import Hledger.Cli.Version
80- import System.IO (localeEncoding )
80+ import System.IO (localeEncoding , hFlush , stdout )
8181
8282
8383setupmode = hledgerCommandMode
@@ -111,10 +111,10 @@ setup _opts@CliOpts{rawopts_=_rawopts, reportspec_=_rspec} _ignoredj = do
111111 color <- useColorOnStdout
112112 when color $
113113 putStrLn $ " Legend: " <> intercalate " , " [
114- good " good"
115- ,neutral " neutral"
116- ,warning " unknown"
117- ,bad " warning"
114+ ansiGood " good"
115+ ,ansiNeutral " neutral"
116+ ,ansiWarning " unknown"
117+ ,ansiBad " warning"
118118 ]
119119 meconf <- setupHledger
120120 setupTerminal meconf
@@ -134,7 +134,8 @@ setupHledger = do
134134 then p Y prognameandversion
135135 else i N prognameandversion
136136
137- pdesc " is up to date ?"
137+ -- flush this one to show what's happening in case user gets a network access warning
138+ pdesc " is up to date ? checking..." >> hFlush stdout
138139 elatestversionnumstr <- getLatestHledgerVersion
139140 case elatestversionnumstr of
140141 Left e -> p U (" couldn't read " <> latestHledgerVersionUrlStr <> " , " <> e)
@@ -473,25 +474,46 @@ supportsColor = (>=! "1.41") -- robust color detection/control (2024)
473474supportsPager = (>=! " 1.41" ) -- use a pager for all output (2024)
474475supportsBashCompletions = (>=! " 1.41" ) -- up to date bash shell completions (2024)
475476
476- -- yes, no, unknown
477+ -- Status of a setup question/statement: yes, no, unknown
477478data YNU = Y | N | U deriving (Eq )
478479
479- -- ANSI styles
480- good = bold' . brightGreen'
481- neutral = bold' . brightBlue'
482- warning = bold' . brightYellow'
483- bad = bold' . brightRed'
484-
485- -- Show status, in red/green/yellow if supported.
480+ -- | Show status, with colours and emojis for added clarity when permitted,
481+ -- decorating Y and N with "good" and "bad" styles respectively. Used by p.
482+ -- See also 'showInfo' below.
483+ --
484+ -- Status is communicated to the user
485+ -- 1. as text: "yes"/"no"/"?"
486+ --
487+ -- and when colour is permitted,
488+ -- 2. in one of four ANSI colours
489+ -- 3. with one of four emojis appended, for added distinctiveness in case of colour blindness.
490+ --
491+ -- The emojis chosen are hopefully somewhat likely to render reasonably well even on non-apple machines;
492+ -- and if they don't, 1 and 2 will still carry the message.
486493instance Show YNU where
487- show Y = good " yes" -- ✅ apple emojis - won't work everywhere
488- show N = bad " no" -- ❌
489- show U = warning " ?"
490-
491- -- Show status, in blue/yellow if supported.
492- showInfo Y = neutral " yes" -- ℹ️
493- showInfo N = neutral " no" -- ℹ️
494- showInfo U = warning " ?"
494+ show Y = ansiGood $ " yes" `andIfColour` " ✅"
495+ show N = ansiBad $ " no" `andIfColour` " ❗"
496+ show U = ansiWarning $ " ?" `andIfColour` " 🔸" -- 🔶
497+
498+ -- | Show status, with colours and emojis for added clarity when permitted,
499+ -- decorating Y and N with "neutral" style. Used by i.
500+ -- See also 'YNU''s Show instance above.
501+ showInfo Y = ansiNeutral $ " yes" `andIfColour` " ℹ️" -- may render as monochrome in some terminals ?
502+ showInfo N = ansiNeutral $ " no" `andIfColour` " ℹ️"
503+ showInfo U = ansiWarning $ " ?" `andIfColour` " 🔸"
504+
505+ -- Dev note: confusingly, these things may not correspond:
506+ -- - "good"/"neutral"/"warning"/"bad" display text & user's perspective
507+ -- - ansiGood/ansiNeutral/ansiWarning/ansiBad styles defined below
508+ -- - warn[IO] and error functions defined elsewhere, which ANSI-decorate and display possibly ANSI-decorated text
509+
510+ -- Apply status-related ANSI styles to text.
511+ ansiGood = bold' . brightGreen'
512+ ansiNeutral = bold' . brightBlue'
513+ ansiWarning = bold' . brightYellow'
514+ ansiBad = bold' . brightRed'
515+
516+ andIfColour a b = a <> if useColorOnStdoutUnsafe then " " <> b else " "
495517
496518-- | Print a test's pass or fail status, as "yes" or "no" or "",
497519-- in green/red if supported, and the (possibly empty) provided message.
0 commit comments