#![crate_name = "term"]
#![experimental]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![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/")]
#![allow(unknown_features)]
#![feature(macro_rules, phase, slicing_syntax, globs)]
#![deny(missing_docs)]
#[phase(plugin, link)] 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 std::io::stdout() as Box<Writer + Send>,
})
}
#[cfg(windows)]
pub fn stdout() -> Option<Box<Terminal<WriterWrapper> + Send>> {
let ti = TerminfoTerminal::new(WriterWrapper {
wrapped: box std::io::stdout() as Box<Writer + Send>,
});
match ti {
Some(t) => Some(t),
None => {
WinConsole::new(WriterWrapper {
wrapped: box std::io::stdout() as Box<Writer + Send>,
})
}
}
}
#[cfg(not(windows))]
pub fn stderr() -> Option<Box<Terminal<WriterWrapper> + Send>> {
TerminfoTerminal::new(WriterWrapper {
wrapped: box std::io::stderr() as Box<Writer + Send>,
})
}
#[cfg(windows)]
pub fn stderr() -> Option<Box<Terminal<WriterWrapper> + Send>> {
let ti = TerminfoTerminal::new(WriterWrapper {
wrapped: box std::io::stderr() as Box<Writer + Send>,
});
match ti {
Some(t) => Some(t),
None => {
WinConsole::new(WriterWrapper {
wrapped: box std::io::stderr() as Box<Writer + Send>,
})
}
}
}
pub mod color {
pub type Color = u16;
pub const BLACK: Color = 0u16;
pub const RED: Color = 1u16;
pub const GREEN: Color = 2u16;
pub const YELLOW: Color = 3u16;
pub const BLUE: Color = 4u16;
pub const MAGENTA: Color = 5u16;
pub const CYAN: Color = 6u16;
pub const WHITE: Color = 7u16;
pub const BRIGHT_BLACK: Color = 8u16;
pub const BRIGHT_RED: Color = 9u16;
pub const BRIGHT_GREEN: Color = 10u16;
pub const BRIGHT_YELLOW: Color = 11u16;
pub const BRIGHT_BLUE: Color = 12u16;
pub const BRIGHT_MAGENTA: Color = 13u16;
pub const BRIGHT_CYAN: Color = 14u16;
pub const BRIGHT_WHITE: Color = 15u16;
}
pub mod attr {
pub use self::Attr::*;
#[deriving(Copy)]
pub enum Attr {
Bold,
Dim,
Italic(bool),
Underline(bool),
Blink,
Standout(bool),
Reverse,
Secure,
ForegroundColor(super::color::Color),
BackgroundColor(super::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::Attr) -> IoResult<bool>;
fn supports_attr(&self, attr: attr::Attr) -> bool;
fn reset(&mut self) -> IoResult<()>;
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;
}