Skip to main content

Module style

Module style 

Source
Expand description

Colour for the admin CLI’s human-readable output.

Hand-rolled and dependency-free, for crate::metrics’s reason: an SGR sequence is \x1b[<n>m and a reset, which is a write!, and every colour crate in the ecosystem brings either a global state cell or a second opinion about what a terminal is.

Nothing here is reachable from --json. A Palette is threaded into the text renderers in crate::cli::render and nowhere else; the JSON branches print a serde_json::Value that never passes through this module, so machine-readable output stays byte-identical whatever the terminal is.

Two rules worth not rediscovering:

  • Pad first, then colour. Every listing renderer builds fixed columns with {:<12}, and a format width counts bytes — padding an already-wrapped field counts the eight-odd bytes of escape and the column collapses. Call sites therefore read palette.status(&format!("{:<11}", status)), never the other way round.
  • Precedence deliberately differs from logging.ansi. [crate::cli::logging] documents that neither its switch nor NO_COLOR can turn colour on against the other, which is right for a configuration file — an ambient setting should not override an ambient veto. A --color always is neither ambient nor a setting: it was typed by the person reading the output, one command ago, and it beats both the TTY test and NO_COLOR. That is what makes piping into less -R work.

Structs§

Palette
Whether colour is on, and the vocabulary for painting with it.

Enums§

ColorChoice
When to colour human-readable output — the --color flag’s values.