summaryrefslogtreecommitdiff
path: root/Messages/Internal.hs
blob: 2495f4fd3feebfc03ad0699293f1b66ed368093e (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
{- git-annex output messages
 -
 - Copyright 2010-2014 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Messages.Internal where

import Common
import Types
import Types.Messages
import qualified Annex

handleMessage :: IO () -> IO () -> Annex ()
handleMessage json normal = withOutputType go
  where
	go NormalOutput = liftIO normal
	go QuietOutput = q
	go (ParallelOutput _) = q
	go JSONOutput = liftIO $ flushed json

q :: Monad m => m ()
q = noop

flushed :: IO () -> IO ()
flushed a = a >> hFlush stdout

withOutputType :: (OutputType -> Annex a) -> Annex a
withOutputType a = outputType <$> Annex.getState Annex.output >>= a