on master help sign in
Merge pull request #1190 from elm-lang/dev

Fix ANSI issue everywhere

commitdf86c1c9b3cf06de3ccb78f26b4d2fac0129ce5a authorEvan Czaplicki <info@elm-lang.org> dateFri 20 Nov 2015, 08:58 (11 years ago) parentcb1bad34a39fdf
2 files changed+47−13
src/Elm/Utils.hs+16−6 src/Reporting/Report.hs+31−7
src/Elm/Utils.hs+16−6
@@ -59,7 +59,9 @@ run :: (MonadError String m, MonadIO m) => String -> [String] -> m String
5959run command args =
6060 do result <- liftIO (unwrappedRun command args)
6161 case result of
62− Right out -> return out
62+ Right out ->
63+ return out
64+
6365 Left err ->
6466 throwError (context (message err))
6567 where
@@ -70,6 +72,7 @@ run command args =
7072 case err of
7173 CommandFailed stderr stdout ->
7274 stdout ++ stderr
75+
7376 MissingExe msg ->
7477 msg
7578
@@ -79,11 +82,18 @@ unwrappedRun command args =
7982 do (exitCode, stdout, stderr) <- readProcessWithExitCode command args ""
8083 return $
8184 case exitCode of
82− ExitSuccess -> Right stdout
83− ExitFailure code
84− | code == 127 -> Left (missingExe command) -- UNIX
85− | code == 9009 -> Left (missingExe command) -- Windows
86− | otherwise -> Left (CommandFailed stdout stderr)
85+ ExitSuccess ->
86+ Right stdout
87+
88+ ExitFailure code ->
89+ if code == 127 then
90+ Left (missingExe command) -- UNIX
91+
92+ else if code == 9009 then
93+ Left (missingExe command) -- Windows
94+
95+ else
96+ Left (CommandFailed stdout stderr)
8797
8898
8999missingExe :: String -> CommandError
src/Reporting/Report.hs+31−7
@@ -13,7 +13,8 @@ import Data.Aeson ((.=))
1313import qualified Data.Aeson.Types as Json
1414import System.IO (Handle)
1515import Text.PrettyPrint.ANSI.Leijen
16− ( Doc, (<>), displayS, displayIO, dullcyan, fillSep, hardline, renderPretty, text
16+ ( Doc, SimpleDoc(..), (<>), displayS, displayIO, dullcyan, fillSep
17+ , hardline, renderPretty, text
1718 )
1819
1920import qualified Reporting.Region as R
@@ -83,15 +84,38 @@ messageBar tag location =
8384-- RENDER DOCS
8485
8586
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+
8694toString :: String -> R.Region -> Report -> String -> String
8795toString location region rprt source =
8896 displayS
89− (renderPretty 1 80 (toDoc location region rprt source))
97+ (stripAnsi (renderPretty 1 80 (toDoc location region rprt source)))
9098 ""
9199
92100
93−toHandle :: Handle -> String -> R.Region -> Report -> String -> IO ()
94−toHandle handle location region rprt source =
95− displayIO
96− handle
97− (renderPretty 1 80 (toDoc location region rprt source))
101+stripAnsi :: SimpleDoc -> SimpleDoc
102+stripAnsi simpleDoc =
103+ case simpleDoc of
104+ SFail ->
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+