pub struct HelpFormatter { /* private fields */ }Expand description
Help text formatter with terminal-aware wrapping.
This struct provides methods for formatting help text with proper indentation, text wrapping, and special formatting for definition lists (options/arguments).
§Example
use click::HelpFormatter;
let mut formatter = HelpFormatter::new(80);
formatter.write_usage("mycli", "[OPTIONS] COMMAND");
formatter.write_paragraph("A helpful CLI tool.");
formatter.write_heading("Options");
formatter.write_definition_list(&[
("--help, -h", "Show this help message"),
("--verbose, -v", "Enable verbose output"),
]);
println!("{}", formatter.get_help());Implementations§
Source§impl HelpFormatter
impl HelpFormatter
Sourcepub fn new(width: usize) -> Self
pub fn new(width: usize) -> Self
Create a new HelpFormatter with the specified terminal width.
If width is 0 or less than minimum, uses default width.
Sourcepub fn detect_width() -> Self
pub fn detect_width() -> Self
Create a new HelpFormatter that detects terminal width.
Sourcepub fn set_indent(&mut self, indent: usize)
pub fn set_indent(&mut self, indent: usize)
Set the current indentation level.
Sourcepub fn write_blank(&mut self)
pub fn write_blank(&mut self)
Write a blank line.
Sourcepub fn write_usage(&mut self, prog: &str, args: &str)
pub fn write_usage(&mut self, prog: &str, args: &str)
Write a usage line.
Format: Usage: prog [OPTIONS] ARGS
Sourcepub fn write_heading(&mut self, heading: &str)
pub fn write_heading(&mut self, heading: &str)
Write a section heading.
The heading is followed by a blank line.
Sourcepub fn write_paragraph(&mut self, text: &str)
pub fn write_paragraph(&mut self, text: &str)
Write a paragraph of text with word wrapping.
Preserves paragraph breaks (double newlines) and wraps text to fit within the terminal width.
Sourcepub fn write_definition_list(&mut self, items: &[(&str, &str)])
pub fn write_definition_list(&mut self, items: &[(&str, &str)])
Write a definition list (term + description pairs).
Used for formatting options and arguments. Each item is a tuple of (term, description).
Format depends on term length:
- Short terms: description on same line
- Long terms: description on next line, indented
Sourcepub fn write_definition_list_strings(&mut self, items: &[(String, String)])
pub fn write_definition_list_strings(&mut self, items: &[(String, String)])
Write a definition list with string tuples.