Skip to content

Commit

Permalink
feat(output): set default global output
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Mar 2, 2023
1 parent 8dfefed commit 7d4a513
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func DefaultOutput() *Output {
return output
}

// SetDefaultOutput sets the default global output.
func SetDefaultOutput(o *Output) {
output = o
}

// NewOutput returns a new Output for the given file descriptor.
func NewOutput(tty io.Writer, opts ...OutputOption) *Output {
o := &Output{
Expand Down
12 changes: 7 additions & 5 deletions termenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ func EnvColorProfile() Profile {
return output.EnvColorProfile()
}

// EnvNoColor returns true if the environment variables explicitly disable color output
// by setting NO_COLOR (https://no-color.org/)
// or CLICOLOR/CLICOLOR_FORCE (https://bixense.com/clicolors/)
// If NO_COLOR is set, this will return true, ignoring CLICOLOR/CLICOLOR_FORCE
// If CLICOLOR=="0", it will be true only if CLICOLOR_FORCE is also "0" or is unset.
// EnvColorProfile returns the color profile based on environment variables set
// Supports NO_COLOR (https://no-color.org/)
// and CLICOLOR/CLICOLOR_FORCE (https://bixense.com/clicolors/)
// If none of these environment variables are set, this behaves the same as ColorProfile()
// It will return the Ascii color profile if EnvNoColor() returns true
// If the terminal does not support any colors, but CLICOLOR_FORCE is set and not "0"
// then the ANSI color profile will be returned.
func (o *Output) EnvColorProfile() Profile {
if o.EnvNoColor() {
return Ascii
Expand Down

0 comments on commit 7d4a513

Please sign in to comment.