Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions compiler/src/Reporting/Doc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import Json.Encode ((==>))
import Json.Encode qualified as E
import Json.String qualified as Json
import System.Console.ANSI.Types qualified as Ansi
import System.Environment qualified
import System.IO (Handle)
import System.Info qualified as Info
import Text.PrettyPrint.ANSI.Leijen qualified as P
Expand Down Expand Up @@ -102,8 +103,16 @@ fromInt n =
-- TO STRING

toAnsi :: Handle -> P.Doc -> IO ()
toAnsi handle doc =
P.displayIO handle (P.renderPretty 1 80 doc)
toAnsi handle doc = do
docOutput <- maybeRemoveDocColors doc
P.displayIO handle (P.renderPretty 1 80 docOutput)

maybeRemoveDocColors :: P.Doc -> IO P.Doc
maybeRemoveDocColors doc = do
noColorEnv <- System.Environment.lookupEnv "NO_COLOR"
pure $ case noColorEnv of
Just noColor | noColor /= "" -> P.plain doc
_ -> doc

toString :: P.Doc -> String
toString doc =
Expand Down
12 changes: 6 additions & 6 deletions terminal/impl/Terminal/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ where
import Data.List qualified as List
import Data.Maybe qualified as Maybe
import GHC.IO.Handle (hIsTerminalDevice)
import Reporting.Doc qualified as D
import Reporting.Suggest as Suggest
import System.Environment qualified as Env
import System.Exit qualified as Exit
Expand Down Expand Up @@ -62,12 +63,11 @@ exitWith code docs =
do
isTerminal <- hIsTerminalDevice stderr
let adjust = if isTerminal then id else P.plain
P.displayIO stderr $
P.renderPretty 1 80 $
adjust $
P.vcat $
concatMap (\d -> [d, ""]) $
trimDocs docs
D.toAnsi stderr $
adjust $
P.vcat $
concatMap (\d -> [d, ""]) $
trimDocs docs
hPutStrLn stderr ""
Exit.exitWith code

Expand Down