Skip to main content

Module style

Module style 

Source
Expand description

Colour, and the “did you mean” a refusal needs to be useful. Terminal styling for the parts of choir a person reads (D58).

Two rules hold this together, and they are what make colour safe in a tool whose other half is an agent:

  1. Data goes to stdout, unstyled, always. Every command that answers with JSON answers with exactly the bytes the node sent. Nothing in here is ever applied to that stream, so a pipeline sees the same thing whether or not a terminal is attached.
  2. Diagnostics go to stderr, styled only when a person is looking. A person is looking when stderr is a terminal, NO_COLOR is unset, and TERM is not dumb.

Hand-rolled rather than owo-colors or console for the reason the rest of the workspace hand-rolls: this is four escape sequences and a predicate, and the two dependencies it would replace pull in terminal-detection stacks whose behaviour we would then have to test anyway.

§Examples

let plain = choir_cli::style::Style::plain();
assert_eq!(plain.bold("choir"), "choir");

Structs§

Style
Whether styled output is wanted, and the sequences for it.

Functions§

distance
Levenshtein distance between two ASCII-ish words, for “did you mean”.
nearest
The closest command name to typed, when one is close enough to be worth suggesting.