Rocket

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 2845b8d4d4edb6b8634b746f89542b8c6d000ef7
parent 831d8dfbe30dd69f0367a75361e027127b2100e1
Author: Sergio Benitez <sb@sergio.bz>
Date:   Sun, 21 Oct 2018 19:46:37 -0700

Add coloring disabling with 'ROCKET_CLI_COLORS=off'.

Resolves #703.

Diffstat:
Mcontrib/lib/src/serve.rs | 2+-
Mcore/codegen_next/src/lib.rs | 2+-
Mcore/lib/src/config/mod.rs | 3++-
Mcore/lib/src/logger.rs | 9+++++++--
4 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/contrib/lib/src/serve.rs b/contrib/lib/src/serve.rs @@ -89,7 +89,7 @@ impl ::std::ops::BitOr for Options { /// /// # 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 /// default), you might write the following: /// diff --git a/core/codegen_next/src/lib.rs b/core/codegen_next/src/lib.rs @@ -147,7 +147,7 @@ macro_rules! route_attribute { /// The generic route attribute is defined as: /// /// ```text - /// generic-route := METHOD ',' path = route + /// generic-route := METHOD ',' 'path' '=' route /// ``` /// /// # Typing Requirements diff --git a/core/lib/src/config/mod.rs b/core/lib/src/config/mod.rs @@ -209,13 +209,14 @@ crate use self::toml_ext::LoggedValue; use logger; use self::Environment::*; use self::environment::CONFIG_ENV; +use logger::COLORS_ENV; use self::toml_ext::parse_simple_toml_value; use http::uncased::uncased_eq; const CONFIG_FILENAME: &str = "Rocket.toml"; const GLOBAL_ENV_NAME: &str = "global"; 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`]. pub type Result<T> = ::std::result::Result<T, ConfigError>; diff --git a/core/lib/src/logger.rs b/core/lib/src/logger.rs @@ -1,11 +1,13 @@ //! Rocket's logging infrastructure. +use std::{fmt, env}; use std::str::FromStr; -use std::fmt; use log; use yansi::Paint; +crate const COLORS_ENV: &str = "ROCKET_CLI_COLORS"; + struct RocketLogger(LoggingLevel); /// Defines the different levels for log messages. @@ -147,7 +149,10 @@ crate fn try_init(level: LoggingLevel, verbose: bool) -> bool { 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(); }