Skip to content

Commit

Permalink
Merge pull request #330 from Luke-zhang-04/master
Browse files Browse the repository at this point in the history
feat: hide logo if terminal size is too wide
  • Loading branch information
o2sh authored Nov 29, 2020
2 parents 940c478 + 2979a77 commit a4698dc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ askalono = "0.4.3"
bytecount = "0.6.1"
clap = "2.33.3"
strum = { version = "0.20.0", features = ["derive"] }
term_size = "0.3.2"
image = "0.23.12"
regex = "1"
error-chain = "0.12"
Expand Down
40 changes: 31 additions & 9 deletions src/onefetch/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ use {
image::DynamicImage,
std::{convert::From, env, str::FromStr},
strum::IntoEnumIterator,
term_size,
};

const MAX_TERM_WIDTH: usize = 95;

pub struct Cli {
pub repo_path: String,
pub ascii_input: Option<String>,
Expand Down Expand Up @@ -94,7 +97,7 @@ impl Cli {
.help("Takes a non-empty STRING as input to replace the ASCII logo.")
.long_help(
"Takes a non-empty STRING as input to replace the ASCII logo. \
It is possible to pass a generated STRING by command substitution. \
It is possible to pass a generated STRING by command substitution. \n\
For example:\n \
'--ascii-input \"$(fortune | cowsay -W 25)\"'"
)
Expand Down Expand Up @@ -129,7 +132,7 @@ impl Cli {
.help("Changes the text colors (X X X...).")
.long_help(
"Changes the text colors (X X X...). \
Goes in order of title, ~, underline, subtitle, colon, and info. \
Goes in order of title, ~, underline, subtitle, colon, and info. \n\
For example:\n \
'--text-colors 9 10 11 12 13 14'"
)
Expand Down Expand Up @@ -218,19 +221,26 @@ impl Cli {
.help("Ignore all files & directories matching EXCLUDE."),
)
.arg(
Arg::with_name("off")
.long("off")
.help("Only shows the info lines.")
.conflicts_with_all(&["image", "ascii-language", "ascii-input"]),
).get_matches();
Arg::with_name("hide-logo")
.long("hide-logo")
.value_name("WHEN")
.takes_value(true)
.possible_values(&["auto", "always"])
.default_value("always")
.hide_default_value(true)
.help("Specify when to hide the logo (auto, *always*).")
.long_help(
"Specify when to hide the logo (auto, *always*). \n\
If set to auto, the logo will be hidden if the terminal's width < 95."
)
).get_matches();

let true_color = cli_utils::is_truecolor_terminal();
let no_bold = matches.is_present("no-bold");
let no_merges = matches.is_present("no-merge-commits");
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 art_off = matches.is_present("off");
let true_color = cli_utils::is_truecolor_terminal();

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

let art_off = match matches.value_of("hide-logo") {
Some("always") => true,
Some("auto") => {
if let Some((width, _)) = term_size::dimensions_stdout() {
width < MAX_TERM_WIDTH
} else {
false
}
}
_ => unreachable!("other values for --hide-logo are not allowed"),
};

let image = if let Some(image_path) = matches.value_of("image") {
Some(image::open(image_path).chain_err(|| "Could not load the specified image")?)
} else {
Expand Down

0 comments on commit a4698dc

Please sign in to comment.