Skip to content

Commit

Permalink
Stop showing ANSI codes on unix-based OSes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
process-bot committed Nov 20, 2015
1 parent 50d4efb commit 4a39fdf
Showing 1 changed file with 31 additions and 7 deletions.
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 4a39fdf

Please sign in to comment.