Documentation ¶
Index ¶
- type ColorPrinter
- func (c *ColorPrinter) Errorf(format string, a ...any) error
- func (c *ColorPrinter) Fprint(w io.Writer, a ...any) (n int, err error)
- func (c *ColorPrinter) Fprintf(w io.Writer, format string, a ...any) (n int, err error)
- func (c *ColorPrinter) Fprintln(w io.Writer, a ...any) (n int, err error)
- func (c *ColorPrinter) Printf(format string, a ...any)
- func (c *ColorPrinter) Println(a ...any)
- func (c *ColorPrinter) SetBGColor(br, bg, bb int)
- func (c *ColorPrinter) SetColor(fr, fg, fb, br, bg, bb int)
- func (c *ColorPrinter) SetFGColor(fr, fg, fb int)
- func (c *ColorPrinter) Sprintf(format string, a ...any) string
- func (c *ColorPrinter) Sprintln(a ...any) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ColorPrinter ¶
type ColorPrinter struct {
// contains filtered or unexported fields
}
ColorPrinter ANSI Escape https://stackoverflow.com/a/69924820/9935654
Example ¶
p := NewColorPrinter(0, 0, 0, 255, 255, 0) log.Println(p.Sprintf("%d %s %q", 123, "Hi", "quote")) p.SetBGColor(0, 255, 0) log.Println(p.Sprintf("%d %s %q", 123, "Hi", "quote")) p.SetFGColor(0, 0, 255) log.Println(p.Sprintf("%d %s %q", 123, "Hi", "quote")) p.SetColor(255, 255, 255, 255, 0, 0) log.Println(p.Sprintf("%d %s %q", 123, "Hi", "quote"))
Output:
Example (Style) ¶
pYellow := NewColorPrinter(0, 0, 0, 255, 255, 0) pHighlight := NewColorPrinter(255, 0, 255, 255, 255, 0) pMark := NewColorPrinter(255, 0, 255, 255, 255, 0) pOK := NewColorPrinter(0, 0, 0, 0, 255, 0) pErr := NewColorPrinter(255, 255, 255, 255, 0, 0) pInfo := NewColorPrinter(255, 255, 255, 0, 0, 255) for _, p := range []*ColorPrinter{ pYellow, pHighlight, pOK, pErr, pMark, pInfo, } { log.Println(p.Sprintf("%d %s %q", 123, "Hi", "quote")) }
Output:
func NewColorPrinter ¶
func NewColorPrinter(fr, fg, fb, br, bg, bb int) *ColorPrinter
func (*ColorPrinter) Fprint ¶
Example ¶
p := NewColorPrinter(0, 0, 0, 255, 255, 0) _, _ = p.Fprint(os.Stderr, 123, "Hi") _, _ = p.Fprint(os.Stderr, 123, "Hi\n") _, _ = p.Fprint(os.Stderr, "abc")
Output:
func (*ColorPrinter) Fprintf ¶
Example ¶
p := NewColorPrinter(0, 0, 0, 255, 255, 0) _, _ = p.Fprintf(os.Stderr, "%d %s %q\n", 123, "Hi", "quote") _, _ = p.Fprintf(os.Stderr, "%d %s %q", 123, "Hi", "quote")
Output:
func (*ColorPrinter) Fprintln ¶
Example ¶
p := NewColorPrinter(0, 0, 0, 255, 255, 0) _, _ = p.Fprintln(os.Stderr, 123, "Hi") _, _ = p.Fprintln(os.Stderr, 123, "Hi") _, _ = p.Fprintln(os.Stderr, "Hi")
Output:
func (*ColorPrinter) Printf ¶
func (c *ColorPrinter) Printf(format string, a ...any)
func (*ColorPrinter) Println ¶
func (c *ColorPrinter) Println(a ...any)
func (*ColorPrinter) SetBGColor ¶
func (c *ColorPrinter) SetBGColor(br, bg, bb int)
func (*ColorPrinter) SetColor ¶
func (c *ColorPrinter) SetColor(fr, fg, fb, br, bg, bb int)
func (*ColorPrinter) SetFGColor ¶
func (c *ColorPrinter) SetFGColor(fr, fg, fb int)
Click to show internal directories.
Click to hide internal directories.