Class Color


  • public final class Color
    extends java.lang.Object
    An immutable terminal color: the terminal default, a named ANSI color, a 256-color palette index, or 24-bit RGB. Instances compare by value.
    • Field Detail

      • DEFAULT

        public static final Color DEFAULT
        The terminal's default color.
      • BLACK

        public static final Color BLACK
      • RED

        public static final Color RED
      • GREEN

        public static final Color GREEN
      • YELLOW

        public static final Color YELLOW
      • BLUE

        public static final Color BLUE
      • MAGENTA

        public static final Color MAGENTA
      • CYAN

        public static final Color CYAN
      • WHITE

        public static final Color WHITE
      • BRIGHT_BLACK

        public static final Color BRIGHT_BLACK
      • BRIGHT_RED

        public static final Color BRIGHT_RED
      • BRIGHT_GREEN

        public static final Color BRIGHT_GREEN
      • BRIGHT_YELLOW

        public static final Color BRIGHT_YELLOW
      • BRIGHT_BLUE

        public static final Color BRIGHT_BLUE
      • BRIGHT_MAGENTA

        public static final Color BRIGHT_MAGENTA
      • BRIGHT_CYAN

        public static final Color BRIGHT_CYAN
      • BRIGHT_WHITE

        public static final Color BRIGHT_WHITE
    • Method Detail

      • ansi256

        public static Color ansi256​(int index)
        Creates a color from a 256-color palette index.
        Parameters:
        index - palette index, clamped to 0-255
        Returns:
        the indexed color
      • rgb

        public static Color rgb​(int red,
                                int green,
                                int blue)
        Creates a 24-bit truecolor.
        Parameters:
        red - red channel, clamped to 0-255
        green - green channel, clamped to 0-255
        blue - blue channel, clamped to 0-255
        Returns:
        the RGB color
      • foregroundSgr

        public java.lang.String foregroundSgr()
        Returns:
        the SGR parameters for this color as the foreground, without the leading separator
      • backgroundSgr

        public java.lang.String backgroundSgr()
        Returns:
        the SGR parameters for this color as the background, without the leading separator
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object