Skip to content

Commit

Permalink
Merge pull request #1190 from elm-lang/dev
Browse files Browse the repository at this point in the history
Fix ANSI issue everywhere
  • Loading branch information
process-bot committed Nov 20, 2015
2 parents cb1bad3 + 4a39fdf commit df86c1c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
22 changes: 16 additions & 6 deletions src/Elm/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -70,6 +72,7 @@ run command args =
case err of
CommandFailed stderr stdout ->
stdout ++ stderr

MissingExe msg ->
msg

Expand All @@ -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
Expand Down
38 changes: 31 additions & 7 deletions src/Reporting/Report.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit df86c1c

Please sign in to comment.