mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-22 22:02:22 -05:00
Merge pull request #676 from blerchy/feat/no-emoji
Replace emojis when NO_EMOJI env variable present
This commit is contained in:
commit
b350945a16
3 changed files with 50 additions and 13 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
use std::env;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::fmt::{self, Display, Formatter};
|
use std::fmt::{self, Display, Formatter};
|
||||||
|
@ -126,8 +127,13 @@ name = "{}"
|
||||||
path = "{}.rs""#,
|
path = "{}.rs""#,
|
||||||
self.name, self.name, self.name
|
self.name, self.name, self.name
|
||||||
);
|
);
|
||||||
|
let cargo_toml_error_msg = if env::var("NO_EMOJI").is_ok() {
|
||||||
|
"Failed to write Clippy Cargo.toml file."
|
||||||
|
} else {
|
||||||
|
"Failed to write 📎 Clippy 📎 Cargo.toml file."
|
||||||
|
};
|
||||||
fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml)
|
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
|
// To support the ability to run the clipy exercises, build
|
||||||
// an executable, in addition to running clippy. With a
|
// an executable, in addition to running clippy. With a
|
||||||
// compilation failure, this would silently fail. But we expect
|
// compilation failure, this would silently fail. But we expect
|
||||||
|
|
38
src/ui.rs
38
src/ui.rs
|
@ -1,23 +1,41 @@
|
||||||
macro_rules! warn {
|
macro_rules! warn {
|
||||||
($fmt:literal, $ex:expr) => {{
|
($fmt:literal, $ex:expr) => {{
|
||||||
|
use std::env;
|
||||||
use console::{style, Emoji};
|
use console::{style, Emoji};
|
||||||
let formatstr = format!($fmt, $ex);
|
let formatstr = format!($fmt, $ex);
|
||||||
println!(
|
if env::var("NO_EMOJI").is_ok() {
|
||||||
"{} {}",
|
println!(
|
||||||
style(Emoji("⚠️ ", "!")).red(),
|
"{} {}",
|
||||||
style(formatstr).red()
|
style("!").red(),
|
||||||
);
|
style(formatstr).red()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
println!(
|
||||||
|
"{} {}",
|
||||||
|
style(Emoji("⚠️ ", "!")).red(),
|
||||||
|
style(formatstr).red()
|
||||||
|
);
|
||||||
|
}
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! success {
|
macro_rules! success {
|
||||||
($fmt:literal, $ex:expr) => {{
|
($fmt:literal, $ex:expr) => {{
|
||||||
|
use std::env;
|
||||||
use console::{style, Emoji};
|
use console::{style, Emoji};
|
||||||
let formatstr = format!($fmt, $ex);
|
let formatstr = format!($fmt, $ex);
|
||||||
println!(
|
if env::var("NO_EMOJI").is_ok() {
|
||||||
"{} {}",
|
println!(
|
||||||
style(Emoji("✅", "✓")).green(),
|
"{} {}",
|
||||||
style(formatstr).green()
|
style("✓").green(),
|
||||||
);
|
style(formatstr).green()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
println!(
|
||||||
|
"{} {}",
|
||||||
|
style(Emoji("✅", "✓")).green(),
|
||||||
|
style(formatstr).green()
|
||||||
|
);
|
||||||
|
}
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::env;
|
||||||
use crate::exercise::{CompiledExercise, Exercise, Mode, State};
|
use crate::exercise::{CompiledExercise, Exercise, Mode, State};
|
||||||
use console::style;
|
use console::style;
|
||||||
use indicatif::ProgressBar;
|
use indicatif::ProgressBar;
|
||||||
|
@ -137,14 +138,26 @@ fn prompt_for_completion(exercise: &Exercise, prompt_output: Option<String>) ->
|
||||||
State::Pending(context) => context,
|
State::Pending(context) => context,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let no_emoji = env::var("NO_EMOJI").is_ok();
|
||||||
|
|
||||||
|
let clippy_success_msg = if no_emoji {
|
||||||
|
"The code is compiling, and Clippy is happy!"
|
||||||
|
} else {
|
||||||
|
"The code is compiling, and 📎 Clippy 📎 is happy!"
|
||||||
|
};
|
||||||
|
|
||||||
let success_msg = match exercise.mode {
|
let success_msg = match exercise.mode {
|
||||||
Mode::Compile => "The code is compiling!",
|
Mode::Compile => "The code is compiling!",
|
||||||
Mode::Test => "The code is compiling, and the tests pass!",
|
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!();
|
||||||
println!("🎉 🎉 {} 🎉 🎉", success_msg);
|
if no_emoji {
|
||||||
|
println!("~*~ {} ~*~", success_msg)
|
||||||
|
} else {
|
||||||
|
println!("🎉 🎉 {} 🎉 🎉", success_msg)
|
||||||
|
}
|
||||||
println!();
|
println!();
|
||||||
|
|
||||||
if let Some(output) = prompt_output {
|
if let Some(output) = prompt_output {
|
||||||
|
|
Loading…
Reference in a new issue