Previous: Color schemes, Up: Diagnostic output   [Contents][Index]


11.4 Enabling the use of color

The Mercury compiler uses two separate mechanisms

This arrangement allow programmers to turn off the use of color temporarily without having to specify the color scheme again in full when they want to turn it back on again.

As with color schemes, programmers can control whether color is enabled in diagnostics using either a compiler option, or by using environment variables.

The compiler option is a boolean option, which, like other boolean options, has two forms: a positive form ‘--color-diagnostics’, which enables the use of color, and a negative form ‘--no-color-diagnostics’, which disables its use.

There are two environment variables that the Mercury compiler consults in its decision: ‘MERCURY_ENABLE_COLOR’, and ‘NO_COLOR’. As their names show, the first is specific to Mercury, while the second is not; it is in fact a defacto standard for disabling color. ‘https://no-color.org’.

The rules the compiler uses to decide whether the use of color in diagnostics is enabled are as follows.

  1. If the command line contains a ‘--color-diagnostics’ option, in either its positive or negative form, then the compiler will obey it.
  2. If the command line contains no ‘--color-diagnostics’ option, but the environment variable ‘MERCURY_ENABLE_COLOR’ exists and contains either ‘never’ or ‘always’, then the compiler will obey it. The compiler also allows ‘0’ as a synonym for ‘never’, and ‘1’ as a synonym for ‘always’.
  3. If the command line contains no ‘--color-diagnostics’ option, and the environment variable ‘MERCURY_ENABLE_COLOR’ either does not exist, or contains a string other than the four listed above, but the environment variable ‘NO_COLOR’ exists and contains a nonempty string, then the compiler will obey it by disabling the use of color.
  4. If the command line contains no ‘--color-diagnostics’ option and neither environment variable has a value that directs the compiler to obey it, but the files named in any ‘--options-file’ compiler options, (or, in the absence of such options, the ‘Mercury.options’ file), include a ‘--color-diagnostics’ option, in either its positive or negative form, among the module-specific ‘MCFLAGS’ for the current module, then the compiler will obey it.
  5. If the preconditions of all four of the above rules are false, i.e. none of them decide the outcome, then the compiler will fall back to its default. The usual default decision is to enable the use of color, though this can be overridden for a given installation of Mercury.

Previous: Color schemes, Up: Diagnostic output   [Contents][Index]