Add coloring disabling with 'ROCKET_CLI_COLORS=off'.

Resolves #703.
This commit is contained in:
Sergio Benitez 2018-10-21 19:46:37 -07:00
parent 831d8dfbe3
commit 2845b8d4d4
4 changed files with 11 additions and 5 deletions

View File

@ -89,7 +89,7 @@ impl ::std::ops::BitOr for Options {
/// ///
/// # Example /// # Example
/// ///
/// To serve files from this directory at the `/public` path, allowing /// To serve files from the `/static` directory at the `/public` path, allowing
/// `index.html` files to be used to respond to requests for a directory (the /// `index.html` files to be used to respond to requests for a directory (the
/// default), you might write the following: /// default), you might write the following:
/// ///

View File

@ -147,7 +147,7 @@ macro_rules! route_attribute {
/// The generic route attribute is defined as: /// The generic route attribute is defined as:
/// ///
/// ```text /// ```text
/// generic-route := METHOD ',' path = route /// generic-route := METHOD ',' 'path' '=' route
/// ``` /// ```
/// ///
/// # Typing Requirements /// # Typing Requirements

View File

@ -209,13 +209,14 @@ crate use self::toml_ext::LoggedValue;
use logger; use logger;
use self::Environment::*; use self::Environment::*;
use self::environment::CONFIG_ENV; use self::environment::CONFIG_ENV;
use logger::COLORS_ENV;
use self::toml_ext::parse_simple_toml_value; use self::toml_ext::parse_simple_toml_value;
use http::uncased::uncased_eq; use http::uncased::uncased_eq;
const CONFIG_FILENAME: &str = "Rocket.toml"; const CONFIG_FILENAME: &str = "Rocket.toml";
const GLOBAL_ENV_NAME: &str = "global"; const GLOBAL_ENV_NAME: &str = "global";
const ENV_VAR_PREFIX: &str = "ROCKET_"; const ENV_VAR_PREFIX: &str = "ROCKET_";
const PREHANDLED_VARS: [&str; 2] = ["ROCKET_CODEGEN_DEBUG", CONFIG_ENV]; const PREHANDLED_VARS: [&str; 3] = ["ROCKET_CODEGEN_DEBUG", CONFIG_ENV, COLORS_ENV];
/// Wraps `std::result` with the error type of [`ConfigError`]. /// Wraps `std::result` with the error type of [`ConfigError`].
pub type Result<T> = ::std::result::Result<T, ConfigError>; pub type Result<T> = ::std::result::Result<T, ConfigError>;

View File

@ -1,11 +1,13 @@
//! Rocket's logging infrastructure. //! Rocket's logging infrastructure.
use std::{fmt, env};
use std::str::FromStr; use std::str::FromStr;
use std::fmt;
use log; use log;
use yansi::Paint; use yansi::Paint;
crate const COLORS_ENV: &str = "ROCKET_CLI_COLORS";
struct RocketLogger(LoggingLevel); struct RocketLogger(LoggingLevel);
/// Defines the different levels for log messages. /// Defines the different levels for log messages.
@ -147,7 +149,10 @@ crate fn try_init(level: LoggingLevel, verbose: bool) -> bool {
return false; return false;
} }
if !::isatty::stdout_isatty() || (cfg!(windows) && !Paint::enable_windows_ascii()) { if !::isatty::stdout_isatty()
|| (cfg!(windows) && !Paint::enable_windows_ascii())
|| env::var_os(COLORS_ENV).map(|v| v == "0" || v == "off").unwrap_or(false)
{
Paint::disable(); Paint::disable();
} }