clap icon indicating copy to clipboard operation
clap copied to clipboard

The header for my examples are not colored like the others

Open epage opened this issue 3 years ago • 6 comments

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

epage avatar Dec 09 '21 12:12 epage

What's the reason behind categorising this as bug? I would think this would be more of an enhancement, right?

pksunkara avatar Dec 09 '21 13:12 pksunkara

Sometimes, its an arbitrary distinction. From a users perspective, its a bug in the application

epage avatar Dec 09 '21 14:12 epage

#1433 has a similar use case for help templates and has a different proposed solution.

epage avatar Dec 09 '21 19:12 epage

https://github.com/clap-rs/clap/issues/2389 might be the path to us exposing some formatting control.

epage avatar Jan 20 '22 21:01 epage

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.

gaborcsardi avatar Jan 20 '22 21:01 gaborcsardi

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

epage avatar Aug 18 '22 13:08 epage