[m-rev.] for review: options to control the use of color

Julien Fischer jfischer at opturion.com
Fri Apr 26 19:28:31 AEST 2024


On Fri, 26 Apr 2024, Zoltan Somogyi wrote:

> Set up options to control colors in diagnostics.

...

> diff --git a/compiler/globals.m b/compiler/globals.m
> index d1735cf33..cfa5c711b 100644
> --- a/compiler/globals.m
> +++ b/compiler/globals.m
> @@ -804,6 +824,64 @@ convert_line_number_range(RangeStr, line_number_range(MaybeMin, MaybeMax)) :-
>
>  %---------------------------------------------------------------------------%
> 
> +convert_color_spec_options(OptionTable) = MaybeColorSpecs :-
> +    getopt.lookup_string_option(OptionTable,
> +        set_color_correct, OptCorrect),
> +    getopt.lookup_string_option(OptionTable,
> +        set_color_incorrect, OptIncorrect),
> +    getopt.lookup_string_option(OptionTable,
> +        set_color_possible_cause, OptCause),
> +    % There is no simple way to convert each option to its name.
> +    MaybeCorrect =
> +        convert_color_spec_option("--set-color-correct", OptCorrect),
> +    MaybeIncorrect =
> +        convert_color_spec_option("--set-color-incorrect", OptIncorrect),
> +    MaybeCause =
> +        convert_color_spec_option("--set-color-possible-cause", OptCause),
> +    ( if
> +        MaybeCorrect = ok1(Correct),
> +        MaybeIncorrect = ok1(Incorrect),
> +        MaybeCause = ok1(Cause)
> +    then
> +        Colors = color_specs(Correct, Incorrect, Cause),
> +        MaybeColorSpecs = ok1(Colors)
> +    else
> +        Specs = get_any_errors1(MaybeCorrect) ++
> +            get_any_errors1(MaybeIncorrect) ++ get_any_errors1(MaybeCause),
> +        MaybeColorSpecs = error1(Specs)
> +    ).
> +
> +:- func convert_color_spec_option(string, string) = maybe1(maybe(color_spec)).
> +
> +convert_color_spec_option(OptionName, OptionValue) = MaybeColorSpec :-
> +    % If/when we want to support 24-bit color, or indeed any form of
> +    % color specification beyond 8-bit, we would do it here.
> +    % (The options that specify colors are strings, not integers,
> +    % specifically to make it possible to specify 24-bit colors
> +    % as strings of the form "R-G-B".)

It would probably be worth allowing the basic ANSI terminal colors to be
specified by their usual names (e.g. black, red, green, yellow, blue etc)
as well.

The diff looks fine.

Julien.


More information about the reviews mailing list