Help us shape the future of Go! Take the 2026 Go Developer Survey

ui

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package ui applies colour and alignment to terminal output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Added

func Added(s string) string

Added marks something created or filed.

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 Enabled

func Enabled() bool

Enabled reports whether colour is being applied.

func Info

func Info(s string) string

Info marks a neutral highlight, such as a status word.

func Muted

func Muted(s string) string

Muted is secondary detail: counts, terms, timings.

func Name

func Name(s string) string

Name marks an identifier — a list or repository name.

func Pad

func Pad(s string, width int) string

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 Removed

func Removed(s string) string

Removed marks something deleted or taken away.

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.

func Title

func Title(s string) string

Title is a heading: a category name, a section.

func Warn

func Warn(s string) string

Warn marks something the user should look at but which is not an error.

func Width

func Width(s string) int

Width reports how many terminal columns s occupies.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL