From 3aa606cb268db38695a47989a774348807102aad Mon Sep 17 00:00:00 2001 From: Petr Gadorek Date: Tue, 16 Jul 2024 12:00:50 +0200 Subject: [PATCH 1/2] added colors to the help command --- Cargo.toml | 2 +- src/cli_args/mod.rs | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f457453..8a1befc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] tokio = {version = "1.37.0", features=["full"]} idf-im-lib = { git = "https://github.com/espressif/idf-im-lib.git", branch="master" } -clap = {version = "4.5", features = ["cargo", "derive"]} +clap = {version = "4.5", features = ["cargo", "derive", "color"]} crossterm = "0.27.0" dialoguer = { git = "https://github.com/Hahihula/dialoguer.git", branch = "folder-select", features = ["folder-select"] } byte-unit = "5.1.4" diff --git a/src/cli_args/mod.rs b/src/cli_args/mod.rs index ea171cd..ae5034a 100644 --- a/src/cli_args/mod.rs +++ b/src/cli_args/mod.rs @@ -1,5 +1,6 @@ -use clap::Parser; -use clap::{arg, ValueEnum}; +use clap::builder::styling::{AnsiColor, Color, Style, Styles}; +use clap::CommandFactory; +use clap::{arg, command, value_parser, ColorChoice, Parser, ValueEnum}; use config::{Config, ConfigError, File}; use log::{debug, error, info}; use serde::{Deserialize, Serialize}; @@ -28,12 +29,31 @@ pub struct Settings { pub idf_mirror: Option, } +fn custom_styles() -> Styles { + Styles::styled() + .header( + Style::new() + .bold() + .underline() + .fg_color(Some(Color::Ansi(AnsiColor::Yellow))), + ) + .usage( + Style::new() + .bold() + .fg_color(Some(Color::Ansi(AnsiColor::Green))), + ) + .literal(Style::new().fg_color(Some(Color::Ansi(AnsiColor::Magenta)))) + .placeholder(Style::new().fg_color(Some(Color::Ansi(AnsiColor::Red)))) +} + #[derive(Parser, Debug)] #[command( author, version = VERSION, about = "ESP-IDF Install Manager", - long_about = "All you need to manage your ESP-IDF installations" + long_about = "All you need to manage your ESP-IDF installations", + color = ColorChoice::Always, + styles = custom_styles() )] pub struct Cli { #[arg(short, long, value_name = "FILE")] From 362cbf779df856cf7337b333ee351f623f68e793 Mon Sep 17 00:00:00 2001 From: Petr Gadorek Date: Tue, 16 Jul 2024 13:24:21 +0200 Subject: [PATCH 2/2] changed the color palette --- src/cli_args/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cli_args/mod.rs b/src/cli_args/mod.rs index ae5034a..3608500 100644 --- a/src/cli_args/mod.rs +++ b/src/cli_args/mod.rs @@ -35,15 +35,15 @@ fn custom_styles() -> Styles { Style::new() .bold() .underline() - .fg_color(Some(Color::Ansi(AnsiColor::Yellow))), + .fg_color(Some(Color::Ansi(AnsiColor::Green))), ) .usage( Style::new() .bold() .fg_color(Some(Color::Ansi(AnsiColor::Green))), ) - .literal(Style::new().fg_color(Some(Color::Ansi(AnsiColor::Magenta)))) - .placeholder(Style::new().fg_color(Some(Color::Ansi(AnsiColor::Red)))) + .literal(Style::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan)))) + .placeholder(Style::new().fg_color(Some(Color::Ansi(AnsiColor::Blue)))) } #[derive(Parser, Debug)]