8000 Make the NO_COLOR environment variable accept strings other than the “true” strings by Songmu · Pull Request #417 · x-motemen/ghq · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Make the NO_COLOR environment variable accept strings other than the “true” strings #417

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

Merged
merged 1 commit into from
Mar 25, 2025
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
10 changes: 3 additions & 7 deletions logger/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"io"
"os"
"strings"

"github.com/motemen/go-colorine"
)
Expand Down Expand Up @@ -51,16 +50,13 @@ var (
)

func init() {
SelectLogger()
selectLogger()
}

func SelectLogger() {
v := os.Getenv("NO_COLOR")

if strings.ToLower(v) == "true" {
func selectLogger() {
if os.Getenv("NO_COLOR") != "" {
logger = loggerWithoutColor
}

SetOutput(os.Stderr)
}

Expand Down
4 changes: 2 additions & 2 deletions logger/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func TestLog(t *testing.T) {
t.Run("with color", func(t *testing.T) {
t.Logf("NO_COLOR: %s", os.Getenv("NO_COLOR"))
SelectLogger()
selectLogger()
// info
Log("default", "should be green")
// verbose
Expand All @@ -25,7 +25,7 @@ func TestLog(t *testing.T) {
t.Run("without color", func(t *testing.T) {
t.Setenv("NO_COLOR", "true")
t.Logf("NO_COLOR: %s", os.Getenv("NO_COLOR"))
SelectLogger()
selectLogger()
// info
Log("default", "should be none")
// verbose
Expand Down
0