[ fix ] emacs' terminal is "dumb"

emacs sets the TERM variable to "dumb" and expects not to have to
handle any ANSI escape codes as a consequence. We need to patch the
renderer to unannotate the Doc in this situation.
This commit is contained in:
Guillaume ALLAIS 2021-05-05 18:49:39 +01:00 committed by G. Allais
parent 62519c5352
commit 7c3960ab52

View File

@ -9,6 +9,8 @@ import Libraries.Text.PrettyPrint.Prettyprinter
import public Libraries.Text.PrettyPrint.Prettyprinter.Render.Terminal
import Libraries.Utils.Term
import System
getPageWidth : {auto o : Ref ROpts REPLOpts} -> Core PageWidth
getPageWidth = do
consoleWidth <- getConsoleWidth
@ -25,11 +27,16 @@ render : {auto o : Ref ROpts REPLOpts} ->
Doc ann -> Core String
render stylerAnn doc = do
color <- getColor
isDumb <- (Just "dumb" ==) <$> coreLift (getEnv "TERM")
-- ^-- emacs sets the TERM variable to `dumb` and expects the compiler
-- to not emit any ANSI escape codes
pageWidth <- getPageWidth
let opts = MkLayoutOptions pageWidth
let layout = layoutPretty opts doc
pure $ renderString $
if color then reAnnotateS stylerAnn layout else unAnnotateS layout
if color && not isDumb
then reAnnotateS stylerAnn layout
else unAnnotateS layout
export
renderWithoutColor : {auto o : Ref ROpts REPLOpts} -> Doc ann -> Core String