commitizen icon indicating copy to clipboard operation
commitizen copied to clipboard

remove coloring from pre-commit prints

Open 12rambau opened this issue 4 years ago • 1 comments

Description

I use the pre-commit framework to apply some sanity check before committing to my repositories. I recently discover this lib and wanted to give it a try. Fantastic work !

I use te following command to create a new commit:

cz commit

And I get the following results (sorry for the image but everything is about coloring):
Capture d’écran 2021-09-07 à 16 41 00

after #258which is the commit message, the pre-commit checks start and normally at the end of their lines skippedshould be blue, passed: green and failed red. when creating a commit with czI loose these colors. I tested back using simply git commitand it worked.

Question then: why is the coloring of pre-commit disabled by cz ?

12rambau avatar Sep 07 '21 14:09 12rambau

Thanks for reporting! if my memory serves me right, we did not do anything to disable the color 🤔 might need to take a look at the pre-commit side as well

Lee-W avatar Sep 11 '21 02:09 Lee-W

Finally took the time to dive into this one:

That's actually quite simple and it's definitely coming from here. Going upstream from cli.py I think commit are created using : cmd.run(f"git commit {args} -F {f.name}") where cmd is a Command object. the run method execute a subprocess call and redirect the resulting lines to out.

If git is called from a subprocess it doesn't know if it's outputted to a terminal and switch off the ANSI coloring (ref: https://stackoverflow.com/questions/42589584/ansi-color-lost-when-using-python-subprocess, https://stackoverflow.com/questions/38084815/can-you-have-subprocesss-popen-retain-color-in-stdout-stderr).

Now the question is: should the ANSI colorisation be authorized in the Command object or should we keep it that way to avoid compatibility issues whith platforms ?

12rambau avatar Jan 15 '23 16:01 12rambau

Hi @12rambau Thanks for your help! Does that mean if we keep the ANSI coloring, we might break platform compatibility? If that's the case, I'd say platform compatibility is way more important.

Lee-W avatar Jan 18 '23 14:01 Lee-W

If that's the case, I'd say platform compatibility is way more important.

Agreed. Then I'll check if it can be set somewhere in the documentation in a note and then I'll close this issue

12rambau avatar Jan 19 '23 07:01 12rambau

@12rambau Great! Thanks for your help!

Lee-W avatar Jan 19 '23 07:01 Lee-W