Skip to content

Commit cc56bf4

Browse files
committed
---
yaml --- r: 62909 b: refs/heads/snap-stage3 c: b570536 h: refs/heads/master i: 62907: efd8624 v: v3
1 parent 131d26e commit cc56bf4

File tree

15 files changed

+161
-865
lines changed

15 files changed

+161
-865
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 11f31b96848c7d04f79e6aaa2c789857bb224526
4+
refs/heads/snap-stage3: b570536b38d3172deabb471f407993a1aa2d4a0d
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libextra/std.rc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ pub mod flate;
118118
#[cfg(unicode)]
119119
mod unicode;
120120

121-
#[path="terminfo/terminfo.rs"]
122-
pub mod terminfo;
123121

124122
// Compiler support modules
125123

Lines changed: 33 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -15,13 +15,9 @@
1515
use core::prelude::*;
1616

1717
use core::io;
18+
use core::option;
1819
use core::os;
1920

20-
use terminfo::*;
21-
use terminfo::searcher::open;
22-
use terminfo::parser::compiled::parse;
23-
use terminfo::parm::{expand, Number};
24-
2521
// FIXME (#2807): Windows support.
2622

2723
pub static color_black: u8 = 0u8;
@@ -43,90 +39,43 @@ pub static color_bright_magenta: u8 = 13u8;
4339
pub static color_bright_cyan: u8 = 14u8;
4440
pub static color_bright_white: u8 = 15u8;
4541

46-
#[cfg(not(target_os = "win32"))]
47-
pub struct Terminal {
48-
color_supported: bool,
49-
priv out: @io::Writer,
50-
priv ti: ~TermInfo
51-
}
42+
pub fn esc(writer: @io::Writer) { writer.write([0x1bu8, '[' as u8]); }
5243

53-
#[cfg(target_os = "win32")]
54-
pub struct Terminal {
55-
color_supported: bool,
56-
priv out: @io::Writer,
44+
/// Reset the foreground and background colors to default
45+
pub fn reset(writer: @io::Writer) {
46+
esc(writer);
47+
writer.write(['0' as u8, 'm' as u8]);
5748
}
5849

59-
#[cfg(not(target_os = "win32"))]
60-
pub impl Terminal {
61-
pub fn new(out: @io::Writer) -> Result<Terminal, ~str> {
62-
let term = os::getenv("TERM");
63-
if term.is_none() {
64-
return Err(~"TERM environment variable undefined");
65-
}
66-
67-
let entry = open(term.unwrap());
68-
if entry.is_err() {
69-
return Err(entry.get_err());
70-
}
71-
72-
let ti = parse(entry.get(), false);
73-
if ti.is_err() {
74-
return Err(entry.get_err());
75-
}
76-
77-
let mut inf = ti.get();
78-
let cs = *inf.numbers.find_or_insert(~"colors", 0) >= 16
79-
&& inf.strings.find(&~"setaf").is_some()
80-
&& inf.strings.find_equiv(&("setab")).is_some();
81-
82-
return Ok(Terminal {out: out, ti: inf, color_supported: cs});
83-
}
84-
fn fg(&self, color: u8) {
85-
if self.color_supported {
86-
let s = expand(*self.ti.strings.find_equiv(&("setaf")).unwrap(),
87-
[Number(color as int)], [], []);
88-
if s.is_ok() {
89-
self.out.write(s.get());
90-
} else {
91-
warn!(s.get_err());
50+
/// Returns true if the terminal supports color
51+
pub fn color_supported() -> bool {
52+
let supported_terms = ~[~"xterm-color", ~"xterm",
53+
~"screen-bce", ~"xterm-256color"];
54+
return match os::getenv("TERM") {
55+
option::Some(ref env) => {
56+
for supported_terms.each |term| {
57+
if *term == *env { return true; }
9258
}
93-
}
94-
}
95-
fn bg(&self, color: u8) {
96-
if self.color_supported {
97-
let s = expand(*self.ti.strings.find_equiv(&("setab")).unwrap(),
98-
[Number(color as int)], [], []);
99-
if s.is_ok() {
100-
self.out.write(s.get());
101-
} else {
102-
warn!(s.get_err());
103-
}
104-
}
105-
}
106-
fn reset(&self) {
107-
if self.color_supported {
108-
let s = expand(*self.ti.strings.find_equiv(&("op")).unwrap(), [], [], []);
109-
if s.is_ok() {
110-
self.out.write(s.get());
111-
} else {
112-
warn!(s.get_err());
113-
}
114-
}
115-
}
59+
false
60+
}
61+
option::None => false
62+
};
11663
}
11764

118-
#[cfg(target_os = "win32")]
119-
pub impl Terminal {
120-
pub fn new(out: @io::Writer) -> Result<Terminal, ~str> {
121-
return Ok(Terminal {out: out, color_supported: false});
122-
}
123-
124-
fn fg(&self, color: u8) {
125-
}
65+
pub fn set_color(writer: @io::Writer, first_char: u8, color: u8) {
66+
assert!((color < 16u8));
67+
esc(writer);
68+
let mut color = color;
69+
if color >= 8u8 { writer.write(['1' as u8, ';' as u8]); color -= 8u8; }
70+
writer.write([first_char, ('0' as u8) + color, 'm' as u8]);
71+
}
12672

127-
fn bg(&self, color: u8) {
128-
}
73+
/// Set the foreground color
74+
pub fn fg(writer: @io::Writer, color: u8) {
75+
return set_color(writer, '3' as u8, color);
76+
}
12977

130-
fn reset(&self) {
131-
}
78+
/// Set the background color
79+
pub fn bg(writer: @io::Writer, color: u8) {
80+
return set_color(writer, '4' as u8, color);
13281
}

branches/snap-stage3/src/libextra/terminfo/parm.rs

Lines changed: 0 additions & 209 deletions
This file was deleted.

0 commit comments

Comments
 (0)