#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/",
html_playground_url = "http://play.rust-lang.org/")]
#![feature(int_uint)]
#![deny(missing_docs)]
#![allow(unstable)]
#[macro_use] extern crate log;
pub use terminfo::TerminfoTerminal;
#[cfg(windows)]
pub use win::WinConsole;
use std::io::IoResult;
pub mod terminfo;
#[cfg(windows)]
mod win;
pub struct WriterWrapper {
wrapped: Box<Writer + Send>,
}
impl Writer for WriterWrapper {
#[inline]
fn write(&mut self, buf: &[u8]) -> IoResult<()> {
self.wrapped.write(buf)
}
#[inline]
fn flush(&mut self) -> IoResult<()> {
self.wrapped.flush()
}
}
#[cfg(not(windows))]
pub fn stdout() -> Option<Box<Terminal<WriterWrapper> + Send>> {
TerminfoTerminal::new(WriterWrapper {
wrapped: Box::new(std::io::stdout()) as Box<Writer + Send>,
})
}
#[cfg(windows)]
pub fn stdout() -> Option<Box<Terminal<WriterWrapper> + Send>> {
let boxed = Box::new(std::io::stdout()) as Box<Writer + Send>;
let wrapped1 = WriterWrapper {wrapped: boxed};
let boxed = Box::new(std::io::stdout()) as Box<Writer + Send>;
let wrapped2 = WriterWrapper {wrapped: boxed};
TerminfoTerminal::new(wrapped1).or(WinConsole::new(wrapped2))
}
#[cfg(not(windows))]
pub fn stderr() -> Option<Box<Terminal<WriterWrapper> + Send>> {
TerminfoTerminal::new(WriterWrapper {
wrapped: Box::new(std::io::stderr()) as Box<Writer + Send>,
})
}
#[cfg(windows)]
pub fn stderr() -> Option<Box<Terminal<WriterWrapper> + Send>> {
let boxed = Box::new(std::io::stderr()) as Box<Writer + Send>;
let wrapped1 = WriterWrapper {wrapped: boxed};
let boxed = Box::new(std::io::stderr()) as Box<Writer + Send>;
let wrapped2 = WriterWrapper {wrapped: boxed};
TerminfoTerminal::new(wrapped1).or(WinConsole::new(wrapped2))
}
pub mod color {
pub type Color = u16;
pub const BLACK: Color = 0;
pub const RED: Color = 1;
pub const GREEN: Color = 2;
pub const YELLOW: Color = 3;
pub const BLUE: Color = 4;
pub const MAGENTA: Color = 5;
pub const CYAN: Color = 6;
pub const WHITE: Color = 7;
pub const BRIGHT_BLACK: Color = 8;
pub const BRIGHT_RED: Color = 9;
pub const BRIGHT_GREEN: Color = 10;
pub const BRIGHT_YELLOW: Color = 11;
pub const BRIGHT_BLUE: Color = 12;
pub const BRIGHT_MAGENTA: Color = 13;
pub const BRIGHT_CYAN: Color = 14;
pub const BRIGHT_WHITE: Color = 15;
}
#[derive(Copy)]
pub enum Attr {
Bold,
Dim,
Italic(bool),
Underline(bool),
Blink,
Standout(bool),
Reverse,
Secure,
ForegroundColor(color::Color),
BackgroundColor(color::Color)
}
pub trait Terminal<T: Writer>: Writer {
fn fg(&mut self, color: color::Color) -> IoResult<bool>;
fn bg(&mut self, color: color::Color) -> IoResult<bool>;
fn attr(&mut self, attr: Attr) -> IoResult<bool>;
fn supports_attr(&self, attr: Attr) -> bool;
fn reset(&mut self) -> IoResult<bool>;
fn get_ref<'a>(&'a self) -> &'a T;
fn get_mut<'a>(&'a mut self) -> &'a mut T;
}
pub trait UnwrappableTerminal<T: Writer>: Terminal<T> {
fn unwrap(self) -> T;
}