summary

Multi-line summary molecule for commands that report tallies of work.

Composes a titled block of count rows, an optional completion message, and an optional trailing hint. A dedicated empty-state message replaces the row block when no rows are pushed, letting callers hand a single component both the “nothing to do” and “here’s what happened” paths.

struct Component

source

pub struct Component

Renders a titled summary block with per-row counts, plus optional completion and hint lines beneath it.

A single Component handles both outcomes a tally-style command needs to print:

  • When rows are pushed, the title is followed by an indented list of rows.
  • When no rows are pushed and an empty_message is set, the empty message replaces the rows (the title is suppressed).

The optional SuccessMessage trailer and muted hint line render after the summary block, separated by blank lines.

Field Type Description
empty_message Option<String> Muted line shown instead of the title and rows when no row is pushed.
hint Option<String> Muted line shown last, after a blank line when anything precedes it.
rows Vec<Row> Count rows in push order.
success Option<SuccessMessage> Completion message shown after the rows, after a blank line when anything precedes it.
title Option<String> Heading shown above the rows; not shown when there are no rows.

Implements Default, Display.

Component::new

source

pub fn new() -> Self

Create an empty summary with no title, rows, message, or hint.

Parameter Type Description
returns Self A summary that displays as nothing until something is set.

Component::empty_message

source

pub fn empty_message(self, message: impl Into<String>) -> Self

Set the message rendered in place of the row block when no rows are pushed.

Parameter Type Description
message impl Into<String> the text for the nothing-to-do case
returns Self The summary with the empty message set.

Component::hint

source

pub fn hint(self, hint: impl Into<String>) -> Self

Append a trailing hint line rendered with the muted theme.

Parameter Type Description
hint impl Into<String> the hint text; a second call replaces the first
returns Self The summary with the hint set.

Component::is_empty

source

pub fn is_empty(&self) -> bool

Report whether any rows have been pushed.

Parameter Type Description
returns bool true when no row has been pushed.

Component::row

source

pub fn row(self, label: impl Into<String>, count: usize) -> Self

Append a row with a label, count, and no detail text.

Parameter Type Description
label impl Into<String> the row name
count usize the number to show
returns Self The summary with the row appended.

Component::row_with_detail

source

pub fn row_with_detail(
    self,
    label: impl Into<String>,
    count: usize,
    detail: Option<impl Into<String>>,
) -> Self

Append a row with a label, count, and optional parenthesized detail text.

Parameter Type Description
label impl Into<String> the row name
count usize the number to show
detail Option<impl Into<String>> the text to show in parentheses; None shows none
returns Self The summary with the row appended.

Component::success

source

pub fn success(self, message: SuccessMessage) -> Self

Attach a completion SuccessMessage rendered beneath the summary block.

Parameter Type Description
message SuccessMessage the completion message
returns Self The summary with the message set.

Component::title

source

pub fn title(self, title: impl Into<String>) -> Self

Set the title rendered above the row block (e.g. Purge summary:).

Parameter Type Description
title impl Into<String> the heading text
returns Self The summary with the title set.

struct Row

source

struct Row

A single row in a Component summary.

Field Type Description
count usize Number shown after the label.
detail Option<String> Text shown in parentheses after the count.
label String Row name, shown before a colon.

fn write_row

source

fn write_row(f: &mut Formatter<'_>, row: &Row) -> fmt::Result

Format a single row as <label>: <count> with an optional (<detail>) suffix.

Parameter Type Description
f &mut Formatter<'_> the formatter to write to
row &Row the row to write
returns fmt::Result The formatter’s result.