Collecting my attempts to improve at tech, art, and life

Colorized my go output with grc

Tags: go shell tools

No image 'cover-colorized-my-go-output-with-grc.png'

Does any of this enlighten, entertain, or otherwise please you? Please consider a Tip. Every little bit helps!

Enjoying myself as I go through Learn Go with Tests by Chris James. I like Go. I like tests. I like this approach.

I didn’t enjoy myself on the official tour, or with whatever LinkedIn course it was that I took. The structure and flow of the learn-by-testing piece gives me a familiar context and the pace seems just about right. It’s giving me ideas where I might enjoy Go for my own projects.

So yeah I like it.

Still having some tiny issues with the output of go test.

plain output

Part of it’s that my brain hasn’t gotten used to how Go displays its errors. Some of it’s that my brain always has — and always will — panic at random symbols without context.

I figured I wasn’t the first with this problem, so I went looking. Found a Stack Overflow answer pointing me to grc. Installed via Homebrew, then followed directions from Stack Overflow to configure grc, with a slight tweak to ~/.grc/conf.gotest.

grc needs an entry in ~/.grc/grc.conf for Go test runs.

Code Sample
     # Go
 \bgo.* test\b
 conf.gotest
  

I did make a slight tweak to the suggested ~/.grc/conf.gotest, so that “panic” lines get highlighted as failures.

Code Sample
    regexp==== RUN .*
colour=blue
-
regexp=--- PASS: .*
colour=green
-
regexp=^PASS$
colour=green
-
regexp=^(ok|\?) .*
colour=magenta
-
regexp=^\s*panic: .*
colour=red
-
regexp=--- FAIL: .*
colour=red
-
regexp=[^\s]+\.go(:\d+)?
colour=cyan
  

Now when I run tests through grc go test, output is colorized and I can track it more easily!

output colorized by grc

Of course I’ll probably get used to how Go presents errors and then forget all about grc, but it’s great for today. Might be more generally useful too, if I want colorized output that my tools don’t already provide!