Documentation
¶
Overview ¶
Package ui applies colour and alignment to terminal output.
Index ¶
- func Added(s string) string
- func Configure()
- func Enabled() bool
- func Info(s string) string
- func Muted(s string) string
- func Name(s string) string
- func Pad(s string, width int) string
- func Removed(s string) string
- func SetEnabled(v bool)
- func Title(s string) string
- func Warn(s string) string
- func Width(s string) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Configure ¶
func Configure()
Configure applies the environment's colour preferences. It is called once from main, rather than from an init function, so that the decision happens at a point the program controls: package initialisation order is implicit, runs even in tests that never wanted it, and hides a global mutation in a place nothing calls.
The decision is made here rather than left to fatih/color, for two reasons. fatih/color checks only stdout, but main writes warnings and errors to stderr, so `constellation plan 2>err.log` would fill the log with escape sequences. And fatih/color captures NO_COLOR into each Color at construction, which pins colour off for the life of the process and stops SetEnabled from turning it back on; keeping the flag here lets SetEnabled always win.
The environment conventions honoured, in order of precedence:
- NO_COLOR set, whatever its value (https://no-color.org): off.
- CLICOLOR_FORCE set to anything but "0" (https://bixense.com/clicolors): on, even when output is not a terminal — the way to keep colour through a pager or a CI log that renders it.
- CLICOLOR=0: off.
- TERM=dumb: off.
- Otherwise on only when both stdout and stderr are terminals.
func Pad ¶
Pad returns the spaces needed to bring s up to width columns.
It measures display width, not runes: a star list named with CJK text or an emoji occupies two columns per character, so counting runes left those rows short and the table ragged. Colour is applied around the padding rather than inside it, since escape sequences occupy no columns but would still be counted by a fixed-width verb.
func SetEnabled ¶
func SetEnabled(v bool)
SetEnabled overrides the detection, for tests and for a future --color flag. It always wins: each Color is switched explicitly, so neither fatih/color's global NoColor nor the NO_COLOR it captured at construction can veto it.
Types ¶
This section is empty.