Class TextCharacter

  • All Implemented Interfaces:
    java.io.Serializable

    public class TextCharacter
    extends java.lang.Object
    implements java.io.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:
    Serialized Form
    • Field Detail

      • DEFAULT_CHARACTER

        public static final TextCharacter DEFAULT_CHARACTER
      • character

        private final java.lang.String 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

        private final TextColor foregroundColor
      • backgroundColor

        private final TextColor backgroundColor
      • modifiers

        private final java.util.EnumSet<SGR> modifiers
    • Constructor Detail

      • TextCharacter

        @Deprecated
        public TextCharacter​(char character)
        Deprecated.
        Use fromCharacter instead
        Creates a ScreenCharacter based on a supplied character, with default colors and no extra modifiers.
        Parameters:
        character - Physical character to use
      • TextCharacter

        @Deprecated
        public TextCharacter​(TextCharacter character)
        Deprecated.
        TextCharacters are immutable so you shouldn't need to call this
        Copies another ScreenCharacter
        Parameters:
        character - screenCharacter to copy from
      • TextCharacter

        @Deprecated
        public TextCharacter​(char character,
                             TextColor foregroundColor,
                             TextColor backgroundColor,
                             SGR... styles)
        Deprecated.
        Use fromCharacter instead
        Creates a new ScreenCharacter based on a physical character, color information and optional modifiers.
        Parameters:
        character - Physical character to refer to
        foregroundColor - Foreground color the character has
        backgroundColor - Background color the character has
        styles - Optional list of modifiers to apply when drawing the character
      • TextCharacter

        @Deprecated
        public TextCharacter​(char character,
                             TextColor foregroundColor,
                             TextColor backgroundColor,
                             java.util.EnumSet<SGR> modifiers)
        Deprecated.
        Use fromCharacter instead
        Creates a new ScreenCharacter based on a physical character, color information and a set of modifiers.
        Parameters:
        character - Physical character to refer to
        foregroundColor - Foreground color the character has
        backgroundColor - Background color the character has
        modifiers - Set of modifiers to apply when drawing the character
      • TextCharacter

        private TextCharacter​(java.lang.String character,
                              TextColor foregroundColor,
                              TextColor backgroundColor,
                              java.util.EnumSet<SGR> modifiers)
        Creates a new ScreenCharacter based on a physical character, color information and a set of modifiers.
        Parameters:
        character - Physical character to refer to
        foregroundColor - Foreground color the character has
        backgroundColor - Background color the character has
        modifiers - Set of modifiers to apply when drawing the character
    • Method Detail

      • toEnumSet

        private static java.util.EnumSet<SGR> toEnumSet​(SGR... modifiers)
      • fromCharacter

        public static TextCharacter[] fromCharacter​(char c)
      • fromString

        public static TextCharacter[] fromString​(java.lang.String string)
      • fromString

        public static TextCharacter[] fromString​(java.lang.String string,
                                                 TextColor foregroundColor,
                                                 TextColor backgroundColor,
                                                 java.util.EnumSet<SGR> modifiers)
      • validateSingleCharacter

        private void validateSingleCharacter​(java.lang.String character)
      • is

        public boolean is​(char otherCharacter)
      • getCharacter

        @Deprecated
        public char getCharacter()
        Deprecated.
        This won't work with advanced characters like emoji
        The actual character this TextCharacter represents
        Returns:
        character of the TextCharacter
      • getCharacterString

        public java.lang.String getCharacterString()
        Returns the character this TextCharacter represents as a String. This is not returning a char
        Returns:
      • getForegroundColor

        public TextColor getForegroundColor()
        Foreground color specified for this TextCharacter
        Returns:
        Foreground color of this TextCharacter
      • getBackgroundColor

        public TextColor getBackgroundColor()
        Background color specified for this TextCharacter
        Returns:
        Background color of this TextCharacter
      • getModifiers

        public java.util.EnumSet<SGR> 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

        public TextCharacter withCharacter​(char character)
        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

        public TextCharacter withForegroundColor​(TextColor foregroundColor)
        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

        public TextCharacter withBackgroundColor​(TextColor backgroundColor)
        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

        public TextCharacter withModifiers​(java.util.Collection<SGR> modifiers)
        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

        public TextCharacter withModifier​(SGR modifier)
        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

        public TextCharacter withoutModifier​(SGR modifier)
        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

        private static boolean isEmoji​(java.lang.String s)
      • equals

        public boolean equals​(java.lang.Object obj)
        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