java.lang.Object
com.googlecode.lanterna.TextCharacter
- All Implemented Interfaces:
Serializable
Represents a single character with additional metadata such as colors and modifiers. This class is immutable and
cannot be modified after creation.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final TextColor
private final String
The "character" might not fit in a Java 16-bit char (emoji and other types) so we store it in a String as of 3.1 instead.static final TextCharacter
private final TextColor
-
Constructor Summary
ConstructorsModifierConstructorDescriptionTextCharacter
(char character) Deprecated.Use fromCharacter insteadTextCharacter
(char character, TextColor foregroundColor, TextColor backgroundColor, SGR... styles) Deprecated.Use fromCharacter insteadTextCharacter
(char character, TextColor foregroundColor, TextColor backgroundColor, EnumSet<SGR> modifiers) Deprecated.Use fromCharacter insteadTextCharacter
(TextCharacter character) Deprecated.TextCharacters are immutable so you shouldn't need to call thisprivate
TextCharacter
(String character, TextColor foregroundColor, TextColor backgroundColor, EnumSet<SGR> modifiers) Creates a newScreenCharacter
based on a physical character, color information and a set of modifiers. -
Method Summary
Modifier and TypeMethodDescriptionboolean
static TextCharacter[]
fromCharacter
(char c) static TextCharacter[]
fromCharacter
(char c, TextColor foregroundColor, TextColor backgroundColor, SGR... modifiers) static TextCharacter[]
fromString
(String string) static TextCharacter[]
fromString
(String string, TextColor foregroundColor, TextColor backgroundColor, SGR... modifiers) static TextCharacter[]
fromString
(String string, TextColor foregroundColor, TextColor backgroundColor, EnumSet<SGR> modifiers) Background color specified for this TextCharacterchar
Deprecated.This won't work with advanced characters like emojiReturns the character this TextCharacter represents as a String.Foreground color specified for this TextCharacterReturns a set of all active modifiers on this TextCharacterint
hashCode()
boolean
is
(char otherCharacter) boolean
Returns true if this TextCharacter has the blink modifier activeboolean
isBold()
Returns true if this TextCharacter has the bold modifier activeboolean
Returns true if this TextCharacter has the bordered modifier activeboolean
Returns true if this TextCharacter has the crossed-out modifier activeboolean
private static boolean
boolean
isItalic()
Returns true if this TextCharacter has the italic modifier activeboolean
Returns true if this TextCharacter has the reverse modifier activeboolean
Returns true if this TextCharacter has the underline modifier activetoString()
private void
validateSingleCharacter
(String character) withBackgroundColor
(TextColor backgroundColor) Returns a copy of this TextCharacter with a specified background colorwithCharacter
(char character) Returns a new TextCharacter with the same colors and modifiers but a different underlying characterwithForegroundColor
(TextColor foregroundColor) Returns a copy of this TextCharacter with a specified foreground colorwithModifier
(SGR modifier) Returns a copy of this TextCharacter with an additional SGR modifier.withModifiers
(Collection<SGR> modifiers) Returns a copy of this TextCharacter with specified list of SGR modifiers.withoutModifier
(SGR modifier) Returns a copy of this TextCharacter with an SGR modifier removed.
-
Field Details
-
DEFAULT_CHARACTER
-
character
The "character" might not fit in a Java 16-bit char (emoji and other types) so we store it in a String as of 3.1 instead. -
foregroundColor
-
backgroundColor
-
modifiers
-
-
Constructor Details
-
TextCharacter
Deprecated.Use fromCharacter insteadCreates aScreenCharacter
based on a supplied character, with default colors and no extra modifiers.- Parameters:
character
- Physical character to use
-
TextCharacter
Deprecated.TextCharacters are immutable so you shouldn't need to call thisCopies anotherScreenCharacter
- Parameters:
character
- screenCharacter to copy from
-
TextCharacter
@Deprecated public TextCharacter(char character, TextColor foregroundColor, TextColor backgroundColor, SGR... styles) Deprecated.Use fromCharacter insteadCreates a newScreenCharacter
based on a physical character, color information and optional modifiers.- Parameters:
character
- Physical character to refer toforegroundColor
- Foreground color the character hasbackgroundColor
- Background color the character hasstyles
- Optional list of modifiers to apply when drawing the character
-
TextCharacter
@Deprecated public TextCharacter(char character, TextColor foregroundColor, TextColor backgroundColor, EnumSet<SGR> modifiers) Deprecated.Use fromCharacter insteadCreates a newScreenCharacter
based on a physical character, color information and a set of modifiers.- Parameters:
character
- Physical character to refer toforegroundColor
- Foreground color the character hasbackgroundColor
- Background color the character hasmodifiers
- Set of modifiers to apply when drawing the character
-
TextCharacter
private TextCharacter(String character, TextColor foregroundColor, TextColor backgroundColor, EnumSet<SGR> modifiers) Creates a newScreenCharacter
based on a physical character, color information and a set of modifiers.- Parameters:
character
- Physical character to refer toforegroundColor
- Foreground color the character hasbackgroundColor
- Background color the character hasmodifiers
- Set of modifiers to apply when drawing the character
-
-
Method Details
-
toEnumSet
-
fromCharacter
-
fromString
-
fromCharacter
public static TextCharacter[] fromCharacter(char c, TextColor foregroundColor, TextColor backgroundColor, SGR... modifiers) -
fromString
public static TextCharacter[] fromString(String string, TextColor foregroundColor, TextColor backgroundColor, SGR... modifiers) -
fromString
-
validateSingleCharacter
-
is
public boolean is(char otherCharacter) -
getCharacter
Deprecated.This won't work with advanced characters like emojiThe actual character this TextCharacter represents- Returns:
- character of the TextCharacter
-
getCharacterString
Returns the character this TextCharacter represents as a String. This is not returning a char- Returns:
-
getForegroundColor
Foreground color specified for this TextCharacter- Returns:
- Foreground color of this TextCharacter
-
getBackgroundColor
Background color specified for this TextCharacter- Returns:
- Background color of this TextCharacter
-
getModifiers
Returns a set of all active modifiers on this TextCharacter- Returns:
- Set of active SGR codes
-
isBold
public boolean isBold()Returns true if this TextCharacter has the bold modifier active- Returns:
true
if this TextCharacter has the bold modifier active
-
isReversed
public boolean isReversed()Returns true if this TextCharacter has the reverse modifier active- Returns:
true
if this TextCharacter has the reverse modifier active
-
isUnderlined
public boolean isUnderlined()Returns true if this TextCharacter has the underline modifier active- Returns:
true
if this TextCharacter has the underline modifier active
-
isBlinking
public boolean isBlinking()Returns true if this TextCharacter has the blink modifier active- Returns:
true
if this TextCharacter has the blink modifier active
-
isBordered
public boolean isBordered()Returns true if this TextCharacter has the bordered modifier active- Returns:
true
if this TextCharacter has the bordered modifier active
-
isCrossedOut
public boolean isCrossedOut()Returns true if this TextCharacter has the crossed-out modifier active- Returns:
true
if this TextCharacter has the crossed-out modifier active
-
isItalic
public boolean isItalic()Returns true if this TextCharacter has the italic modifier active- Returns:
true
if this TextCharacter has the italic modifier active
-
withCharacter
Returns a new TextCharacter with the same colors and modifiers but a different underlying character- Parameters:
character
- Character the copy should have- Returns:
- Copy of this TextCharacter with different underlying character
-
withForegroundColor
Returns a copy of this TextCharacter with a specified foreground color- Parameters:
foregroundColor
- Foreground color the copy should have- Returns:
- Copy of the TextCharacter with a different foreground color
-
withBackgroundColor
Returns a copy of this TextCharacter with a specified background color- Parameters:
backgroundColor
- Background color the copy should have- Returns:
- Copy of the TextCharacter with a different background color
-
withModifiers
Returns a copy of this TextCharacter with specified list of SGR modifiers. None of the currently active SGR codes will be carried over to the copy, only those in the passed in value.- Parameters:
modifiers
- SGR modifiers the copy should have- Returns:
- Copy of the TextCharacter with a different set of SGR modifiers
-
withModifier
Returns a copy of this TextCharacter with an additional SGR modifier. All of the currently active SGR codes will be carried over to the copy, in addition to the one specified.- Parameters:
modifier
- SGR modifiers the copy should have in additional to all currently present- Returns:
- Copy of the TextCharacter with a new SGR modifier
-
withoutModifier
Returns a copy of this TextCharacter with an SGR modifier removed. All of the currently active SGR codes will be carried over to the copy, except for the one specified. If the current TextCharacter doesn't have the SGR specified, it will return itself.- Parameters:
modifier
- SGR modifiers the copy should not have- Returns:
- Copy of the TextCharacter without the SGR modifier
-
isDoubleWidth
public boolean isDoubleWidth() -
isEmoji
-
equals
-
hashCode
public int hashCode() -
toString
-