Skip to content

Commit

Permalink
fix --off flag after bad merge
Browse files Browse the repository at this point in the history
  • Loading branch information
o2sh committed Oct 23, 2020
1 parent 522514d commit c2883d1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 41 deletions.
10 changes: 5 additions & 5 deletions src/onefetch/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Cli {
Arg::with_name("languages")
.short("l")
.long("languages")
.help("Prints out supported languages"),
.help("Prints out supported languages."),
)
.arg(
Arg::with_name("image")
Expand All @@ -130,7 +130,7 @@ impl Cli {
.value_name("IMAGE")
.takes_value(true)
.max_values(1)
.help("Path to the IMAGE file"),
.help("Path to the IMAGE file."),
)
.arg(
Arg::with_name("image-backend")
Expand All @@ -144,12 +144,12 @@ impl Cli {
.arg(
Arg::with_name("no-merge-commits")
.long("no-merge-commits")
.help("Ignores merge commits"),
.help("Ignores merge commits."),
)
.arg(
Arg::with_name("no-color-blocks")
.long("no-color-blocks")
.help("Hides the color blocks"),
.help("Hides the color blocks."),
)
.arg(
Arg::with_name("authors-number")
Expand Down Expand Up @@ -181,7 +181,7 @@ impl Cli {
.arg(
Arg::with_name("off")
.long("off")
.help("Prevents the ASCII art or image from displaying")
.help("Only shows the info lines.")
.conflicts_with_all(&["image", "ascii-language", "ascii-input"]),
).get_matches();

Expand Down
73 changes: 37 additions & 36 deletions src/onefetch/cli_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,49 @@ impl<W: Write> Printer<W> {
let colors: Vec<Color> = Vec::new();
let mut buf = String::new();

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")
}
if self.info.config.art_off {
buf.push_str(&info_str);
} else 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)
} 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)
} else {
AsciiArt::new(
self.get_ascii(),
&self.info.colors,
!self.info.config.no_bold,
)
};
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 c2883d1

Please sign in to comment.