How to have Go coverage HTML with light background?
Asked Answered
K

2

7

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)

Keffiyeh answered 13/2, 2019 at 11:12 Comment(7)
@downvoter: It would be really nice if you could explain what is wrong with the question. I think the need is genuine and I also did a reasonable effort to find the answer myself before asking here.Keffiyeh
Also, do I understand correctly that asking about any Golang tool (e.g. go fmt, go imports, etc...) is not OK here, because it is not strictly related to programming?Keffiyeh
If you have some programing related question about go vet you can ask here. But how to change the color of a GUI tool is totally not related to programming. IMHO such stuff does not belong on an stackexchange forum. You should ask on reddit or golang-nuts.Padang
@Volker: if your question generally covers...software tools commonly used by programmers; and is a practical, answerable problem that is unique to software development...then you’re in the right place to ask your question! I would say that description fits this question: it is about a practical, answerable problem with a development-specific tool. Questions about Git, IDEs, and other developer tools have long been accepted on SO.Guido
@Guido I think the question is not practical and not answerable (except "you cannot"). This seems about taste.Padang
@Volker: for me "you cannot" is also an answer (I generally write it explicitly in my questions, this time I forgot). Because if I know that "you cannot", I know that I did not miss anything and do not keep looking.Keffiyeh
Also, before asking the question, how would I know in advance that the answer is "you cannot"?Keffiyeh
P
8

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.

Predominant answered 13/2, 2019 at 11:31 Comment(0)
H
8

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.

Huberty answered 13/2, 2019 at 12:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.