1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 15:35:14 +03:00

Pass the chunk renderer into unified

This commit is contained in:
Matt Diephouse 2016-01-21 13:05:15 -05:00
parent bd74e7d971
commit 160c2e309a
2 changed files with 7 additions and 5 deletions

View File

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

View File

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