Skip to content

Commit a4698dc

Browse files
authored
Merge pull request #330 from Luke-zhang-04/master
feat: hide logo if terminal size is too wide
2 parents 940c478 + 2979a77 commit a4698dc

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
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

+31-9
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ use {
1010
image::DynamicImage,
1111
std::{convert::From, env, str::FromStr},
1212
strum::IntoEnumIterator,
13+
term_size,
1314
};
1415

16+
const MAX_TERM_WIDTH: usize = 95;
17+
1518
pub struct Cli {
1619
pub repo_path: String,
1720
pub ascii_input: Option<String>,
@@ -94,7 +97,7 @@ impl Cli {
9497
.help("Takes a non-empty STRING as input to replace the ASCII logo.")
9598
.long_help(
9699
"Takes a non-empty STRING as input to replace the ASCII logo. \
97-
It is possible to pass a generated STRING by command substitution. \
100+
It is possible to pass a generated STRING by command substitution. \n\
98101
For example:\n \
99102
'--ascii-input \"$(fortune | cowsay -W 25)\"'"
100103
)
@@ -129,7 +132,7 @@ impl Cli {
129132
.help("Changes the text colors (X X X...).")
130133
.long_help(
131134
"Changes the text colors (X X X...). \
132-
Goes in order of title, ~, underline, subtitle, colon, and info. \
135+
Goes in order of title, ~, underline, subtitle, colon, and info. \n\
133136
For example:\n \
134137
'--text-colors 9 10 11 12 13 14'"
135138
)
@@ -218,19 +221,26 @@ impl Cli {
218221
.help("Ignore all files & directories matching EXCLUDE."),
219222
)
220223
.arg(
221-
Arg::with_name("off")
222-
.long("off")
223-
.help("Only shows the info lines.")
224-
.conflicts_with_all(&["image", "ascii-language", "ascii-input"]),
225-
).get_matches();
224+
Arg::with_name("hide-logo")
225+
.long("hide-logo")
226+
.value_name("WHEN")
227+
.takes_value(true)
228+
.possible_values(&["auto", "always"])
229+
.default_value("always")
230+
.hide_default_value(true)
231+
.help("Specify when to hide the logo (auto, *always*).")
232+
.long_help(
233+
"Specify when to hide the logo (auto, *always*). \n\
234+
If set to auto, the logo will be hidden if the terminal's width < 95."
235+
)
236+
).get_matches();
226237

238+
let true_color = cli_utils::is_truecolor_terminal();
227239
let no_bold = matches.is_present("no-bold");
228240
let no_merges = matches.is_present("no-merge-commits");
229241
let no_color_palette = matches.is_present("no-color-palette");
230242
let print_languages = matches.is_present("languages");
231243
let print_package_managers = matches.is_present("package-managers");
232-
let art_off = matches.is_present("off");
233-
let true_color = cli_utils::is_truecolor_terminal();
234244

235245
let fields_to_hide: Vec<String> = if let Some(values) = matches.values_of("disable-fields")
236246
{
@@ -239,6 +249,18 @@ impl Cli {
239249
Vec::new()
240250
};
241251

252+
let art_off = match matches.value_of("hide-logo") {
253+
Some("always") => true,
254+
Some("auto") => {
255+
if let Some((width, _)) = term_size::dimensions_stdout() {
256+
width < MAX_TERM_WIDTH
257+
} else {
258+
false
259+
}
260+
}
261+
_ => unreachable!("other values for --hide-logo are not allowed"),
262+
};
263+
242264
let image = if let Some(image_path) = matches.value_of("image") {
243265
Some(image::open(image_path).chain_err(|| "Could not load the specified image")?)
244266
} else {

0 commit comments

Comments
 (0)