Skip to content

Commit 711e41e

Browse files
committed
remove off option, allow user to define termianl width
Signed-off-by: Luke-zhang-04 <[email protected]>
1 parent bce8f07 commit 711e41e

File tree

1 file changed

+21
-39
lines changed

1 file changed

+21
-39
lines changed

Diff for: src/onefetch/cli.rs

+21-39
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use {
77
language::Language,
88
},
99
clap::{crate_description, crate_name, crate_version, App, AppSettings, Arg},
10-
colored::Colorize,
1110
image::DynamicImage,
1211
std::{convert::From, env, str::FromStr},
1312
strum::IntoEnumIterator,
@@ -219,40 +218,33 @@ impl Cli {
219218
.takes_value(true)
220219
.help("Ignore all files & directories matching EXCLUDE."),
221220
)
222-
.arg(
223-
Arg::with_name("off")
224-
.long("off")
225-
.help("Only shows the info lines. DEPRECATED: use \"--hide-logo true\" instead.")
226-
.conflicts_with_all(&["image", "ascii-language", "ascii-input", "hide-logo"]),
227-
)
228221
.arg(
229222
Arg::with_name("hide-logo")
223+
.short("H")
230224
.long("hide-logo")
231-
.value_name("auto | true | false")
225+
.value_name("WIDTH_THRESHOLD")
232226
.takes_value(true)
233227
.max_values(1)
234-
.multiple(false)
235-
.possible_values(&["auto", "true", "false"])
236-
.help("Will hide the logo if true. If set to auto, the logo will be hidden if the terminal size is too small. If set to false, the logo will be shown no matter what.")
237-
.conflicts_with("off")
228+
.default_value("95")
229+
.help("If ASCII logo should be hidden when terminal width is below WIDTH_THRESHOLD.")
230+
.validator(
231+
|t| {
232+
t.parse::<u32>()
233+
.map_err(|_t| "must be a number")
234+
.map(|_t|())
235+
.map_err(|e| e.to_string())
236+
},
237+
)
238238
).get_matches();
239239

240240
let no_bold = matches.is_present("no-bold");
241241
let no_merges = matches.is_present("no-merge-commits");
242242
let no_color_palette = matches.is_present("no-color-palette");
243243
let print_languages = matches.is_present("languages");
244244
let print_package_managers = matches.is_present("package-managers");
245-
let mut art_off = matches.is_present("off");
245+
let mut art_off = false;
246246
let true_color = cli_utils::is_truecolor_terminal();
247-
let max_term_size = 95;
248-
249-
// The --off flag was passed in
250-
if art_off {
251-
std::println!(
252-
"{}",
253-
("The --off option is deprecated. Use \"--hide-logo true\" instead.").yellow(),
254-
);
255-
}
247+
let max_term_size: usize = matches.value_of("hide-logo").unwrap().parse().unwrap();
256248

257249
let fields_to_hide: Vec<String> = if let Some(values) = matches.values_of("disable-fields")
258250
{
@@ -277,23 +269,13 @@ impl Cli {
277269
None
278270
};
279271

280-
if let Some(should_hide_logo) = matches.value_of("hide-logo").or(Some("auto")) {
281-
if should_hide_logo == "true" {
282-
art_off = true;
283-
} else if should_hide_logo == "false" {
284-
art_off = false;
285-
} else if !art_off {
286-
if let Some((width, _)) = term_size::dimensions_stdout() {
287-
art_off = width <= max_term_size;
288-
} else {
289-
std::eprintln!(
290-
"{}",
291-
("Could not get terminal width. ASCII art will be displayed."),
292-
);
293-
294-
art_off = false;
295-
}
296-
}
272+
if let Some((width, _)) = term_size::dimensions_stdout() {
273+
art_off = width <= max_term_size && matches.is_present("hide-logo");
274+
} else {
275+
std::eprintln!(
276+
"{}",
277+
("Could not get terminal width. ASCII art will be displayed."),
278+
);
297279
}
298280

299281
if image.is_some() && image_backend.is_none() {

0 commit comments

Comments
 (0)