Skip to content

Commit b350945

Browse files
authored
Merge pull request #676 from blerchy/feat/no-emoji
Replace emojis when NO_EMOJI env variable present
2 parents 1ef368a + 01e7f27 commit b350945

File tree

3 files changed

+50
-13
lines changed

3 files changed

+50
-13
lines changed

src/exercise.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::env;
12
use regex::Regex;
23
use serde::Deserialize;
34
use std::fmt::{self, Display, Formatter};
@@ -126,8 +127,13 @@ name = "{}"
126127
path = "{}.rs""#,
127128
self.name, self.name, self.name
128129
);
130+
let cargo_toml_error_msg = if env::var("NO_EMOJI").is_ok() {
131+
"Failed to write Clippy Cargo.toml file."
132+
} else {
133+
"Failed to write 📎 Clippy 📎 Cargo.toml file."
134+
};
129135
fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml)
130-
.expect("Failed to write 📎 Clippy 📎 Cargo.toml file.");
136+
.expect(cargo_toml_error_msg);
131137
// To support the ability to run the clipy exercises, build
132138
// an executable, in addition to running clippy. With a
133139
// compilation failure, this would silently fail. But we expect

src/ui.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
11
macro_rules! warn {
22
($fmt:literal, $ex:expr) => {{
3+
use std::env;
34
use console::{style, Emoji};
45
let formatstr = format!($fmt, $ex);
5-
println!(
6-
"{} {}",
7-
style(Emoji("⚠️ ", "!")).red(),
8-
style(formatstr).red()
9-
);
6+
if env::var("NO_EMOJI").is_ok() {
7+
println!(
8+
"{} {}",
9+
style("!").red(),
10+
style(formatstr).red()
11+
);
12+
} else {
13+
println!(
14+
"{} {}",
15+
style(Emoji("⚠️ ", "!")).red(),
16+
style(formatstr).red()
17+
);
18+
}
1019
}};
1120
}
1221

1322
macro_rules! success {
1423
($fmt:literal, $ex:expr) => {{
24+
use std::env;
1525
use console::{style, Emoji};
1626
let formatstr = format!($fmt, $ex);
17-
println!(
18-
"{} {}",
19-
style(Emoji("✅", "✓")).green(),
20-
style(formatstr).green()
21-
);
27+
if env::var("NO_EMOJI").is_ok() {
28+
println!(
29+
"{} {}",
30+
style("✓").green(),
31+
style(formatstr).green()
32+
);
33+
} else {
34+
println!(
35+
"{} {}",
36+
style(Emoji("✅", "✓")).green(),
37+
style(formatstr).green()
38+
);
39+
}
2240
}};
2341
}

src/verify.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::env;
12
use crate::exercise::{CompiledExercise, Exercise, Mode, State};
23
use console::style;
34
use indicatif::ProgressBar;
@@ -137,14 +138,26 @@ fn prompt_for_completion(exercise: &Exercise, prompt_output: Option<String>) ->
137138
State::Pending(context) => context,
138139
};
139140

141+
let no_emoji = env::var("NO_EMOJI").is_ok();
142+
143+
let clippy_success_msg = if no_emoji {
144+
"The code is compiling, and Clippy is happy!"
145+
} else {
146+
"The code is compiling, and 📎 Clippy 📎 is happy!"
147+
};
148+
140149
let success_msg = match exercise.mode {
141150
Mode::Compile => "The code is compiling!",
142151
Mode::Test => "The code is compiling, and the tests pass!",
143-
Mode::Clippy => "The code is compiling, and 📎 Clippy 📎 is happy!",
152+
Mode::Clippy => clippy_success_msg,
144153
};
145154

146155
println!();
147-
println!("🎉 🎉 {} 🎉 🎉", success_msg);
156+
if no_emoji {
157+
println!("~*~ {} ~*~", success_msg)
158+
} else {
159+
println!("🎉 🎉 {} 🎉 🎉", success_msg)
160+
}
148161
println!();
149162

150163
if let Some(output) = prompt_output {

0 commit comments

Comments
 (0)