Package software.amazon.smithy.cli
Class ColorBuffer
java.lang.Object
software.amazon.smithy.cli.ColorBuffer
- All Implemented Interfaces:
Appendable,AutoCloseable
An
Appendable that supports color provided by a ColorFormatter.
A ColorBuffer is not thread-safe and is meant to write short contiguous output text that will
eventually be written to other things like a CliPrinter.
When wrapping a CliPrinter, ensure you use close() to write to the printer. Alternatively,
wrap the buffer in a try-with-resources block.
-
Method Summary
Modifier and TypeMethodDescriptionappend(char c) append(CharSequence csq) append(CharSequence csq, int start, int end) voidclose()static ColorBufferof(ColorFormatter colors, Appendable sink) Create a new ColorBuffer that directly writes to the givensink.static ColorBufferof(ColorFormatter colors, CliPrinter sink) Create a new ColorBuffer that stores all output to an internal buffer and only writes to the givenCliPrinterwhenclose()is called.Writes styled text to the builder using the CliPrinter's color settings.println()Writes a system-dependent new line.Prints a line of styled text to the buffer.style(Consumer<ColorBuffer> bufferConsumer, Style... styles) toString()
-
Method Details
-
of
Create a new ColorBuffer that directly writes to the givensink.No additional buffering is used when buffering over an
Appendable. Each call to write to the buffer will write to the appendable.- Parameters:
colors- ColorFormatter used to provide colors and style.sink- Where to write.- Returns:
- Returns the created buffer.
-
of
Create a new ColorBuffer that stores all output to an internal buffer and only writes to the givenCliPrinterwhenclose()is called.- Parameters:
colors- ColorFormatter used to provide colors and style.sink- Where to write.- Returns:
- Returns the created buffer.
-
toString
-
append
- Specified by:
appendin interfaceAppendable
-
append
- Specified by:
appendin interfaceAppendable
-
append
- Specified by:
appendin interfaceAppendable
-
print
Writes styled text to the builder using the CliPrinter's color settings.- Parameters:
text- Text to write.styles- Styles to apply to the text.- Returns:
- Returns self.
-
println
Prints a line of styled text to the buffer.- Parameters:
text- Text to print.styles- Styles to apply.- Returns:
- Returns self.
-
println
Writes a system-dependent new line.- Returns:
- Returns the buffer.
-
style
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-