on master help sign in
Stop showing ANSI codes on unix-based OSes

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

commit4a39fdf0a2668459d86d1e45c01b4fec4c6b4dbc authorEvan Czaplicki <info@elm-lang.org> dateFri 20 Nov 2015, 08:09 (11 years ago) parent50d4efb
1 file changed+31−7
src/Reporting/Report.hs+31−7
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+