Refactor extra::term a bit

Move all the colors into a nested mod named color instead of prefixing
with "color_".

Define a new type color::Color, and make this a u16 instead of a u8 (to
allow for easy comparisons against num_colors, which is a u16).

Remove color_supported and replace it with num_colors.

Teach fg() and bg() to "dim" bright colors down to the normal intensity
if num_colors isn't high enough.

Remove unnecessary copies, and fix a bug where a terminfo parse failure
would try to use the wrong error and end up failing.
This commit is contained in:
Kevin Ballard 2013-06-25 16:38:32 -07:00 committed by Corey Richardson
parent 00b4138857
commit 0ae203a779
4 changed files with 82 additions and 64 deletions

View file

@ -13,18 +13,18 @@ use core::io;
use core::result::*;
pub fn note(msg: &str) {
pretty_message(msg, "note: ", term::color_green, io::stdout())
pretty_message(msg, "note: ", term::color::green, io::stdout())
}
pub fn warn(msg: &str) {
pretty_message(msg, "warning: ", term::color_yellow, io::stdout())
pretty_message(msg, "warning: ", term::color::yellow, io::stdout())
}
pub fn error(msg: &str) {
pretty_message(msg, "error: ", term::color_red, io::stdout())
pretty_message(msg, "error: ", term::color::red, io::stdout())
}
fn pretty_message<'a>(msg: &'a str, prefix: &'a str, color: u8, out: @io::Writer) {
fn pretty_message<'a>(msg: &'a str, prefix: &'a str, color: term::color::Color, out: @io::Writer) {
let term = term::Terminal::new(out);
match term {
Ok(ref t) => {