Ajout : Lib.Foldable : tests.
[comptalang.git] / cli / Hcompta / CLI / Write.hs
index 7f6c470003a65828a935d08076eea738069e8f4c..9426e61ea16ace086cbc5ca46d8213bf14b66612 100644 (file)
@@ -14,15 +14,31 @@ with_color context h =
         Nothing -> IO.hIsTerminalDevice h
         Just b -> return b
 
+debug :: Context -> String -> IO ()
+debug context msg = do
+       case Context.verbosity context of
+        v | v >= Context.Verbosity_Debug -> do
+               color <- with_color context IO.stderr
+               when color $
+                       ANSI.hSetSGR IO.stderr [ANSI.SetColor ANSI.Foreground ANSI.Dull ANSI.Magenta]
+               IO.hPutStr IO.stderr "DEBUG"
+               when color $
+                       ANSI.hSetSGR IO.stderr [ANSI.Reset]
+               IO.hPutStr IO.stderr $ concat [": ", msg, "\n"]
+        _ -> return ()
+
 error :: Context -> String -> IO ()
 error context msg = do
-       color <- with_color context IO.stderr
-       when color $
-               ANSI.hSetSGR IO.stderr [ANSI.SetColor ANSI.Foreground ANSI.Dull ANSI.Red]
-       IO.hPutStr IO.stderr "ERROR"
-       when color $
-               ANSI.hSetSGR IO.stderr [ANSI.Reset]
-       IO.hPutStr IO.stderr $ concat [": ", msg, "\n"]
+       case Context.verbosity context of
+        v | v >= Context.Verbosity_Error -> do
+               color <- with_color context IO.stderr
+               when color $
+                       ANSI.hSetSGR IO.stderr [ANSI.SetColor ANSI.Foreground ANSI.Dull ANSI.Red]
+               IO.hPutStr IO.stderr "ERROR"
+               when color $
+                       ANSI.hSetSGR IO.stderr [ANSI.Reset]
+               IO.hPutStr IO.stderr $ concat [": ", msg, "\n"]
+        _ -> return ()
 
 fatal :: Context -> String -> IO a
 fatal context msg = do