}
enum AdequateTerminal<T> {
- NoColor(BasicTerminal<T>),
+ NoColor(T),
Color(Box<Terminal<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 })
}
}
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(())
}
}
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
}
}
}
}
}
}
-
-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()
- }
-}
-