summaryrefslogtreecommitdiff
path: root/Propellor/Message.hs
diff options
context:
space:
mode:
authorJoey Hess2014-03-31 18:31:08 -0400
committerJoey Hess2014-03-31 18:31:08 -0400
commitc246a8ee745723140150c8b8d35b7a7121c90c11 (patch)
treedf25d3e13ef919e14ee51f1c70e82073c1077209 /Propellor/Message.hs
parent549df2612c0e12d44bf4e998cabdfcf3bb0a7344 (diff)
propellor spin
Diffstat (limited to 'Propellor/Message.hs')
-rw-r--r--Propellor/Message.hs40
1 files changed, 40 insertions, 0 deletions
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!"