aurora icon indicating copy to clipboard operation
aurora copied to clipboard

Switch to no-op methods when not writing to a terminal (control chars)

Open amills-vibeirl opened this issue 2 years ago • 5 comments

great lib!

is there a switch (env var) that can noop methods so we don't get control chars?

Control chars seem to be good for displaying to terminal, but when we are writing to a non-terminal (a pipe for example) I want to noop the colors so I don't get control chars etc.

amills-vibeirl avatar Dec 25 '23 18:12 amills-vibeirl

I see this: https://github.com/logrusorgru/aurora?tab=readme-ov-file#enabledisable-colors

but it would be much better if there was an env var instead of just a flag

amills-vibeirl avatar Dec 25 '23 18:12 amills-vibeirl

Tell me if this looks good? It might be good for the readme:

package au

import (
	"os"
	"github.com/logrusorgru/aurora/v4"
)

var colors = os.Getenv("my_app_with_color")
var hasColor = colors != "no"

var Col = aurora.New(aurora.WithColors(hasColor))

amills-vibeirl avatar Dec 25 '23 18:12 amills-vibeirl

package au

import (
	"os"
	"github.com/logrusorgru/aurora/v4"
)

var au = aurora.New(aurora.WithColors(os.Getenv("COLORS") != ""))

?

to aviod some variables in global namespace

logrusorgru avatar Jan 19 '24 14:01 logrusorgru

Also, there's a way to autodetect a terminal & choose color mode -- https://github.com/logrusorgru/aurora/issues/2#issuecomment-299030108

logrusorgru avatar Jan 19 '24 14:01 logrusorgru

A lot of software supports disabling colors via the NO_COLOR environment variable. If Aurora is considering adding support for disabling color globally when an environment variable is set, NO_COLOR would be a good choice.

daveyarwood avatar Aug 04 '24 23:08 daveyarwood