robotframework-tidy icon indicating copy to clipboard operation
robotframework-tidy copied to clipboard

Option to output in colour when piped

Open Zeckie opened this issue 2 years ago • 3 comments

Currently, when the output is piped (whether to an application or file), it seems as though --color is ignored. We have a script running in CI that runs robotidy, and captures the output. It would be nice if we could get it to work in colour.

For example, this is in colour:

robotidy --check --diff --color .

But this is not (replace type with cat if not using windows):

robotidy --check --diff --color . > output.txt
type output.txt

Zeckie avatar Nov 29 '22 03:11 Zeckie

It looks like this is how to do it using rich: https://rich.readthedocs.io/en/stable/console.html#interactive-mode

Zeckie avatar Nov 29 '22 04:11 Zeckie

Similar issue with mypy: https://github.com/python/mypy/issues/7771

Zeckie avatar Nov 29 '22 04:11 Zeckie

Sorry for the late reply - I've actually read the issue right away and I keep coming back to it but I wasn't sure how to approach it. By including color you mean color codes I use to print to the cli?

In this case following command (temporary option name):

robotidy --check --diff --color --force-color-codes . > output.txt

would output something akin to:

[green] +++ 12
Some line of code
[/green]

The actual color codes are different of course, just an example.

bhirsz avatar Mar 24 '23 14:03 bhirsz