blob: 1501c072a5587fbdc779461097f5478708729069 (
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
{- git-annex output messages
-
- Copyright 2010-2014 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
{-# LANGUAGE CPP #-}
module Messages.Internal where
import Common
import Types
import Types.Messages
import qualified Annex
#ifdef WITH_CONCURRENTOUTPUT
import System.Console.Concurrent
#endif
outputMessage :: IO () -> String -> Annex ()
outputMessage json s = withOutputType go
where
go NormalOutput = liftIO $
flushed $ putStr s
go QuietOutput = q
go (ConcurrentOutput _) = liftIO $
#ifdef WITH_CONCURRENTOUTPUT
outputConcurrent s
#else
q
#endif
go JSONOutput = liftIO $ flushed json
outputError :: String -> Annex ()
outputError s = withOutputType go
where
go (ConcurrentOutput _) = liftIO $
#ifdef WITH_CONCURRENTOUTPUT
errorConcurrent s
#else
q
#endif
go _ = liftIO $ do
hFlush stdout
hPutStr stderr s
hFlush stderr
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
|