mirror of
https://github.com/github/semantic.git
synced 2024-12-25 16:02:43 +03:00
Pass the chunk renderer into unified
This commit is contained in:
parent
bd74e7d971
commit
160c2e309a
@ -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
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user