1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 08:25:19 +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.Detect as Detect
import qualified Data.Text.ICU.Convert as Convert import qualified Data.Text.ICU.Convert as Convert
import Data.Bifunctor.Join import Data.Bifunctor.Join
import Rainbow
-- | The available types of diff rendering. -- | The available types of diff rendering.
data Format = Unified | Split | Patch 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. -- | Return a renderer from the command-line arguments that will print the diff.
printDiff :: Arguments -> Renderer T.Text (IO ()) printDiff :: Arguments -> Renderer T.Text (IO ())
printDiff arguments diff sources = case format arguments of 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 Split -> put (output arguments) =<< split diff sources
where where
put Nothing rendered = TextIO.putStr rendered put Nothing rendered = TextIO.putStr rendered

View File

@ -14,10 +14,9 @@ import Data.List hiding (foldl)
import qualified Data.OrderedMap as Map import qualified Data.OrderedMap as Map
import Rainbow import Rainbow
unified :: Renderer a (IO ByteString) unified :: (Chunk String -> [ByteString] -> [ByteString]) -> Renderer a ByteString
unified diff (before, after) = do unified renderer diff (before, after) =
renderer <- byteStringMakerFromEnvironment mconcat . chunksToByteStrings renderer . fst $ iter g mapped where
return . mconcat . chunksToByteStrings renderer . fst $ iter g mapped where
mapped = fmap (unifiedPatch &&& range) diff mapped = fmap (unifiedPatch &&& range) diff
g (Annotated (_, info) syntax) = annotationAndSyntaxToChunks after info syntax g (Annotated (_, info) syntax) = annotationAndSyntaxToChunks after info syntax
annotationAndSyntaxToChunks source (Info range _) (Leaf _) = (pure . chunk . toList $ slice range source, Just range) annotationAndSyntaxToChunks source (Info range _) (Leaf _) = (pure . chunk . toList $ slice range source, Just range)