- java.lang.Object
-
- com.googlecode.lanterna.TextColor.Indexed
-
- All Implemented Interfaces:
TextColor,java.io.Serializable
- Enclosing interface:
- TextColor
public static class TextColor.Indexed extends java.lang.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:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.googlecode.lanterna.TextColor
TextColor.ANSI, TextColor.Factory, TextColor.Indexed, TextColor.RGB
-
-
Field Summary
Fields Modifier and Type Field Description private static byte[][]COLOR_TABLEprivate intcolorIndex
-
Constructor Summary
Constructors Constructor Description Indexed(int colorIndex)Creates a new TextColor using the XTerm 256 color indexed mode, with the specified index value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)private static TextColor.IndexedfromGreyRamp(int intensity)Picks out a color from the grey-scale ramp area of the color index.static TextColor.IndexedfromRGB(int red, int green, int blue)Picks out a color approximated from the supplied RGB componentsbyte[]getBackgroundSGRSequence()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.intgetBlue()byte[]getForegroundSGRSequence()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.intgetGreen()intgetRed()inthashCode()java.awt.ColortoColor()Converts this color to an AWT color object, assuming a standard VGA palette.java.lang.StringtoString()
-
-
-
Method Detail
-
getForegroundSGRSequence
public byte[] getForegroundSGRSequence()
Description copied from interface:TextColorReturns 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:
getForegroundSGRSequencein interfaceTextColor- Returns:
- Byte array out data to output in between of CSI and 'm'
-
getBackgroundSGRSequence
public byte[] getBackgroundSGRSequence()
Description copied from interface:TextColorReturns 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:
getBackgroundSGRSequencein interfaceTextColor- Returns:
- Byte array out data to output in between of CSI and 'm'
-
getRed
public int getRed()
-
getGreen
public int getGreen()
-
getBlue
public int getBlue()
-
toColor
public java.awt.Color toColor()
Description copied from interface:TextColorConverts this color to an AWT color object, assuming a standard VGA palette.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.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 255green- Red intensity, from 0 to 255blue- 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
-
-