Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/libsyntax/errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use errors::{Level, RenderSpan, DiagnosticBuilder};
use errors::RenderSpan::*;
use errors::Level::*;

use std::{cmp, fmt};
use std::{cmp, fmt, env};
use std::io::prelude::*;
use std::io;
use std::rc::Rc;
Expand Down Expand Up @@ -55,7 +55,8 @@ impl ColorConfig {
match *self {
ColorConfig::Always => true,
ColorConfig::Never => false,
ColorConfig::Auto => stderr_isatty(),
ColorConfig::Auto => env::var("CLICOLOR_FORCE").unwrap_or("0".to_string()) != "0" ||
(stderr_isatty() && env::var("CLICOLOR").unwrap_or("1".to_string()) != "0"),
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/libterm/terminfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use Attr;
use color;
use Terminal;
use self::searcher::get_dbpath_for_term;
use self::parser::compiled::{parse, msys_terminfo};
use self::parser::compiled::{parse, ansi_terminfo};
use self::parm::{expand, Variables, Param};


Expand Down Expand Up @@ -81,14 +81,18 @@ impl fmt::Display for Error {
impl TermInfo {
/// Create a TermInfo based on current environment.
pub fn from_env() -> Result<TermInfo, Error> {
if env::var("CLICOLOR_FORCE").unwrap_or("0".to_string()) != "0" {
return Ok(ansi_terminfo());
}
let term = match env::var("TERM") {
Ok(name) => TermInfo::from_name(&name),
Err(..) => return Err(Error::TermUnset),
};

if term.is_err() && env::var("MSYSCON").ok().map_or(false, |s| "mintty.exe" == s) {
if term.is_err() && (env::var("MSYSCON").ok().map_or(false, |s| "mintty.exe" == s) ||
env::var("CLICOLOR").unwrap_or("0".to_string()) != "0") {
// msys terminal
Ok(msys_terminfo())
Ok(ansi_terminfo())
} else {
term
}
Expand Down
5 changes: 3 additions & 2 deletions src/libterm/terminfo/parser/compiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,9 @@ pub fn parse(file: &mut io::Read, longnames: bool) -> Result<TermInfo, String> {
})
}

/// Create a dummy TermInfo struct for msys terminals
pub fn msys_terminfo() -> TermInfo {
/// Create a dummy TermInfo struct which only supports ISO 6429 (ANSI) color sequences. This is
/// used for msys and when CLICOLOR(_FORCE) is set.
pub fn ansi_terminfo() -> TermInfo {
let mut strings = HashMap::new();
strings.insert("sgr0".to_string(), b"\x1B[0m".to_vec());
strings.insert("bold".to_string(), b"\x1B[1m".to_vec());
Expand Down