From cac7297784a4eb953f0d6108d7e67e97be9285ad Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Sep 2016 12:57:42 -0400 Subject: disentangle concurrency and message type This makes -Jn work with --json and --quiet, where before setting -Jn disabled those options. Concurrent json output is currently a mess though since threads output chunks over top of one-another. --- Messages.hs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'Messages.hs') diff --git a/Messages.hs b/Messages.hs index f1055efb8..61702530f 100644 --- a/Messages.hs +++ b/Messages.hs @@ -40,7 +40,7 @@ module Messages ( commandProgressDisabled, outputMessage, implicitMessage, - withOutputType, + withMessageState, ) where import System.Log.Logger @@ -155,17 +155,15 @@ indent = intercalate "\n" . map (\l -> " " ++ l) . lines {- Shows a JSON chunk only when in json mode. -} maybeShowJSON :: JSONChunk v -> Annex () -maybeShowJSON v = withOutputType $ liftIO . go - where - go JSONOutput = JSON.add v - go _ = return () +maybeShowJSON v = withMessageState $ \s -> case outputType s of + JSONOutput -> liftIO $ JSON.add v + _ -> return () {- Shows a complete JSON value, only when in json mode. -} showFullJSON :: JSONChunk v -> Annex Bool -showFullJSON v = withOutputType $ liftIO . go - where - go JSONOutput = JSON.complete v >> return True - go _ = return False +showFullJSON v = withMessageState $ \s -> case outputType s of + JSONOutput -> liftIO $ JSON.complete v >> return True + _ -> return False {- Performs an action that outputs nonstandard/customized output, and - in JSON mode wraps its output in JSON.start and JSON.end, so it's @@ -216,11 +214,11 @@ debugEnabled = do {- Should commands that normally output progress messages have that - output disabled? -} commandProgressDisabled :: Annex Bool -commandProgressDisabled = withOutputType $ \t -> return $ case t of - QuietOutput -> True - JSONOutput -> True - NormalOutput -> False - ConcurrentOutput {} -> True +commandProgressDisabled = withMessageState $ \s -> return $ + case outputType s of + QuietOutput -> True + JSONOutput -> True + NormalOutput -> concurrentOutputEnabled s {- Use to show a message that is displayed implicitly, and so might be - disabled when running a certian command that needs more control over its -- cgit v1.2.3