-
Notifications
You must be signed in to change notification settings - Fork 60
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: Add the ability to selectively preserve colors #1225
base: master
Are you sure you want to change the base?
Conversation
This seems like an unnecessarily hacky way to restore the functionality in the linked commit. All you would need to do is add a color-preserving variant of |
That's not what this functionality does. It allows me to say
I was just adding back functionality that was removed before without good motivation presented that was used and was useful. We could add a non-newline terminating version, non-decoloring of G_LogPrintf(), but that makes that callsite busy too... It would be something like:
The conditional is fabricated. In reality, this code would be duplicated twice, one for |
All right I looked at it closer and understand that G_LogPrintf prints to two log targets with and without color. I think the goal here could be achieved by decoloring the format string, rather that the formatted string, and then doing the sprintf once for each target. If that doesn't work out somehow, the decoloring-with-control-codes function should be written in the sgame instead of the engine. This would be easy to write using |
I'm not sure I follow the first proposal. In my head, I like the current approach, hacky as it is because it allows fine grained control of whether something should be decolored or not in the same string. It offers maximum flexibility. Re-implementing this in the sgame would basically be duplicating StripColors. |
If you call StripColors on the format string (e.g.
Which is not a problem as a basic StripColors implementation is less than 10 lines. |
That won't work when the you have two format strings, and you want one to be stripped and the other to not be stripped. The case that inspired this whole PR in the first place is this: https://github.com/Unvanquished/Unvanquished/blob/master/src/sgame/sg_client.cpp#L1187-L1190 The previous behavior was one %s == stripped netname, and the other %s is the unstripped netname. I still maintain this is the best path forward. if you insist on it being in sgame instead of daemon, I can move it, but I honestly think it's better to keep it in daemon because I expect that this won't be the first instance of this as we start to expand our tooling. |
That case is easily handled.
|
Again, you're missing the core issue. G_LogPrintf (https://github.com/Unvanquished/Unvanquished/blob/0614b6650439c9c5aedefb7d183988343f0b46f4/src/sgame/sg_main.cpp#L1588) is doing the stripping not us. That's why I've been saying the only other path forward that I would consider would be writing a version of G_LogPrintf that doesn't do newline termination and optionally does stripping. |
The difference between the two methods is basically a question of whether you want the default for interpolated strings to be with or without color. If you do it the old way, the default is without color and you have to add the control codes to keep color. If you do it with my first proposal, the default is to keep colors and the caller must call StripColors to remove them. Thoughts? |
|
To recap: My new behavior: takes a string, prints to console, strips colors except within control markers, writes to log file. I think we should largely maintain this behavior. So far, I've only encountered two use cases for this, so it doesn't make sense to go through the codebase and change it.
If you absolutely despise this method, I can add another logging function with more options, but honestly, the old way seems cleaner to me. Same code in trem: https://github.com/darklegion/tremulous/blob/c862a5340c8de44dcc7abaff170c20c04f9340e8/src/game/g_client.c#L905-L909 |
My last message didn't make sense. Sorry about that. My very first idea of a color-preserving G_LogPrintf seems to work well though. PTAL at https://github.com/Unvanquished/Unvanquished/compare/slipher/log-colored-names?expand=1. I think this restores all of the lost functionality. It seems a bit better than the original old version since in the in-console message, the names are also printed once with an once without color. Printing twice with color in the console would look stupid. I doubt that a general method for partially decoloring is something that will frequently come in handy. If it does it should be in a separate function from StripColors. |
The proposal doesn't allow stripping things that are both inside the format string and within the interpolated string. For example:
Here, the ^* is maintained and I don't want it to be. I just want the name to be maintained. It's not part of the user's name, but it's in the quotes, so its included in the user's name when it wasn't part of their name. |
Ok cool. I just ask that decolor with control codes be a different function in the gamelogic rather than a mandatory part of the official StripColors. |
26a0635
to
9218f94
Compare
9218f94
to
4ee556a
Compare
Why not using a bit longer markup to only reserve one special character for opening/ending markup? Like for example G_LogPrintf("^1Strip this %c[^3Keep this%c]", Color::Constants::DECOLOR, Color::Constants::DECOLOR); I would like to see a similar feature one day to mark substrings that would be replaced with The sequences could also be |
Also, is there a need for a special character at all? We may standardize universal opening/closing sequences in the form of So we could either write it plain: G_LogPrintf("^1Strip this ^!D[^3Keep this^!D]"); or use an enum: G_LogPrintf("^1Strip this %c^3Keep this%c", Color::Markups::DECOLOR_BEGIN, Color::Markups::DECOLOR_END); |
Sure, this same facility could be extended for log redaction. I don't think the actual escape codes matter as long as they are available in an enum/constant. We should definitely not be using them directly. |
Indeed, this can be modified and extended later. I'm fine with the current implementation. |
This adds back the "DECOLOR" functionality that was removed as part of Unvanquished/Unvanquished@d61c9d2. No motivation was given for the removal, and the DECOLOR functionality is important for external tools that parse game logs to display player colors leading to a richer experience.
4ee556a
to
92c33c1
Compare
This adds back the "DECOLOR" functionality that was removed as part of Unvanquished/Unvanquished@d61c9d2. No motivation was given for the removal, and the DECOLOR functionality is important for external tools that parse game logs to display player colors leading to a richer experience.