You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We got a Dependabot bump to this version. Previously we were on a
pre-1.0 version, but 1.0 came out this month.
There were some minor API breaks - renamed fields and slightly changed
concepts. The main difference that I can see, though, is that direct
handling of colours was removed.
In the `ci list` subcommand, we output a table containing the check runs
and statuses for a pull request or commit. As a bonus feature on a
terminal we'll colour those ("Passed" is green, etc). We also pass them
through a [`caser`] to make them into Title Case.
The removal of the colour support isn't too bad in itself. We already
had a function to map check statuses to colours. All we needed to do
there was to move this over to the type's `String()` method, using the
[`color`] library which we already use.
The problem comes when we then try to title case these strings. The
title caser has no understanding of terminal colour codes at all. So
here we make a wrapper [`transformer`] that strips the colour codes
before passing the plain text to the underlying `caser`, before
reassembling back to keep the colours.
This ended up being quite a bit of work due to the way that transformers
work - they can be called partially in a sort of streaming mode. But
it's all in here and working now. The wrapper has an extensive testsuite
to help build confidence that it works properly, since it's challenging
code to follow and the concepts involved are a bit difficult to
understand too.
Why is it OK to include colour codes in the string results? That's
because the `fatih/color` library auto-detects if the output is going to
a terminal or not before emitting the codes. In fact, we already did
this for the case of job names.
[`caser`]: https://pkg.go.dev/golang.org/x/text/cases#Title
[`color`]: https://pkg.go.dev/github.com/fatih/color
[`transformer`]: https://pkg.go.dev/golang.org/x/text/transform#Transformer
0 commit comments