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

Do not output colors e.g. into a pipe, unless forced. #1077

Merged
merged 2 commits into from
May 8, 2018

Conversation

lanurmi
Copy link
Contributor

@lanurmi lanurmi commented May 2, 2018

Use the de-factoish environment variables CLICOLOR(_FORCE) to override default color behavior.

Use the de-factoish environment variables CLICOLOR(_FORCE) to override default color behavior.
@ratzlaff
Copy link
Contributor

ratzlaff commented May 2, 2018

No windows option?

@tvandijck
Copy link
Contributor

windows already does not put color information into the I/O stream, it has this special API to put the console in a certain color mode. It just works very differently.. So I don't think this really needs a windows option..

@ratzlaff
Copy link
Contributor

ratzlaff commented May 2, 2018

Yea, I understand that part (about putting color information in the stream). I was just thinking more about keeping things consistent between platforms.

If I have CLICOLOR=0 in my linux environment, I would like to see the same thing happen (interactively) when I set the environment variable in windows.

The functions for retrieving environment variables and testing for tty are available on windows too.

Colors probably cannot be forced on though, because of different implementation on Windows.
@lanurmi
Copy link
Contributor Author

lanurmi commented May 4, 2018

I added support for Windows too, as much as it can be supported due to the different way it works. I can squash the two commits into one, if desired.

Copy link
Contributor

@TurkeyMan TurkeyMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this function result be cached?

static int shouldUseColors() {
// CLICOLOR* documented at: http://bixense.com/clicolors/
return ((getenvOrFallback("CLICOLOR", "1")[0] != '0') && canUseColors())
|| getenvOrFallback("CLICOLOR_FORCE", "0")[0] != '0';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like, given the code below, that this function could be called a LOT...
Like, it appears to do this work every time you wanna change colour, is that right?
Can't this just be executed once at startup?

Copy link
Contributor

@tvandijck tvandijck May 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt it's of big impact... we don't set colors that often... only for errors, which are fatal generally, so it's a one time event...

I do agree that we could at startup however.. if @lanurmi has the time to do that, that would be great? but if not, I don't want to hold off for too long and let this PR sit around.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, give him a few days, and if not... just merge ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as premake doesn't color each character in regular output with a different color, is there a scenario where term_doSetTextColor() would be called a lot in the first place? What does one need to do wrong to get hundreds or thousands of colored lines (i.e. warnings or errors) currently?

I can make it cache the result, sure, but it adds some complexity, and we don't even know if shouldUseColors() is a hotspot in profiling.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a scenario where term_doSetTextColor() would be called a lot in the first place?

The unit tests now do this, sorry! It will be called 8200+ times when running the unit tests now, so it might be a good idea to cache the result. Additionally, Premake core might not call it a lot in regular usage, but that doesn't mean that modules can't call it a lot for any number of reasons.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets merge it, and I'll take care of the caching...

@tvandijck tvandijck merged commit f8c7edf into premake:master May 8, 2018
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

Successfully merging this pull request may close these issues.

5 participants