1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
// 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(ioivec::buf_writer writer) { writer.write(~[0x1bu8, '[' as u8]); }
fn reset(ioivec::buf_writer writer) {
esc(writer);
writer.write(~['0' as u8, 'm' as u8]);
}
fn color_supported() -> bool {
auto supported_terms = ~["xterm-color", "xterm", "screen-bce"];
ret alt (generic_os::getenv("TERM")) {
case (option::some(?env)) {
for (str term in supported_terms) {
if (str::eq(term, env)) { true }
}
false
}
case (option::none) { false }
};
}
fn set_color(ioivec::buf_writer writer, u8 first_char, u8 color) {
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(ioivec::buf_writer writer, u8 color) {
ret set_color(writer, '3' as u8, color);
}
fn bg(ioivec::buf_writer writer, u8 color) {
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:
|