Remove unnecessary BasicTerminal

This commit is contained in:
Yehuda Katz 2014-05-27 22:06:38 -07:00
parent d5a7bc33d2
commit 7ed3bd8b9c
1 changed files with 9 additions and 62 deletions

View File

@ -11,7 +11,7 @@ pub struct ShellConfig {
}
enum AdequateTerminal<T> {
NoColor(BasicTerminal<T>),
NoColor(T),
Color(Box<Terminal<T>>)
}
@ -26,7 +26,7 @@ impl<T: Writer + Send> Shell<T> {
let term: Option<term::TerminfoTerminal<T>> = Terminal::new(out);
term.map(|t| Shell { terminal: Color(box t as Box<Terminal<T>>), config: config })
} else {
Some(Shell { terminal: NoColor(BasicTerminal { writer: out }), config: config })
Some(Shell { terminal: NoColor(out), config: config })
}
}
@ -56,35 +56,35 @@ impl<T: Writer + Send> Terminal<T> for Shell<T> {
fn fg(&mut self, color: color::Color) -> IoResult<bool> {
match self.terminal {
Color(ref mut c) => c.fg(color),
NoColor(ref mut n) => n.fg(color)
NoColor(_) => Ok(false)
}
}
fn bg(&mut self, color: color::Color) -> IoResult<bool> {
match self.terminal {
Color(ref mut c) => c.bg(color),
NoColor(ref mut n) => n.bg(color)
NoColor(_) => Ok(false)
}
}
fn attr(&mut self, attr: Attr) -> IoResult<bool> {
match self.terminal {
Color(ref mut c) => c.attr(attr),
NoColor(ref mut n) => n.attr(attr)
NoColor(_) => Ok(false)
}
}
fn supports_attr(&self, attr: Attr) -> bool {
match self.terminal {
Color(ref c) => c.supports_attr(attr),
NoColor(ref n) => n.supports_attr(attr)
NoColor(_) => false
}
}
fn reset(&mut self) -> IoResult<()> {
match self.terminal {
Color(ref mut c) => c.reset(),
NoColor(ref mut n) => n.reset()
NoColor(_) => Ok(())
}
}
@ -95,14 +95,14 @@ impl<T: Writer + Send> Terminal<T> for Shell<T> {
fn get_ref<'a>(&'a self) -> &'a T {
match self.terminal {
Color(ref c) => c.get_ref(),
NoColor(ref n) => n.get_ref()
NoColor(ref w) => w
}
}
fn get_mut<'a>(&'a mut self) -> &'a mut T {
match self.terminal {
Color(ref mut c) => c.get_mut(),
NoColor(ref mut n) => n.get_mut()
NoColor(ref mut w) => w
}
}
}
@ -122,56 +122,3 @@ impl<T: Writer + Send> Writer for Shell<T> {
}
}
}
pub struct BasicTerminal<T> {
writer: T
}
impl<T: Writer + Send> Terminal<T> for BasicTerminal<T> {
fn new(out: T) -> Option<BasicTerminal<T>> {
Some(BasicTerminal { writer: out })
}
fn fg(&mut self, _: Color) -> IoResult<bool> {
Ok(false)
}
fn bg(&mut self, _: Color) -> IoResult<bool> {
Ok(false)
}
fn attr(&mut self, _: Attr) -> IoResult<bool> {
Ok(false)
}
fn supports_attr(&self, _: Attr) -> bool {
false
}
fn reset(&mut self) -> IoResult<()> {
Ok(())
}
fn unwrap(self) -> T {
self.writer
}
fn get_ref<'a>(&'a self) -> &'a T {
&self.writer
}
fn get_mut<'a>(&'a mut self) -> &'a mut T {
&mut self.writer
}
}
impl<T: Writer + Send> Writer for BasicTerminal<T> {
fn write(&mut self, buf: &[u8]) -> IoResult<()> {
self.writer.write(buf)
}
fn flush(&mut self) -> IoResult<()> {
self.writer.flush()
}
}