Struct clap_help::Printer

source ·
pub struct Printer<'t> {
    pub full_width: bool,
    pub max_width: Option<usize>,
    /* private fields */
}
Expand description

An object which you can configure to print the help of a command

Fields§

§full_width: bool§max_width: Option<usize>

Implementations§

source§

impl<'t> Printer<'t>

source

pub fn new(cmd: Command) -> Self

Examples found in repository?
examples/area/main.rs (line 53)
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
Hide additional examples
examples/with-additional-option/main.rs (line 27)
26
27
28
29
30
31
32
33
34
35
36
37
pub fn print_help() {
    let mut printer = clap_help::Printer::new(Args::command())
        .without("author");
    printer
        .expander_mut()
        .sub("option-lines")
        .set("short", "-z")
        .set("long", "--zeta")
        .set("value", "ZETA")
        .set("help", "Set the index of the last letter of the greek alphabet");
    printer.print_help();
}
examples/with-examples/main.rs (line 57)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pub fn print_help() {
    let args = Args::parse();
    let mut printer = clap_help::Printer::new(Args::command())
        .with("introduction", INTRO_TEMPLATE)
        .without("author");
    if args.ascii {
        printer.skin_mut().limit_to_ascii();
    }
    printer.template_keys_mut().push("examples");
    printer.set_template("examples", EXAMPLES_TEMPLATE);
    for (i, example) in EXAMPLES.iter().enumerate() {
        printer
            .expander_mut()
            .sub("examples")
            .set("example-number", i + 1)
            .set("example-title", example.title)
            .set("example-cmd", example.cmd)
            .set_md("example-comments", example.comments);
    }
    printer.print_help();
}
examples/custom/main.rs (line 67)
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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));
        skin.table_border_chars = termimad::ROUNDED_TABLE_BORDER_CHARS;
        printer.print_help();
        return;
    }

    let (w, h) = (args.width, args.height);
    println!("Computation strategy: {:?}", args.strategy);
    println!("{w} x {h} = {}", w * h);
}
source

pub fn make_skin() -> MadSkin

Build a skin for the detected theme of the terminal (i.e. dark, light, or other)

source

pub fn with_skin(self, skin: MadSkin) -> Self

Use the provided skin

source

pub fn with_max_width(self, w: usize) -> Self

Set a maximal width, so that the whole terminal width isn’t used.

This may make some long sentences easier to read on super wide terminals, especially when the whole text is short. Depending on your texts and parameters, you may set up a width of 100 or 150.

source

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?
examples/with-examples/main.rs (line 61)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pub fn print_help() {
    let args = Args::parse();
    let mut printer = clap_help::Printer::new(Args::command())
        .with("introduction", INTRO_TEMPLATE)
        .without("author");
    if args.ascii {
        printer.skin_mut().limit_to_ascii();
    }
    printer.template_keys_mut().push("examples");
    printer.set_template("examples", EXAMPLES_TEMPLATE);
    for (i, example) in EXAMPLES.iter().enumerate() {
        printer
            .expander_mut()
            .sub("examples")
            .set("example-number", i + 1)
            .set("example-title", example.title)
            .set("example-cmd", example.cmd)
            .set_md("example-comments", example.comments);
    }
    printer.print_help();
}
More examples
Hide additional examples
examples/custom/main.rs (line 71)
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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));
        skin.table_border_chars = termimad::ROUNDED_TABLE_BORDER_CHARS;
        printer.print_help();
        return;
    }

    let (w, h) = (args.width, args.height);
    println!("Computation strategy: {:?}", args.strategy);
    println!("{w} x {h} = {}", w * h);
}
source

pub fn set_template(&mut self, key: &'static str, template: &'t str)

Change a template

Examples found in repository?
examples/with-examples/main.rs (line 64)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pub fn print_help() {
    let args = Args::parse();
    let mut printer = clap_help::Printer::new(Args::command())
        .with("introduction", INTRO_TEMPLATE)
        .without("author");
    if args.ascii {
        printer.skin_mut().limit_to_ascii();
    }
    printer.template_keys_mut().push("examples");
    printer.set_template("examples", EXAMPLES_TEMPLATE);
    for (i, example) in EXAMPLES.iter().enumerate() {
        printer
            .expander_mut()
            .sub("examples")
            .set("example-number", i + 1)
            .set("example-title", example.title)
            .set("example-cmd", example.cmd)
            .set_md("example-comments", example.comments);
    }
    printer.print_help();
}
source

pub fn with(self, key: &'static str, template: &'t str) -> Self

Change or add a template

Examples found in repository?
examples/area/main.rs (line 54)
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
Hide additional examples
examples/with-examples/main.rs (line 58)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pub fn print_help() {
    let args = Args::parse();
    let mut printer = clap_help::Printer::new(Args::command())
        .with("introduction", INTRO_TEMPLATE)
        .without("author");
    if args.ascii {
        printer.skin_mut().limit_to_ascii();
    }
    printer.template_keys_mut().push("examples");
    printer.set_template("examples", EXAMPLES_TEMPLATE);
    for (i, example) in EXAMPLES.iter().enumerate() {
        printer
            .expander_mut()
            .sub("examples")
            .set("example-number", i + 1)
            .set("example-title", example.title)
            .set("example-cmd", example.cmd)
            .set_md("example-comments", example.comments);
    }
    printer.print_help();
}
examples/custom/main.rs (line 69)
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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));
        skin.table_border_chars = termimad::ROUNDED_TABLE_BORDER_CHARS;
        printer.print_help();
        return;
    }

    let (w, h) = (args.width, args.height);
    println!("Computation strategy: {:?}", args.strategy);
    println!("{w} x {h} = {}", w * h);
}
source

pub fn without(self, key: &'static str) -> Self

Unset a template

Examples found in repository?
examples/area/main.rs (line 55)
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
Hide additional examples
examples/with-additional-option/main.rs (line 28)
26
27
28
29
30
31
32
33
34
35
36
37
pub fn print_help() {
    let mut printer = clap_help::Printer::new(Args::command())
        .without("author");
    printer
        .expander_mut()
        .sub("option-lines")
        .set("short", "-z")
        .set("long", "--zeta")
        .set("value", "ZETA")
        .set("help", "Set the index of the last letter of the greek alphabet");
    printer.print_help();
}
examples/with-examples/main.rs (line 59)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pub fn print_help() {
    let args = Args::parse();
    let mut printer = clap_help::Printer::new(Args::command())
        .with("introduction", INTRO_TEMPLATE)
        .without("author");
    if args.ascii {
        printer.skin_mut().limit_to_ascii();
    }
    printer.template_keys_mut().push("examples");
    printer.set_template("examples", EXAMPLES_TEMPLATE);
    for (i, example) in EXAMPLES.iter().enumerate() {
        printer
            .expander_mut()
            .sub("examples")
            .set("example-number", i + 1)
            .set("example-title", example.title)
            .set("example-cmd", example.cmd)
            .set_md("example-comments", example.comments);
    }
    printer.print_help();
}
examples/custom/main.rs (line 68)
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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));
        skin.table_border_chars = termimad::ROUNDED_TABLE_BORDER_CHARS;
        printer.print_help();
        return;
    }

    let (w, h) = (args.width, args.height);
    println!("Computation strategy: {:?}", args.strategy);
    println!("{w} x {h} = {}", w * h);
}
source

pub fn template_keys_mut(&mut self) -> &mut 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

Examples found in repository?
examples/with-examples/main.rs (line 63)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pub fn print_help() {
    let args = Args::parse();
    let mut printer = clap_help::Printer::new(Args::command())
        .with("introduction", INTRO_TEMPLATE)
        .without("author");
    if args.ascii {
        printer.skin_mut().limit_to_ascii();
    }
    printer.template_keys_mut().push("examples");
    printer.set_template("examples", EXAMPLES_TEMPLATE);
    for (i, example) in EXAMPLES.iter().enumerate() {
        printer
            .expander_mut()
            .sub("examples")
            .set("example-number", i + 1)
            .set("example-title", example.title)
            .set("example-cmd", example.cmd)
            .set_md("example-comments", example.comments);
    }
    printer.print_help();
}
source

pub fn template_order_mut(&mut self) -> &mut Vec<&'static str>

👎Deprecated since 0.6.2: use template_keys_mut instead

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

source

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

Examples found in repository?
examples/with-additional-option/main.rs (line 30)
26
27
28
29
30
31
32
33
34
35
36
37
pub fn print_help() {
    let mut printer = clap_help::Printer::new(Args::command())
        .without("author");
    printer
        .expander_mut()
        .sub("option-lines")
        .set("short", "-z")
        .set("long", "--zeta")
        .set("value", "ZETA")
        .set("help", "Set the index of the last letter of the greek alphabet");
    printer.print_help();
}
More examples
Hide additional examples
examples/with-examples/main.rs (line 67)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pub fn print_help() {
    let args = Args::parse();
    let mut printer = clap_help::Printer::new(Args::command())
        .with("introduction", INTRO_TEMPLATE)
        .without("author");
    if args.ascii {
        printer.skin_mut().limit_to_ascii();
    }
    printer.template_keys_mut().push("examples");
    printer.set_template("examples", EXAMPLES_TEMPLATE);
    for (i, example) in EXAMPLES.iter().enumerate() {
        printer
            .expander_mut()
            .sub("examples")
            .set("example-number", i + 1)
            .set("example-title", example.title)
            .set("example-cmd", example.cmd)
            .set_md("example-comments", example.comments);
    }
    printer.print_help();
}
source

pub fn print_template(&self, template: &str)

Print the provided template with the printer’s expander

It’s normally more convenient to change template_keys or some templates, unless you want none of the standard templates

source

pub fn print_help(&self)

Print all the templates, in order

Examples found in repository?
examples/area/main.rs (line 56)
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
Hide additional examples
examples/with-additional-option/main.rs (line 36)
26
27
28
29
30
31
32
33
34
35
36
37
pub fn print_help() {
    let mut printer = clap_help::Printer::new(Args::command())
        .without("author");
    printer
        .expander_mut()
        .sub("option-lines")
        .set("short", "-z")
        .set("long", "--zeta")
        .set("value", "ZETA")
        .set("help", "Set the index of the last letter of the greek alphabet");
    printer.print_help();
}
examples/with-examples/main.rs (line 74)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pub fn print_help() {
    let args = Args::parse();
    let mut printer = clap_help::Printer::new(Args::command())
        .with("introduction", INTRO_TEMPLATE)
        .without("author");
    if args.ascii {
        printer.skin_mut().limit_to_ascii();
    }
    printer.template_keys_mut().push("examples");
    printer.set_template("examples", EXAMPLES_TEMPLATE);
    for (i, example) in EXAMPLES.iter().enumerate() {
        printer
            .expander_mut()
            .sub("examples")
            .set("example-number", i + 1)
            .set("example-title", example.title)
            .set("example-cmd", example.cmd)
            .set_md("example-comments", example.comments);
    }
    printer.print_help();
}
examples/custom/main.rs (line 77)
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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));
        skin.table_border_chars = termimad::ROUNDED_TABLE_BORDER_CHARS;
        printer.print_help();
        return;
    }

    let (w, h) = (args.width, args.height);
    println!("Computation strategy: {:?}", args.strategy);
    println!("{w} x {h} = {}", w * h);
}

Auto Trait Implementations§

§

impl<'t> RefUnwindSafe for Printer<'t>

§

impl<'t> Send for Printer<'t>

§

impl<'t> Sync for Printer<'t>

§

impl<'t> Unpin for Printer<'t>

§

impl<'t> UnwindSafe for Printer<'t>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.