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

Color is disabled in debug mode #590

Closed
rcdailey opened this issue Feb 15, 2016 · 10 comments
Closed

Color is disabled in debug mode #590

rcdailey opened this issue Feb 15, 2016 · 10 comments

Comments

@rcdailey
Copy link

I noticed that while running a debug build, colors are disabled. This is noticable in the single-header catch.hpp:

    void Colour::use( Code _colourCode ) {
        static IColourImpl* impl = isDebuggerActive()
            ? NoColourImpl::instance()
            : platformColourInstance();
        impl->use( _colourCode );
    }

Why are colors disabled if the debugger is active? I was wondering why I was getting no color output; I thought initially it was bugged. The reason for this is not documented anywhere. As such, I am not able to directly understand the reasoning for this.

@refi64
Copy link

refi64 commented Feb 15, 2016

I would think that it would cause insanely weird coloring if a breakpoint were activated before the ANSI color reset code is printed.

@rcdailey
Copy link
Author

But logs are not printed while stepping through a test case right? And isn't your issue specific to Linux?

@philsquared
Copy link
Collaborator

That's a very good question.
I can see that I specifically made that change in a dedicated commit (dbcd833) three years ago - but the commit message just says, "Don't use ANSI colour codes when debugging" - with no rationale or associated issue number (go me!)

I think it's to do with the messages being sent to a debug output console (e.g. in XCode). Depending on your environment and how it is set-up this may or may not happen - so it would be nice to have finer grained control.

There is a --force-colour command line option (which I have just noticed is not documented - must fix that). Currently that's only looked at once it has already selected the platformColourInstance() path - but it probably makes sense to consult it here too. I might actually be changing that flag anyway (to incorporate #502 as well). I'll try and cover all bases soon...

@rcdailey
Copy link
Author

I think you are on the right track to step back and rethink and redesign this small feature. I can see how having colors enabled could not work well in certain consoles. So toggling this via command line parameter is reasonable. Thanks for your feedback.

On Tue, Feb 23, 2016, 1:55 AM Phil Nash [email protected] wrote:

That's a very good question.
I can see that I specifically made that change in a dedicated commit (
dbcd833
dbcd833)
three years ago - but the commit message just says, "Don't use ANSI colour
codes when debugging" - with no rationale or associated issue number (go
me!)

I think it's to do with the messages being sent to a debug output
console (e.g. in XCode). Depending on your environment and how it is set-up
this may or may not happen - so it would be nice to have finer grained
control.

There is a --force-colour command line option (which I have just noticed
is not documented - must fix that). Currently that's only looked at once it
has already selected the platformColourInstance() path - but it probably
makes sense to consult it here too. I might actually be changing that flag
anyway (to incorporate #502
#502 as well). I'll try and
cover all bases soon...


Reply to this email directly or view it on GitHub
#590 (comment).

@nabijaczleweli
Copy link
Contributor

Can --force-colour/some other option set ANSI escapes regardless of platform? It'd be great for IDEs.

@philsquared
Copy link
Collaborator

@nabijaczleweli not easily. The platform specific parts of the code make platform specific calls (e.g. isatty() in the POSIX case and SetConsoleTextAttribute() in the Windows case). So those definitions are not even compiled in unless the platform is detected.
I know there are some cases where more than one platform may be detected (cygwin?) and I suppose it's possible in that case but the code would have to be changed considerable for that case.

@nabijaczleweli
Copy link
Contributor

With --force-colour you don't need to check if isatty(), so you can compile the ANSI colourer and the WinAPI colourer at the same time and select them at runtime.

@philsquared
Copy link
Collaborator

...only if the platform is Windows.
It's not that it's not doable - it will just require a fair bit of rearranging the code - along with introducing certain inconsistencies.
I'm not sure if it's a valuable enough shade of feature at this point (but am open to being convinced).

@philsquared
Copy link
Collaborator

ok. I have --use-colour working now (in a local commit). It takes yes, no or auto (although the latter is the default).
If yes or no are specified they override the debugger present or isatty() conditions.
I'll push soon.
I'll look at the platform override angle later.

@philsquared
Copy link
Collaborator

I should have mentioned before that --use-colour is in.

@horenmar horenmar added the Resolved - pending review Issue waiting for feedback from the original author label Jan 14, 2017
@horenmar horenmar removed the Resolved - pending review Issue waiting for feedback from the original author label Feb 6, 2017
horenmar pushed a commit that referenced this issue May 6, 2018
The documentation added is based on output from `-?` (help),
and comments to #590.
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

5 participants