From 4a09b4bbbd654538fe4912c617531da241da482a Mon Sep 17 00:00:00 2001 From: Joey Hess <joeyh@joeyh.name> Date: Fri, 9 Sep 2016 14:21:06 -0400 Subject: [PATCH] make maybeShowJSON also add to the buffer --- Messages.hs | 8 ++------ Messages/Internal.hs | 14 +++++++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Messages.hs b/Messages.hs index b8764be551..83f444a99c 100644 --- a/Messages.hs +++ b/Messages.hs @@ -155,15 +155,11 @@ indent = intercalate "\n" . map (\l -> " " ++ l) . lines {- Shows a JSON chunk only when in json mode. -} maybeShowJSON :: JSONChunk v -> Annex () -maybeShowJSON v = withMessageState $ \s -> case outputType s of - JSONOutput -> liftIO $ JSON.add v - _ -> return () +maybeShowJSON v = void $ withMessageState $ outputJSON (JSON.add v) False {- Shows a complete JSON value, only when in json mode. -} showFullJSON :: JSONChunk v -> Annex Bool -showFullJSON v = withMessageState $ \s -> case outputType s of - JSONOutput -> liftIO $ JSON.complete v >> return True - _ -> return False +showFullJSON v = withMessageState $ outputJSON (JSON.complete v) True {- Performs an action that outputs nonstandard/customized output, and - in JSON mode wraps its output in JSON.start and JSON.end, so it's diff --git a/Messages/Internal.hs b/Messages/Internal.hs index b8af2f73f4..21d11d8113 100644 --- a/Messages/Internal.hs +++ b/Messages/Internal.hs @@ -26,8 +26,13 @@ outputMessage' endmessage json msg = withMessageState $ \s -> case outputType s NormalOutput | concurrentOutputEnabled s -> concurrentMessage s False msg q | otherwise -> liftIO $ flushed $ putStr msg + JSONOutput -> void $ outputJSON json endmessage s + QuietOutput -> q + +outputJSON :: IO () -> Bool -> MessageState -> Annex Bool +outputJSON json endmessage s = case outputType s of JSONOutput - | concurrentOutputEnabled s -> + | concurrentOutputEnabled s -> do -- Buffer json fragments until end is reached. if endmessage then do @@ -38,8 +43,11 @@ outputMessage' endmessage json msg = withMessageState $ \s -> case outputType s json else Annex.changeState $ \st -> st { Annex.output = s { jsonBuffer = json : jsonBuffer s } } - | otherwise -> liftIO $ flushed json - QuietOutput -> q + return True + | otherwise -> do + liftIO $ flushed json + return True + _ -> return False outputError :: String -> Annex () outputError msg = withMessageState $ \s ->