Skip to content

Commit 8d62a99

Browse files
committed
feat: Replace emojis when NO_EMOJI env variable present
1 parent 0d894e6 commit 8d62a99

File tree

3 files changed

+53
-13
lines changed

3 files changed

+53
-13
lines changed

src/exercise.rs

Lines changed: 6 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,12 @@ name = "{}"
126127
path = "{}.rs""#,
127128
self.name, self.name, self.name
128129
);
130+
let cargo_toml_error_msg = match env::var("NO_EMOJI").is_ok() {
131+
true => "Failed to write Clippy Cargo.toml file.",
132+
false => "Failed to write 📎 Clippy 📎 Cargo.toml file."
133+
};
129134
fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml)
130-
.expect("Failed to write 📎 Clippy 📎 Cargo.toml file.");
135+
.expect(cargo_toml_error_msg);
131136
// To support the ability to run the clipy exercises, build
132137
// an executable, in addition to running clippy. With a
133138
// compilation failure, this would silently fail. But we expect

src/ui.rs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,47 @@
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+
match env::var("NO_EMOJI").is_ok() {
7+
true => {
8+
println!(
9+
"{} {}",
10+
style("!").red(),
11+
style(formatstr).red()
12+
);
13+
},
14+
false => {
15+
println!(
16+
"{} {}",
17+
style(Emoji("⚠️ ", "!")).red(),
18+
style(formatstr).red()
19+
);
20+
}
21+
}
1022
}};
1123
}
1224

1325
macro_rules! success {
1426
($fmt:literal, $ex:expr) => {{
27+
use std::env;
1528
use console::{style, Emoji};
1629
let formatstr = format!($fmt, $ex);
17-
println!(
18-
"{} {}",
19-
style(Emoji("✅", "✓")).green(),
20-
style(formatstr).green()
21-
);
30+
match env::var("NO_EMOJI").is_ok() {
31+
true => {
32+
println!(
33+
"{} {}",
34+
style("✓").green(),
35+
style(formatstr).green()
36+
);
37+
},
38+
false => {
39+
println!(
40+
"{} {}",
41+
style(Emoji("✅", "✓")).green(),
42+
style(formatstr).green()
43+
);
44+
}
45+
}
2246
}};
2347
}

src/verify.rs

Lines changed: 13 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,24 @@ 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 = match no_emoji {
144+
true => "The code is compiling, and Clippy is happy!",
145+
false => "The code is compiling, and 📎 Clippy 📎 is happy!"
146+
};
147+
140148
let success_msg = match exercise.mode {
141149
Mode::Compile => "The code is compiling!",
142150
Mode::Test => "The code is compiling, and the tests pass!",
143-
Mode::Clippy => "The code is compiling, and 📎 Clippy 📎 is happy!",
151+
Mode::Clippy => clippy_success_msg,
144152
};
145153

146154
println!();
147-
println!("🎉 🎉 {} 🎉 🎉", success_msg);
155+
match no_emoji {
156+
true => println!("~*~ {} ~*~", success_msg),
157+
false => println!("🎉 🎉 {} 🎉 🎉", success_msg)
158+
};
148159
println!();
149160

150161
if let Some(output) = prompt_output {

0 commit comments

Comments
 (0)