Skip to content

Commit ca4d157

Browse files
AlexendooSergioBenitez
authored andcommitted
Hide emoji on Windows.
Closes #1122.
1 parent a8b029e commit ca4d157

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

core/lib/src/fairing/fairings.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{Rocket, Request, Response, Data};
22
use crate::fairing::{Fairing, Kind};
3+
use crate::logger::PaintExt;
34

45
use yansi::Paint;
56

@@ -93,7 +94,7 @@ impl Fairings {
9394

9495
pub fn pretty_print_counts(&self) {
9596
if !self.all_fairings.is_empty() {
96-
info!("{}{}:", Paint::masked("📡 "), Paint::magenta("Fairings"));
97+
info!("{}{}:", Paint::emoji("📡 "), Paint::magenta("Fairings"));
9798
self.info_for("launch", &self.launch);
9899
self.info_for("request", &self.request);
99100
self.info_for("response", &self.response);

core/lib/src/logger.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,21 @@ pub(crate) fn pop_max_level() {
210210
}
211211
}
212212

213+
pub(crate) trait PaintExt {
214+
fn emoji(item: &str) -> Paint<&str>;
215+
}
216+
217+
impl PaintExt for Paint<&str> {
218+
/// Paint::masked(), but hidden on Windows due to broken output. See #1122.
219+
fn emoji(item: &str) -> Paint<&str> {
220+
if cfg!(windows) {
221+
Paint::masked("")
222+
} else {
223+
Paint::masked(item)
224+
}
225+
}
226+
}
227+
213228
#[doc(hidden)]
214229
pub fn init(level: LoggingLevel) -> bool {
215230
try_init(level, true)

core/lib/src/rocket.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::catcher::{self, Catcher};
2121
use crate::outcome::Outcome;
2222
use crate::error::{LaunchError, LaunchErrorKind};
2323
use crate::fairing::{Fairing, Fairings};
24+
use crate::logger::PaintExt;
2425

2526
use crate::http::{Method, Status, Header};
2627
use crate::http::hyper::{self, header};
@@ -403,7 +404,7 @@ impl Rocket {
403404
logger::push_max_level(logger::LoggingLevel::Normal);
404405
}
405406

406-
launch_info!("{}Configured for {}.", Paint::masked("🔧 "), config.environment);
407+
launch_info!("{}Configured for {}.", Paint::emoji("🔧 "), config.environment);
407408
launch_info_!("address: {}", Paint::default(&config.address).bold());
408409
launch_info_!("port: {}", Paint::default(&config.port).bold());
409410
launch_info_!("log: {}", Paint::default(config.log_level).bold());
@@ -503,7 +504,7 @@ impl Rocket {
503504
#[inline]
504505
pub fn mount<R: Into<Vec<Route>>>(mut self, base: &str, routes: R) -> Self {
505506
info!("{}{} {}{}",
506-
Paint::masked("🛰 "),
507+
Paint::emoji("🛰 "),
507508
Paint::magenta("Mounting"),
508509
Paint::blue(base),
509510
Paint::magenta(":"));
@@ -562,7 +563,7 @@ impl Rocket {
562563
/// ```
563564
#[inline]
564565
pub fn register(mut self, catchers: Vec<Catcher>) -> Self {
565-
info!("{}{}", Paint::masked("👾 "), Paint::magenta("Catchers:"));
566+
info!("{}{}", Paint::emoji("👾 "), Paint::magenta("Catchers:"));
566567
for c in catchers {
567568
if self.catchers.get(&c.code).map_or(false, |e| !e.is_default) {
568569
info_!("{} {}", c, Paint::yellow("(warning: duplicate catcher!)"));
@@ -721,7 +722,7 @@ impl Rocket {
721722

722723
let full_addr = format!("{}:{}", self.config.address, self.config.port);
723724
launch_info!("{}{} {}{}",
724-
Paint::masked("🚀 "),
725+
Paint::emoji("🚀 "),
725726
Paint::default("Rocket has launched from").bold(),
726727
Paint::default(proto).bold().underline(),
727728
Paint::default(&full_addr).bold().underline());

0 commit comments

Comments
 (0)