Enum Class AnsiColor
- All Implemented Interfaces:
Serializable, Comparable<AnsiColor>, Constable
ANSI Color Code Enumeration - Defines Terminal Color Escape Sequences
ANSI 颜色代码枚举 - 定义终端颜色转义序列
This enum provides standard ANSI escape codes for terminal text coloring, including normal colors, bright variants, and bold styles.
此枚举提供标准 ANSI 转义码用于终端文本着色, 包括普通颜色、亮色变体和粗体样式。
Features | 主要功能:
- 16 standard and bright foreground colors - 16 种标准和亮色前景色
- Bold style variants - 粗体样式变体
- Convenient text wrapping with automatic reset - 便捷的文本包装并自动重置
- Safe for terminals that do not support ANSI - 对不支持 ANSI 的终端安全
Usage Examples | 使用示例:
// Wrap text with color
String red = AnsiColor.RED.wrap("Error message");
// Get raw escape code
String code = AnsiColor.GREEN.getCode();
Security | 安全性:
- Thread-safe: Yes (immutable enum) - 线程安全: 是(不可变枚举)
- Since:
- JDK 25, opencode-base-log V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionBlack foreground - 黑色前景Blue foreground - 蓝色前景Bold style - 粗体样式Bold green - 粗体绿色Bold red - 粗体红色Bold yellow - 粗体黄色Bright black (gray) foreground - 亮黑色(灰色)前景Bright blue foreground - 亮蓝色前景Bright cyan foreground - 亮青色前景Bright green foreground - 亮绿色前景Bright magenta foreground - 亮洋红色前景Bright red foreground - 亮红色前景Bright white foreground - 亮白色前景Bright yellow foreground - 亮黄色前景Cyan foreground - 青色前景Green foreground - 绿色前景Magenta foreground - 洋红色前景Red foreground - 红色前景Reset all attributes - 重置所有属性White foreground - 白色前景Yellow foreground - 黄色前景 -
Method Summary
Modifier and TypeMethodDescriptiongetCode()Returns the ANSI escape code.toString()Returns the ANSI escape code.static AnsiColorReturns the enum constant of this class with the specified name.static AnsiColor[]values()Returns an array containing the constants of this enum class, in the order they are declared.Wraps the given text with this color code and a trailing RESET.
-
Enum Constant Details
-
RESET
Reset all attributes - 重置所有属性 -
BLACK
Black foreground - 黑色前景 -
RED
Red foreground - 红色前景 -
GREEN
Green foreground - 绿色前景 -
YELLOW
Yellow foreground - 黄色前景 -
BLUE
Blue foreground - 蓝色前景 -
MAGENTA
Magenta foreground - 洋红色前景 -
CYAN
Cyan foreground - 青色前景 -
WHITE
White foreground - 白色前景 -
BRIGHT_BLACK
Bright black (gray) foreground - 亮黑色(灰色)前景 -
BRIGHT_RED
Bright red foreground - 亮红色前景 -
BRIGHT_GREEN
Bright green foreground - 亮绿色前景 -
BRIGHT_YELLOW
Bright yellow foreground - 亮黄色前景 -
BRIGHT_BLUE
Bright blue foreground - 亮蓝色前景 -
BRIGHT_MAGENTA
Bright magenta foreground - 亮洋红色前景 -
BRIGHT_CYAN
Bright cyan foreground - 亮青色前景 -
BRIGHT_WHITE
Bright white foreground - 亮白色前景 -
BOLD
Bold style - 粗体样式 -
BOLD_RED
Bold red - 粗体红色 -
BOLD_YELLOW
Bold yellow - 粗体黄色 -
BOLD_GREEN
Bold green - 粗体绿色
-
-
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
-
getCode
Returns the ANSI escape code. 返回 ANSI 转义码。- Returns:
- the escape code string - 转义码字符串
-
wrap
Wraps the given text with this color code and a trailing RESET. 使用此颜色代码包装给定文本,并在末尾添加 RESET。- Parameters:
text- the text to wrap - 要包装的文本- Returns:
- the colored text - 着色后的文本
- Throws:
NullPointerException- if text is null - 如果 text 为 null
-
toString
-