1 module ColourfulMoon;
2 /**
3 * Simple text styling library
4 */
5 
6 /**
7 * Text style
8 * Params:
9 *	s = input text
10 * Returns: Styled text.
11 */
12 string Reset(string s = "") {
13 	return s ~ "\033[0m";
14 }
15 /// ditto
16 string Bold(string s = "") {
17 	return "\033[1m" ~ s;
18 }
19 /// ditto
20 string Underline(string s = "") {
21 	return "\033[4m" ~ s;
22 }
23 /// ditto
24 string Blink(string s = "") {
25 	return "\033[5m" ~ s;
26 }
27 /// ditto
28 string Reverse(string s = "") {
29 	return "\033[7m" ~ s;
30 }
31 
32 private string Colour(ubyte R = 0, ubyte G = 0, ubyte B = 0) {
33 	import std.math : floor;
34 	import std.conv : to;
35 
36 	if(R == G && R == B) {
37 		return to!string((R > 239) ? 15 : floor(cast(real) R / 10) + 232);
38 	} else {
39 		return to!string(16 + 36 * floor(cast(real) R / 51) + 6 * floor(cast(real) G / 51) + floor(cast(real) B / 51));
40 	}
41 }
42 
43 /**
44 * Text colour
45 * Params:
46 *	s = input text
47 *	R = Red
48 *	G = Green
49 *	B = Blue
50 * Returns: Coloured text.
51 */
52 string Foreground(string s = "", ubyte R = 0, ubyte G = 0, ubyte B = 0) {
53 	return "\033[38;05;" ~ Colour(R, G, B) ~ "m" ~ s;
54 }
55 /// ditto
56 string Background(string s = "", ubyte R = 0, ubyte G = 0, ubyte B = 0) {
57 	return "\033[48;05;" ~ Colour(R, G, B) ~ "m" ~ s;
58 }