Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have Go coverage HTML with light background?

Consider the following command:

go tool cover -html=coverage.out

Is there a way to make the resulting HTML dark on light (rather than the default light characters on dark background)?

I did not find anything about this neither in the documentation nor in the help pages referenced therein (go tool cover --help and go help testflag)

like image 308
Attilio Avatar asked Feb 13 '19 11:02

Attilio


2 Answers

Not with the built-in tool. There's nothing preventing you from piping the output through some script to change CSS colors, though, or to reference an external CSS file that sets the colors you prefer.

like image 63
Flimzy Avatar answered Sep 28 '22 06:09

Flimzy


As mentioned by @Flimzy, this is not supported with the built-in tool.

Though, looking at the coverage.html file output by the cover tool.

You can do something like this:

go tool cover -o coverage.html -html=coverage.out; sed -i 's/black/whitesmoke/g' coverage.html; sensible-browser coverage.html

which will write the output to coverage.html using the -o flag and then use sed to change occurrences of black to whitesmoke. It will then use your default browser to open the file.

Note #1: Obviously, this will not work once the tool is updated not to output black color background. Though, if this changes, there is probably a lot better support for different color schemes.

Note #2: If you use heat maps -covermode=count, the light green might look awkward on the smokewhite color. Feel free to try different color accents though.

like image 41
ifnotak Avatar answered Sep 28 '22 07:09

ifnotak