christophercrouzet / rexo

Neat single-file cross-platform unit testing framework for C/C++.
The Unlicense
27 stars 6 forks source link

Feature: disable color #13

Open markand opened 2 years ago

markand commented 2 years ago

I propose a runtime option to disable colors using -c.

christophercrouzet commented 2 years ago

Hi @markand, thanks for opening this issue! :smile:

I agree, that would be great! Although the way that I was hoping to implement that was through this feature described in the roadmap:

allow choosing the output format of the summary (e.g.: jUnit XML).

Where we'd basically have a choice of options like these (the actual labelling is not definitive):

Otherwise, if a color flag was implemented separately, it might work for some output formats but not others, which might not be ideal.

Would that make sense?

markand commented 2 years ago

Otherwise, if a color flag was implemented separately, it might work for some output formats but not others, which might not be ideal.

I don't think so, for example, the command line tool jq supports coloring the JSON format in the terminal. Basically we could color anything depending on the user choice and export. Just like an editor would color <xml> tags or JSON properties.

I think having an option that disable color should disable them if the output format support them.

christophercrouzet commented 2 years ago

I feel like colorizing only makes sense when we want to log output onto a shell for users to consume in a human-friendly fashion, as a way to inform them of the result of running their unit tests.

In contrast, XML, JSON, and other formats are mostly intended to be forwarded onto other commands for further processing rather than being directly consumed by users. In fact, colorizing such outputs would likely make them impossible to be parsed by these other commands.

We should aim at keeping things relevant to the scope of this project and to keep things as simple as possible—Rexo is not a syntax colouring library for XML, JSON, and other formats. If such a feature is needed, I'm sure that there are other commands out there that are built for this specific purpose and that can be piped to the output of Rexo. However, if colorizing the output can help increasing readability of some non-standard output from Rexo that is intended to be consumed by the users, then sure!

As a result, I personally dislike having flags that work only when some other flags have specific values set. I'd rather think of a design that doesn't need this sort of coupling, and that's why I would much prefer what I suggested in my previous comment.

default-writer commented 1 year ago

currently i did not see any colorisation on .devcontainer in vscode for both main and no-asan, so [PASSED] printed out normally. is it expected or just a glitch? i do not understand, thanks!

christophercrouzet commented 1 year ago

Hi @default-writer!

Rexo will colorize the output using ANSI escape codes (https://en.wikipedia.org/wiki/ANSI_escape_code#Colors) if:

However, I don't know the specifics of .devcontainer / vscode, sorry :sweat_smile: