- Notifications
You must be signed in to change notification settings - Fork 670
/
Copy pathterminal.ts
43 lines (38 loc) · 1.3 KB
/
terminal.ts
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
/**
* @fileoverview Terminal utility.
* @license Apache-2.0
*/
/** Gray terminal color code. */
exportconstCOLOR_GRAY="\u001b[90m";
/** Red terminal color code. */
exportconstCOLOR_RED="\u001b[91m";
/** Green terminal color code. */
exportconstCOLOR_GREEN="\u001b[92m";
/** Yellow terminal color code. */
exportconstCOLOR_YELLOW="\u001b[93m";
/** Blue terminal color code. */
exportconstCOLOR_BLUE="\u001b[94m";
/** Magenta terminal color code. */
exportconstCOLOR_MAGENTA="\u001b[95m";
/** Cyan terminal color code. */
exportconstCOLOR_CYAN="\u001b[96m";
/** White terminal color code. */
exportconstCOLOR_WHITE="\u001b[97m";
/** Terminal color reset code. */
exportconstCOLOR_RESET="\u001b[0m";
/** Whether terminal colors are enabled or not. */
letcolorsEnabled=true;
/** Checks whether terminal colors are enabled or not. */
exportfunctionisColorsEnabled(): bool{
returncolorsEnabled;
}
/** Sets whether terminal colors are enabled or not. */
exportfunctionsetColorsEnabled(isEnabled: bool): bool{
letwasEnabled=isEnabled;
colorsEnabled=isEnabled;
returnwasEnabled;
}
/** Wraps the specified text in the specified terminal color code. */
exportfunctioncolorize(text: string,color: string): string{
returncolorsEnabled ? color+text+COLOR_RESET : text;
}