Skip to content

Package io.github.qishr.cascara.common.util

Class Text

java.lang.Object
        io.github.qishr.cascara.common.util.CommandLine.Help.Ansi.Text

All Implemented Interfaces:
    Cloneable


public class Text

Encapsulates rich text with styles and colors.Text objects may be constructed with Strings containing markup like @|bg(red),white,underline some text|@, and this class converts the markup to ANSI escape codes.

Internally keeps both an enriched and a plain text representation to allow layout components to calculate text width while remaining unaware of the embedded ANSI escape codes.

Constructor Summary

Constructor Description
Text(int maxLength) Constructs a Text with the specified max length (for use in a TextTable Column).
Text(int maxLength, ColorScheme colorScheme) Constructs a Text with the specified max length (for use in a TextTable Column).
Text(Text other) Copy constructor.
Text(String input) Constructs a Text with the specified String, which may contain markup like @|bg(red),white,underline some text|@.
Text(String input, ColorScheme colorScheme) Constructs a Text with the specified String (which may contain markup), and ColorScheme.

Method Summary

Modifier and Type Method Description
public Object clone()
public Text[] splitLines()
public Text substring(int start) Returns a new Text instance that is a substring of this Text.
public Text substring(int start, int end) Returns a new Text instance that is a substring of this Text.
public Text append(String string)
public Text append(Text text)
public Text concat(String string) Returns a copy of this Text instance with the specified text concatenated to the end.
public Text concat(Text other) Returns a copy of this Text instance with the specified text concatenated to the end.
public void getStyledChars(int from, int length, Text destination, int offset) Copies the specified substring of this Text into the specified destination, preserving the markup.
public String plainString() Returns the plain text without any formatting.
public boolean equals(Object obj)
public int hashCode()
public String toString() Returns a String representation of the text with ANSI escape codes embedded, unless ANSI is not enabled}, in which case the plain text is returned.
public int getCJKAdjustedLength() Returns the number of columns this Text will occupy on the console, adjusted for wide CJK characters.
public int getCJKAdjustedLength(int fromPosition, int charCount) Returns the number of columns that the specified portion of this Text will occupy on the console, adjusted for wide CJK characters.

Method Details

clone

public Object clone()


splitLines

public Text[] splitLines()


substring

public Text substring(int start)

Returns a new Text instance that is a substring of this Text.Does not modify this instance!

Parameters:

start - index in the plain text where to start the substring

Returns:

a new Text instance that is a substring of this Text


substring

public Text substring(int start, int end)

Returns a new Text instance that is a substring of this Text.Does not modify this instance!

Parameters:

start - index in the plain text where to start the substring

end - index in the plain text where to end the substring

Returns:

a new Text instance that is a substring of this Text


append

public Text append(String string)

Deprecation

use concat.concat instead


append

public Text append(Text text)

Deprecation

use concat.concat instead


concat

public Text concat(String string)

Returns a copy of this Text instance with the specified text concatenated to the end.Does not modify this instance!

Parameters:

string - the text to concatenate to the end of this Text

Returns:

a new Text instance

Since:

3.0


concat

public Text concat(Text other)

Returns a copy of this Text instance with the specified text concatenated to the end.Does not modify this instance!

Parameters:

other - the text to concatenate to the end of this Text

Returns:

a new Text instance

Since:

3.0


getStyledChars

public void getStyledChars(int from, int length, Text destination, int offset)

Copies the specified substring of this Text into the specified destination, preserving the markup.

Parameters:

from - start of the substring

length - length of the substring

destination - destination Text to modify

offset - indentation (padding)


plainString

public String plainString()

Returns the plain text without any formatting.

Returns:

the plain text without any formatting


equals

public boolean equals(Object obj)


hashCode

public int hashCode()


toString

public String toString()

Returns a String representation of the text with ANSI escape codes embedded, unless ANSI is not enabled}, in which case the plain text is returned.

Returns:

a String representation of the text with ANSI escape codes embedded (if enabled)


getCJKAdjustedLength

public int getCJKAdjustedLength()

Returns the number of columns this Text will occupy on the console, adjusted for wide CJK characters.

Returns:

the number of columns this Text will occupy on the console, adjusted for wide CJK characters

Since:

4.0


getCJKAdjustedLength

public int getCJKAdjustedLength(int fromPosition, int charCount)

Returns the number of columns that the specified portion of this Text will occupy on the console, adjusted for wide CJK characters.

Parameters:

fromPosition - the position to start counting

charCount - the number of characters in this Text to consider

Returns:

the number of columns that the specified portion of this Text will occupy on the console, adjusted for wide CJK characters

Since:

4.0