Skip to content

Commit

Permalink
feat: Replace emojis when NO_EMOJI env variable present
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-lebl committed Mar 19, 2021
1 parent 0d894e6 commit 8d62a99
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
7 changes: 6 additions & 1 deletion src/exercise.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use regex::Regex;
use serde::Deserialize;
use std::fmt::{self, Display, Formatter};
Expand Down Expand Up @@ -126,8 +127,12 @@ name = "{}"
path = "{}.rs""#,
self.name, self.name, self.name
);
let cargo_toml_error_msg = match env::var("NO_EMOJI").is_ok() {
true => "Failed to write Clippy Cargo.toml file.",
false => "Failed to write 📎 Clippy 📎 Cargo.toml file."
};
fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml)
.expect("Failed to write 📎 Clippy 📎 Cargo.toml file.");
.expect(cargo_toml_error_msg);
// To support the ability to run the clipy exercises, build
// an executable, in addition to running clippy. With a
// compilation failure, this would silently fail. But we expect
Expand Down
44 changes: 34 additions & 10 deletions src/ui.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
macro_rules! warn {
($fmt:literal, $ex:expr) => {{
use std::env;
use console::{style, Emoji};
let formatstr = format!($fmt, $ex);
println!(
"{} {}",
style(Emoji("⚠️ ", "!")).red(),
style(formatstr).red()
);
match env::var("NO_EMOJI").is_ok() {
true => {
println!(
"{} {}",
style("!").red(),
style(formatstr).red()
);
},
false => {
println!(
"{} {}",
style(Emoji("⚠️ ", "!")).red(),
style(formatstr).red()
);
}
}
}};
}

macro_rules! success {
($fmt:literal, $ex:expr) => {{
use std::env;
use console::{style, Emoji};
let formatstr = format!($fmt, $ex);
println!(
"{} {}",
style(Emoji("✅", "✓")).green(),
style(formatstr).green()
);
match env::var("NO_EMOJI").is_ok() {
true => {
println!(
"{} {}",
style("✓").green(),
style(formatstr).green()
);
},
false => {
println!(
"{} {}",
style(Emoji("✅", "✓")).green(),
style(formatstr).green()
);
}
}
}};
}
15 changes: 13 additions & 2 deletions src/verify.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use crate::exercise::{CompiledExercise, Exercise, Mode, State};
use console::style;
use indicatif::ProgressBar;
Expand Down Expand Up @@ -137,14 +138,24 @@ fn prompt_for_completion(exercise: &Exercise, prompt_output: Option<String>) ->
State::Pending(context) => context,
};

let no_emoji = env::var("NO_EMOJI").is_ok();

let clippy_success_msg = match no_emoji {
true => "The code is compiling, and Clippy is happy!",
false => "The code is compiling, and 📎 Clippy 📎 is happy!"
};

let success_msg = match exercise.mode {
Mode::Compile => "The code is compiling!",
Mode::Test => "The code is compiling, and the tests pass!",
Mode::Clippy => "The code is compiling, and 📎 Clippy 📎 is happy!",
Mode::Clippy => clippy_success_msg,
};

println!();
println!("🎉 🎉 {} 🎉 🎉", success_msg);
match no_emoji {
true => println!("~*~ {} ~*~", success_msg),
false => println!("🎉 🎉 {} 🎉 🎉", success_msg)
};
println!();

if let Some(output) = prompt_output {
Expand Down

0 comments on commit 8d62a99

Please sign in to comment.