Skip to content

Commit

Permalink
fix: DetectColorProfile takes a writer
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed May 13, 2024
1 parent a6dc2ab commit d059cfa
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions env.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package lipgloss

import (
"io"
"log"
"os"
"strconv"
"strings"
Expand All @@ -17,14 +19,14 @@ import (
// CLICOLOR/CLICOLOR_FORCE environment variables.
//
// See https://no-color.org/ and https://bixense.com/clicolors/ for more information.
func DetectColorProfile(stdout term.File, environ []string) Profile {
func DetectColorProfile(output io.Writer, environ []string) Profile {
if environ == nil {
environ = os.Environ()
}

env := environMap(environ)
p := envColorProfile(env)
if stdout == nil || !term.IsTerminal(stdout.Fd()) {
if out, ok := output.(term.File); !ok || !term.IsTerminal(out.Fd()) {
p = NoTTY
}

Expand Down Expand Up @@ -117,6 +119,7 @@ func envColorProfile(env map[string]string) (p Profile) {
p = Ascii // Default to ASCII
setProfile := func(profile Profile) {
if profile < p {
log.Output(3, "Setting profile to "+profile.String())

Check failure on line 122 in env.go

View workflow job for this annotation

GitHub Actions / lint-soft

Magic number: 3, in <argument> detected (gomnd)

Check failure on line 122 in env.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `log.Output` is not checked (errcheck)
p = profile
}
}
Expand Down

0 comments on commit d059cfa

Please sign in to comment.