Created
September 15, 2017 09:09
-
-
Save MichaelBurge/1cc8e45ac021729c133fd42155a6284f to your computer and use it in GitHub Desktop.
Haskell -- diff anything
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.IO.Temp | |
import System.IO.Unsafe | |
import System.Process | |
import Data.Text | |
debugDiffIO :: Show a => a -> a -> IO (Maybe Text) | |
debugDiffIO x y = do | |
xf <- writeSystemTempFile "x" $ show x | |
yf <- writeSystemTempFile "y" $ show y | |
(exitCode, result, _) <- readProcessWithExitCode "git" ["diff", "--no-index", "--color-words=.", xf, yf] "" | |
case exitCode of | |
ExitSuccess -> return Nothing | |
ExitFailure n -> return $ Just $ pack result | |
debugDiff' :: Show a => a -> a -> Maybe Text | |
debugDiff' x y = unsafePerformIO $ debugDiffIO x y | |
debugDiff x y = fromMaybe "" $ debugDiff' x y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment