Skip to content

Commit

Permalink
Merge pull request #288 from akrantz01/disable-ascii-art
Browse files Browse the repository at this point in the history
Add CLI option to disable image
  • Loading branch information
o2sh authored Oct 23, 2020
2 parents 0b37765 + 3bf51c5 commit 522514d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 35 deletions.
9 changes: 9 additions & 0 deletions src/onefetch/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct Cli {
pub excluded: Vec<String>,
pub print_languages: bool,
pub true_color: bool,
pub art_off: bool,
}

impl Cli {
Expand Down Expand Up @@ -176,12 +177,19 @@ impl Cli {
.multiple(true)
.takes_value(true)
.help("Ignore all files & directories matching EXCLUDE."),
)
.arg(
Arg::with_name("off")
.long("off")
.help("Prevents the ASCII art or image from displaying")
.conflicts_with_all(&["image", "ascii-language", "ascii-input"]),
).get_matches();

let no_bold = matches.is_present("no-bold");
let no_merges = matches.is_present("no-merge-commits");
let no_color_blocks = matches.is_present("no-color-blocks");
let print_languages = matches.is_present("languages");
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 Down Expand Up @@ -252,6 +260,7 @@ impl Cli {
excluded,
print_languages,
true_color,
art_off,
})
}
}
72 changes: 37 additions & 35 deletions src/onefetch/cli_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,49 @@ impl<W: Write> Printer<W> {
let mut info_lines = info_str.lines();
let colors: Vec<Color> = Vec::new();
let mut buf = String::new();
if let Some(custom_image) = &self.info.config.image {
if let Some(image_backend) = &self.info.config.image_backend {
buf.push_str(&image_backend.add_image(
info_lines.map(|s| format!("{}{}", center_pad, s)).collect(),
custom_image,
));
} else {
panic!("No image backend found")
}
} else {
let mut logo_lines = if let Some(custom_ascii) = &self.info.config.ascii_input {
AsciiArt::new(custom_ascii, &colors, !self.info.config.no_bold)

if !self.info.config.art_off {
if let Some(custom_image) = &self.info.config.image {
if let Some(image_backend) = &self.info.config.image_backend {
buf.push_str(&image_backend.add_image(
info_lines.map(|s| format!("{}{}", center_pad, s)).collect(),
custom_image,
));
} else {
panic!("No image backend found")
}
} else {
AsciiArt::new(
self.get_ascii(),
&self.info.colors,
!self.info.config.no_bold,
)
};
let mut logo_lines = if let Some(custom_ascii) = &self.info.config.ascii_input {
AsciiArt::new(custom_ascii, &colors, !self.info.config.no_bold)
} else {
AsciiArt::new(
self.get_ascii(),
&self.info.colors,
!self.info.config.no_bold,
)
};

loop {
match (logo_lines.next(), info_lines.next()) {
(Some(logo_line), Some(info_line)) => {
buf.push_str(&format!("{}{}{:^}\n", logo_line, center_pad, info_line))
}
(Some(logo_line), None) => buf.push_str(&format!("{}\n", logo_line)),
(None, Some(info_line)) => buf.push_str(&format!(
"{:<width$}{}{:^}\n",
"",
center_pad,
info_line,
width = logo_lines.width()
)),
(None, None) => {
buf.push('\n');
break;
loop {
match (logo_lines.next(), info_lines.next()) {
(Some(logo_line), Some(info_line)) => {
buf.push_str(&format!("{}{}{:^}\n", logo_line, center_pad, info_line))
}
(Some(logo_line), None) => buf.push_str(&format!("{}\n", logo_line)),
(None, Some(info_line)) => buf.push_str(&format!(
"{:<width$}{}{:^}\n",
"",
center_pad,
info_line,
width = logo_lines.width()
)),
(None, None) => {
buf.push('\n');
break;
}
}
}
}
}

writeln!(self.writer, "{}", buf)?;

Ok(())
Expand Down

0 comments on commit 522514d

Please sign in to comment.