auto merge of #11031 : jhasse/rust/patch-msys-3, r=cmr
Enable ANSI colors if TERM is set to cygwin and terminfo is not available (msys terminal on Windows). See #2807
This commit is contained in:
commit
45d24a5f7c
2 changed files with 28 additions and 45 deletions
|
@ -15,11 +15,11 @@
|
||||||
|
|
||||||
use std::io::{Decorator, Writer};
|
use std::io::{Decorator, Writer};
|
||||||
|
|
||||||
#[cfg(not(target_os = "win32"))] use std::os;
|
use std::os;
|
||||||
#[cfg(not(target_os = "win32"))] use terminfo::*;
|
use terminfo::*;
|
||||||
#[cfg(not(target_os = "win32"))] use terminfo::searcher::open;
|
use terminfo::searcher::open;
|
||||||
#[cfg(not(target_os = "win32"))] use terminfo::parser::compiled::parse;
|
use terminfo::parser::compiled::{parse, msys_terminfo};
|
||||||
#[cfg(not(target_os = "win32"))] use terminfo::parm::{expand, Number, Variables};
|
use terminfo::parm::{expand, Number, Variables};
|
||||||
|
|
||||||
// FIXME (#2807): Windows support.
|
// FIXME (#2807): Windows support.
|
||||||
|
|
||||||
|
@ -74,7 +74,6 @@ pub mod attr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "win32"))]
|
|
||||||
fn cap_for_attr(attr: attr::Attr) -> &'static str {
|
fn cap_for_attr(attr: attr::Attr) -> &'static str {
|
||||||
match attr {
|
match attr {
|
||||||
attr::Bold => "bold",
|
attr::Bold => "bold",
|
||||||
|
@ -93,29 +92,24 @@ fn cap_for_attr(attr: attr::Attr) -> &'static str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "win32"))]
|
|
||||||
pub struct Terminal<T> {
|
pub struct Terminal<T> {
|
||||||
priv num_colors: u16,
|
priv num_colors: u16,
|
||||||
priv out: T,
|
priv out: T,
|
||||||
priv ti: ~TermInfo
|
priv ti: ~TermInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "win32")]
|
|
||||||
pub struct Terminal<T> {
|
|
||||||
priv num_colors: u16,
|
|
||||||
priv out: T,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "win32"))]
|
|
||||||
impl<T: Writer> Terminal<T> {
|
impl<T: Writer> Terminal<T> {
|
||||||
pub fn new(out: T) -> Result<Terminal<T>, ~str> {
|
pub fn new(out: T) -> Result<Terminal<T>, ~str> {
|
||||||
let term = os::getenv("TERM");
|
let term = match os::getenv("TERM") {
|
||||||
if term.is_none() {
|
Some(t) => t,
|
||||||
return Err(~"TERM environment variable undefined");
|
None => return Err(~"TERM environment variable undefined")
|
||||||
}
|
};
|
||||||
|
|
||||||
let entry = open(term.unwrap());
|
let entry = open(term);
|
||||||
if entry.is_err() {
|
if entry.is_err() {
|
||||||
|
if "cygwin" == term { // msys terminal
|
||||||
|
return Ok(Terminal {out: out, ti: msys_terminfo(), num_colors: 8});
|
||||||
|
}
|
||||||
return Err(entry.unwrap_err());
|
return Err(entry.unwrap_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,32 +235,6 @@ impl<T: Writer> Terminal<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "win32")]
|
|
||||||
impl<T: Writer> Terminal<T> {
|
|
||||||
pub fn new(out: T) -> Result<Terminal<T>, ~str> {
|
|
||||||
return Ok(Terminal {out: out, num_colors: 0});
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn fg(&mut self, _color: color::Color) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bg(&mut self, _color: color::Color) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn attr(&mut self, _attr: attr::Attr) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn supports_attr(&self, _attr: attr::Attr) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reset(&self) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Writer> Decorator<T> for Terminal<T> {
|
impl<T: Writer> Decorator<T> for Terminal<T> {
|
||||||
fn inner(self) -> T {
|
fn inner(self) -> T {
|
||||||
self.out
|
self.out
|
||||||
|
|
|
@ -316,6 +316,21 @@ pub fn parse(file: &mut io::Reader,
|
||||||
Ok(~TermInfo {names: term_names, bools: bools_map, numbers: numbers_map, strings: string_map })
|
Ok(~TermInfo {names: term_names, bools: bools_map, numbers: numbers_map, strings: string_map })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a dummy TermInfo struct for msys terminals
|
||||||
|
pub fn msys_terminfo() -> ~TermInfo {
|
||||||
|
let mut strings = HashMap::new();
|
||||||
|
strings.insert(~"sgr0", bytes!("\x1b[0m").to_owned());
|
||||||
|
strings.insert(~"bold", bytes!("\x1b[1m;").to_owned());
|
||||||
|
strings.insert(~"setaf", bytes!("\x1b[3%p1%dm").to_owned());
|
||||||
|
strings.insert(~"setab", bytes!("\x1b[4%p1%dm").to_owned());
|
||||||
|
~TermInfo {
|
||||||
|
names: ~[~"cygwin"], // msys is a fork of an older cygwin version
|
||||||
|
bools: HashMap::new(),
|
||||||
|
numbers: HashMap::new(),
|
||||||
|
strings: strings
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue