]> Git — Sourcephile - comptalang.git/blob - cli/Hcompta/CLI/Write.hs
Modif : Calc.Balance.Equilibre : retourne ce qui n’est pas équilibré.
[comptalang.git] / cli / Hcompta / CLI / Write.hs
1 module Hcompta.CLI.Write where
2
3 import Control.Monad (when)
4 import qualified System.IO as IO
5 import qualified System.Console.ANSI as ANSI
6 import System.Exit (exitWith, ExitCode(..))
7
8 import qualified Hcompta.CLI.Context as Context
9 import Hcompta.CLI.Context (Context)
10
11 with_color :: Context -> IO.Handle -> IO Bool
12 with_color context h =
13 case Context.color context of
14 Nothing -> IO.hIsTerminalDevice h
15 Just b -> return b
16
17 error :: Context -> String -> IO ()
18 error context msg = do
19 color <- with_color context IO.stderr
20 when color $
21 ANSI.hSetSGR IO.stderr [ANSI.SetColor ANSI.Foreground ANSI.Dull ANSI.Red]
22 IO.hPutStr IO.stderr "ERROR"
23 when color $
24 ANSI.hSetSGR IO.stderr [ANSI.Reset]
25 IO.hPutStr IO.stderr $ concat [": ", msg, "\n"]
26
27 fatal :: Context -> String -> IO a
28 fatal context msg = do
29 Hcompta.CLI.Write.error context msg
30 exitWith $ ExitFailure 1