[m-rev.] for review: integrate env vars for colors into the option list

Peter Wang novalazy at gmail.com
Tue Jun 11 13:44:09 AEST 2024


On Sat, 08 Jun 2024 13:00:06 +1000 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> For review by Peter. The diff is with -b.
> 
> Zoltan.

> Integrate envvars for colors into the option list.
> 

> @@ -328,6 +330,33 @@ real_main_after_expansion(ProgressStream, ErrorStream, CmdLineArgs, !IO) :-
>          io.set_exit_status(1, !IO)
>      ).
>  
> +:- pred get_args_representing_env_vars(list(string)::out,
> +    io::di, io::uo) is det.
> +
> +get_args_representing_env_vars(EnvVarArgs, !IO) :-
> +    io.environment.get_environment_var("MERCURY_COLOR_SCHEME",
> +        MaybeColorScheme, !IO),
> +    ( if
> +        MaybeColorScheme = yes(ColorScheme),
> +        % XXX Should we let MERCURY_COLOR_SCHEME being set to ""
> +        % override the default color scheme? Having this test here
> +        % assumes that our preferred answer is "no".
> +        ColorScheme \= ""
> +    then
> +        EnvVarColorSchemeArgs = ["--color-scheme-envvar", ColorScheme]
> +    else
> +        EnvVarColorSchemeArgs = []
> +    ),
> +    io.environment.get_environment_var("NO_COLOR", MaybeNoColor, !IO),
> +    (
> +        MaybeNoColor = yes(_),
> +        EnvVarNoColorArgs = ["--no-enable-color-diagnostics"]

According to https://no-color.org, we should check if NO_COLOR is
present and non-empty.

> @@ -1372,7 +1396,11 @@ optdef(oc_verbosity, enable_color_diagnostics,          bool_special).
>  optdef(oc_verbosity, enable_color_diagnostics_is_set,   bool(no)).
>  optdef(oc_verbosity, enable_color_diagnostics_is_set_to, bool(no)).
>  optdef(oc_verbosity, use_color_diagnostics,             bool(no)).
> -optdef(oc_verbosity, color_scheme,                      maybe_string(no)).
> +optdef(oc_verbosity, color_scheme,                      string_special).
> +optdef(oc_verbosity, color_scheme_envvar,               string_special).
> +optdef(oc_verbosity, color_scheme_set_by,               string("default")).
> +optdef(oc_verbosity, color_scheme_set_to,               string("dark256")).

Set the default to light16.

That looks fine, otherwise.

Peter


More information about the reviews mailing list