on master help sign in
Merge pull request #1190 from elm-lang/dev
df86c1cEvan Czaplicki
src/Elm/Utils.hs+16−6
@@ -59,7 +59,9 @@ run :: (MonadError String m, MonadIO m) => String -> [String] -> m String
59run command args =
59run command args =
60 do result <- liftIO (unwrappedRun command args)
60 do result <- liftIO (unwrappedRun command args)
61 case result of
61 case result of
62+ Right out ->
62− Right out -> return out
63+ return out
64+
63 Left err ->
65 Left err ->
64 throwError (context (message err))
66 throwError (context (message err))
65 where
67 where
@@ -70,6 +72,7 @@ run command args =
70 case err of
72 case err of
71 CommandFailed stderr stdout ->
73 CommandFailed stderr stdout ->
72 stdout ++ stderr
74 stdout ++ stderr
75+
73 MissingExe msg ->
76 MissingExe msg ->
74 msg
77 msg
75
78
@@ -79,11 +82,18 @@ unwrappedRun command args =
79 do (exitCode, stdout, stderr) <- readProcessWithExitCode command args ""
82 do (exitCode, stdout, stderr) <- readProcessWithExitCode command args ""
80 return $
83 return $
81 case exitCode of
84 case exitCode of
82− ExitSuccess -> Right stdout
85+ ExitSuccess ->
86+ Right stdout
87+
83− ExitFailure code
88+ ExitFailure code ->
89+ if code == 127 then
84− | code == 127 -> Left (missingExe command) -- UNIX
90+ Left (missingExe command) -- UNIX
91+
92+ else if code == 9009 then
85− | code == 9009 -> Left (missingExe command) -- Windows
93+ Left (missingExe command) -- Windows
94+
95+ else
86− | otherwise -> Left (CommandFailed stdout stderr)
96+ Left (CommandFailed stdout stderr)
87
97
88
98
89missingExe :: String -> CommandError
99missingExe :: String -> CommandError
src/Reporting/Report.hs+31−7
@@ -13,7 +13,8 @@ import Data.Aeson ((.=))
13import qualified Data.Aeson.Types as Json
13import qualified Data.Aeson.Types as Json
14import System.IO (Handle)
14import System.IO (Handle)
15import Text.PrettyPrint.ANSI.Leijen
15import Text.PrettyPrint.ANSI.Leijen
16− ( Doc, (<>), displayS, displayIO, dullcyan, fillSep, hardline, renderPretty, text
16+ ( Doc, SimpleDoc(..), (<>), displayS, displayIO, dullcyan, fillSep
17+ , hardline, renderPretty, text
17 )
18 )
18
19
19import qualified Reporting.Region as R
20import qualified Reporting.Region as R
@@ -83,15 +84,38 @@ messageBar tag location =
83-- RENDER DOCS
84-- RENDER DOCS
84
85
85
86
87+toHandle :: Handle -> String -> R.Region -> Report -> String -> IO ()
88+toHandle handle location region rprt source =
89+ displayIO
90+ handle
91+ (renderPretty 1 80 (toDoc location region rprt source))
92+
93+
86toString :: String -> R.Region -> Report -> String -> String
94toString :: String -> R.Region -> Report -> String -> String
87toString location region rprt source =
95toString location region rprt source =
88 displayS
96 displayS
89− (renderPretty 1 80 (toDoc location region rprt source))
97+ (stripAnsi (renderPretty 1 80 (toDoc location region rprt source)))
90 ""
98 ""
91
99
92
100
93−toHandle :: Handle -> String -> R.Region -> Report -> String -> IO ()
101+stripAnsi :: SimpleDoc -> SimpleDoc
94−toHandle handle location region rprt source =
102+stripAnsi simpleDoc =
95− displayIO
103+ case simpleDoc of
96− handle
104+ SFail ->
97− (renderPretty 1 80 (toDoc location region rprt source))
105+ SFail
106+
107+ SEmpty ->
108+ SEmpty
109+
110+ SChar chr subDoc ->
111+ SChar chr (stripAnsi subDoc)
112+
113+ SText n str subDoc ->
114+ SText n str (stripAnsi subDoc)
115+
116+ SLine n subDoc ->
117+ SLine n (stripAnsi subDoc)
118+
119+ SSGR _ subDoc ->
120+ stripAnsi subDoc
121+