Class TextColor.Indexed

java.lang.Object
com.googlecode.lanterna.TextColor.Indexed
All Implemented Interfaces:
TextColor, Serializable
Enclosing interface:
TextColor

public static class TextColor.Indexed extends Object implements TextColor
This class represents a color expressed in the indexed XTerm 256 color extension, where each color is defined in a lookup-table. All in all, there are 256 codes, but in order to know which one to know you either need to have the table at hand, or you can use the two static helper methods which can help you convert from three 8-bit RGB values to the closest approximate indexed color number. If you are interested, the 256 index values are actually divided like this:
0 .. 15 - System colors, same as ANSI, but the actual rendered color depends on the terminal emulators color scheme
16 .. 231 - Forms a 6x6x6 RGB color cube
232 .. 255 - A gray scale ramp (without black and white endpoints)

Support for indexed colors is somewhat widely adopted, not as much as the ANSI colors (TextColor.ANSI) but more than the RGB (TextColor.RGB).

For more details on this, please see this commit message to Konsole.

See Also:
  • Field Details

    • COLOR_TABLE

      private static final byte[][] COLOR_TABLE
    • colorIndex

      private final int colorIndex
  • Constructor Details

    • Indexed

      public Indexed(int colorIndex)
      Creates a new TextColor using the XTerm 256 color indexed mode, with the specified index value. You must choose a value between 0 and 255.
      Parameters:
      colorIndex - Index value to use for this color.
  • Method Details

    • getForegroundSGRSequence

      public byte[] getForegroundSGRSequence()
      Description copied from interface: TextColor
      Returns the byte sequence in between CSI and character 'm' that is used to enable this color as the foreground color on an ANSI-compatible terminal.
      Specified by:
      getForegroundSGRSequence in interface TextColor
      Returns:
      Byte array out data to output in between of CSI and 'm'
    • getBackgroundSGRSequence

      public byte[] getBackgroundSGRSequence()
      Description copied from interface: TextColor
      Returns the byte sequence in between CSI and character 'm' that is used to enable this color as the background color on an ANSI-compatible terminal.
      Specified by:
      getBackgroundSGRSequence in interface TextColor
      Returns:
      Byte array out data to output in between of CSI and 'm'
    • getRed

      public int getRed()
      Specified by:
      getRed in interface TextColor
      Returns:
      Red intensity of this color, from 0 to 255
    • getGreen

      public int getGreen()
      Specified by:
      getGreen in interface TextColor
      Returns:
      Green intensity of this color, from 0 to 255
    • getBlue

      public int getBlue()
      Specified by:
      getBlue in interface TextColor
      Returns:
      Blue intensity of this color, from 0 to 255
    • toColor

      public Color toColor()
      Description copied from interface: TextColor
      Converts this color to an AWT color object, assuming a standard VGA palette.
      Specified by:
      toColor in interface TextColor
      Returns:
      TextColor as an AWT Color
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • fromRGB

      public static TextColor.Indexed fromRGB(int red, int green, int blue)
      Picks out a color approximated from the supplied RGB components
      Parameters:
      red - Red intensity, from 0 to 255
      green - Red intensity, from 0 to 255
      blue - Red intensity, from 0 to 255
      Returns:
      Nearest color from the 6x6x6 RGB color cube or from the 24 entries grey-scale ramp (whichever is closest)
    • fromGreyRamp

      private static TextColor.Indexed fromGreyRamp(int intensity)
      Picks out a color from the grey-scale ramp area of the color index.
      Parameters:
      intensity - Intensity, 0 - 255
      Returns:
      Indexed color from the grey-scale ramp which is the best match for the supplied intensity