Skip to content

Commit 522514d

Browse files
authored
Merge pull request #288 from akrantz01/disable-ascii-art
Add CLI option to disable image
2 parents 0b37765 + 3bf51c5 commit 522514d

File tree

2 files changed

+46
-35
lines changed

2 files changed

+46
-35
lines changed

Diff for: src/onefetch/cli.rs

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub struct Cli {
2727
pub excluded: Vec<String>,
2828
pub print_languages: bool,
2929
pub true_color: bool,
30+
pub art_off: bool,
3031
}
3132

3233
impl Cli {
@@ -176,12 +177,19 @@ impl Cli {
176177
.multiple(true)
177178
.takes_value(true)
178179
.help("Ignore all files & directories matching EXCLUDE."),
180+
)
181+
.arg(
182+
Arg::with_name("off")
183+
.long("off")
184+
.help("Prevents the ASCII art or image from displaying")
185+
.conflicts_with_all(&["image", "ascii-language", "ascii-input"]),
179186
).get_matches();
180187

181188
let no_bold = matches.is_present("no-bold");
182189
let no_merges = matches.is_present("no-merge-commits");
183190
let no_color_blocks = matches.is_present("no-color-blocks");
184191
let print_languages = matches.is_present("languages");
192+
let art_off = matches.is_present("off");
185193
let true_color = cli_utils::is_truecolor_terminal();
186194

187195
let fields_to_hide: Vec<String> = if let Some(values) = matches.values_of("disable-fields")
@@ -252,6 +260,7 @@ impl Cli {
252260
excluded,
253261
print_languages,
254262
true_color,
263+
art_off,
255264
})
256265
}
257266
}

Diff for: src/onefetch/cli_utils.rs

+37-35
Original file line numberDiff line numberDiff line change
@@ -20,47 +20,49 @@ impl<W: Write> Printer<W> {
2020
let mut info_lines = info_str.lines();
2121
let colors: Vec<Color> = Vec::new();
2222
let mut buf = String::new();
23-
if let Some(custom_image) = &self.info.config.image {
24-
if let Some(image_backend) = &self.info.config.image_backend {
25-
buf.push_str(&image_backend.add_image(
26-
info_lines.map(|s| format!("{}{}", center_pad, s)).collect(),
27-
custom_image,
28-
));
29-
} else {
30-
panic!("No image backend found")
31-
}
32-
} else {
33-
let mut logo_lines = if let Some(custom_ascii) = &self.info.config.ascii_input {
34-
AsciiArt::new(custom_ascii, &colors, !self.info.config.no_bold)
23+
24+
if !self.info.config.art_off {
25+
if let Some(custom_image) = &self.info.config.image {
26+
if let Some(image_backend) = &self.info.config.image_backend {
27+
buf.push_str(&image_backend.add_image(
28+
info_lines.map(|s| format!("{}{}", center_pad, s)).collect(),
29+
custom_image,
30+
));
31+
} else {
32+
panic!("No image backend found")
33+
}
3534
} else {
36-
AsciiArt::new(
37-
self.get_ascii(),
38-
&self.info.colors,
39-
!self.info.config.no_bold,
40-
)
41-
};
35+
let mut logo_lines = if let Some(custom_ascii) = &self.info.config.ascii_input {
36+
AsciiArt::new(custom_ascii, &colors, !self.info.config.no_bold)
37+
} else {
38+
AsciiArt::new(
39+
self.get_ascii(),
40+
&self.info.colors,
41+
!self.info.config.no_bold,
42+
)
43+
};
4244

43-
loop {
44-
match (logo_lines.next(), info_lines.next()) {
45-
(Some(logo_line), Some(info_line)) => {
46-
buf.push_str(&format!("{}{}{:^}\n", logo_line, center_pad, info_line))
47-
}
48-
(Some(logo_line), None) => buf.push_str(&format!("{}\n", logo_line)),
49-
(None, Some(info_line)) => buf.push_str(&format!(
50-
"{:<width$}{}{:^}\n",
51-
"",
52-
center_pad,
53-
info_line,
54-
width = logo_lines.width()
55-
)),
56-
(None, None) => {
57-
buf.push('\n');
58-
break;
45+
loop {
46+
match (logo_lines.next(), info_lines.next()) {
47+
(Some(logo_line), Some(info_line)) => {
48+
buf.push_str(&format!("{}{}{:^}\n", logo_line, center_pad, info_line))
49+
}
50+
(Some(logo_line), None) => buf.push_str(&format!("{}\n", logo_line)),
51+
(None, Some(info_line)) => buf.push_str(&format!(
52+
"{:<width$}{}{:^}\n",
53+
"",
54+
center_pad,
55+
info_line,
56+
width = logo_lines.width()
57+
)),
58+
(None, None) => {
59+
buf.push('\n');
60+
break;
61+
}
5962
}
6063
}
6164
}
6265
}
63-
6466
writeln!(self.writer, "{}", buf)?;
6567

6668
Ok(())

0 commit comments

Comments
 (0)