From c246a8ee745723140150c8b8d35b7a7121c90c11 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 31 Mar 2014 18:31:08 -0400 Subject: propellor spin --- Propellor/Message.hs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Propellor/Message.hs (limited to 'Propellor/Message.hs') diff --git a/Propellor/Message.hs b/Propellor/Message.hs new file mode 100644 index 00000000..a7ceff91 --- /dev/null +++ b/Propellor/Message.hs @@ -0,0 +1,40 @@ +module Propellor.Message where + +import System.Console.ANSI +import System.IO + +import Propellor.Types + +-- | Shows a message while performing an action, with a colored status +-- display. +actionMessage :: ActionResult r => Desc -> IO r -> IO r +actionMessage desc a = do + setTitle desc + showdesc + putStrLn "starting" + hFlush stdout + + r <- a + + let (msg, intensity, color) = getActionResult r + showdesc + setSGR [SetColor Foreground intensity color] + putStrLn msg + setSGR [] + hFlush stdout + + return r + where + showdesc = putStr $ desc ++ " ... " + +warningMessage :: String -> IO () +warningMessage s = do + setSGR [SetColor Foreground Vivid Red] + putStrLn $ "** warning: " ++ s + setSGR [] + hFlush stdout + +errorMessage :: String -> IO a +errorMessage s = do + warningMessage s + error "Propellor failed!" -- cgit v1.2.3