[ fix ] make color output toggling simpler and also more robust. (#2848)

* make color output toggling simpler and also more robust

* don't unintentionally assert that tests are run in an environment where colors are turned on.

* Update src/Idris/Env.idr
This commit is contained in:
Mathew Polzin 2023-01-22 13:35:57 -06:00 committed by GitHub
parent ea4a4c0f85
commit 4bedaac811
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 12 deletions

View File

@ -195,7 +195,7 @@ options args = case args of
mkOptions : String -> List String -> IO (Maybe Options)
mkOptions exe rest
= do color <- (Just "DUMB" /=) <$> getEnv "TERM"
= do color <- [ (isNothing noc) && tty | noc <- getEnv "NO_COLOR", tty <- isTTY stdout ]
let Just (acc, opts) = go rest initAcc (initOptions exe color)
| Nothing => pure Nothing
extraOnlyNames <- the (IO (List String)) $ case acc.onlyFile of

View File

@ -28,6 +28,8 @@ import Data.List
import Data.String
import System
import System.Directory
import System.File.Meta
import System.File.Virtual
import Libraries.Utils.Path
import Libraries.Utils.Term
@ -49,6 +51,8 @@ updateEnv : {auto c : Ref Ctxt Defs} ->
Core ()
updateEnv
= do defs <- get Ctxt
noColor <- coreLift [ isJust noc || not tty | noc <- idrisGetEnv "NO_COLOR", tty <- isTTY stdout ]
when noColor $ setColor False
bprefix <- coreLift $ idrisGetEnv "IDRIS2_PREFIX"
setPrefix (fromMaybe yprefix bprefix)
bpath <- coreLift $ idrisGetEnv "IDRIS2_PATH"

View File

@ -43,7 +43,8 @@ envs = [
MkEnvDesc "CPPFLAGS" "RefC backend: C preprocessor flags (IDRIS2_CPPFLAGS takes precedence).",
MkEnvDesc "LDFLAGS" "RefC backend: C linker flags (IDRIS2_LDFLAGS takes precedence).",
MkEnvDesc "NODE" "NodeJS backend: NodeJS executable.",
MkEnvDesc "PATH" "PATH variable is used to search for executables in certain codegens."]
MkEnvDesc "PATH" "PATH variable is used to search for executables in certain codegens.",
MkEnvDesc "NO_COLOR" "Instruct Idris not to print color to stdout. Passing the --color/--colour option will supersede this env var."]
--- `public export` only for `auto` to work in `idrisGetEnv`
public export

View File

@ -29,14 +29,11 @@ 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 && not isDumb
if color
then reAnnotateS stylerAnn layout
else unAnnotateS layout

View File

@ -4,4 +4,4 @@ Uncaught error: EmptyFC:Failed to resolve the dependencies for test3:
Uncaught error: EmptyFC:Failed to resolve the dependencies for test4:
required baz any but no matching version is installed
Warning: Deprecation warning: version numbers must now be of the form x.y.z
Warning: Deprecation warning: version numbers must now be of the form x.y.z

View File

@ -1,8 +1,8 @@
rm -rf build
$1 --build test1.ipkg
$1 --build test2.ipkg
$1 --build test3.ipkg
$1 --build test4.ipkg
$1 --build test5.ipkg
$1 --no-color --build test1.ipkg
$1 --no-color --build test2.ipkg
$1 --no-color --build test3.ipkg
$1 --no-color --build test4.ipkg
$1 --no-color --build test5.ipkg