forked from DoomsdaySettlers/doomsday-season2-hitbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.colour.js
87 lines (61 loc) · 1.75 KB
/
console.colour.js
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
87
let cons = {};
cons.colours = {
black: 30,
red: 31,
green: 32,
yellow: 33,
blue: 34,
magenta: 35,
cyan: 36,
white: 37,
}
cons.colour = function(){
let args = [];
for(let i = 0; i < arguments.length; i++){
args.push(arguments[i]);
}
for(let i = 0; i < args.length; i++){
if(typeof args[i] === "string"){
let text = args[i];
let search, replacement;
for(let colour in cons.colours){
search = "@clear@";
replacement = "\x1b[0m";
text = text.replace(new RegExp(search, 'g'), replacement);
search = "#clear#";
text = text.replace(new RegExp(search, 'g'), replacement);
search = "@dark-"+colour+"@";
replacement = "\x1b["+cons.colours[colour]+"m";
text = text.replace(new RegExp(search, 'g'), replacement);
search = "@"+colour+"@";
replacement = "\x1b[1;"+cons.colours[colour]+"m";
text = text.replace(new RegExp(search, 'g'), replacement);
search = "#dark-"+colour+"#";
replacement = "\x1b["+(cons.colours[colour]+10)+"m";
text = text.replace(new RegExp(search, 'g'), replacement);
search = "#"+colour+"#";
replacement = "\x1b[1;"+(cons.colours[colour]+10)+"m";
text = text.replace(new RegExp(search, 'g'), replacement);
}
args[i] = text;
}
}
args.push("\x1b[0m");
console.log(...args);
}
for(let colour in cons.colours){
cons[colour] = function() {
cons.colour("@" + colour + "@", ...arguments);
}
cons[colour+"$"] = function() {
cons.colour("#" + colour + "#", ...arguments);
}
let colourName = colour.substr(0,1).toUpperCase() + colour.substr(1);
cons["dark"+colourName] = function(){
cons.colour("@dark-"+colour+"@",...arguments);
}
cons["dark"+colourName+"$"] = function(){
cons.colour("#dark-"+colour+"#",...arguments);
}
}
module.exports = cons;