From 82dbbc0eed18c86aae1a8f1f92a0c98684e63409 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Tue, 26 Jan 2021 19:05:58 -0500 Subject: Create Biz.Log library, extracted from Biz.Bild --- Biz/Log.hs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Biz/Log.hs (limited to 'Biz/Log.hs') 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 -- cgit v1.2.3