X Tutup
Skip to content

Add FORCE_COLOR environment variable support#280

Open
veeceey wants to merge 1 commit intofatih:mainfrom
veeceey:feat/issue-155-force-color
Open

Add FORCE_COLOR environment variable support#280
veeceey wants to merge 1 commit intofatih:mainfrom
veeceey:feat/issue-155-force-color

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 17, 2026

Fixes #155

Adds support for the FORCE_COLOR environment variable. When FORCE_COLOR is set to any value other than "0", colors are enabled regardless of TTY detection. NO_COLOR takes precedence over FORCE_COLOR.

This is useful for CI systems like GitHub Actions and GitLab CI that support ANSI colors but aren't detected as TTYs. The FORCE_COLOR convention has been standardized at https://force-color.org and is already widely supported in the Node.js ecosystem (chalk, etc.) and increasingly in other languages.

Changes

  • color.go: Added forceColorIsSet() helper and integrated it into the NoColor global initialization and New() constructor
  • color_test.go: Added tests for forceColorIsSet(), color output with FORCE_COLOR, and NO_COLOR precedence over FORCE_COLOR
  • README.md: Documented FORCE_COLOR support and updated the GitHub Actions section

Testing

$ go test ./... -v
--- PASS: Test_forceColorIsSet (0.00s)
    --- PASS: Test_forceColorIsSet/default (0.00s)
    --- PASS: Test_forceColorIsSet/FORCE_COLOR=1 (0.00s)
    --- PASS: Test_forceColorIsSet/FORCE_COLOR=0 (0.00s)
    --- PASS: Test_forceColorIsSet/FORCE_COLOR=true (0.00s)
    --- PASS: Test_forceColorIsSet/FORCE_COLOR= (0.00s)
--- PASS: TestForceColor (0.00s)
--- PASS: TestForceColorOverriddenByNoColor (0.00s)
PASS
ok  	github.com/fatih/color	0.239s

Add support for the FORCE_COLOR environment variable (https://force-color.org).
When FORCE_COLOR is set to any value other than "0", colors are enabled
regardless of terminal detection. NO_COLOR takes precedence over FORCE_COLOR.

This is useful in CI environments like GitHub Actions and GitLab CI that
support ANSI colors but are not detected as TTYs.

Fixes fatih#155
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for FORCE_COLOR

1 participant

X Tutup