From c72dbbe116d038cc455ba0c94df57f5ff95eeefb Mon Sep 17 00:00:00 2001 From: Luke-zhang-04 Date: Sun, 29 Nov 2020 00:04:23 -0500 Subject: [PATCH] Modified CLI (See full commit msg for details) - --hide-logo no longer takes an argument - new flags --hide-logo and --show-logo force logo display - new flag --max-width allows the user to set the max width (default 95) - passing no flags will automatically decide if the logo should be shown Signed-off-by: Luke-zhang-04 --- src/onefetch/cli.rs | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/onefetch/cli.rs b/src/onefetch/cli.rs index c04df64a6..c867a7474 100644 --- a/src/onefetch/cli.rs +++ b/src/onefetch/cli.rs @@ -218,15 +218,31 @@ impl Cli { .takes_value(true) .help("Ignore all files & directories matching EXCLUDE."), ) + .arg( + Arg::with_name("show-logo") + .short("S") + .long("show-logo") + .takes_value(false) + .help("If ASCII logo should be shown in all circumstances.") + .conflicts_with("hide-logo") + ) .arg( Arg::with_name("hide-logo") .short("H") .long("hide-logo") - .value_name("WIDTH_THRESHOLD") + .takes_value(false) + .help("If ASCII logo should be hidden in all circumstances.") + .conflicts_with("show-logo") + ) + .arg( + Arg::with_name("max-width") + .short("w") + .long("max-width") + .value_name("AMOUNT") .takes_value(true) .max_values(1) .default_value("95") - .help("If ASCII logo should be hidden when terminal width is below WIDTH_THRESHOLD.") + .help("If ASCII logo should be hidden when terminal width is below AMOUNT.") .validator( |t| { t.parse::() @@ -242,9 +258,9 @@ impl Cli { let no_color_palette = matches.is_present("no-color-palette"); let print_languages = matches.is_present("languages"); let print_package_managers = matches.is_present("package-managers"); - let mut art_off = false; + let mut art_off = matches.is_present("hide-logo") || !matches.is_present("show-logo"); let true_color = cli_utils::is_truecolor_terminal(); - let max_term_size: usize = matches.value_of("hide-logo").unwrap().parse().unwrap(); + let max_term_size: usize = matches.value_of("max-width").unwrap().parse().unwrap(); let fields_to_hide: Vec = if let Some(values) = matches.values_of("disable-fields") { @@ -269,10 +285,15 @@ impl Cli { None }; - if let Some((width, _)) = term_size::dimensions_stdout() { - art_off = width <= max_term_size && matches.is_present("hide-logo"); - } else { - std::eprintln!("{}", ("Could not get terminal width. ASCII art will be displayed.")); + if !matches.is_present("hide-logo") && !matches.is_present("show-logo") { + if let Some((width, _)) = term_size::dimensions_stdout() { + art_off = width <= max_term_size; + } else { + std::eprintln!( + "{}", + ("Could not get terminal width. ASCII art will be displayed.") + ); + } } if image.is_some() && image_backend.is_none() {