clap
clap copied to clipboard
The header for my examples are not colored like the others
Please complete the following tasks
- [X] I have searched the discussions
- [X] I have searched the existing issues
Rust Version
rustc 1.55.0 (c8dfcfe04 2021-09-06)
Clap Version
v3.0.0-rc.0
Minimal reproducible code
use clap::Parser;
const AFTER_TEST: &str = "
Examples:
foo --hello
";
#[derive(Parser, Debug)]
#[clap(author, about)]
#[clap(after_help = AFTER_TEST)]
struct Opt {}
fn main() {
let opt = Opt::parse();
dbg!(opt);
}
Steps to reproduce the bug with the above code
cargo run -- --help
Actual Behaviour
Examples isn't colored:
test-clap
Me
From Cargo.toml
USAGE:
test-clap
OPTIONS:
-h, --help Print help information
Examples:
foo --hello
Expected Behaviour
Examples is colored
Additional Context
Inspired by help2man in #3096.
Including example commands is a really useful pattern and now that we color by default, doing this stands out.
Something like #1790 could help. Alternatively, we could have after_help take a section name, maybe as an Option. Like with override_usage, we'd probably want the indentation to be user-defined.
Debug Output
No response
What's the reason behind categorising this as bug? I would think this would be more of an enhancement, right?
Sometimes, its an arbitrary distinction. From a users perspective, its a bug in the application
#1433 has a similar use case for help templates and has a different proposed solution.
https://github.com/clap-rs/clap/issues/2389 might be the path to us exposing some formatting control.
Yet another way to solve this relatively painlessly is to allow calling before_help() and after_help() (and maybe about()) multiple times, each time possibly with a heading. The individual calls would be concatenated to create the final output.
My plan is for the API to accept ANSI colored strings. When we output, we use a special stdout/stderr that adapt the ANSI color codes to the capabilities of the terminal.
Blocked on https://github.com/epage/anstyle/issues/5