summaryrefslogtreecommitdiff
path: root/Biz/Log.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2021-01-26 19:05:58 -0500
committerBen Sima <ben@bsima.me>2021-01-26 19:50:06 -0500
commit82dbbc0eed18c86aae1a8f1f92a0c98684e63409 (patch)
tree66319a88e1f1f4383a15ac070079c3459b0fc7f8 /Biz/Log.hs
parent0ec6b06acee62b57a50ed9718b8da31fced18c4d (diff)
Create Biz.Log library, extracted from Biz.Bild
Diffstat (limited to 'Biz/Log.hs')
-rw-r--r--Biz/Log.hs44
1 files changed, 44 insertions, 0 deletions
diff --git a/Biz/Log.hs b/Biz/Log.hs
new file mode 100644
index 0000000..c713946
--- /dev/null
+++ b/Biz/Log.hs
@@ -0,0 +1,44 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE NoImplicitPrelude #-}
+
+module Biz.Log
+ ( Lvl (..),
+ good,
+ pass,
+ info,
+ warn,
+ fail,
+ -- | Low-level
+ msg,
+ br,
+ )
+where
+
+import Alpha hiding (pass)
+import qualified Data.Text as Text
+import Rainbow (chunk, fore, green, putChunk, red, white, yellow)
+
+data Lvl = Good | Pass | Info | Warn | Fail
+
+msg :: Lvl -> [Text] -> IO ()
+msg lvl labels = putChunk <| fore color <| clear <> txt <> "\r"
+ where
+ txt = chunk <| Text.intercalate gap (label : labels)
+ (color, label) = case lvl of
+ Good -> (green, "good")
+ Pass -> (green, "pass")
+ Info -> (white, "info")
+ Warn -> (yellow, "warn")
+ Fail -> (red, "fail")
+ gap = ": "
+ clear = "\ESC[2K"
+
+br :: IO ()
+br = putChunk "\n"
+
+good, pass, info, warn, fail :: [Text] -> IO ()
+good = msg Good
+pass = msg Pass
+info = msg Info
+warn = msg Warn
+fail = msg Fail