From 7d4a5139fa9d8446b112a72ec767722597d82ec2 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Thu, 2 Mar 2023 16:55:21 -0500 Subject: [PATCH] feat(output): set default global output --- output.go | 5 +++++ termenv.go | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/output.go b/output.go index 37a0db9..3c06c03 100644 --- a/output.go +++ b/output.go @@ -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{ diff --git a/termenv.go b/termenv.go index e39ccc5..8eb8f74 100644 --- a/termenv.go +++ b/termenv.go @@ -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