about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-04-26 11:48:07 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-04-26 13:08:48 -0700
commit79d27ccb586148eae822276d8513359c9a373f32 (patch)
treecc5d90b4dbb5ba71422deeac6c7f05d152402ea3 /src
parent6b11f6c46fcece9dceb92cab009e1d9f42f9672e (diff)
downloadrust-79d27ccb586148eae822276d8513359c9a373f32.tar.gz
rust-79d27ccb586148eae822276d8513359c9a373f32.zip
stdlib: Add a silly ANSI color library
Diffstat (limited to 'src')
-rw-r--r--src/lib/Term.rs54
-rw-r--r--src/lib/std.rc1
2 files changed, 55 insertions, 0 deletions
diff --git a/src/lib/Term.rs b/src/lib/Term.rs
new file mode 100644
index 00000000000..9bf90b1cdb0
--- /dev/null
+++ b/src/lib/Term.rs
@@ -0,0 +1,54 @@
+// Simple ANSI color library.
+//
+// TODO: Windows support.
+
+const u8 color_black = 0u8;
+const u8 color_red = 1u8;
+const u8 color_green = 2u8;
+const u8 color_yellow = 3u8;
+const u8 color_blue = 4u8;
+const u8 color_magenta = 5u8;
+const u8 color_cyan = 6u8;
+const u8 color_light_gray = 7u8;
+const u8 color_light_grey = 7u8;
+const u8 color_dark_gray = 8u8;
+const u8 color_dark_grey = 8u8;
+const u8 color_bright_red = 9u8;
+const u8 color_bright_green = 10u8;
+const u8 color_bright_yellow = 11u8;
+const u8 color_bright_blue = 12u8;
+const u8 color_bright_magenta = 13u8;
+const u8 color_bright_cyan = 14u8;
+const u8 color_bright_white = 15u8;
+
+fn esc(io.buf_writer writer) {
+    writer.write(vec(0x1bu8, '[' as u8));
+}
+
+fn reset(io.buf_writer writer) {
+    esc(writer);
+    writer.write(vec('0' as u8, 'm' as u8));
+}
+
+fn set_color(io.buf_writer writer, u8 first_char, u8 color) {
+    check (color < 16u8);
+
+    esc(writer);
+    if (color >= 8u8) {
+        writer.write(vec('1' as u8, ';' as u8));
+        color -= 8u8;
+    }
+    writer.write(vec(first_char, ('0' as u8) + color, 'm' as u8));
+}
+
+fn fg(io.buf_writer writer, u8 color) {
+    ret set_color(writer, '3' as u8, color);
+}
+
+fn bg(io.buf_writer writer, u8 color) {
+    ret set_color(writer, '4' as u8, color);
+}
+
+// export fg;
+// export bg;
+
diff --git a/src/lib/std.rc b/src/lib/std.rc
index 9fc1b7b8cbf..8a9ee42d0da 100644
--- a/src/lib/std.rc
+++ b/src/lib/std.rc
@@ -71,6 +71,7 @@ mod UFind;
 mod ExtFmt;
 mod Box;
 mod GetOpts;
+mod Term;
 
 // Local Variables:
 // mode: rust;