java.lang.Object
com.googlecode.lanterna.TextColor.Indexed
- All Implemented Interfaces:
TextColor
,Serializable
- Enclosing interface:
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)
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.googlecode.lanterna.TextColor
TextColor.ANSI, TextColor.Factory, TextColor.Indexed, TextColor.RGB
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[][]
private final int
-
Constructor Summary
ConstructorsConstructorDescriptionIndexed
(int colorIndex) Creates a new TextColor using the XTerm 256 color indexed mode, with the specified index value. -
Method Summary
Modifier and TypeMethodDescriptionboolean
private static TextColor.Indexed
fromGreyRamp
(int intensity) Picks out a color from the grey-scale ramp area of the color index.static TextColor.Indexed
fromRGB
(int red, int green, int blue) Picks out a color approximated from the supplied RGB componentsbyte[]
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.int
getBlue()
byte[]
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.int
getGreen()
int
getRed()
int
hashCode()
toColor()
Converts this color to an AWT color object, assuming a standard VGA palette.toString()
-
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 interfaceTextColor
- 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 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
Description copied from interface:TextColor
Converts this color to an AWT color object, assuming a standard VGA palette. -
toString
-
hashCode
public int hashCode() -
equals
-
fromRGB
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
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
-