mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-25 23:04:17 -05:00
optimized the UI code (#1830)
This commit is contained in:
parent
c46a711526
commit
17ee0e3c7a
1 changed files with 13 additions and 18 deletions
31
src/ui.rs
31
src/ui.rs
|
@ -1,33 +1,28 @@
|
||||||
macro_rules! warn {
|
macro_rules! print_emoji {
|
||||||
($fmt:literal, $ex:expr) => {{
|
($emoji:expr, $sign:expr, $color: ident ,$fmt:literal, $ex:expr) => {{
|
||||||
use console::{style, Emoji};
|
use console::{style, Emoji};
|
||||||
use std::env;
|
use std::env;
|
||||||
let formatstr = format!($fmt, $ex);
|
let formatstr = format!($fmt, $ex);
|
||||||
if env::var("NO_EMOJI").is_ok() {
|
if env::var("NO_EMOJI").is_ok() {
|
||||||
println!("{} {}", style("!").red(), style(formatstr).red());
|
println!("{} {}", style($sign).$color(), style(formatstr).$color());
|
||||||
} else {
|
} else {
|
||||||
println!(
|
println!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
style(Emoji("⚠️ ", "!")).red(),
|
style(Emoji($emoji, $sign)).$color(),
|
||||||
style(formatstr).red()
|
style(formatstr).$color()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! success {
|
macro_rules! warn {
|
||||||
($fmt:literal, $ex:expr) => {{
|
($fmt:literal, $ex:expr) => {{
|
||||||
use console::{style, Emoji};
|
print_emoji!("⚠️ ", "!", red, $fmt, $ex);
|
||||||
use std::env;
|
}};
|
||||||
let formatstr = format!($fmt, $ex);
|
}
|
||||||
if env::var("NO_EMOJI").is_ok() {
|
|
||||||
println!("{} {}", style("✓").green(), style(formatstr).green());
|
macro_rules! success {
|
||||||
} else {
|
($fmt:literal, $ex:expr) => {{
|
||||||
println!(
|
print_emoji!("✅ ", "✓", green, $fmt, $ex);
|
||||||
"{} {}",
|
|
||||||
style(Emoji("✅", "✓")).green(),
|
|
||||||
style(formatstr).green()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue