From 160c2e309abe2a1efb1081097a608281bcf537c2 Mon Sep 17 00:00:00 2001 From: Matt Diephouse Date: Thu, 21 Jan 2016 13:05:15 -0500 Subject: [PATCH] Pass the chunk renderer into unified --- app/Main.hs | 5 ++++- src/Unified.hs | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index ec2387bb6..9400e5240 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -23,6 +23,7 @@ import qualified System.IO as IO import qualified Data.Text.ICU.Detect as Detect import qualified Data.Text.ICU.Convert as Convert import Data.Bifunctor.Join +import Rainbow -- | The available types of diff rendering. data Format = Unified | Split | Patch @@ -59,7 +60,9 @@ 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 =<< unified diff sources + Unified -> B1.putStr =<< render <$> byteStringMakerFromEnvironment + where + render renderer = unified renderer diff sources 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 ccb3874ad..f112d2ec4 100644 --- a/src/Unified.hs +++ b/src/Unified.hs @@ -14,10 +14,9 @@ import Data.List hiding (foldl) import qualified Data.OrderedMap as Map import Rainbow -unified :: Renderer a (IO ByteString) -unified diff (before, after) = do - renderer <- byteStringMakerFromEnvironment - return . mconcat . chunksToByteStrings renderer . fst $ iter g mapped where +unified :: (Chunk String -> [ByteString] -> [ByteString]) -> Renderer a ByteString +unified renderer diff (before, after) = + mconcat . chunksToByteStrings renderer . fst $ iter g mapped where mapped = fmap (unifiedPatch &&& range) diff g (Annotated (_, info) syntax) = annotationAndSyntaxToChunks after info syntax annotationAndSyntaxToChunks source (Info range _) (Leaf _) = (pure . chunk . toList $ slice range source, Just range)