Skip to main content

Module paint

Module paint 

Source
Expand description

How wide the help is, and who lays it out.

§clap cannot wrap in this workspace, and term_width will not make it

StyledStr::wrap is pub(crate) fn wrap(&mut self, _hard_width: usize) {} under #[cfg(not(feature = "wrap_help"))], and this workspace takes clap with derive alone. So Command::term_width sets a number every renderer reads and nothing acts on, and every help string reached a caller on one line however long it was — 1,126 columns at the widest.

Taking the wrap_help feature is the route the crate offers and it is the wrong one here. It pulls terminal_size, which measures the terminal the process is attached to, and a width that depends on the terminal makes a piped run and a run under a terminal write different bytes. Every recorded fixture and every test that reads this help would then be reading the terminal of whoever ran it.

So the strings are folded here, before clap sees them, at a width this module decides. Nothing in the path reads a terminal: dimensions() is (None, None) without wrap_help, so clap asks no question about the stream it is writing to, and neither does this.

§The one indent, and how it is known

painted declares next_line_help on every command of the tree, which puts an argument’s help on the line under the argument rather than in a column whose width is a function of the longest argument at that node. The indent is then TAB plus NEXT_LINE_INDENT — two spaces and eight — at every node, so INDENT is a constant rather than a computation, and one folded string is right wherever clap decides to print it.

§What clap appends after a help string, and why folding has to know

HelpTemplate::help writes the string this module folded and then appends the spec values — [default: 0], [possible values: …], [aliases: …] — on the same line after a space. A fold that did not account for them would be right about the text and wrong about the line. [reserved] measures what is coming and fold_at keeps the last word of the text and that suffix on one line together.

§Color reads the terminal on purpose, and the masthead is why it must

HW-DR-0045 departs from the rule two sections up, deliberately: an escape sequence leaked into a pipe or a log file actively harms whoever reads it, where a column-wrap choice never did, and every fixture this corpus pins already runs headless. So color_of is a pure function in exactly the shape width_of already is — unit-testable with a table and no real terminal — and its one live caller, stdout_color or stderr_color, reads a stream’s own terminal state, which nothing above this line ever does.

--no-color, --no-banner and their environment variables are read the way --wide already is: scanned raw, before clap builds the tree, because banner runs inside first_screen, which is built before parsing runs.

Enums§

ColorMode
Whether a stream renders the palette below, or its plain-text fallback.
Role
One semantic role HW-DR-0045’s palette names.

Constants§

INDENT
The column an argument’s help starts at, at every node of the tree.
WIDEST
The width and the fill, which live in headwater_check::fill and are named here so that a caller of this module keeps writing paint::WIDTH.
WIDTH
The width and the fill, which live in headwater_check::fill and are named here so that a caller of this module keeps writing paint::WIDTH.

Functions§

banner
The masthead HW-DR-0045 rules on, or today’s plain name line where banner_suppressed holds.
banner_suppressed
Whether --no-banner or HEADWATER_NO_BANNER suppress the masthead, scanned the way [no_color_flag] and NO_COLOR are.
color_choice
The clap color choice a ColorMode means, stated rather than sensed.
color_of
ColorMode, Role, color_of, paint and dim moved to headwater_check::paint, and are re-exported here unchanged.
dim
ColorMode, Role, color_of, paint and dim moved to headwater_check::paint, and are re-exported here unchanged.
flattened
The same tree with every string put back on one line.
fold
The width and the fill, which live in headwater_check::fill and are named here so that a caller of this module keeps writing paint::WIDTH.
fold_at
The width and the fill, which live in headwater_check::fill and are named here so that a caller of this module keeps writing paint::WIDTH.
fold_indented
A block of text folded to width and indented, with its closing newline.
glyph
ColorMode, Role, color_of, paint and dim moved to headwater_check::paint, and are re-exported here unchanged.
help_styles
The palette clap paints a help page with, in the roles HW-DR-0045 names.
paint
ColorMode, Role, color_of, paint and dim moved to headwater_check::paint, and are re-exported here unchanged.
painted
The tree, with every string folded and every node laid out the same way.
painted_row
The same row with the name painted, and the layout decided before it is.
row
One row of a two-column list, folded so that no line passes width.
severity_role
ColorMode, Role, color_of, paint and dim moved to headwater_check::paint, and are re-exported here unchanged.
severity_word
ColorMode, Role, color_of, paint and dim moved to headwater_check::paint, and are re-exported here unchanged.
stderr_color
The mode standard error renders in, for this run of the binary.
stdout_color
The mode standard output renders in, for this run of the binary.
wants_root_help
Whether the raw command line asks for the root help screen: -h or --help present, and no token that names a verb.
width
The width this process lays the help out at.
width_of
The width a --wide and a COLUMNS reading come to.