Skip to content

Commit 51a7a4b

Browse files
committed
auto, always, never options for hide-logo with always as default
1 parent c72dbbe commit 51a7a4b

File tree

1 file changed

+26
-44
lines changed

1 file changed

+26
-44
lines changed

src/onefetch/cli.rs

+26-44
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use {
1313
term_size,
1414
};
1515

16+
const MAX_TERM_WIDTH: usize = 95;
17+
1618
pub struct Cli {
1719
pub repo_path: String,
1820
pub ascii_input: Option<String>,
@@ -95,7 +97,7 @@ impl Cli {
9597
.help("Takes a non-empty STRING as input to replace the ASCII logo.")
9698
.long_help(
9799
"Takes a non-empty STRING as input to replace the ASCII logo. \
98-
It is possible to pass a generated STRING by command substitution. \
100+
It is possible to pass a generated STRING by command substitution. \n\
99101
For example:\n \
100102
'--ascii-input \"$(fortune | cowsay -W 25)\"'"
101103
)
@@ -130,7 +132,7 @@ impl Cli {
130132
.help("Changes the text colors (X X X...).")
131133
.long_help(
132134
"Changes the text colors (X X X...). \
133-
Goes in order of title, ~, underline, subtitle, colon, and info. \
135+
Goes in order of title, ~, underline, subtitle, colon, and info. \n\
134136
For example:\n \
135137
'--text-colors 9 10 11 12 13 14'"
136138
)
@@ -218,49 +220,27 @@ impl Cli {
218220
.takes_value(true)
219221
.help("Ignore all files & directories matching EXCLUDE."),
220222
)
221-
.arg(
222-
Arg::with_name("show-logo")
223-
.short("S")
224-
.long("show-logo")
225-
.takes_value(false)
226-
.help("If ASCII logo should be shown in all circumstances.")
227-
.conflicts_with("hide-logo")
228-
)
229223
.arg(
230224
Arg::with_name("hide-logo")
231-
.short("H")
232225
.long("hide-logo")
233-
.takes_value(false)
234-
.help("If ASCII logo should be hidden in all circumstances.")
235-
.conflicts_with("show-logo")
236-
)
237-
.arg(
238-
Arg::with_name("max-width")
239-
.short("w")
240-
.long("max-width")
241-
.value_name("AMOUNT")
226+
.value_name("WHEN")
242227
.takes_value(true)
243-
.max_values(1)
244-
.default_value("95")
245-
.help("If ASCII logo should be hidden when terminal width is below AMOUNT.")
246-
.validator(
247-
|t| {
248-
t.parse::<u32>()
249-
.map_err(|_t| "must be a number")
250-
.map(|_t|())
251-
.map_err(|e| e.to_string())
252-
},
228+
.possible_values(&["auto", "never", "always"])
229+
.default_value("always")
230+
.hide_default_value(true)
231+
.help("Specify when to hide the logo (auto, never, *always*).")
232+
.long_help(
233+
"Specify when to hide the logo (auto, never, *always*). \n\
234+
If set to auto, the logo will be hidden if the terminal's width < 95."
253235
)
254236
).get_matches();
255237

238+
let true_color = cli_utils::is_truecolor_terminal();
256239
let no_bold = matches.is_present("no-bold");
257240
let no_merges = matches.is_present("no-merge-commits");
258241
let no_color_palette = matches.is_present("no-color-palette");
259242
let print_languages = matches.is_present("languages");
260243
let print_package_managers = matches.is_present("package-managers");
261-
let mut art_off = matches.is_present("hide-logo") || !matches.is_present("show-logo");
262-
let true_color = cli_utils::is_truecolor_terminal();
263-
let max_term_size: usize = matches.value_of("max-width").unwrap().parse().unwrap();
264244

265245
let fields_to_hide: Vec<String> = if let Some(values) = matches.values_of("disable-fields")
266246
{
@@ -269,6 +249,19 @@ impl Cli {
269249
Vec::new()
270250
};
271251

252+
let art_off = match matches.value_of("hide-logo") {
253+
Some("always") => true,
254+
Some("never") => false,
255+
Some("auto") => {
256+
if let Some((width, _)) = term_size::dimensions_stdout() {
257+
width < MAX_TERM_WIDTH
258+
} else {
259+
false
260+
}
261+
}
262+
_ => unreachable!("other values for --hide-logo are not allowed"),
263+
};
264+
272265
let image = if let Some(image_path) = matches.value_of("image") {
273266
Some(image::open(image_path).chain_err(|| "Could not load the specified image")?)
274267
} else {
@@ -285,17 +278,6 @@ impl Cli {
285278
None
286279
};
287280

288-
if !matches.is_present("hide-logo") && !matches.is_present("show-logo") {
289-
if let Some((width, _)) = term_size::dimensions_stdout() {
290-
art_off = width <= max_term_size;
291-
} else {
292-
std::eprintln!(
293-
"{}",
294-
("Could not get terminal width. ASCII art will be displayed.")
295-
);
296-
}
297-
}
298-
299281
if image.is_some() && image_backend.is_none() {
300282
return Err("Could not detect a supported image backend".into());
301283
}

0 commit comments

Comments
 (0)