mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-11-28 02:23:44 +03:00
[ 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:
parent
ea4a4c0f85
commit
4bedaac811
@ -195,7 +195,7 @@ options args = case args of
|
|||||||
|
|
||||||
mkOptions : String -> List String -> IO (Maybe Options)
|
mkOptions : String -> List String -> IO (Maybe Options)
|
||||||
mkOptions exe rest
|
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)
|
let Just (acc, opts) = go rest initAcc (initOptions exe color)
|
||||||
| Nothing => pure Nothing
|
| Nothing => pure Nothing
|
||||||
extraOnlyNames <- the (IO (List String)) $ case acc.onlyFile of
|
extraOnlyNames <- the (IO (List String)) $ case acc.onlyFile of
|
||||||
|
@ -28,6 +28,8 @@ import Data.List
|
|||||||
import Data.String
|
import Data.String
|
||||||
import System
|
import System
|
||||||
import System.Directory
|
import System.Directory
|
||||||
|
import System.File.Meta
|
||||||
|
import System.File.Virtual
|
||||||
import Libraries.Utils.Path
|
import Libraries.Utils.Path
|
||||||
import Libraries.Utils.Term
|
import Libraries.Utils.Term
|
||||||
|
|
||||||
@ -49,6 +51,8 @@ updateEnv : {auto c : Ref Ctxt Defs} ->
|
|||||||
Core ()
|
Core ()
|
||||||
updateEnv
|
updateEnv
|
||||||
= do defs <- get Ctxt
|
= 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"
|
bprefix <- coreLift $ idrisGetEnv "IDRIS2_PREFIX"
|
||||||
setPrefix (fromMaybe yprefix bprefix)
|
setPrefix (fromMaybe yprefix bprefix)
|
||||||
bpath <- coreLift $ idrisGetEnv "IDRIS2_PATH"
|
bpath <- coreLift $ idrisGetEnv "IDRIS2_PATH"
|
||||||
|
@ -43,7 +43,8 @@ envs = [
|
|||||||
MkEnvDesc "CPPFLAGS" "RefC backend: C preprocessor flags (IDRIS2_CPPFLAGS takes precedence).",
|
MkEnvDesc "CPPFLAGS" "RefC backend: C preprocessor flags (IDRIS2_CPPFLAGS takes precedence).",
|
||||||
MkEnvDesc "LDFLAGS" "RefC backend: C linker flags (IDRIS2_LDFLAGS takes precedence).",
|
MkEnvDesc "LDFLAGS" "RefC backend: C linker flags (IDRIS2_LDFLAGS takes precedence).",
|
||||||
MkEnvDesc "NODE" "NodeJS backend: NodeJS executable.",
|
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` only for `auto` to work in `idrisGetEnv`
|
||||||
public export
|
public export
|
||||||
|
@ -29,14 +29,11 @@ render : {auto o : Ref ROpts REPLOpts} ->
|
|||||||
Doc ann -> Core String
|
Doc ann -> Core String
|
||||||
render stylerAnn doc = do
|
render stylerAnn doc = do
|
||||||
color <- getColor
|
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
|
pageWidth <- getPageWidth
|
||||||
let opts = MkLayoutOptions pageWidth
|
let opts = MkLayoutOptions pageWidth
|
||||||
let layout = layoutPretty opts doc
|
let layout = layoutPretty opts doc
|
||||||
pure $ renderString $
|
pure $ renderString $
|
||||||
if color && not isDumb
|
if color
|
||||||
then reAnnotateS stylerAnn layout
|
then reAnnotateS stylerAnn layout
|
||||||
else unAnnotateS layout
|
else unAnnotateS layout
|
||||||
|
|
||||||
|
@ -4,4 +4,4 @@ Uncaught error: EmptyFC:Failed to resolve the dependencies for test3:
|
|||||||
Uncaught error: EmptyFC:Failed to resolve the dependencies for test4:
|
Uncaught error: EmptyFC:Failed to resolve the dependencies for test4:
|
||||||
required baz any but no matching version is installed
|
required baz any but no matching version is installed
|
||||||
|
|
||||||
[38;5;3;1mWarning:[0m 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
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
rm -rf build
|
rm -rf build
|
||||||
|
|
||||||
$1 --build test1.ipkg
|
$1 --no-color --build test1.ipkg
|
||||||
$1 --build test2.ipkg
|
$1 --no-color --build test2.ipkg
|
||||||
$1 --build test3.ipkg
|
$1 --no-color --build test3.ipkg
|
||||||
$1 --build test4.ipkg
|
$1 --no-color --build test4.ipkg
|
||||||
$1 --build test5.ipkg
|
$1 --no-color --build test5.ipkg
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user