Package nz.org.riskscape.picocli
Class CommandLine.Help.Ansi.Text
java.lang.Object
nz.org.riskscape.picocli.CommandLine.Help.Ansi.Text
- All Implemented Interfaces:
Cloneable
- Enclosing class:
- CommandLine.Help.Ansi
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
ConstructorDescriptionText
(int maxLength) Constructs a Text with the specified max length (for use in a TextTable Column).Constructs a Text with the specified String, which may contain markup like@|bg(red),white,underline some text|@
.Text
(CommandLine.Help.Ansi.Text other) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.Deprecated.useconcat(Text)
insteadclone()
Returns a copy of thisText
instance with the specified text concatenated to the end.concat
(CommandLine.Help.Ansi.Text other) Returns a copy of thisText
instance with the specified text concatenated to the end.boolean
int
Returns the number of columns this Text will occupy on the console, adjusted for wide CJK characters.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.void
getStyledChars
(int from, int length, CommandLine.Help.Ansi.Text destination, int offset) Copies the specified substring of this Text into the specified destination, preserving the markup.int
hashCode()
Returns the plain text without any formatting.substring
(int start) Returns a newText
instance that is a substring of this Text.substring
(int start, int end) Returns a newText
instance that is a substring of this Text.toString()
Returns a String representation of the text with ANSI escape codes embedded, unless ANSI is CommandLine.Help.Ansi.enabled() not enabled}, in which case the plain text is returned.
-
Constructor Details
-
Text
public Text(int maxLength) Constructs a Text with the specified max length (for use in a TextTable Column).- Parameters:
maxLength
- max length of this text
-
Text
Copy constructor.- Since:
- 3.9
-
Text
Constructs a Text with the specified String, which may contain markup like
@|bg(red),white,underline some text|@
.- Parameters:
input
- the string with markup to parse
-
-
Method Details
-
clone
-
splitLines
-
substring
Returns a newText
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
Returns a newText
instance that is a substring of this Text. Does not modify this instance!- Parameters:
start
- index in the plain text where to start the substringend
- index in the plain text where to end the substring- Returns:
- a new Text instance that is a substring of this Text
-
append
Deprecated.useconcat(String)
instead -
append
Deprecated.useconcat(Text)
instead -
concat
Returns a copy of thisText
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
Returns a copy of thisText
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, CommandLine.Help.Ansi.Text destination, int offset) Copies the specified substring of this Text into the specified destination, preserving the markup.
- Parameters:
from
- start of the substringlength
- length of the substringdestination
- destination Text to modifyoffset
- indentation (padding)
-
plainString
Returns the plain text without any formatting.- Returns:
- the plain text without any formatting
-
equals
-
hashCode
public int hashCode() -
toString
Returns a String representation of the text with ANSI escape codes embedded, unless ANSI is CommandLine.Help.Ansi.enabled() not enabled}, in which case the plain text is returned. -
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 countingcharCount
- 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
-
concat(String)
instead