1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 01:47:01 +03:00

Make unified into a Renderer of [Chunk String]

This commit is contained in:
Matt Diephouse 2016-01-21 13:27:16 -05:00
parent a166c354e3
commit b074325f67
2 changed files with 6 additions and 4 deletions

View File

@ -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

View File

@ -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