Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(logger): add FORCE_COLOR environment variable support #1003

Merged
merged 5 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions docs/docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down