|
16 | 16 | module color; |
17 | 17 | import unistd; |
18 | 18 |
|
19 | | -public const char[] Black = "\033[0;30m"; |
20 | | -public const char[] Red = "\033[0;31m"; |
21 | | -public const char[] Green = "\033[0;32m"; |
22 | | -public const char[] Yellow = "\033[0;33m"; |
23 | | -public const char[] Blue = "\033[0;34m"; |
24 | | -public const char[] Magenta = "\033[0;35m"; |
25 | | -public const char[] Cyan = "\033[0;36m"; |
26 | | -public const char[] Grey = "\033[0;37m"; |
27 | | -public const char[] Darkgrey = "\033[01;30m"; |
28 | | -public const char[] Bred = "\033[01;31m"; |
29 | | -public const char[] Bgreen = "\033[01;32m"; |
30 | | -public const char[] Byellow = "\033[01;33m"; |
31 | | -public const char[] Bblue = "\033[01;34m"; |
32 | | -public const char[] Bmagenta = "\033[01;35m"; |
33 | | -public const char[] Bcyan = "\033[01;36m"; |
34 | | -public const char[] White = "\033[01;37m"; |
35 | | -public const char[] Normal = "\033[0m"; |
| 19 | +public type Color enum u8 { |
| 20 | + None, |
| 21 | + Black, |
| 22 | + Red, |
| 23 | + Green, |
| 24 | + Yellow, |
| 25 | + Blue, |
| 26 | + Magenta, |
| 27 | + Cyan, |
| 28 | + Grey, |
| 29 | + Darkgrey, |
| 30 | + Bred, |
| 31 | + Bgreen, |
| 32 | + Byellow, |
| 33 | + Bblue, |
| 34 | + Bmagenta, |
| 35 | + Bcyan, |
| 36 | + White, |
| 37 | + Normal, |
| 38 | +} |
| 39 | + |
| 40 | +public const Color Black = Black; |
| 41 | +public const Color Red = Red; |
| 42 | +public const Color Green = Green; |
| 43 | +public const Color Yellow = Yellow; |
| 44 | +public const Color Blue = Blue; |
| 45 | +public const Color Magenta = Magenta; |
| 46 | +public const Color Cyan = Cyan; |
| 47 | +public const Color Grey = Grey; |
| 48 | +public const Color Darkgrey = Darkgrey; |
| 49 | +public const Color Bred = Bred; |
| 50 | +public const Color Bgreen = Bgreen; |
| 51 | +public const Color Byellow = Byellow; |
| 52 | +public const Color Bblue = Bblue; |
| 53 | +public const Color Bmagenta = Bmagenta; |
| 54 | +public const Color Bcyan = Bcyan; |
| 55 | +public const Color White = White; |
| 56 | +public const Color Normal = Normal; |
| 57 | + |
| 58 | +const char*[elemsof(Color)] defaultColors = { |
| 59 | + [Color.None] = "", |
| 60 | + [Color.Black] = "\033[0;30m", |
| 61 | + [Color.Red] = "\033[0;31m", |
| 62 | + [Color.Green] = "\033[0;32m", |
| 63 | + [Color.Yellow] = "\033[0;33m", |
| 64 | + [Color.Blue] = "\033[0;34m", |
| 65 | + [Color.Magenta] = "\033[0;35m", |
| 66 | + [Color.Cyan] = "\033[0;36m", |
| 67 | + [Color.Grey] = "\033[0;37m", |
| 68 | + [Color.Darkgrey] = "\033[1;30m", |
| 69 | + [Color.Bred] = "\033[1;31m", |
| 70 | + [Color.Bgreen] = "\033[1;32m", |
| 71 | + [Color.Byellow] = "\033[1;33m", |
| 72 | + [Color.Bblue] = "\033[1;34m", |
| 73 | + [Color.Bmagenta] = "\033[1;35m", |
| 74 | + [Color.Bcyan] = "\033[1;36m", |
| 75 | + [Color.White] = "\033[1;37m", |
| 76 | + [Color.Normal] = "\033[0m", |
| 77 | +} |
36 | 78 |
|
37 | 79 | public fn bool useColor() { |
38 | 80 | return unistd.isatty(1); |
39 | 81 | } |
40 | 82 |
|
| 83 | +public fn const char* Color.str(Color col) { |
| 84 | + return defaultColors[col]; |
| 85 | +} |
0 commit comments