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);
}More examples
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
fn main() {
let args = Args::parse();
if args.help {
let mut printer = Printer::new(Args::command())
.without("author")
.with("introduction", INTRO)
.with("options", TEMPLATE_OPTIONS);
let skin = printer.skin_mut();
skin.headers[0].compound_style.set_fg(ansi(202));
skin.bold.set_fg(ansi(202));
skin.italic = termimad::CompoundStyle::with_fg(ansi(45));
skin.inline_code = termimad::CompoundStyle::with_fg(ansi(223));
printer.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
Examples found in repository?
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
fn main() {
let args = Args::parse();
if args.help {
let mut printer = Printer::new(Args::command())
.without("author")
.with("introduction", INTRO)
.with("options", TEMPLATE_OPTIONS);
let skin = printer.skin_mut();
skin.headers[0].compound_style.set_fg(ansi(202));
skin.bold.set_fg(ansi(202));
skin.italic = termimad::CompoundStyle::with_fg(ansi(45));
skin.inline_code = termimad::CompoundStyle::with_fg(ansi(223));
printer.print_help();
return;
}
let (w, h) = (args.width, args.height);
println!("Computation strategy: {:?}", args.strategy);
println!("{w} x {h} = {}", w*h);
}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);
}More examples
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
fn main() {
let args = Args::parse();
if args.help {
let mut printer = Printer::new(Args::command())
.without("author")
.with("introduction", INTRO)
.with("options", TEMPLATE_OPTIONS);
let skin = printer.skin_mut();
skin.headers[0].compound_style.set_fg(ansi(202));
skin.bold.set_fg(ansi(202));
skin.italic = termimad::CompoundStyle::with_fg(ansi(45));
skin.inline_code = termimad::CompoundStyle::with_fg(ansi(223));
printer.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);
}More examples
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
fn main() {
let args = Args::parse();
if args.help {
let mut printer = Printer::new(Args::command())
.without("author")
.with("introduction", INTRO)
.with("options", TEMPLATE_OPTIONS);
let skin = printer.skin_mut();
skin.headers[0].compound_style.set_fg(ansi(202));
skin.bold.set_fg(ansi(202));
skin.italic = termimad::CompoundStyle::with_fg(ansi(45));
skin.inline_code = termimad::CompoundStyle::with_fg(ansi(223));
printer.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, or add new variables for your own templates
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);
}More examples
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
fn main() {
let args = Args::parse();
if args.help {
let mut printer = Printer::new(Args::command())
.without("author")
.with("introduction", INTRO)
.with("options", TEMPLATE_OPTIONS);
let skin = printer.skin_mut();
skin.headers[0].compound_style.set_fg(ansi(202));
skin.bold.set_fg(ansi(202));
skin.italic = termimad::CompoundStyle::with_fg(ansi(45));
skin.inline_code = termimad::CompoundStyle::with_fg(ansi(223));
printer.print_help();
return;
}
let (w, h) = (args.width, args.height);
println!("Computation strategy: {:?}", args.strategy);
println!("{w} x {h} = {}", w*h);
}