From 50d4efb705171f45179ea3895fbbdaa3829dc7f1 Mon Sep 17 00:00:00 2001 From: Evan Czaplicki Date: Fri, 20 Nov 2015 08:06:04 -0800 Subject: [PATCH 1/2] cosmetic: use nicer indentation and if style --- src/Elm/Utils.hs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Elm/Utils.hs b/src/Elm/Utils.hs index 7bee46656..1fe365762 100644 --- a/src/Elm/Utils.hs +++ b/src/Elm/Utils.hs @@ -59,7 +59,9 @@ run :: (MonadError String m, MonadIO m) => String -> [String] -> m String run command args = do result <- liftIO (unwrappedRun command args) case result of - Right out -> return out + Right out -> + return out + Left err -> throwError (context (message err)) where @@ -70,6 +72,7 @@ run command args = case err of CommandFailed stderr stdout -> stdout ++ stderr + MissingExe msg -> msg @@ -79,11 +82,18 @@ unwrappedRun command args = do (exitCode, stdout, stderr) <- readProcessWithExitCode command args "" return $ case exitCode of - ExitSuccess -> Right stdout - ExitFailure code - | code == 127 -> Left (missingExe command) -- UNIX - | code == 9009 -> Left (missingExe command) -- Windows - | otherwise -> Left (CommandFailed stdout stderr) + ExitSuccess -> + Right stdout + + ExitFailure code -> + if code == 127 then + Left (missingExe command) -- UNIX + + else if code == 9009 then + Left (missingExe command) -- Windows + + else + Left (CommandFailed stdout stderr) missingExe :: String -> CommandError From 4a39fdf0a2668459d86d1e45c01b4fec4c6b4dbc Mon Sep 17 00:00:00 2001 From: Evan Czaplicki Date: Fri, 20 Nov 2015 08:09:14 -0800 Subject: [PATCH 2/2] Stop showing ANSI codes on unix-based OSes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cc @jvoigtlaender I thought that displayIO was for ANSI and displayS was for not-ANSI. It turns out that displayS will add the ANSI codes into the string if you are on not-Windows. This meant that garbage characters were ending up in the output of JSON errors or reactor errors @rtfeldman, I’ll try to get a new set of binaries ready for linux 32-bit and mac --- src/Reporting/Report.hs | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Reporting/Report.hs b/src/Reporting/Report.hs index 918c7fbda..f1c7ad4c9 100644 --- a/src/Reporting/Report.hs +++ b/src/Reporting/Report.hs @@ -13,7 +13,8 @@ import Data.Aeson ((.=)) import qualified Data.Aeson.Types as Json import System.IO (Handle) import Text.PrettyPrint.ANSI.Leijen - ( Doc, (<>), displayS, displayIO, dullcyan, fillSep, hardline, renderPretty, text + ( Doc, SimpleDoc(..), (<>), displayS, displayIO, dullcyan, fillSep + , hardline, renderPretty, text ) import qualified Reporting.Region as R @@ -83,15 +84,38 @@ messageBar tag location = -- RENDER DOCS +toHandle :: Handle -> String -> R.Region -> Report -> String -> IO () +toHandle handle location region rprt source = + displayIO + handle + (renderPretty 1 80 (toDoc location region rprt source)) + + toString :: String -> R.Region -> Report -> String -> String toString location region rprt source = displayS - (renderPretty 1 80 (toDoc location region rprt source)) + (stripAnsi (renderPretty 1 80 (toDoc location region rprt source))) "" -toHandle :: Handle -> String -> R.Region -> Report -> String -> IO () -toHandle handle location region rprt source = - displayIO - handle - (renderPretty 1 80 (toDoc location region rprt source)) +stripAnsi :: SimpleDoc -> SimpleDoc +stripAnsi simpleDoc = + case simpleDoc of + SFail -> + SFail + + SEmpty -> + SEmpty + + SChar chr subDoc -> + SChar chr (stripAnsi subDoc) + + SText n str subDoc -> + SText n str (stripAnsi subDoc) + + SLine n subDoc -> + SLine n (stripAnsi subDoc) + + SSGR _ subDoc -> + stripAnsi subDoc +