1 //basic ansi color formatting
2 module util.colour;
3 import std.format : format;
4 
5 void toggleColour()
6 {
7     if(colouredOutput)
8         colouredOutput = false;
9     else 
10         colouredOutput = true;
11 }
12 bool colouredOutput = true;
13 ///Codes for ANSI Text Attributes
14 enum TextAttribute : byte
15 {
16     allOff = 0,
17     bold = 1,
18     underline = 4,
19     blink = 5,
20     reverseVideo = 7,
21     concealed = 8
22 }
23 ////Basic foregroudn colours
24 enum ForegroundColour : byte
25 {
26     Black = 30,
27     Red = 31,
28     Green = 32,
29     Yellow = 33,
30     Blue = 34,
31     Magenta = 35,
32     Cyan = 36,
33     White = 37
34 }
35 ///Basic background colors
36 enum BackgroundColour : byte
37 {
38     Black = 40,
39     Red = 41,
40     Green = 42,
41     Yellow = 43,
42     Blue = 44,
43     Magenta = 45,
44     Cyan = 46,
45     White = 47
46 }
47 ///Who cares about efficiency, write string with attribute applied
48 string attributeString(string term = "\033[0m")(string input, TextAttribute ta)
49 {
50     if(!colouredOutput) return input;
51     return format!"\033[%dm%s%s"(ta, input, term);
52 }
53 string colourString(string term = "\033[0m")(string input,
54         ForegroundColour fg = ForegroundColour.White, BackgroundColour bg = BackgroundColour.Black)
55 {
56     if(!colouredOutput) return input;
57     return format!"\033[%d;%dm%s%s"(fg, bg, input, term);
58 
59 }