Package org.aesh.terminal.formatting
Class TerminalString
java.lang.Object
org.aesh.terminal.formatting.TerminalString
- All Implemented Interfaces:
Comparable<TerminalString>
Value object that describe how a string should be displayed
- Author:
- Ståle W. Pedersen
-
Constructor Summary
ConstructorsConstructorDescriptionTerminalString(String chars) Create a terminal string with default formatting.TerminalString(String chars, boolean ignoreRendering) Create a terminal string with optional rendering.TerminalString(String chars, String hyperlinkUrl, TerminalColor color, TerminalTextStyle style) Create a terminal string with a hyperlink URL, color and style.TerminalString(String chars, TerminalColor color) Create a terminal string with the specified color.TerminalString(String chars, TerminalColor color, TerminalTextStyle style) Create a terminal string with the specified color and style.TerminalString(String chars, TerminalTextStyle style) Create a terminal string with the specified style. -
Method Summary
Modifier and TypeMethodDescriptioncloneRenderingAttributes(String chars) Create a new terminal string with the same rendering attributes.intcompareTo(TerminalString terminalString) booleanCheck if the string contains spaces.booleanbooleanCheck if this terminal string has the same style and color as another, ignoring the actual character content.intGet the length of ANSI escape sequences.Get the character content.Get the hyperlink URL.getStyle()Get the text style.inthashCode()booleanCheck if this string has any formatting applied.voidsetCharacters(String chars) Set the character content.voidsetHyperlinkUrl(String url) Set the hyperlink URL.voidReplace spaces with escaped spaces in the character content.toString()toString(TerminalString prev) Get the string representation relative to a previous terminal string.voidwrite(PrintStream out) Write this terminal string to a print stream.
-
Constructor Details
-
TerminalString
Create a terminal string with the specified color and style.- Parameters:
chars- the character contentcolor- the terminal colorstyle- the text style
-
TerminalString
Create a terminal string with the specified color.- Parameters:
chars- the character contentcolor- the terminal color
-
TerminalString
Create a terminal string with the specified style.- Parameters:
chars- the character contentstyle- the text style
-
TerminalString
Create a terminal string with default formatting.- Parameters:
chars- the character content
-
TerminalString
Create a terminal string with optional rendering.- Parameters:
chars- the character contentignoreRendering- if true, no ANSI codes will be applied
-
TerminalString
public TerminalString(String chars, String hyperlinkUrl, TerminalColor color, TerminalTextStyle style) Create a terminal string with a hyperlink URL, color and style. When rendered, the text will be wrapped in OSC 8 hyperlink escape sequences.- Parameters:
chars- the character contenthyperlinkUrl- the URL for the hyperlinkcolor- the terminal colorstyle- the text style
-
-
Method Details
-
getCharacters
Get the character content.- Returns:
- the characters
-
setCharacters
Set the character content.- Parameters:
chars- the new characters
-
getHyperlinkUrl
Get the hyperlink URL.- Returns:
- the hyperlink URL, or null if not set
-
setHyperlinkUrl
Set the hyperlink URL.- Parameters:
url- the hyperlink URL
-
containSpaces
public boolean containSpaces()Check if the string contains spaces.- Returns:
- true if spaces are present
-
switchSpacesToEscapedSpaces
public void switchSpacesToEscapedSpaces()Replace spaces with escaped spaces in the character content. -
getStyle
Get the text style.- Returns:
- the text style
-
getANSILength
public int getANSILength()Get the length of ANSI escape sequences.- Returns:
- the ANSI code length, or 0 if rendering is ignored
-
cloneRenderingAttributes
Create a new terminal string with the same rendering attributes.- Parameters:
chars- the new character content- Returns:
- a new terminal string with the same style and color
-
isFormatted
public boolean isFormatted()Check if this string has any formatting applied.- Returns:
- true if color or style formatting is applied
-
toString
Get the string representation relative to a previous terminal string. Only outputs ANSI codes for attributes that differ.- Parameters:
prev- the previous terminal string- Returns:
- the formatted string with ANSI codes
-
toString
-
write
Write this terminal string to a print stream.- Parameters:
out- the output stream to write to
-
equalsIgnoreCharacter
Check if this terminal string has the same style and color as another, ignoring the actual character content.- Parameters:
that- the terminal string to compare with- Returns:
- true if style and color are equal
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareToin interfaceComparable<TerminalString>
-