summaryrefslogtreecommitdiff
path: root/Propellor/Message.hs
blob: 90163649ece7f8c7a640afec4e8793698676d6f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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 $ "propellor: " ++ desc
	hFlush stdout

	r <- a

	let (msg, intensity, color) = getActionResult r
	putStr $ desc ++ " ... "
	setSGR [SetColor Foreground intensity color]
	putStrLn msg
	setSGR []
	setTitle "propellor: running"
	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!"