rename to use_colored_tty; used match as well

This commit is contained in:
clippered 2017-11-13 20:10:46 +11:00
parent d2f2f25463
commit 794a215b27
4 changed files with 8 additions and 9 deletions

View file

@ -92,10 +92,9 @@ impl CliOptions {
}
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))),
}
}

View file

@ -44,7 +44,7 @@ use checkstyle::{output_footer, output_header};
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()) {

View file

@ -13,7 +13,7 @@ use diff;
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 @@ where
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),

View file

@ -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,