Class StyledText
java.lang.Object
org.strassburger.tui4j.formatting.StyledText
Represents styled text composed of multiple spans, each with its own style.
Example usage:
StyledText styled = StyledText.text("Hello, ")
.fg(Color.fromHex("00ff00"))
.append(StyledText.text("World!").bold())
.underline();
-
Method Summary
Modifier and TypeMethodDescriptionAppend a plain string to this StyledTextAppend a string with the given style to this StyledTextappend(StyledText other) Append another StyledText to this onebg(org.strassburger.colorlab4j.color.Color color) Set the background color of the last spanbold()Make the last span boldfg(org.strassburger.colorlab4j.color.Color color) Set the foreground color of the last spangetSpans()Prepend a plain string to this StyledTextPrepend a string with the given style to this StyledTextprepend(StyledText other) Prepend another StyledText to this onerepeat(int count) Repeat the entire StyledText a specified number of timesReplace occurrences of a target string with a replacement string in all spansreversed()Inverse the colors of the last spanstatic StyledTextCreate a StyledText with a single span of plain textstatic StyledTextCreate a StyledText with a single span of text and the given styletoString()Make the last span italic
-
Method Details
-
getSpans
-
text
Create a StyledText with a single span of plain text- Parameters:
text- the text content- Returns:
- the StyledText instance
-
text
Create a StyledText with a single span of text and the given style- Parameters:
text- the text contentstyle- the style to apply- Returns:
- the StyledText instance
-
append
Append another StyledText to this one- Parameters:
other- the other StyledText to append- Returns:
- a new StyledText instance representing the combined text
-
prepend
Prepend another StyledText to this one- Parameters:
other- the other StyledText to prepend- Returns:
- a new StyledText instance representing the combined text
-
append
Append a string with the given style to this StyledText- Parameters:
text- the text contentstyle- the style to apply- Returns:
- a new StyledText instance representing the combined text
-
append
Append a plain string to this StyledText- Parameters:
text- the text content- Returns:
- a new StyledText instance representing the combined text
-
prepend
Prepend a string with the given style to this StyledText- Parameters:
text- the text contentstyle- the style to apply- Returns:
- a new StyledText instance representing the combined text
-
prepend
Prepend a plain string to this StyledText- Parameters:
text- the text content- Returns:
- a new StyledText instance representing the combined text
-
replace
Replace occurrences of a target string with a replacement string in all spans- Parameters:
target- the string to be replacedreplacement- the string to replace with- Returns:
- a new StyledText instance with the replacements made
-
repeat
Repeat the entire StyledText a specified number of times- Parameters:
count- the number of times to repeat- Returns:
- a new StyledText instance with the repeated content
-
fg
Set the foreground color of the last span- Parameters:
color- the foreground color- Returns:
- the modified StyledText
-
bg
Set the background color of the last span- Parameters:
color- the background color- Returns:
- the modified StyledText
-
bold
Make the last span bold- Returns:
- the modified StyledText
-
underline
Make the last span italic- Returns:
- the modified StyledText
-
reversed
Inverse the colors of the last span- Returns:
- the modified StyledText
-
toString
-