Skip to content

Commit add14cf

Browse files
committed
feat: hide logo if terminal size is too wide
a new CLI option to configure whether the logo should be shown if configued to auto, Onefetch will detect the terminal size and hide/show the logo based off that. Signed-off-by: Luke-zhang-04 <[email protected]>
1 parent 72e3682 commit add14cf

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ askalono = "0.4.3"
2828
bytecount = "0.6.1"
2929
clap = "2.33.3"
3030
strum = { version = "0.20.0", features = ["derive"] }
31+
term_size = "0.3.2"
3132
image = "0.23.12"
3233
regex = "1"
3334
error-chain = "0.12"

src/onefetch/cli.rs

+46-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ use {
77
language::Language,
88
},
99
clap::{crate_description, crate_name, crate_version, App, AppSettings, Arg},
10+
colored::Colorize,
1011
image::DynamicImage,
1112
std::{convert::From, env, str::FromStr},
1213
strum::IntoEnumIterator,
14+
term_size,
1315
};
1416

1517
pub struct Cli {
@@ -220,17 +222,38 @@ impl Cli {
220222
.arg(
221223
Arg::with_name("off")
222224
.long("off")
223-
.help("Only shows the info lines.")
224-
.conflicts_with_all(&["image", "ascii-language", "ascii-input"]),
225-
).get_matches();
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+
)
228+
.arg(
229+
Arg::with_name("hide-logo")
230+
.long("hide-logo")
231+
.value_name("auto | true | false")
232+
.takes_value(true)
233+
.max_values(1)
234+
.multiple(false)
235+
.default_value("auto")
236+
.possible_values(&["auto", "true", "false"])
237+
.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.")
238+
.conflicts_with("off")
239+
).get_matches();
226240

227241
let no_bold = matches.is_present("no-bold");
228242
let no_merges = matches.is_present("no-merge-commits");
229243
let no_color_palette = matches.is_present("no-color-palette");
230244
let print_languages = matches.is_present("languages");
231245
let print_package_managers = matches.is_present("package-managers");
232-
let art_off = matches.is_present("off");
246+
let mut art_off = matches.is_present("off");
233247
let true_color = cli_utils::is_truecolor_terminal();
248+
let max_term_size = 95;
249+
250+
// The --off flag was passed in
251+
if art_off {
252+
std::println!(
253+
"{}",
254+
("The --off option is deprecated. Use \"--hide-logo true\" instead.").yellow(),
255+
);
256+
}
234257

235258
let fields_to_hide: Vec<String> = if let Some(values) = matches.values_of("disable-fields")
236259
{
@@ -255,6 +278,25 @@ impl Cli {
255278
None
256279
};
257280

281+
if let Some(should_hide_logo) = matches.value_of("hide-logo") {
282+
if should_hide_logo == "true" {
283+
art_off = true;
284+
} else if should_hide_logo == "false" {
285+
art_off = false;
286+
} else {
287+
if let Some((width, _)) = term_size::dimensions_stdout() {
288+
art_off = width <= max_term_size;
289+
} else {
290+
std::println!(
291+
"{}",
292+
("Coult not get terminal width. ASCII art will be displayed.").yellow(),
293+
);
294+
295+
art_off = false;
296+
}
297+
}
298+
}
299+
258300
if image.is_some() && image_backend.is_none() {
259301
return Err("Could not detect a supported image backend".into());
260302
}

0 commit comments

Comments
 (0)