Package software.amazon.smithy.cli
Class ColorBuffer
- java.lang.Object
- 
- software.amazon.smithy.cli.ColorBuffer
 
- 
- All Implemented Interfaces:
- java.lang.Appendable,- java.lang.AutoCloseable
 
 public final class ColorBuffer extends java.lang.Object implements java.lang.Appendable, java.lang.AutoCloseableAnAppendablethat supports color provided by aColorFormatter.A ColorBufferis not thread-safe and is meant to write short contiguous output text that will eventually be written to other things like aCliPrinter.When wrapping a CliPrinter, ensure you useclose()to write to the printer. Alternatively, wrap the buffer in a try-with-resources block.
- 
- 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ColorBufferappend(char c)ColorBufferappend(java.lang.CharSequence csq)ColorBufferappend(java.lang.CharSequence csq, int start, int end)voidclose()static ColorBufferof(ColorFormatter colors, java.lang.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.ColorBufferprint(java.lang.String text, Style... styles)Writes styled text to the builder using the CliPrinter's color settings.ColorBufferprintln()Writes a system-dependent new line.ColorBufferprintln(java.lang.String text, Style... styles)Prints a line of styled text to the buffer.ColorBufferstyle(java.util.function.Consumer<ColorBuffer> bufferConsumer, Style... styles)java.lang.StringtoString()
 
- 
- 
- 
Method Detail- 
ofpublic static ColorBuffer of(ColorFormatter colors, java.lang.Appendable sink) 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.
 
 - 
ofpublic static ColorBuffer of(ColorFormatter colors, CliPrinter sink) 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.
 
 - 
toStringpublic java.lang.String toString() - Overrides:
- toStringin class- java.lang.Object
 
 - 
appendpublic ColorBuffer append(java.lang.CharSequence csq) - Specified by:
- appendin interface- java.lang.Appendable
 
 - 
appendpublic ColorBuffer append(java.lang.CharSequence csq, int start, int end) - Specified by:
- appendin interface- java.lang.Appendable
 
 - 
appendpublic ColorBuffer append(char c) - Specified by:
- appendin interface- java.lang.Appendable
 
 - 
printpublic ColorBuffer print(java.lang.String text, Style... styles) 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.
 
 - 
printlnpublic ColorBuffer println(java.lang.String text, Style... styles) Prints a line of styled text to the buffer.- Parameters:
- text- Text to print.
- styles- Styles to apply.
- Returns:
- Returns self.
 
 - 
printlnpublic ColorBuffer println() Writes a system-dependent new line.- Returns:
- Returns the buffer.
 
 - 
stylepublic ColorBuffer style(java.util.function.Consumer<ColorBuffer> bufferConsumer, Style... styles) 
 - 
closepublic void close() - Specified by:
- closein interface- java.lang.AutoCloseable
 
 
- 
 
-