Enum Class TerminalColor
- All Implemented Interfaces:
Serializable, Comparable<TerminalColor>, Constable
ANSI escape sequences for colors, to style text in terminal
environments.
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescription -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionStyle the given string with this color.private intgetCode(boolean bright, boolean background) private StringgetEscape(boolean bright, boolean background, boolean bold) static Stringstyle(String text, TerminalColor foreground, TerminalColor background, boolean brightFg, boolean brightBg, boolean boldText) Style both foreground and background.static TerminalColorReturns the enum constant of this class with the specified name.static TerminalColor[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
COL_BLACK
-
COL_RED
-
COL_GREEN
-
COL_YELLOW
-
COL_BLUE
-
COL_MAGENTA
-
COL_CYAN
-
COL_WHITE
-
-
Field Details
-
ANSI_RESET
-
ESCAPE
- See Also:
-
fgCode
private final int fgCode
-
-
Constructor Details
-
TerminalColor
private TerminalColor(int fgCode)
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
getEscape
-
getCode
private int getCode(boolean bright, boolean background) -
apply
Style the given string with this color. All text attributes are reset at the end.- Parameters:
text- Text to colorbright- Whether to use a bright version of this colorbackground- Whether to set the color on the text background rather than on the colorbold- Whether to set the text as bold- Returns:
- A string surrounded by escape sequences
-
style
public static String style(String text, TerminalColor foreground, TerminalColor background, boolean brightFg, boolean brightBg, boolean boldText) Style both foreground and background. Returns a new string containing the parameter, which uses this ANSI code at the beginning, and resets all text attributes at the end.- Parameters:
text- Text to colorforeground- Text colorbackground- Background colorbrightFg- Whether text color is brightbrightBg- Whether background color is brightboldText- Whether to set the text as bold- Returns:
- A string surrounded by escape sequences
-