Skip to content

Commit

Permalink
chore(config): Reuse colorize.ShouldColor
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Jun 26, 2024
1 parent 2c2b4ef commit 1c05d46
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
4 changes: 2 additions & 2 deletions internal/colorize/colorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func format(attr color.Attribute) string {
return escape + "[" + strconv.Itoa(int(attr)) + "m"
}

func shouldColor(w io.Writer) bool {
func ShouldColor(w io.Writer) bool {
if os.Getenv("NO_COLOR") != "" || os.Getenv("TERM") == "dumb" {
return false
}
Expand All @@ -29,7 +29,7 @@ func shouldColor(w io.Writer) bool {
}

func WriteString(w io.Writer, s string) error {
if shouldColor(w) {
if ShouldColor(w) {
s = Colorize(s)
}

Expand Down
9 changes: 3 additions & 6 deletions internal/config/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package config
import (
"fmt"
"io"
"os"

"github.com/clevyr/yampl/internal/colorize"
"github.com/fatih/color"
"github.com/mattn/go-isatty"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -34,10 +33,8 @@ func logFormat(out io.Writer, format string) io.Writer {
var useColor bool
switch format {
case Auto:
if w, ok := out.(*os.File); ok {
if useColor = isatty.IsTerminal(w.Fd()); !useColor {
break
}
if useColor = colorize.ShouldColor(out); !useColor {
break
}
fallthrough
case Color:
Expand Down

0 comments on commit 1c05d46

Please sign in to comment.