Skip to main content

Module colour

Module colour 

Source
Expand description

When the driver’s human output is coloured, and the few styles it uses.

One decision for the whole process, set once from the global --color (alias --colour) flag: auto (the default), always or never. Under auto a stream is coloured when it is a terminal, or when FORCE_COLOR or CLICOLOR_FORCE asks for colour without one, and never when NO_COLOR is set (allowed has the exact rules). always and never override the terminal check and the environment alike.

The palette has one meaning per colour: blue for information, green for success, red for an error or a failure, amber for a warning, and bold for a heading.

Machine-readable output (--format json, ndjson, and bynk check’s and bynk doctor’s short) is never coloured, whatever the choice: only the human renderings ask this module.

Structs§

TestLines
bynk test’s human output (the runner’s, as it is forwarded), coloured a line at a time: a passing case’s ✓ green, a failing case red, a suite heading bold, a detached effect’s report yellow, and the closing tally’s counts green and, when any failed, red. Any other line passes through as it is. A heading is a line the runner starts after a blank one (each suite’s results end with one, and Running tests... with two), so a test’s own console.log("Response:") mid-suite is not taken for one.

Enums§

ColourChoice
--color <WHEN>: when to colour the driver’s human output.
Style
A style the driver paints text in: one meaning per colour.

Functions§

apply_to_child
Make a child process (a wrangler) whose output reaches the user colour as we do: under never, NO_COLOR set and FORCE_COLOR taken away; under always, the reverse. Under auto the child decides for itself, unless its output is piped through us, where it can no longer see our terminal: then FORCE_COLOR when we would colour stderr.
choice
This process’s choice.
coverage_style
The style for a coverage percentage: green from 80%, yellow (amber) from 50%, red below.
eprint
eprint!("{text}"), coloured as stderr_message has it.
eprint_message
Print text and a newline to stderr, as stderr_message has it. What emsg! expands to.
eprintln
eprintln!("{text}"), coloured as stderr_message has it.
message
A message for stderr (bynk: warning: …), with its error:, warning: or note: label red, amber or blue: the first such label on each line, whether it opens the line (after any indent or = ) or follows the bynk …: or <program> …: that names who is speaking. Nothing else changes, so a line with no label is returned as it is.
paint
text in style when on, otherwise text unchanged.
set_choice
Set this process’s choice (from --color). Until it is called the choice is ColourChoice::Auto.
stderr
Whether human output on stderr is coloured.
stderr_message
text for stderr: its labels coloured as message does when stderr is coloured, and unchanged when it isn’t.
stdout
Whether human output on stdout is coloured.