From 4a39fdf0a2668459d86d1e45c01b4fec4c6b4dbc Mon Sep 17 00:00:00 2001 From: Evan Czaplicki Date: Fri, 20 Nov 2015 08:09:14 -0800 Subject: [PATCH] Stop showing ANSI codes on unix-based OSes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/Reporting/Report.hs | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Reporting/Report.hs b/src/Reporting/Report.hs index 918c7fbda..f1c7ad4c9 100644 --- a/src/Reporting/Report.hs +++ b/src/Reporting/Report.hs @@ -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 @@ -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 +