diff options
| author | Joey Hess <joey@kitenet.net> | 2014-04-10 17:22:32 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-04-10 17:23:43 -0400 |
| commit | 25942fb0cca0ca90933026bf959506e099ff95a4 (patch) | |
| tree | 2f84378c71abaa4458c5078e8cb8e6726bffbefd /Propellor/Message.hs | |
| parent | 5acaf8758f752574140dd79de7996d91a81d1cd4 (diff) | |
Propellor monad is a Reader for HostAttr
So far, the hostname is only used to improve a message in withPrivData,
but I anticipate using HostAttr for a lot more.
Diffstat (limited to 'Propellor/Message.hs')
| -rw-r--r-- | Propellor/Message.hs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/Propellor/Message.hs b/Propellor/Message.hs index 5a7d8c4b..2e63061e 100644 --- a/Propellor/Message.hs +++ b/Propellor/Message.hs @@ -1,30 +1,35 @@ +{-# LANGUAGE PackageImports #-} + module Propellor.Message where import System.Console.ANSI import System.IO import System.Log.Logger +import "mtl" Control.Monad.Reader import Propellor.Types -- | Shows a message while performing an action, with a colored status -- display. -actionMessage :: ActionResult r => Desc -> IO r -> IO r +actionMessage :: (MonadIO m, ActionResult r) => Desc -> m r -> m r actionMessage desc a = do - setTitle $ "propellor: " ++ desc - hFlush stdout + liftIO $ do + setTitle $ "propellor: " ++ desc + hFlush stdout r <- a - setTitle "propellor: running" - let (msg, intensity, color) = getActionResult r - putStr $ desc ++ " ... " - colorLine intensity color msg - hFlush stdout + liftIO $ do + setTitle "propellor: running" + let (msg, intensity, color) = getActionResult r + putStr $ desc ++ " ... " + colorLine intensity color msg + hFlush stdout return r -warningMessage :: String -> IO () -warningMessage s = colorLine Vivid Red $ "** warning: " ++ s +warningMessage :: MonadIO m => String -> m () +warningMessage s = liftIO $ colorLine Vivid Red $ "** warning: " ++ s colorLine :: ColorIntensity -> Color -> String -> IO () colorLine intensity color msg = do |
