Class CommandLine.Help.Ansi.Text
- java.lang.Object
-
- org.apache.logging.log4j.core.tools.picocli.CommandLine.Help.Ansi.Text
-
- All Implemented Interfaces:
java.lang.Cloneable
- Enclosing class:
- CommandLine.Help.Ansi
public class CommandLine.Help.Ansi.Text extends java.lang.Object implements java.lang.Cloneable
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
Constructors Constructor Description Text(int maxLength)
Constructs a Text with the specified max length (for use in a TextTable Column).Text(java.lang.String input)
Constructs a Text with the specified String, which may contain markup like@|bg(red),white,underline some text|@
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addStyledSection(int start, int length, java.lang.String startStyle, java.lang.String endStyle)
CommandLine.Help.Ansi.Text
append(java.lang.String string)
Returns a newText
instance with the specified text appended.CommandLine.Help.Ansi.Text
append(CommandLine.Help.Ansi.Text other)
Returns a newText
instance with the specified text appended.java.lang.Object
clone()
boolean
equals(java.lang.Object obj)
private CommandLine.Help.Ansi.StyledSection
findSectionContaining(int index)
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()
java.lang.String
plainString()
Returns the plain text without any formatting.CommandLine.Help.Ansi.Text[]
splitLines()
CommandLine.Help.Ansi.Text
substring(int start)
Returns a newText
instance that is a substring of this Text.CommandLine.Help.Ansi.Text
substring(int start, int end)
Returns a newText
instance that is a substring of this Text.java.lang.String
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.
-
-
-
Field Detail
-
maxLength
private final int maxLength
-
from
private int from
-
length
private int length
-
plain
private java.lang.StringBuilder plain
-
sections
private java.util.List<CommandLine.Help.Ansi.StyledSection> sections
-
-
Constructor Detail
-
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
public Text(java.lang.String input)
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 Detail
-
addStyledSection
private void addStyledSection(int start, int length, java.lang.String startStyle, java.lang.String endStyle)
-
clone
public java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
splitLines
public CommandLine.Help.Ansi.Text[] splitLines()
-
substring
public CommandLine.Help.Ansi.Text substring(int start)
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
public CommandLine.Help.Ansi.Text substring(int start, int end)
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
public CommandLine.Help.Ansi.Text append(java.lang.String string)
Returns a newText
instance with the specified text appended. Does not modify this instance!- Parameters:
string
- the text to append- Returns:
- a new Text instance
-
append
public CommandLine.Help.Ansi.Text append(CommandLine.Help.Ansi.Text other)
Returns a newText
instance with the specified text appended. Does not modify this instance!- Parameters:
other
- the text to append- Returns:
- a new Text instance
-
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
public java.lang.String plainString()
Returns the plain text without any formatting.- Returns:
- the plain text without any formatting
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String 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.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a String representation of the text with ANSI escape codes embedded (if enabled)
-
findSectionContaining
private CommandLine.Help.Ansi.StyledSection findSectionContaining(int index)
-
-