2015-11-04 20:19:00 +00:00
|
|
|
{- git-annex output messages, including concurrent output to display regions
|
2015-04-03 20:48:30 +00:00
|
|
|
-
|
2015-11-04 18:52:07 +00:00
|
|
|
- Copyright 2010-2015 Joey Hess <id@joeyh.name>
|
2015-04-03 20:48:30 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Messages.Internal where
|
|
|
|
|
|
|
|
import Common
|
2015-11-04 18:52:07 +00:00
|
|
|
import Annex
|
2015-04-03 20:48:30 +00:00
|
|
|
import Types.Messages
|
2015-11-05 21:22:45 +00:00
|
|
|
import Messages.Concurrent
|
2015-11-04 17:45:34 +00:00
|
|
|
|
2015-11-04 18:52:07 +00:00
|
|
|
withOutputType :: (OutputType -> Annex a) -> Annex a
|
|
|
|
withOutputType a = outputType <$> Annex.getState Annex.output >>= a
|
|
|
|
|
2015-11-04 17:45:34 +00:00
|
|
|
outputMessage :: IO () -> String -> Annex ()
|
|
|
|
outputMessage json s = withOutputType go
|
2015-04-03 20:48:30 +00:00
|
|
|
where
|
2015-11-04 17:45:34 +00:00
|
|
|
go NormalOutput = liftIO $
|
|
|
|
flushed $ putStr s
|
2015-04-03 20:48:30 +00:00
|
|
|
go QuietOutput = q
|
2016-02-14 19:02:42 +00:00
|
|
|
go o@(ConcurrentOutput {}) = concurrentMessage o False s q
|
2015-04-03 20:48:30 +00:00
|
|
|
go JSONOutput = liftIO $ flushed json
|
|
|
|
|
2015-11-04 17:45:34 +00:00
|
|
|
outputError :: String -> Annex ()
|
|
|
|
outputError s = withOutputType go
|
|
|
|
where
|
2016-02-14 19:02:42 +00:00
|
|
|
go o@(ConcurrentOutput {}) = concurrentMessage o True s (go NormalOutput)
|
2015-11-04 17:45:34 +00:00
|
|
|
go _ = liftIO $ do
|
|
|
|
hFlush stdout
|
|
|
|
hPutStr stderr s
|
|
|
|
hFlush stderr
|
|
|
|
|
2015-04-03 20:48:30 +00:00
|
|
|
q :: Monad m => m ()
|
|
|
|
q = noop
|
|
|
|
|
|
|
|
flushed :: IO () -> IO ()
|
|
|
|
flushed a = a >> hFlush stdout
|