Skip to content

Commit a904846

Browse files
committed
---
yaml --- r: 90014 b: refs/heads/master c: 525878f h: refs/heads/master v: v3
1 parent 18bd6db commit a904846

File tree

10 files changed

+142
-191
lines changed

10 files changed

+142
-191
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 09eca11805fd523b569047d0ec257cfbf439a73c
2+
refs/heads/master: 525878fc96deb41bdc8f68daf5ba686688889d79
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d3e57dca68fde4effdda3e4ae2887aa535fcd6
55
refs/heads/try: b160761e35efcd1207112b3b782c06633cf441a8

trunk/src/libextra/term.rs

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#[allow(missing_doc)];
1414

1515

16-
use std::io::{Decorator, Writer};
16+
use std::io;
1717

1818
#[cfg(not(target_os = "win32"))] use std::os;
1919
#[cfg(not(target_os = "win32"))] use terminfo::*;
@@ -94,21 +94,21 @@ fn cap_for_attr(attr: attr::Attr) -> &'static str {
9494
}
9595

9696
#[cfg(not(target_os = "win32"))]
97-
pub struct Terminal<T> {
97+
pub struct Terminal {
9898
priv num_colors: u16,
99-
priv out: T,
99+
priv out: @mut io::Writer,
100100
priv ti: ~TermInfo
101101
}
102102

103103
#[cfg(target_os = "win32")]
104-
pub struct Terminal<T> {
104+
pub struct Terminal {
105105
priv num_colors: u16,
106-
priv out: T,
106+
priv out: @mut io::Writer,
107107
}
108108

109109
#[cfg(not(target_os = "win32"))]
110-
impl<T: Writer> Terminal<T> {
111-
pub fn new(out: T) -> Result<Terminal<T>, ~str> {
110+
impl Terminal {
111+
pub fn new(out: @mut io::Writer) -> Result<Terminal, ~str> {
112112
let term = os::getenv("TERM");
113113
if term.is_none() {
114114
return Err(~"TERM environment variable undefined");
@@ -138,7 +138,7 @@ impl<T: Writer> Terminal<T> {
138138
/// the corresponding normal color will be used instead.
139139
///
140140
/// Returns true if the color was set, false otherwise.
141-
pub fn fg(&mut self, color: color::Color) -> bool {
141+
pub fn fg(&self, color: color::Color) -> bool {
142142
let color = self.dim_if_necessary(color);
143143
if self.num_colors > color {
144144
let s = expand(*self.ti.strings.find_equiv(&("setaf")).unwrap(),
@@ -158,7 +158,7 @@ impl<T: Writer> Terminal<T> {
158158
/// the corresponding normal color will be used instead.
159159
///
160160
/// Returns true if the color was set, false otherwise.
161-
pub fn bg(&mut self, color: color::Color) -> bool {
161+
pub fn bg(&self, color: color::Color) -> bool {
162162
let color = self.dim_if_necessary(color);
163163
if self.num_colors > color {
164164
let s = expand(*self.ti.strings.find_equiv(&("setab")).unwrap(),
@@ -175,7 +175,7 @@ impl<T: Writer> Terminal<T> {
175175

176176
/// Sets the given terminal attribute, if supported.
177177
/// Returns true if the attribute was supported, false otherwise.
178-
pub fn attr(&mut self, attr: attr::Attr) -> bool {
178+
pub fn attr(&self, attr: attr::Attr) -> bool {
179179
match attr {
180180
attr::ForegroundColor(c) => self.fg(c),
181181
attr::BackgroundColor(c) => self.bg(c),
@@ -210,7 +210,7 @@ impl<T: Writer> Terminal<T> {
210210
}
211211

212212
/// Resets all terminal attributes and color to the default.
213-
pub fn reset(&mut self) {
213+
pub fn reset(&self) {
214214
let mut cap = self.ti.strings.find_equiv(&("sgr0"));
215215
if cap.is_none() {
216216
// are there any terminals that have color/attrs and not sgr0?
@@ -242,20 +242,20 @@ impl<T: Writer> Terminal<T> {
242242
}
243243

244244
#[cfg(target_os = "win32")]
245-
impl<T: Writer> Terminal<T> {
246-
pub fn new(out: T) -> Result<Terminal<T>, ~str> {
245+
impl Terminal {
246+
pub fn new(out: @mut io::Writer) -> Result<Terminal, ~str> {
247247
return Ok(Terminal {out: out, num_colors: 0});
248248
}
249249

250-
pub fn fg(&mut self, _color: color::Color) -> bool {
250+
pub fn fg(&self, _color: color::Color) -> bool {
251251
false
252252
}
253253

254-
pub fn bg(&mut self, _color: color::Color) -> bool {
254+
pub fn bg(&self, _color: color::Color) -> bool {
255255
false
256256
}
257257

258-
pub fn attr(&mut self, _attr: attr::Attr) -> bool {
258+
pub fn attr(&self, _attr: attr::Attr) -> bool {
259259
false
260260
}
261261

@@ -266,27 +266,3 @@ impl<T: Writer> Terminal<T> {
266266
pub fn reset(&self) {
267267
}
268268
}
269-
270-
impl<T: Writer> Decorator<T> for Terminal<T> {
271-
fn inner(self) -> T {
272-
self.out
273-
}
274-
275-
fn inner_ref<'a>(&'a self) -> &'a T {
276-
&self.out
277-
}
278-
279-
fn inner_mut_ref<'a>(&'a mut self) -> &'a mut T {
280-
&mut self.out
281-
}
282-
}
283-
284-
impl<T: Writer> Writer for Terminal<T> {
285-
fn write(&mut self, buf: &[u8]) {
286-
self.out.write(buf);
287-
}
288-
289-
fn flush(&mut self) {
290-
self.out.flush();
291-
}
292-
}

0 commit comments

Comments
 (0)