From b074325f674ed5a17373dcb49a207bb870c0bd05 Mon Sep 17 00:00:00 2001 From: Matt Diephouse Date: Thu, 21 Jan 2016 13:27:16 -0500 Subject: [PATCH] Make unified into a Renderer of [Chunk String] --- app/Main.hs | 6 ++++-- src/Unified.hs | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 9400e5240..1dcf39193 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -60,9 +60,11 @@ diff = interpret comparable -- | Return a renderer from the command-line arguments that will print the diff. printDiff :: Arguments -> Renderer T.Text (IO ()) printDiff arguments diff sources = case format arguments of - Unified -> B1.putStr =<< render <$> byteStringMakerFromEnvironment + Unified -> put $ unified diff sources where - render renderer = unified renderer diff sources + put chunks = do + renderer <- byteStringMakerFromEnvironment + B1.putStr $ mconcat $ chunksToByteStrings renderer chunks Split -> put (output arguments) =<< split diff sources where put Nothing rendered = TextIO.putStr rendered diff --git a/src/Unified.hs b/src/Unified.hs index 5a2af9eea..9257f6057 100644 --- a/src/Unified.hs +++ b/src/Unified.hs @@ -15,8 +15,8 @@ import qualified Data.OrderedMap as Map import Rainbow -- | Render a diff with the unified format. -unified :: (Chunk String -> [ByteString] -> [ByteString]) -> Renderer a ByteString -unified renderer diff (before, after) = mconcat . chunksToByteStrings renderer . fst $ iter g mapped +unified :: Renderer a [Chunk String] +unified diff (before, after) = fst $ iter g mapped where mapped = fmap (unifiedPatch &&& range) diff g (Annotated (_, info) syntax) = annotationAndSyntaxToChunks after info syntax