Skip to content

Conversation

@starsep
Copy link
Contributor

@starsep starsep commented Nov 23, 2025

I used clap-cargo as it's easy to use and provides sensible default styles.
User can disable colors via NO_COLOR=1 environment variable

Output of onefetch -h:

before after NO_COLOR=1
onefetch-before onefetch-colors onefetch-no-color

Copy link
Owner

@o2sh o2sh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better with colors, thanks @starsep 🎉

@o2sh o2sh merged commit 87d4d5a into o2sh:main Nov 23, 2025
4 checks passed
@starsep starsep deleted the colorful-help branch November 23, 2025 12:26
@Sk7Str1p3
Copy link
Contributor

I think this could be done without adding one more dependency. Also, most likely it's incompatible with #1632

@spenserblack
Copy link
Collaborator

I think this could be done without adding one more dependency.

Yeah, looks like the value's type comes from clap-builder. https://docs.rs/clap-cargo/latest/clap_cargo/style/constant.CLAP_STYLING.html

So we could probably define our own if we wanted.

@starsep
Copy link
Contributor Author

starsep commented Nov 23, 2025

I don't know whether it's compatible with i18n PR.


Yes, it's possible to do without dependency.
Similar effect can be done with

use clap::builder::styling::{AnsiColor, Effects};
use clap::builder::Styles;

// ...

const STYLES: Styles = Styles::styled()
    .header(AnsiColor::Green.on_default().effects(Effects::BOLD))
    .usage(AnsiColor::Green.on_default().effects(Effects::BOLD))
    .literal(AnsiColor::Cyan.on_default().effects(Effects::BOLD))
    .placeholder(AnsiColor::Cyan.on_default());

// ...
#[command(styles = STYLES)]
pub struct CliOptions {

I can prepare PR if you prefer this approach.

@o2sh
Copy link
Owner

o2sh commented Nov 23, 2025

Indeed, for something that simple, using a dependency isn't very useful.

BTW, we could probably use the same styling as clap https://docs.rs/clap/latest/clap/builder/struct.Styles.html#example

/// Terminal styling definitions
///
/// See also [`Command::styles`][crate::Command::styles].
///
/// # Example
///
/// clap v3 styling
/// ```rust
/// # use clap_builder as clap;
/// # use clap::builder::styling::*;
/// let styles = Styles::styled()
///     .header(AnsiColor::Yellow.on_default())
///     .usage(AnsiColor::Green.on_default())
///     .literal(AnsiColor::Green.on_default())
///     .placeholder(AnsiColor::Green.on_default());
/// ```

@starsep
Copy link
Contributor Author

starsep commented Nov 23, 2025

I used above style in #1634

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants