Package org.pkl.core.util
Class AnsiStringBuilder
java.lang.Object
org.pkl.core.util.AnsiStringBuilder
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappend(char value) Append the string representation ofvalueto the string.append(int value) Append the string representation ofvalueto the string.Append the string representation ofvalueto the string.Appendvalueto the string.append(EnumSet<AnsiStringBuilder.AnsiCode> codes, Runnable runnable) append(Set<AnsiStringBuilder.AnsiCode> codes, String value) Appendvalueto the string, ensuring it is formatted withcodes.append(AnsiStringBuilder.AnsiCode code, int value) Appendvalueto the string, ensuring it is formatted withcodes.append(AnsiStringBuilder.AnsiCode code, Runnable runnable) Applycodeto every appended element withinrunnable.append(AnsiStringBuilder.AnsiCode code, String value) Appendvalueto the string, ensuring it is formatted withcodes.appendSandboxed(Runnable runnable) Provides a runnable where anything appended is not affected by the existing context.appendUntrusted(String value) Append a string whose contents are unknown, and might contain ANSI color codes.intlength()Returns a fresh instance of this string builder.voidsetLength(int length) toString()Builds the data represented by this builder into aString.
-
Constructor Details
-
AnsiStringBuilder
public AnsiStringBuilder(boolean usingColor)
-
-
Method Details
-
append
Appendvalueto the string, ensuring it is formatted withcodes. -
append
Appendvalueto the string, ensuring it is formatted withcodes. -
append
Appendvalueto the string, ensuring it is formatted withcodes. -
append
Applycodeto every appended element withinrunnable.This is a helper method. With this:
- There is no need to repeat the same style for multiple appends in a row.
- The parent style is added to any styles added applied in the children.
For example, in the following snippet,
"hello"is formatted in both bold and red:var sb = new AnsiCodingStringBuilder(true); sb.append(AnsiCode.RED, () -> { sb.append(AnsiCode.BOLD, "hello"); });
-
append
-
appendSandboxed
Provides a runnable where anything appended is not affected by the existing context. -
appendUntrusted
Append a string whose contents are unknown, and might contain ANSI color codes.Always add a reset and re-apply all colors after appending the string.
-
append
Appendvalueto the string.If called within
append(AnsiCode, Runnable), applies any styles in the current context. -
append
Append the string representation ofvalueto the string.If called within
append(AnsiCode, Runnable), applies any styles in the current context. -
append
Append the string representation ofvalueto the string.If called within
append(AnsiCode, Runnable), applies any styles in the current context. -
append
Append the string representation ofvalueto the string.If called within
append(AnsiCode, Runnable), applies any styles in the current context. -
newInstance
Returns a fresh instance of this string builder. -
toPrintWriter
-
length
public int length() -
setLength
public void setLength(int length) -
toString
Builds the data represented by this builder into aString.
-