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

Allow to disable colors (or automatically disable colors if stdout is not a tty) #29

Closed
felipecrs opened this issue Jun 23, 2024 · 2 comments

Comments

@felipecrs
Copy link

I'm writing a script that uses gext to detect whether some extension is installed or not:

image

gext list | grep --quiet "(arcmenu@arcmenu.com)"

But this doesn't work because gext's output is colorized and therefore grep doesn't match.

The workaround is https://stackoverflow.com/a/51141872:

gext list | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g' | grep --quiet "(arcmenu@arcmenu.com)"

But I believe this could be better handled by gext itself. For example, it could disable colors automatically when the stdout is not attached to a terminal (i.e. running in a pipeline).

felipecrs added a commit to felipecrs/dotfiles that referenced this issue Jun 23, 2024
@essembeh
Copy link
Owner

Hi

This is an excellent point.
When I tried to write an alternative to colorama I added an env variable to globally disable the colors and styles.

I choosed colorama over pytput to handle styles in this project, I did not think about this.

I'll develop a solution in gext since this is a totally valid point, idk if it will be an env var or an argument yet.

@essembeh
Copy link
Owner

After some research, there is no existing feature for now working with an env variable.

There was a PR that was closed without merge.

But I think I'll go with the solution proposed here, kudos to thetasine.

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