Skip to content

Conversation

IsaacOscar
Copy link
Contributor

@IsaacOscar IsaacOscar commented Oct 4, 2025

This adds a -c option to pcre2test that will print various different output in colour.

For ease of reviewing I've split the changes into two commits:

  1. contains the interesting changes, but it doesn't compile without the second commit.
  2. simply changes all remaining printf, pchars, etc. calls to also include the colour to use.

Most output from pcre2test is given an explicit colour, however this is often just clr_output which is the terminals default colour (i.e. it likely won't be in "colour").

@IsaacOscar IsaacOscar force-pushed the pcre2test_colour branch 3 times, most recently from 06318ae to 6539820 Compare October 4, 2025 16:11
This commit makes various changes to to pcre2test to support colourising
the output, in particular, the following colour scheme is intended:
 * Comments from the inputfile are in grey (but not those entered in
   interactively)
 * All other input is in green
 * Messages related to PCRE2 api errors are in magenta
 * Messages related to errors with using pcre2test itself are in red
 * Timing and memory usage information is in blue
 * Normal output is in your terminal's default foreground colour
 * The interactive prompt is in blue
 * Anything withought an explicit colour set (e.g. stuff printed by
   valgrind) should be in yellow
This finishes of the work started by the previous commit.
@NWilson
Copy link
Member

NWilson commented Oct 4, 2025

This is great! I have a few requests:

  • I think I prefer having the output FILE* be explicit, and only output to stdout if it's not specified. This matches the C convention - printf goes to stdout, and all the other methods (fprintf etc) have an explicit output destination. This basically means adding "outfile" as an argument to your cprintf throughout. Thoughts?
  • I'd prefer --color={always,auto,never} instead of the confusingly-short -c. (I'm happy to add auto later myself. If it were to be the default, it would need to check isatty and getenv("NO_COLOR") per https://no-color.org/.)
  • I'm not sure about the valgrind errors being yellow. Speculatively switching to yellow just in case anything else is printed seems a little eager. Why not just restore standard white for anything that doesn't need an explicit colour.

Copy link
Member

@NWilson NWilson left a comment

Choose a reason for hiding this comment

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

I've made those changes. I'll merge it soon, unless you message to say there are additional changes you'd like to make.

Thank you very much Isaac!

@NWilson NWilson merged commit 0288afe into PCRE2Project:master Oct 12, 2025
35 checks passed
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.

2 participants