Skip to content

Commit

Permalink
Modified CLI (See full commit msg for details)
Browse files Browse the repository at this point in the history
- --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 <luke.zhang2004dev@gmail.com>
  • Loading branch information
Luke-zhang-04 committed Nov 29, 2020
1 parent 5762b15 commit c72dbbe
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/onefetch/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u32>()
Expand All @@ -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<String> = if let Some(values) = matches.values_of("disable-fields")
{
Expand All @@ -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() {
Expand Down

0 comments on commit c72dbbe

Please sign in to comment.