diff --git a/src/DiffOutput.hs b/src/DiffOutput.hs index 87a1fbf2f..6fd0bb386 100644 --- a/src/DiffOutput.hs +++ b/src/DiffOutput.hs @@ -30,5 +30,5 @@ printDiff parser arguments sources = case format arguments of then path (takeFileName outputPath -<.> ".html") else path IO.withFile outputPath IO.WriteMode (`TextIO.hPutStr` rendered) - Patch -> putStrLn =<< diffFiles parser P.patch sources + Patch -> putStr =<< diffFiles parser P.patch sources JSON -> B.putStr =<< diffFiles parser J.json sources diff --git a/src/Renderer/Patch.hs b/src/Renderer/Patch.hs index 3ce346dad..08f932389 100644 --- a/src/Renderer/Patch.hs +++ b/src/Renderer/Patch.hs @@ -46,8 +46,11 @@ rowIncrement = fmap lineIncrement -- | Given the before and after sources, render a hunk to a string. showHunk :: Both SourceBlob -> Hunk (SplitDiff a Info) -> String -showHunk blobs hunk = header blobs hunk ++ concat (showChange sources <$> changes hunk) ++ showLines (snd sources) ' ' (snd <$> trailingContext hunk) +showHunk blobs hunk = if last sourceHunk /= '\n' + then sourceHunk ++ "\n\\ No newline at end of file\n" + else sourceHunk where sources = source <$> blobs + sourceHunk = header blobs hunk ++ concat (showChange sources <$> changes hunk) ++ showLines (snd sources) ' ' (snd <$> trailingContext hunk) -- | Given the before and after sources, render a change to a string. showChange :: Both (Source Char) -> Change (SplitDiff a Info) -> String