fmt

package
v2.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 3 Imported by: 1

Documentation

Index

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) Errorf

func (c *ColorPrinter) Errorf(format string, a ...any) error

func (*ColorPrinter) Fprint

func (c *ColorPrinter) Fprint(w io.Writer, a ...any) (n int, err error)
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

func (c *ColorPrinter) Fprintf(w io.Writer, format string, a ...any) (n int, err error)
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

func (c *ColorPrinter) Fprintln(w io.Writer, a ...any) (n int, err error)
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)

func (*ColorPrinter) Sprintf

func (c *ColorPrinter) Sprintf(format string, a ...any) string

func (*ColorPrinter) Sprintln

func (c *ColorPrinter) Sprintln(a ...any) string
Example
p := NewColorPrinter(0, 0, 0, 255, 255, 0)
log.Print(p.Sprintln(123, "Hi", "quote"))
p.SetBGColor(0, 255, 0)
log.Println(p.Sprintln(123))
Output:

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL