-
Notifications
You must be signed in to change notification settings - Fork 339
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
Terminal ansi colors #427
Terminal ansi colors #427
Conversation
…ument to sendto_stream_target function so severity of message can be accessed from inside function, and fixed headers so compliant with script
…o add documentation following the style of other comments in the same file. Fixed the headers so enum stumpless_severity is visible in this file.
… visible within the function
… stumpless_open_stdout_target and stumpless_open_stderr_target functions (this may be replaced by something cleaner using a macro). Initialised the severity color codes to be a zero-length c-string in the open_stream_target function. Wrote implementation (thread and memory safe, checking for out of bounds errors and using the n variant of string functions to prevent buffer overflow) for stumpless_set_severity_color. Fixed headers so compliant with script.
…sult each time we send in case there is an error
Do I need to 'sign the commit' so it can be merged? Or is anything else missing? |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## latest #427 +/- ##
==========================================
+ Coverage 90.79% 90.85% +0.05%
==========================================
Files 48 47 -1
Lines 4335 4384 +49
Branches 577 586 +9
==========================================
+ Hits 3936 3983 +47
- Misses 268 269 +1
- Partials 131 132 +1 ☔ View full report in Codecov by Sentry. |
Sorry for the delay in response, I have been focused on a different project for a bit. First of all, thank you for tackling this issue! As I am sure you saw in the issue history it has drawn many contenders but remains yet unconquered. Signing commits is not a requirement for PRs here, particularly since they are typically squashed anyway. However, I do recommend you work through that process for your own education (if education is something you're into, at least). But don't worry about signing and re-pushing your work or anything like that. At first glance this seems like a solid contribution that shouldn't need much re-shaping, but I need to set aside time to sit down and review it in detail. I will get back to you within the next week with a review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for putting this together, and your patience in waiting for a review. This is great work! The changes below should be relatively straightforward.
However, you will also need to write some tests for this functionality. This will be a little more involved - the way I would approach this is to create a file, and use the stream to create a new stream target that writes into it. You can then check the file contents after the writing to make sure that the expected escape codes are there (or not, depending on the test).
…invalid_severity instead
… locked for the duration of the code that uses it.
…1 big one to prevent interleaving of messages
…aken in sendto_stream_target
…ean in event of success
You're closing in on done! Just two more changes needed - you'll need to resolve the Windows test failures, which will probably require some refactoring of the tests themselves to be a bit more portable. You may need to create a new file instead of using the stderr/stdout targets, but I'll leave this up to you. Also, please add a test where you attempt to call |
…hat the test compiles on windows
I have added some preprocessor directives so the syscalls to dup etc. are conformant with the required windows ISO C rules. In the end I thought it was better to redirect stdout/stderr since in theory (as I understand) files should not have these escape codes (unless set manually). I am aware that it may be possible to make this code simpler using some sort of macro to distinguish between code needed for windows vs unix. (however I wasn't sure what your policy on macros is, I can rewrite the code in this way if you want). Also if you think the file approach is cleaner I will rewrite the test. Also note that for some reason running on my windows machine I get that the regex expression is invalid? Is this a bug in the windows version of gtest or my fault? Sorry for the inconvenience. Edit: PS. Should the test for |
The tests have a more relaxed standard for macros and wrapping up OS-specific functionality, so I think what you've done here is fine, no need to rewrite at this point. As long as they run on the major tested systems (which are currently the ones covered by CI) then I think we're good to go. Hmm, I'm not sure why the Windows regexes are not working properly - perhaps the underlying implementation is more strict about regular expressions with non-displayable characters in them? Does changing the escape character to Yes, I think that |
…bly complex regex expressions on windows
In the end the regex bug was due to gtest having limited regex support on windows (as seen here). I assume they will add better support in the future, so I put in a bit of a 'janky' solution for windows using one of GTEST's processor macros (so when they do add the functionality the actual regex is called). |
This will be okay, though I will ask that you please add a comment to the test code before the preprocessor conditional that explains why this is done so that others reading the tests will know why this is being done without finding this conversation. It looks like you just need to update the |
…emory is freed by stumpless_free_all
Thank you again for working through this, and I hope that you feel a sense of accomplishment for completing an issue that gave so many others quite a bit of trouble! I try to give contributors a shoutout on X when I can, especially for larger contributions like this one. I don't see one listed on your profile here though: if you have an account let me know (via email or private Gitter if you want it to remain hidden) and I will post something there. |
Adds support for using ansi escape codes to represent different severity levels when printing to a terminal, and presents some default escape codes. Allows for . Solves #103.
Unit tests were not written however, as I was unsure how to capture the stdout to check it was correctly printing ansi terminals (I did check with a script on my side that it was working).
This is my first open source contribution so any feedback is welcome.