diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index 3841b854..6d5e32d8 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -22,5 +22,5 @@ log = "^0.3" compiletest_rs = "^0.2" [build-dependencies] -ansi_term = "0.9" +yansi = "0.2" version_check = "0.1" diff --git a/codegen/build.rs b/codegen/build.rs index 6adc6416..3c7f2572 100644 --- a/codegen/build.rs +++ b/codegen/build.rs @@ -1,10 +1,10 @@ //! This tiny build script ensures that rocket_codegen is not compiled with an //! incompatible version of rust. -extern crate ansi_term; +extern crate yansi; extern crate version_check; -use ansi_term::Color::{Red, Yellow, Blue, White}; +use yansi::Color::{Red, Yellow, Blue, White}; use version_check::{is_nightly, is_min_version, is_min_date}; // Specifies the minimum nightly version needed to compile Rocket's codegen. @@ -37,7 +37,7 @@ fn main() { (Some(is_nightly), Some((ok_version, version)), Some((ok_date, date))) => { if !is_nightly { printerr!("{} {}", - Red.bold().paint("Error:"), + Red.paint("Error:").bold(), White.paint("Rocket requires a nightly version of Rust.")); print_version_err(&*version, &*date); printerr!("{}{}{}", @@ -49,7 +49,7 @@ fn main() { if !ok_version || !ok_date { printerr!("{} {}", - Red.bold().paint("Error:"), + Red.paint("Error:").bold(), White.paint("Rocket codegen requires a more recent version of rustc.")); printerr!("{}{}{}", Blue.paint("Use `"), diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 71db0670..9c7b4226 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -18,7 +18,7 @@ categories = ["web-programming::http-server"] tls = ["rustls", "hyper-rustls"] [dependencies] -term-painter = "0.2" +yansi = "0.2" log = "0.3" url = "1" toml = { version = "0.2", default-features = false } @@ -47,5 +47,5 @@ lazy_static = "0.2" rocket_codegen = { version = "0.2.8", path = "../codegen" } [build-dependencies] -ansi_term = "0.9" +yansi = "0.2" version_check = "^0.1" diff --git a/lib/build.rs b/lib/build.rs index 69125818..6768de95 100644 --- a/lib/build.rs +++ b/lib/build.rs @@ -1,10 +1,10 @@ //! This tiny build script ensures that rocket is not compiled with an //! incompatible version of rust. -extern crate ansi_term; +extern crate yansi; extern crate version_check; -use ansi_term::Color::{Red, Yellow, Blue, White}; +use yansi::Color::{Red, Yellow, Blue, White}; use version_check::{is_nightly, is_min_version}; // Specifies the minimum nightly version needed to compile Rocket. @@ -32,7 +32,7 @@ fn main() { if let (Some(is_nightly), Some((ok_version, version))) = (ok_nightly, ok_version) { if !is_nightly { printerr!("{} {}", - Red.bold().paint("Error:"), + Red.paint("Error:").bold(), White.paint("Rocket requires a nightly version of Rust.")); print_version_err(&*version); printerr!("{}{}{}", @@ -44,7 +44,7 @@ fn main() { if !ok_version { printerr!("{} {}", - Red.bold().paint("Error:"), + Red.paint("Error:").bold(), White.paint("Rocket requires a newer version of rustc.")); printerr!("{}{}{}", Blue.paint("Use `"), diff --git a/lib/src/catcher.rs b/lib/src/catcher.rs index 7184ef6b..fd53315c 100644 --- a/lib/src/catcher.rs +++ b/lib/src/catcher.rs @@ -5,8 +5,7 @@ use error::Error; use request::Request; use std::fmt; -use term_painter::ToStyle; -use term_painter::Color::*; +use yansi::Color::*; /// An error catching route. /// diff --git a/lib/src/config/error.rs b/lib/src/config/error.rs index 01179d2f..6ca2c6b8 100644 --- a/lib/src/config/error.rs +++ b/lib/src/config/error.rs @@ -5,8 +5,7 @@ use std::fmt; use super::Environment; use self::ConfigError::*; -use term_painter::Color::White; -use term_painter::ToStyle; +use yansi::Color::White; /// The type of a configuration parsing error. #[derive(Debug, PartialEq, Clone)] diff --git a/lib/src/fairing/fairings.rs b/lib/src/fairing/fairings.rs index ca16cfa4..0aeee959 100644 --- a/lib/src/fairing/fairings.rs +++ b/lib/src/fairing/fairings.rs @@ -82,8 +82,7 @@ impl Fairings { } pub fn pretty_print_counts(&self) { - use term_painter::ToStyle; - use term_painter::Color::{White, Magenta}; + use yansi::Paint; if self.all_fairings.is_empty() { return @@ -92,12 +91,12 @@ impl Fairings { fn info_if_nonempty(kind: &str, fairings: &[&Fairing]) { let names: Vec<&str> = fairings.iter().map(|f| f.info().name).collect(); info_!("{} {}: {}", - White.paint(fairings.len()), + Paint::white(fairings.len()), kind, - White.paint(names.join(", "))); + Paint::white(names.join(", "))); } - info!("📡 {}:", Magenta.paint("Fairings")); + info!("📡 {}:", Paint::purple("Fairings")); info_if_nonempty("launch", &self.launch); info_if_nonempty("request", &self.request); info_if_nonempty("response", &self.response); diff --git a/lib/src/lib.rs b/lib/src/lib.rs index e07e453d..c14b5707 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -101,7 +101,7 @@ #[macro_use] extern crate pear; #[cfg(feature = "tls")] extern crate rustls; #[cfg(feature = "tls")] extern crate hyper_rustls; -extern crate term_painter; +extern crate yansi; extern crate hyper; extern crate url; extern crate toml; diff --git a/lib/src/logger.rs b/lib/src/logger.rs index 60fc8eb0..8e6d88ff 100644 --- a/lib/src/logger.rs +++ b/lib/src/logger.rs @@ -4,8 +4,7 @@ use std::str::FromStr; use std::fmt; use log::{self, Log, LogLevel, LogRecord, LogMetadata}; -use term_painter::Color::*; -use term_painter::ToStyle; +use yansi::Color::*; struct RocketLogger(LoggingLevel); @@ -119,20 +118,20 @@ impl Log for RocketLogger { use log::LogLevel::*; match level { Info => println!("{}", Blue.paint(record.args())), - Trace => println!("{}", Magenta.paint(record.args())), + Trace => println!("{}", Purple.paint(record.args())), Error => { println!("{} {}", - Red.bold().paint("Error:"), + Red.paint("Error:").bold(), Red.paint(record.args())) } Warn => { println!("{} {}", - Yellow.bold().paint("Warning:"), + Yellow.paint("Warning:").bold(), Yellow.paint(record.args())) } Debug => { let loc = record.location(); - print!("\n{} ", Blue.bold().paint("-->")); + print!("\n{} ", Blue.paint("-->").bold()); println!("{}:{}", Blue.paint(loc.file()), Blue.paint(loc.line())); println!("{}", record.args()); } diff --git a/lib/src/outcome.rs b/lib/src/outcome.rs index b9dc5415..204174ab 100644 --- a/lib/src/outcome.rs +++ b/lib/src/outcome.rs @@ -81,9 +81,7 @@ use std::fmt; -use term_painter::Color::*; -use term_painter::Color; -use term_painter::ToStyle; +use yansi::{Paint, Color}; use self::Outcome::*; @@ -422,9 +420,9 @@ impl Outcome { #[inline] fn formatting(&self) -> (Color, &'static str) { match *self { - Success(..) => (Green, "Success"), - Failure(..) => (Red, "Failure"), - Forward(..) => (Yellow, "Forward"), + Success(..) => (Color::Green, "Success"), + Failure(..) => (Color::Red, "Failure"), + Forward(..) => (Color::Yellow, "Forward"), } } } @@ -438,6 +436,6 @@ impl fmt::Debug for Outcome { impl fmt::Display for Outcome { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let (color, string) = self.formatting(); - write!(f, "{}", color.paint(string)) + write!(f, "{}", Paint::new(string).fg(color)) } } diff --git a/lib/src/request/request.rs b/lib/src/request/request.rs index b6513c96..355cddbd 100644 --- a/lib/src/request/request.rs +++ b/lib/src/request/request.rs @@ -3,8 +3,7 @@ use std::net::SocketAddr; use std::fmt; use std::str; -use term_painter::Color::*; -use term_painter::ToStyle; +use yansi::Paint; use state::{Container, Storage}; @@ -580,10 +579,10 @@ impl<'r> fmt::Display for Request<'r> { /// Pretty prints a Request. This is primarily used by Rocket's logging /// infrastructure. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{} {}", Green.paint(&self.method), Blue.paint(&self.uri))?; + write!(f, "{} {}", Paint::green(&self.method), Paint::blue(&self.uri))?; if let Some(content_type) = self.content_type() { if self.method.supports_payload() { - write!(f, " {}", Yellow.paint(content_type))?; + write!(f, " {}", Paint::yellow(content_type))?; } } diff --git a/lib/src/rocket.rs b/lib/src/rocket.rs index bace2744..9de347a8 100644 --- a/lib/src/rocket.rs +++ b/lib/src/rocket.rs @@ -5,8 +5,7 @@ use std::net::SocketAddr; use std::io::{self, Write}; use std::mem; -use term_painter::Color::*; -use term_painter::ToStyle; +use yansi::Paint; use state::Container; #[cfg(feature = "tls")] use hyper_rustls::TlsServer; @@ -111,7 +110,7 @@ impl Rocket { #[inline] fn issue_response(&self, response: Response, hyp_res: hyper::FreshResponse) { match self.write_response(response, hyp_res) { - Ok(_) => info_!("{}", Green.paint("Response succeeded.")), + Ok(_) => info_!("{}", Paint::green("Response succeeded.")), Err(e) => error_!("Failed to write response: {:?}.", e) } } @@ -251,7 +250,7 @@ impl Rocket { // There was no matching route. if request.method() == Method::Head { - info_!("Autohandling {} request.", White.paint("HEAD")); + info_!("Autohandling {} request.", Paint::white("HEAD")); request.set_method(Method::Get); let mut response = self.dispatch(request, data); response.strip_body(); @@ -298,7 +297,7 @@ impl Rocket { // Check if the request processing completed or if the request needs // to be forwarded. If it does, continue the loop to try again. - info_!("{} {}", White.paint("Outcome:"), outcome); + info_!("{} {}", Paint::white("Outcome:"), outcome); match outcome { o@Outcome::Success(_) | o @Outcome::Failure(_) => return o, Outcome::Forward(unused_data) => data = unused_data, @@ -315,7 +314,7 @@ impl Rocket { // 500 catcher is executed. if there is no registered catcher for `status`, // the default catcher is used. fn handle_error<'r>(&self, status: Status, req: &'r Request) -> Response<'r> { - warn_!("Responding with {} catcher.", Red.paint(&status)); + warn_!("Responding with {} catcher.", Paint::red(&status)); // Try to get the active catcher but fallback to user's 500 catcher. let catcher = self.catchers.get(&status.code).unwrap_or_else(|| { @@ -396,28 +395,28 @@ impl Rocket { } info!("🔧 Configured for {}.", config.environment); - info_!("address: {}", White.paint(&config.address)); - info_!("port: {}", White.paint(&config.port)); - info_!("log: {}", White.paint(config.log_level)); - info_!("workers: {}", White.paint(config.workers)); - info_!("secret key: {}", White.paint(config.secret_key.kind())); - info_!("limits: {}", White.paint(&config.limits)); + info_!("address: {}", Paint::white(&config.address)); + info_!("port: {}", Paint::white(&config.port)); + info_!("log: {}", Paint::white(config.log_level)); + info_!("workers: {}", Paint::white(config.workers)); + info_!("secret key: {}", Paint::white(config.secret_key.kind())); + info_!("limits: {}", Paint::white(&config.limits)); let tls_configured = config.tls.is_some(); if tls_configured && cfg!(feature = "tls") { - info_!("tls: {}", White.paint("enabled")); + info_!("tls: {}", Paint::white("enabled")); } else { if tls_configured { - error_!("tls: {}", White.paint("disabled")); + error_!("tls: {}", Paint::white("disabled")); error_!("tls is configured, but the tls feature is disabled"); } else { - info_!("tls: {}", White.paint("disabled")); + info_!("tls: {}", Paint::white("disabled")); } } for (name, value) in config.extras() { info_!("{} {}: {}", - Yellow.paint("[extra]"), name, White.paint(LoggedValue(value))); + Paint::yellow("[extra]"), name, Paint::white(LoggedValue(value))); } Rocket { @@ -483,7 +482,7 @@ impl Rocket { /// ``` #[inline] pub fn mount(mut self, base: &str, routes: Vec) -> Self { - info!("🛰 {} '{}':", Magenta.paint("Mounting"), base); + info!("🛰 {} '{}':", Paint::purple("Mounting"), base); if base.contains('<') { error_!("Bad mount point: '{}'.", base); @@ -534,11 +533,11 @@ impl Rocket { /// ``` #[inline] pub fn catch(mut self, catchers: Vec) -> Self { - info!("👾 {}:", Magenta.paint("Catchers")); + info!("👾 {}:", Paint::purple("Catchers")); for c in catchers { if self.catchers.get(&c.code).map_or(false, |e| !e.is_default()) { let msg = "(warning: duplicate catcher!)"; - info_!("{} {}", c, Yellow.paint(msg)); + info_!("{} {}", c, Paint::yellow(msg)); } else { info_!("{}", c); } @@ -685,9 +684,9 @@ impl Rocket { let full_addr = format!("{}:{}", self.config.address, self.config.port); launch_info!("🚀 {} {}{}", - White.paint("Rocket has launched from"), - White.bold().paint(proto), - White.bold().paint(&full_addr)); + Paint::white("Rocket has launched from"), + Paint::white(proto).bold(), + Paint::white(&full_addr).bold()); let threads = self.config.workers as usize; if let Err(e) = server.handle_threads(self, threads) { diff --git a/lib/src/router/route.rs b/lib/src/router/route.rs index 55da3f23..548497cc 100644 --- a/lib/src/router/route.rs +++ b/lib/src/router/route.rs @@ -1,8 +1,7 @@ use std::fmt; use std::convert::From; -use term_painter::ToStyle; -use term_painter::Color::*; +use yansi::Color::*; use codegen::StaticRouteInfo; use handler::Handler;