-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolors.js
244 lines (216 loc) · 7.49 KB
/
colors.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
// TODO: EASILY CONSOLE.LOG COLORS, PATTERNS, YOU NAME IT
// Foreground (text) colors:
const CyanText = (text) => `\x1b[36m${text}\x1b[0m`;
const BlackText = (text) => `\x1b[30m${text}\x1b[0m`;
const GreenText = (text) => `\x1b[32m${text}\x1b[0m`;
const RedText = (text) => `\x1b[31m${text}\x1b[0m`;
const YellowText = (text) => `\x1b[33m${text}\x1b[0m`;
const BlueText = (text) => `\x1b[34m${text}\x1b[0m`;
const MagentaText = (text) => `\x1b[35m${text}\x1b[0m`;
const WhiteText = (text) => `\x1b[37m${text}\x1b[0m`;
const OrangeText = (text) => `\x1b[38;5;208m${text}\x1b[0m`;
// Bright foreground colors:
const BrightCyanText = (text) => `\x1b[96m${text}\x1b[0m`;
const BrightBlackText = (text) => `\x1b[90m${text}\x1b[0m`;
const BrightGreenText = (text) => `\x1b[92m${text}\x1b[0m`;
const BrightRedText = (text) => `\x1b[91m${text}\x1b[0m`;
const BrightYellowText = (text) => `\x1b[93m${text}\x1b[0m`;
const BrightBlueText = (text) => `\x1b[94m${text}\x1b[0m`;
const BrightMagentaText = (text) => `\x1b[95m${text}\x1b[0m`;
const BrightWhiteText = (text) => `\x1b[97m${text}\x1b[0m`;
const BrightOrangeText = (text) => `\x1b[1;38;5;214m${text}\x1b[0m`;
// Background colors:
const CyanBackground = (text) => `\x1b[46m${text}\x1b[0m`;
const BlackBackground = (text) => `\x1b[40m${text}\x1b[0m`;
const GreenBackground = (text) => `\x1b[42m${text}\x1b[0m`;
const RedBackground = (text) => `\x1b[41m${text}\x1b[0m`;
const YellowBackground = (text) => `\x1b[43m${text}\x1b[0m`;
const BlueBackground = (text) => `\x1b[44m${text}\x1b[0m`;
const MagentaBackground = (text) => `\x1b[45m${text}\x1b[0m`;
const WhiteBackground = (text) => `\x1b[47m${text}\x1b[0m`;
const OrangeBackground = (text) => `\x1b[48;5;208m${text}\x1b[0m`;
// Bright background colors:
const BrightCyanBackground = (text) => `\x1b[106m${text}\x1b[0m`;
const BrightBlackBackground = (text) => `\x1b[100m${text}\x1b[0m`;
const BrightGreenBackground = (text) => `\x1b[102m${text}\x1b[0m`;
const BrightRedBackground = (text) => `\x1b[101m${text}\x1b[0m`;
const BrightYellowBackground = (text) => `\x1b[103m${text}\x1b[0m`;
const BrightBlueBackground = (text) => `\x1b[104m${text}\x1b[0m`;
const BrightMagentaBackground = (text) => `\x1b[105m${text}\x1b[0m`;
const BrightWhiteBackground = (text) => `\x1b[107m${text}\x1b[0m`;
const BrightOrangeBackground = (text) => `\x1b[1;48;5;214m${text}\x1b[0m`;
// ! ------------------------------------------------------------------------------------------------
const RainbowText = (text) => {
const colors = [
"\x1b[31m", // Red
"\x1b[33m", // Yellow
"\x1b[32m", // Green
"\x1b[36m", // Cyan
"\x1b[34m", // Blue
"\x1b[35m", // Magenta
];
const reset = "\x1b[0m";
let rainbowOutput = "";
for (let i = 0; i < text.length; i++) {
const color = colors[i % colors.length];
rainbowOutput += color + text[i];
}
return rainbowOutput + reset;
};
const ChristmasText = (text) => {
const colors = [
"\x1b[31m", // Red
"\x1b[37m", // White
"\x1b[32m", // Green
];
const reset = "\x1b[0m";
let christmasOutput = "";
for (let i = 0; i < text.length; i++) {
const color = colors[i % colors.length];
christmasOutput += color + text[i];
}
return christmasOutput + reset;
};
const IcyText = (text) => {
const colors = [
"\x1b[94m", // Bright Blue
"\x1b[37m", // White
"\x1b[96m", // Bright Cyan
];
const reset = "\x1b[0m";
let icyOutput = "";
for (let i = 0; i < text.length; i++) {
const color = colors[i % colors.length];
icyOutput += color + text[i];
}
return icyOutput + reset;
};
const FieryText = (text) => {
const colors = [
"\x1b[91m", // Bright Red
"\x1b[93m", // Bright Yellow
"\x1b[37m", // White
];
const reset = "\x1b[0m";
let fieryOutput = "";
for (let i = 0; i < text.length; i++) {
const color = colors[i % colors.length];
fieryOutput += color + text[i];
}
return fieryOutput + reset;
};
const ZebraText = (text) => {
let result = "";
for (let i = 0; i < text.length; i++) {
// Alternate between black and white background
const backgroundColor = i % 2 === 0 ? "\x1b[40m" : "\x1b[47m";
// Set text color to black or white
const textColor = i % 2 === 0 ? "\x1b[37m" : "\x1b[30m";
// Add ANSI escape codes for background and text color
result += `${backgroundColor}${textColor}${text[i]}`;
}
// Reset colors at the end
result += "\x1b[0m";
return result;
};
// ! ------------------------------------------------------------------------------------------------
const ItalicText = (text) => `\x1b[3m${text}\x1b[0m`;
const BoldText = (text) => `\x1b[1m${text}\x1b[0m`;
const UnderlineText = (text) => `\x1b[4m${text}\x1b[0m`;
const OverlineText = (text) => `\x1b[53m${text}\x1b[0m`;
const DoubleUnderlineText = (text) => `\x1b[21m${text}\x1b[0m`;
// ? These do not work, at least not in my environment
// const DottedUnderlineText = (text) => `\x1b[4:3m${text}\x1b[0m`;
// const CurlyUnderlineText = (text) => `\x1b[4:4m${text}\x1b[0m`;
// const FramedText = (text) => `\x1b[51m${text}\x1b[0m`;
// const EncircledText = (text) => `\x1b[52m${text}\x1b[0m`;
const InverseColors = (text) => `\x1b[7m${text}\x1b[0m`;
const FaintText = (text) => `\x1b[2m${text}\x1b[0m`;
// ? Blink is outdated, poses accessibility concerns, and doesn't work in general. I'm still keeping it here commented out.
// const Blink = (text) => `\x1b[5m${text}\x1b[0m`;
// const SlowBlinkText = (text) => `\x1b[6m${text}\x1b[0m`;
// const FastBlinkText = (text) => `\x1b[25m${text}\x1b[0m`;
const Hidden = (text) => `\x1b[8m${text}\x1b[0m`;
const CrossedOut = (text) => `\x1b[9m${text}\x1b[0m`;
// ! ------------------------------------------------------------------------------------------------
const colors = {
CyanText,
BlackText,
GreenText,
RedText,
OrangeText,
YellowText,
BlueText,
MagentaText,
WhiteText,
BrightCyanText,
BrightBlackText,
BrightGreenText,
BrightRedText,
BrightOrangeText,
BrightYellowText,
BrightBlueText,
BrightMagentaText,
BrightWhiteText,
RainbowText,
ChristmasText,
IcyText,
FieryText,
ZebraText,
UnderlineText,
DoubleUnderlineText,
ItalicText,
BoldText,
OverlineText,
InverseColors,
FaintText,
Hidden,
CrossedOut,
CyanBackground,
BlackBackground,
GreenBackground,
RedBackground,
OrangeBackground,
YellowBackground,
BlueBackground,
MagentaBackground,
WhiteBackground,
BrightCyanBackground,
BrightBlackBackground,
BrightGreenBackground,
BrightRedBackground,
BrightOrangeBackground,
BrightYellowBackground,
BrightBlueBackground,
BrightMagentaBackground,
BrightWhiteBackground,
};
const testPrint = () => {
const colorFunctions = {};
// Iterate over the functions in the module
for (const functionName in colors) {
const functionValue = colors[functionName];
// Check if it's a function
if (typeof functionValue === "function") {
// Add the function to the colorFunctions object
colorFunctions[functionName] = functionValue;
}
}
// Now you can use colorFunctions in the loop
for (const [colorName, colorFunction] of Object.entries(colorFunctions)) {
const coloredText = colorFunction(colorName);
console.log(coloredText);
}
};
// ! ------------------------------------------------------------------------------------------------
const RGBtoANSIfuncs = require("./RGBtoANSI");
const CSStoANSIfuncs = require("./CSStoANSI");
const HEXtoANSIfuncs = require("./HEXtoANSI");
const allFunctions = {
...colors,
testPrint,
...RGBtoANSIfuncs,
...CSStoANSIfuncs,
...HEXtoANSIfuncs,
};
module.exports = allFunctions;