From 674fb0911c2eb9aeaa2abdf03b6e4e8756f1cf78 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 11 Aug 2011 22:55:08 -0700 Subject: Rename std::termivec to std::term --- src/comp/syntax/codemap.rs | 10 +++--- src/lib/std.rc | 2 +- src/lib/term.rs | 86 ++++++++++++++++++++++++++++++++++++++++++++++ src/lib/termivec.rs | 86 ---------------------------------------------- src/lib/test.rs | 14 ++++---- 5 files changed, 99 insertions(+), 99 deletions(-) create mode 100644 src/lib/term.rs delete mode 100644 src/lib/termivec.rs (limited to 'src') diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs index 40021bd4e56..38f99123a4e 100644 --- a/src/comp/syntax/codemap.rs +++ b/src/comp/syntax/codemap.rs @@ -1,7 +1,7 @@ import std::ivec; import std::uint; import std::str; -import std::termivec; +import std::term; import std::io; import std::option; import std::option::some; @@ -85,12 +85,12 @@ fn emit_diagnostic(sp: &option::t[span], msg: &str, kind: &str, color: u8, none. { } } io::stdout().write_str(ss + ": "); - if termivec::color_supported() { - termivec::fg(io::stdout().get_buf_writer(), color); + if term::color_supported() { + term::fg(io::stdout().get_buf_writer(), color); } io::stdout().write_str(#fmt("%s:", kind)); - if termivec::color_supported() { - termivec::reset(io::stdout().get_buf_writer()); + if term::color_supported() { + term::reset(io::stdout().get_buf_writer()); } io::stdout().write_str(#fmt(" %s\n", msg)); diff --git a/src/lib/std.rc b/src/lib/std.rc index 847ca6e6b6d..94e23646ca6 100644 --- a/src/lib/std.rc +++ b/src/lib/std.rc @@ -93,7 +93,7 @@ mod ptr; mod test; mod unsafe; mod ebmlivec = "ebml.rs"; -mod termivec; +mod term; // Local Variables: // mode: rust; diff --git a/src/lib/term.rs b/src/lib/term.rs new file mode 100644 index 00000000000..4d635e780b2 --- /dev/null +++ b/src/lib/term.rs @@ -0,0 +1,86 @@ + + + +// Simple ANSI color library. +// +// TODO: Windows support. +const color_black: u8 = 0u8; + +const color_red: u8 = 1u8; + +const color_green: u8 = 2u8; + +const color_yellow: u8 = 3u8; + +const color_blue: u8 = 4u8; + +const color_magenta: u8 = 5u8; + +const color_cyan: u8 = 6u8; + +const color_light_gray: u8 = 7u8; + +const color_light_grey: u8 = 7u8; + +const color_dark_gray: u8 = 8u8; + +const color_dark_grey: u8 = 8u8; + +const color_bright_red: u8 = 9u8; + +const color_bright_green: u8 = 10u8; + +const color_bright_yellow: u8 = 11u8; + +const color_bright_blue: u8 = 12u8; + +const color_bright_magenta: u8 = 13u8; + +const color_bright_cyan: u8 = 14u8; + +const color_bright_white: u8 = 15u8; + +fn esc(writer: io::buf_writer) { writer.write(~[0x1bu8, '[' as u8]); } + +fn reset(writer: io::buf_writer) { + esc(writer); + writer.write(~['0' as u8, 'm' as u8]); +} + +fn color_supported() -> bool { + let supported_terms = ~["xterm-color", "xterm", "screen-bce"]; + ret alt generic_os::getenv("TERM") { + option::some(env) { + for term: str in supported_terms { + if str::eq(term, env) { ret true; } + } + false + } + option::none. { false } + }; +} + +fn set_color(writer: io::buf_writer, first_char: u8, color: u8) { + assert (color < 16u8); + esc(writer); + if color >= 8u8 { writer.write(~['1' as u8, ';' as u8]); color -= 8u8; } + writer.write(~[first_char, ('0' as u8) + color, 'm' as u8]); +} + +fn fg(writer: io::buf_writer, color: u8) { + ret set_color(writer, '3' as u8, color); +} + +fn bg(writer: io::buf_writer, color: u8) { + ret set_color(writer, '4' as u8, color); +} +// export fg; +// export bg; + +// Local Variables: +// fill-column: 78; +// indent-tabs-mode: nil +// c-basic-offset: 4 +// buffer-file-coding-system: utf-8-unix +// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'"; +// End: diff --git a/src/lib/termivec.rs b/src/lib/termivec.rs deleted file mode 100644 index 4d635e780b2..00000000000 --- a/src/lib/termivec.rs +++ /dev/null @@ -1,86 +0,0 @@ - - - -// Simple ANSI color library. -// -// TODO: Windows support. -const color_black: u8 = 0u8; - -const color_red: u8 = 1u8; - -const color_green: u8 = 2u8; - -const color_yellow: u8 = 3u8; - -const color_blue: u8 = 4u8; - -const color_magenta: u8 = 5u8; - -const color_cyan: u8 = 6u8; - -const color_light_gray: u8 = 7u8; - -const color_light_grey: u8 = 7u8; - -const color_dark_gray: u8 = 8u8; - -const color_dark_grey: u8 = 8u8; - -const color_bright_red: u8 = 9u8; - -const color_bright_green: u8 = 10u8; - -const color_bright_yellow: u8 = 11u8; - -const color_bright_blue: u8 = 12u8; - -const color_bright_magenta: u8 = 13u8; - -const color_bright_cyan: u8 = 14u8; - -const color_bright_white: u8 = 15u8; - -fn esc(writer: io::buf_writer) { writer.write(~[0x1bu8, '[' as u8]); } - -fn reset(writer: io::buf_writer) { - esc(writer); - writer.write(~['0' as u8, 'm' as u8]); -} - -fn color_supported() -> bool { - let supported_terms = ~["xterm-color", "xterm", "screen-bce"]; - ret alt generic_os::getenv("TERM") { - option::some(env) { - for term: str in supported_terms { - if str::eq(term, env) { ret true; } - } - false - } - option::none. { false } - }; -} - -fn set_color(writer: io::buf_writer, first_char: u8, color: u8) { - assert (color < 16u8); - esc(writer); - if color >= 8u8 { writer.write(~['1' as u8, ';' as u8]); color -= 8u8; } - writer.write(~[first_char, ('0' as u8) + color, 'm' as u8]); -} - -fn fg(writer: io::buf_writer, color: u8) { - ret set_color(writer, '3' as u8, color); -} - -fn bg(writer: io::buf_writer, color: u8) { - ret set_color(writer, '4' as u8, color); -} -// export fg; -// export bg; - -// Local Variables: -// fill-column: 78; -// indent-tabs-mode: nil -// c-basic-offset: 4 -// buffer-file-coding-system: utf-8-unix -// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'"; -// End: diff --git a/src/lib/test.rs b/src/lib/test.rs index eeaf472c865..de6a4555cf1 100644 --- a/src/lib/test.rs +++ b/src/lib/test.rs @@ -181,25 +181,25 @@ fn run_tests_console_(opts: &test_opts, tests: &[test_desc], ret success; fn write_ok(out: &io::writer, use_color: bool) { - write_pretty(out, "ok", termivec::color_green, use_color); + write_pretty(out, "ok", term::color_green, use_color); } fn write_failed(out: &io::writer, use_color: bool) { - write_pretty(out, "FAILED", termivec::color_red, use_color); + write_pretty(out, "FAILED", term::color_red, use_color); } fn write_ignored(out: &io::writer, use_color: bool) { - write_pretty(out, "ignored", termivec::color_yellow, use_color); + write_pretty(out, "ignored", term::color_yellow, use_color); } fn write_pretty(out: &io::writer, word: &str, color: u8, use_color: bool) { - if use_color && termivec::color_supported() { - termivec::fg(out.get_buf_writer(), color); + if use_color && term::color_supported() { + term::fg(out.get_buf_writer(), color); } out.write_str(word); - if use_color && termivec::color_supported() { - termivec::reset(out.get_buf_writer()); + if use_color && term::color_supported() { + term::reset(out.get_buf_writer()); } } } -- cgit 1.4.1-3-g733a5