pub struct Printer<'t> { /* private fields */ }
Expand description
An object which you can configure to print the help of a command
Implementations§
source§impl<'t> Printer<'t>
impl<'t> Printer<'t>
sourcepub fn new(cmd: Command) -> Self
pub fn new(cmd: Command) -> Self
Examples found in repository?
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
fn main() {
let args = Args::parse();
if args.help {
Printer::new(Args::command())
.with("introduction", INTRO)
.without("author")
.print_help();
return;
}
let (w, h) = (args.width, args.height);
println!("Computation strategy: {:?}", args.strategy);
println!("{w} x {h} = {}", w*h);
}
sourcepub fn make_skin() -> MadSkin
pub fn make_skin() -> MadSkin
Build a skin for the detected theme of the terminal (i.e. dark, light, or other)
sourcepub fn skin_mut(&mut self) -> &mut MadSkin
pub fn skin_mut(&mut self) -> &mut MadSkin
Give a mutable reference to the current skin (by default the automatically selected one) so that it can be modified
sourcepub fn with(self, key: &'static str, template: &'t str) -> Self
pub fn with(self, key: &'static str, template: &'t str) -> Self
Change a template
Examples found in repository?
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
fn main() {
let args = Args::parse();
if args.help {
Printer::new(Args::command())
.with("introduction", INTRO)
.without("author")
.print_help();
return;
}
let (w, h) = (args.width, args.height);
println!("Computation strategy: {:?}", args.strategy);
println!("{w} x {h} = {}", w*h);
}
sourcepub fn without(self, key: &'static str) -> Self
pub fn without(self, key: &'static str) -> Self
Unset a template
Examples found in repository?
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
fn main() {
let args = Args::parse();
if args.help {
Printer::new(Args::command())
.with("introduction", INTRO)
.without("author")
.print_help();
return;
}
let (w, h) = (args.width, args.height);
println!("Computation strategy: {:?}", args.strategy);
println!("{w} x {h} = {}", w*h);
}
sourcepub fn template_order_mut(&mut self) -> &Vec<&'static str>
pub fn template_order_mut(&mut self) -> &Vec<&'static str>
A mutable reference to the list of template keys, so that you can insert new keys, or change their order. Any key without matching template will just be ignored
sourcepub fn expander_mut(&mut self) -> &mut OwningTemplateExpander<'static>
pub fn expander_mut(&mut self) -> &mut OwningTemplateExpander<'static>
Give you a mut reference to the expander, so that you can overload the variable of the expander used to fill the templates of the help
sourcepub fn print_template(&self, template: &str)
pub fn print_template(&self, template: &str)
Print the provided template with the printer’s expander
It’s normally more convenient to change template_order or some templates, unless you want none of the standard templates
sourcepub fn print_help(&self)
pub fn print_help(&self)
Print all the templates, in order
Examples found in repository?
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
fn main() {
let args = Args::parse();
if args.help {
Printer::new(Args::command())
.with("introduction", INTRO)
.without("author")
.print_help();
return;
}
let (w, h) = (args.width, args.height);
println!("Computation strategy: {:?}", args.strategy);
println!("{w} x {h} = {}", w*h);
}