rexo icon indicating copy to clipboard operation
rexo copied to clipboard

Feature: disable color

Open markand opened this issue 3 years ago • 5 comments

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

markand avatar Oct 20 '21 07:10 markand

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):

  • plain
  • colored (default)
  • jUnit XML
  • ...

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?

christophercrouzet avatar Oct 20 '21 18:10 christophercrouzet

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.

markand avatar Oct 22 '21 08:10 markand

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.

christophercrouzet avatar Oct 22 '21 20:10 christophercrouzet

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!

default-writer avatar Nov 27 '22 17:11 default-writer

Hi @default-writer!

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

  • RXP_LOG_STYLING is set to 1 https://github.com/christophercrouzet/rexo/blob/ce0ffbd940b9212a5244b2aa69e7def17be96794/include/rexo.h#L609
  • stderr looks like a shell https://github.com/christophercrouzet/rexo/blob/ce0ffbd940b9212a5244b2aa69e7def17be96794/include/rexo.h#L2917

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

christophercrouzet avatar Nov 29 '22 07:11 christophercrouzet