diff --git a/src/bin/rustfmt.rs b/src/bin/rustfmt.rs index fd9f9021484..4a041144789 100644 --- a/src/bin/rustfmt.rs +++ b/src/bin/rustfmt.rs @@ -92,10 +92,9 @@ fn from_matches(matches: &Matches) -> FmtResult { } if let Some(ref color) = matches.opt_str("color") { - if let Ok(color) = Color::from_str(color) { - options.color = Some(color); - } else { - return Err(FmtError::from(format!("Invalid color: {}", color))); + match Color::from_str(color) { + Ok(color) => options.color = Some(color), + _ => return Err(FmtError::from(format!("Invalid color: {}", color))), } } diff --git a/src/lib.rs b/src/lib.rs index dfdf4b5143f..1eec30833b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,7 +44,7 @@ use config::Config; use filemap::FileMap; use issues::{BadIssueSeeker, Issue}; -use utils::iscolored; +use utils::use_colored_tty; use visitor::FmtVisitor; pub use self::summary::Summary; @@ -581,7 +581,7 @@ pub fn run(input: Input, config: &Config) -> Summary { if report.has_warnings() { match term::stderr() { Some(ref t) - if iscolored(config.color()) && t.supports_color() + if use_colored_tty(config.color()) && t.supports_color() && t.supports_attr(term::Attr::Bold) => { match report.print_warnings_fancy(term::stderr().unwrap()) { diff --git a/src/rustfmt_diff.rs b/src/rustfmt_diff.rs index 858fb876f6e..daad73dc6ab 100644 --- a/src/rustfmt_diff.rs +++ b/src/rustfmt_diff.rs @@ -13,7 +13,7 @@ use std::collections::VecDeque; use std::io; use term; -use utils::iscolored; +use utils::use_colored_tty; #[derive(Debug, PartialEq)] pub enum DiffLine { @@ -102,7 +102,7 @@ pub fn print_diff(diff: Vec, get_section_title: F, color: Color) F: Fn(u32) -> String, { match term::stdout() { - Some(ref t) if iscolored(color) && t.supports_color() => { + Some(ref t) if use_colored_tty(color) && t.supports_color() => { print_diff_fancy(diff, get_section_title, term::stdout().unwrap()) } _ => print_diff_basic(diff, get_section_title), diff --git a/src/utils.rs b/src/utils.rs index 68fca8789d3..b87e2eaf493 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -485,7 +485,7 @@ pub fn isatty() -> bool { } } -pub fn iscolored(color: Color) -> bool { +pub fn use_colored_tty(color: Color) -> bool { match color { Color::Always => true, Color::Never => false,