Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
amills-vibeirl opened this issue Dec 25, 2023 · 4 comments

Comments

@amills-vibeirl
Copy link

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 amills-vibeirl changed the title Switch to no-op methods when not-writing to a terminal (control chars) Switch to no-op methods when not writing to a terminal (control chars) Dec 25, 2023
@amills-vibeirl
Copy link
Author

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
Copy link
Author

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))

@logrusorgru
Copy link
Owner

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
Copy link
Owner

logrusorgru commented Jan 19, 2024

Also, there's a way to autodetect a terminal & choose color mode -- #2 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants