forked from auberonedu/truffula
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathConsoleColor.java
More file actions
98 lines (86 loc) · 2.06 KB
/
ConsoleColor.java
File metadata and controls
98 lines (86 loc) · 2.06 KB
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
/**
* Enum representing ANSI escape codes for console text colors.
*
* These colors can be used to format console output by applying the corresponding
* ANSI escape codes. The colors affect the text color in supported terminals.
*
* To apply a color, prepend the ANSI code to the text, and append the RESET code
* ("\033[0m") after the text to reset the color back to default.
*
* Supported Colors:
* - BLACK : Black text
* - RED : Red text
* - GREEN : Green text
* - YELLOW : Yellow text
* - BLUE : Blue text
* - PURPLE : Purple text
* - CYAN : Cyan text
* - WHITE : White text
* - RESET : Resets the text color to default
*/
public enum ConsoleColor
{
/**
* Black text color (ANSI code: \033[0;30m).
*/
BLACK("\033[0;30m"),
/**
* Red text color (ANSI code: \033[0;31m).
*/
RED("\033[0;31m"),
/**
* Green text color (ANSI code: \033[0;32m).
*/
GREEN("\033[0;32m"),
/**
* Yellow text color (ANSI code: \033[0;33m).
*/
YELLOW("\033[0;33m"),
/**
* Blue text color (ANSI code: \033[0;34m).
*/
BLUE("\033[0;34m"),
/**
* Purple text color (ANSI code: \033[0;35m).
*/
PURPLE("\033[0;35m"),
/**
* Cyan text color (ANSI code: \033[0;36m).
*/
CYAN("\033[0;36m"),
/**
* White text color (ANSI code: \033[0;37m).
*/
WHITE("\033[0;37m"),
/**
* Resets the text color to the terminal's default color (ANSI code: \033[0m).
*/
RESET("\033[0m");
private final String code;
/**
* Constructs a ConsoleColor with the given ANSI escape code.
*
* @param code the ANSI escape code for the color
*/
ConsoleColor(String code) {
this.code = code;
}
/**
* Returns the ANSI escape code associated with the color.
*
* @return the ANSI escape code as a String
*/
public String getCode() {
return code;
}
/**
* Returns the ANSI escape code as a String. This allows the enum to be used
* directly in print statements.
*
* @return the ANSI escape code as a String
*/
@Override
public String toString() {
return code;
}
}