Skip to content

Commit

Permalink
refactor: rename exported functions to be more idiomatic
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Sep 13, 2024
1 parent 383e9bc commit f8f1fbf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func printColor(profile colorprofile.Profile, c color.Color) {

func main() {
// Get the terminal's color profile
profile := colorprofile.DetectProfile(os.Stdout, os.Environ())
profile := colorprofile.Detect(os.Stdout, os.Environ())

// Convert 24-bit RGB color to the terminal's color profile.
// This will return the closest color in the profile's palette
Expand Down
11 changes: 5 additions & 6 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/xo/terminfo"
)

// DetectProfile returns the color profile based on the terminal output, and
// Detect returns the color profile based on the terminal output, and
// environment variables. This respects NO_COLOR, CLICOLOR, and CLICOLOR_FORCE
// environment variables.
//
Expand All @@ -24,15 +24,14 @@ import (
// colors but not text decoration, i.e. bold, italic, faint, etc.
//
// See https://no-color.org/ and https://bixense.com/clicolors/ for more information.
func DetectProfile(output io.Writer, environ []string) (p Profile) {
func Detect(output io.Writer, environ []string) (p Profile) {
out, ok := output.(term.File)
isatty := ok && term.IsTerminal(out.Fd())
return colorProfile(isatty, environ)
}

// EnvProfile returns the color profile based on the terminal environment
// variables. This respects NO_COLOR, CLICOLOR, and CLICOLOR_FORCE environment
// variables.
// Env returns the color profile based on the terminal environment variables.
// This respects NO_COLOR, CLICOLOR, and CLICOLOR_FORCE environment variables.
//
// The rules as follows:
// - TERM=dumb is always treated as NoTTY unless CLICOLOR_FORCE=1 is set.
Expand All @@ -45,7 +44,7 @@ func DetectProfile(output io.Writer, environ []string) (p Profile) {
// colors but not text decoration, i.e. bold, italic, faint, etc.
//
// See https://no-color.org/ and https://bixense.com/clicolors/ for more information.
func EnvProfile(environ []string) (p Profile) {
func Env(environ []string) (p Profile) {
return colorProfile(true, environ)
}

Expand Down
2 changes: 1 addition & 1 deletion env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ var cases = []struct {
func TestEnvColorProfile(t *testing.T) {
for i, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
p := EnvProfile(tc.environ)
p := Env(tc.environ)
if p != tc.expected {
t.Errorf("case %d: expected %v, got %v", i, tc.expected, p)
}
Expand Down
2 changes: 1 addition & 1 deletion profile_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
func NewWriter(w io.Writer, environ []string) *Writer {
return &Writer{
Forward: w,
Profile: DetectProfile(w, environ),
Profile: Detect(w, environ),
}
}

Expand Down

0 comments on commit f8f1fbf

Please sign in to comment.