propellor/Propellor/Message.hs

38 lines
780 B
Haskell
Raw Normal View History

2014-03-31 22:31:08 +00:00
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
2014-03-31 23:31:35 +00:00
setTitle $ "propellor: " ++ desc
2014-03-31 22:31:08 +00:00
hFlush stdout
r <- a
let (msg, intensity, color) = getActionResult r
2014-03-31 22:36:53 +00:00
putStr $ desc ++ " ... "
2014-03-31 22:31:08 +00:00
setSGR [SetColor Foreground intensity color]
putStrLn msg
setSGR []
2014-03-31 23:31:35 +00:00
setTitle "propellor: running"
2014-03-31 22:31:08 +00:00
hFlush stdout
return r
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!"