diff --git a/Help/envvar/CLICOLOR.rst b/Help/envvar/CLICOLOR.rst index b899dedd52..b976a2529e 100644 --- a/Help/envvar/CLICOLOR.rst +++ b/Help/envvar/CLICOLOR.rst @@ -9,11 +9,11 @@ Set to ``0`` to tell command-line tools not to print color messages even if connected to a terminal. This is a `common convention`_ among command-line tools in general. -See also the :envvar:`CLICOLOR_FORCE` environment variable. -:envvar:`CLICOLOR_FORCE`, if activated, takes precedence over +See also the :envvar:`NO_COLOR` and :envvar:`CLICOLOR_FORCE` environment +variables. If either of them is activated, it takes precedence over :envvar:`!CLICOLOR`. See the :variable:`CMAKE_COLOR_DIAGNOSTICS` variable to control color in a generated build system. -.. _`common convention`: https://web.archive.org/web/20230417221418/https://bixense.com/clicolors/ +.. _`common convention`: https://web.archive.org/web/20250410160803/https://bixense.com/clicolors/ diff --git a/Help/envvar/CLICOLOR_FORCE.rst b/Help/envvar/CLICOLOR_FORCE.rst index 60a54fb677..80a66e3c7f 100644 --- a/Help/envvar/CLICOLOR_FORCE.rst +++ b/Help/envvar/CLICOLOR_FORCE.rst @@ -9,11 +9,12 @@ Set to a non-empty value, other than ``0``, to tell command-line tools to print color messages even if not connected to a terminal. This is a `common convention`_ among command-line tools in general. -See also the :envvar:`CLICOLOR` environment variable. -:envvar:`!CLICOLOR_FORCE`, if activated, takes precedence over -:envvar:`CLICOLOR`. +See also the :envvar:`NO_COLOR` and :envvar:`CLICOLOR` environment variables. +If :envvar:`NO_COLOR` is activated, it takes precedence over +:envvar:`!CLICOLOR_FORCE`. Otherwise, if :envvar:`!CLICOLOR_FORCE` is +activated, it takes precedence over :envvar:`CLICOLOR`. See the :variable:`CMAKE_COLOR_DIAGNOSTICS` variable to control color in a generated build system. -.. _`common convention`: https://web.archive.org/web/20230417221418/https://bixense.com/clicolors/ +.. _`common convention`: https://web.archive.org/web/20250410160803/https://bixense.com/clicolors/ diff --git a/Help/envvar/NO_COLOR.rst b/Help/envvar/NO_COLOR.rst new file mode 100644 index 0000000000..39fa218248 --- /dev/null +++ b/Help/envvar/NO_COLOR.rst @@ -0,0 +1,19 @@ +NO_COLOR +-------- + +.. versionadded:: 4.1 + +.. include:: include/ENV_VAR.rst + +Set to a non-empty value, other than ``0``, to tell command-line +tools not to print color messages even if connected to a terminal. +This is a `common convention`_ among command-line tools in general. + +See also the :envvar:`CLICOLOR_FORCE` and :envvar:`CLICOLOR` environment +variables. If :envvar:`!NO_COLOR` is activated, it takes precedence +over both of them. + +See the :variable:`CMAKE_COLOR_DIAGNOSTICS` variable to control +color in a generated build system. + +.. _`common convention`: https://web.archive.org/web/20250410160803/https://bixense.com/clicolors/ diff --git a/Help/manual/cmake-env-variables.7.rst b/Help/manual/cmake-env-variables.7.rst index c4c38eb738..e4936555df 100644 --- a/Help/manual/cmake-env-variables.7.rst +++ b/Help/manual/cmake-env-variables.7.rst @@ -32,6 +32,7 @@ Environment Variables that Change Behavior /envvar/CMAKE_PROGRAM_PATH /envvar/CMAKE_TLS_VERIFY /envvar/CMAKE_TLS_VERSION + /envvar/NO_COLOR /envvar/SSL_CERT_DIR /envvar/SSL_CERT_FILE diff --git a/Source/cmStdIoTerminal.cxx b/Source/cmStdIoTerminal.cxx index dfb3aa9ea0..5baff5e38b 100644 --- a/Source/cmStdIoTerminal.cxx +++ b/Source/cmStdIoTerminal.cxx @@ -101,6 +101,13 @@ void SetVT100Attrs(std::ostream& os, TermAttrSet const& attrs) } auto const TermEnv = []() -> cm::optional { + /* Disable color according to https://bixense.com/clicolors/ convention. */ + if (cm::optional noColor = + cmSystemTools::GetEnvVar("NO_COLOR")) { + if (!noColor->empty() && *noColor != "0"_s) { + return TermKind::None; + } + } /* Force color according to https://bixense.com/clicolors/ convention. */ if (cm::optional cliColorForce = cmSystemTools::GetEnvVar("CLICOLOR_FORCE")) { diff --git a/Tests/EnforceConfig.cmake.in b/Tests/EnforceConfig.cmake.in index f9f476d556..78dea0020d 100644 --- a/Tests/EnforceConfig.cmake.in +++ b/Tests/EnforceConfig.cmake.in @@ -29,6 +29,7 @@ if(NOT CTEST_CONFIGURATION_TYPE) endif() # Isolate tests from user configuration in the environment. +unset(ENV{NO_COLOR}) unset(ENV{CLICOLOR}) unset(ENV{CLICOLOR_FORCE}) unset(ENV{CMAKE_GENERATOR})