Enum Class AnsiColor

java.lang.Object
java.lang.Enum<AnsiColor>
cloud.opencode.base.log.spi.AnsiColor
All Implemented Interfaces:
Serializable, Comparable<AnsiColor>, Constable

public enum AnsiColor extends Enum<AnsiColor>
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:
  • Enum Constant Details

    • RESET

      public static final AnsiColor RESET
      Reset all attributes - 重置所有属性
    • BLACK

      public static final AnsiColor BLACK
      Black foreground - 黑色前景
    • RED

      public static final AnsiColor RED
      Red foreground - 红色前景
    • GREEN

      public static final AnsiColor GREEN
      Green foreground - 绿色前景
    • YELLOW

      public static final AnsiColor YELLOW
      Yellow foreground - 黄色前景
    • BLUE

      public static final AnsiColor BLUE
      Blue foreground - 蓝色前景
    • MAGENTA

      public static final AnsiColor MAGENTA
      Magenta foreground - 洋红色前景
    • CYAN

      public static final AnsiColor CYAN
      Cyan foreground - 青色前景
    • WHITE

      public static final AnsiColor WHITE
      White foreground - 白色前景
    • BRIGHT_BLACK

      public static final AnsiColor BRIGHT_BLACK
      Bright black (gray) foreground - 亮黑色(灰色)前景
    • BRIGHT_RED

      public static final AnsiColor BRIGHT_RED
      Bright red foreground - 亮红色前景
    • BRIGHT_GREEN

      public static final AnsiColor BRIGHT_GREEN
      Bright green foreground - 亮绿色前景
    • BRIGHT_YELLOW

      public static final AnsiColor BRIGHT_YELLOW
      Bright yellow foreground - 亮黄色前景
    • BRIGHT_BLUE

      public static final AnsiColor BRIGHT_BLUE
      Bright blue foreground - 亮蓝色前景
    • BRIGHT_MAGENTA

      public static final AnsiColor BRIGHT_MAGENTA
      Bright magenta foreground - 亮洋红色前景
    • BRIGHT_CYAN

      public static final AnsiColor BRIGHT_CYAN
      Bright cyan foreground - 亮青色前景
    • BRIGHT_WHITE

      public static final AnsiColor BRIGHT_WHITE
      Bright white foreground - 亮白色前景
    • BOLD

      public static final AnsiColor BOLD
      Bold style - 粗体样式
    • BOLD_RED

      public static final AnsiColor BOLD_RED
      Bold red - 粗体红色
    • BOLD_YELLOW

      public static final AnsiColor BOLD_YELLOW
      Bold yellow - 粗体黄色
    • BOLD_GREEN

      public static final AnsiColor BOLD_GREEN
      Bold green - 粗体绿色
  • Method Details

    • values

      public static AnsiColor[] 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

      public static AnsiColor valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • getCode

      public String getCode()
      Returns the ANSI escape code. 返回 ANSI 转义码。
      Returns:
      the escape code string - 转义码字符串
    • wrap

      public String wrap(String text)
      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

      public String toString()
      Returns the ANSI escape code. 返回 ANSI 转义码。
      Overrides:
      toString in class Enum<AnsiColor>
      Returns:
      the escape code string - 转义码字符串