From 9af056e746a551a99b7f4d2bc49011029ba3920b Mon Sep 17 00:00:00 2001 From: Aleksandr Komlev Date: Fri, 17 Feb 2023 03:12:44 +0300 Subject: [PATCH] Add FORCE_COLOR env support (#1003) --- CHANGELOG.md | 1 + docs/docs/api_reference.md | 1 + internal/logger/logger.go | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f68aaa9b..636eb378 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fixed a bug where tasks were sometimes incorrectly marked as internal ([#1007](https://github.com/go-task/task/pull/1007) by @pd93). - Update to Go 1.20 (bump minimum version to 1.19) ([#1010](https://github.com/go-task/task/pull/1010) by @pd93) +- Added environment variable `FORCE_COLOR` support to force color output. Usefull for environments without TTY ([#1003](https://github.com/go-task/task/pull/1003) by @automation-stack) ## v3.20.0 - 2023-01-14 diff --git a/docs/docs/api_reference.md b/docs/docs/api_reference.md index d2dd6fbd..e9c3edc2 100644 --- a/docs/docs/api_reference.md +++ b/docs/docs/api_reference.md @@ -73,6 +73,7 @@ Some environment variables can be overriden to adjust Task behavior. | `TASK_COLOR_YELLOW` | `33` | Color used for yellow. | | `TASK_COLOR_MAGENTA` | `35` | Color used for magenta. | | `TASK_COLOR_RED` | `31` | Color used for red. | +| `FORCE_COLOR` | `undefined` | Force color output usage. | ## Schema diff --git a/internal/logger/logger.go b/internal/logger/logger.go index d3e86db2..42b6d453 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -34,6 +34,10 @@ func Red() PrintFunc { } func envColor(env string, defaultColor color.Attribute) color.Attribute { + if os.Getenv("FORCE_COLOR") != "" { + color.NoColor = false + } + override, err := strconv.Atoi(os.Getenv(env)) if err == nil { return color.Attribute(override)