Documentation
¶
Index ¶
- Constants
- func IsNop(w io.Writer) bool
- func NopOutput() io.Writer
- func Rich(text string, colorCode int, options ...RichOption) string
- func SupportsColor(w io.Writer) bool
- func WriteRich(w io.Writer, text string, colorCode int, options ...RichOption) (int, error)
- type Printer
- func (p *Printer) AddOutput(writers ...io.Writer)
- func (p *Printer) Clone() *Printer
- func (p *Printer) Print(v any) (int, error)
- func (p *Printer) Printf(format string, a ...any) (int, error)
- func (p *Printer) Println(v any) (int, error)
- func (p *Printer) Scan(r io.Reader) (cancel func())
- func (p *Printer) SetOutput(w io.Writer)
- func (p *Printer) Terminal() (*Printer, bool)
- func (p *Printer) TerminalOrStderr() io.Writer
- func (p *Printer) TerminalOrStdout() io.Writer
- func (p *Printer) Write(data []byte) (int, error)
- func (p *Printer) WriteRich(text string, colorCode int, options ...RichOption) (int, error)
- func (p *Printer) WriteString(s string) (n int, err error)
- type RichOption
Constants ¶
const ( Black = 30 + iota Red Green Yellow Blue Magenta Cyan White Gray = White ColorReset = 0 )
Standard color codes, any color code can be passed to `Rich` package-level function, when the destination terminal supports.
Variables ¶
This section is empty.
Functions ¶
func Rich ¶
func Rich(text string, colorCode int, options ...RichOption) string
Rich returns a formatted string with color and style codes. If colors are disabled, returns the plain text.
func SupportsColor ¶
SupportsColor determines if the output supports ANSI color codes.
Types ¶
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer is a simple printer that manages multiple output writers and provides thread-safe atomic writes.
func NewPrinter ¶
NewPrinter creates a new Printer with the given initial writer.
func (*Printer) Clone ¶
Clone creates a deep copy of the Printer, including its writers and rich map.
func (*Printer) Println ¶
Println writes the string representation of v followed by a newline to all writers.
func (*Printer) Scan ¶
Scan scans from the provided reader and writes lines to the printer. It returns a cancel function to stop the scanning operation.
func (*Printer) Terminal ¶
Terminal returns a new Printer that includes the writers that output destination is a terminal kind. If no terminal writers exist, it returns nil and false.
func (*Printer) TerminalOrStderr ¶
TerminalOrStderr returns an io.Writer that includes the writers that output destination is a terminal kind. If no terminal writers exist, it returns os.Stderr.
func (*Printer) TerminalOrStdout ¶
TerminalOrStdout returns an io.Writer that includes the writers that output destination is a terminal kind. If no terminal writers exist, it returns os.Stdout.
type RichOption ¶
type RichOption int
Style options for rich text formatting
const ( Background RichOption = iota Underline Bold )