Skip to content

Commit

Permalink
Add color printer interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jcwillox committed Nov 5, 2021
1 parent 0f24cd7 commit 2aa666c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions ansi.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,33 @@ func ColorFuncVar(style string) (func(string) string, string) {
}, color
}

func ColorInterface(style string) ColorPrinter {
color := ColorCode(style)
return ColorPrinter{ANSI: color}
}

type ColorPrinter struct {
ANSI string
}

func (c ColorPrinter) Print(a ...interface{}) {
Print(c.ANSI)
Print(a...)
Print(Reset)
}

func (c ColorPrinter) Printf(format string, a ...interface{}) {
Print(c.ANSI)
Printf(format, a...)
Print(Reset)
}

func (c ColorPrinter) Println(a ...interface{}) {
Print(c.ANSI)
Print(a...)
Println(Reset)
}

// DisableColors disables ANSI color codes. The default is false (colors are on).
func disableAnsiColors(disable bool) {
if plain == disable {
Expand Down

0 comments on commit 2aa666c

Please sign in to comment.