From 91c95bbf8f1ac828aab71c238f1478abbf9aa7c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 7 Nov 2023 16:05:27 +0100 Subject: [PATCH] Respect NO_COLOR and CLICOLOR_FORCE (#2295) http://bixense.com/clicolors/ --- README.md | 2 ++ bin/ruby-build | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c1ece7f845..1df4744a04 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,8 @@ The build process may be configured through the following environment variables: | `RUBY_CONFIGURE_OPTS` | Additional `./configure` options (applies only to Ruby source). | | `RUBY_MAKE_OPTS` | Additional `make` options (applies only to Ruby source). | | `RUBY_MAKE_INSTALL_OPTS` | Additional `make install` options (applies only to Ruby source). | +| `NO_COLOR` | Disable ANSI colors in output. The default is to use colors for output connected to a terminal. | +| `CLICOLOR_FORCE` | Use ANSI colors in output even when not connected to a terminal. | #### Applying Patches diff --git a/bin/ruby-build b/bin/ruby-build index 167b6d9952..176ace3c4f 100755 --- a/bin/ruby-build +++ b/bin/ruby-build @@ -100,8 +100,10 @@ sanitize() { } colorize() { - if [ -t 1 ]; then printf "\e[%sm%s\e[m" "$1" "$2" - else echo -n "$2" + if [[ -n $CLICOLOR_FORCE || ( -z $NO_COLOR && -t 1 ) ]]; then + printf "\e[%sm%s\e[m" "$1" "$2" + else + printf "%s" "$2" fi }