@@ -6,17 +6,16 @@ import (
66 "github.com/fatih/color"
77)
88
9+ type Color func () PrintFunc
910type PrintFunc func (io.Writer , string , ... interface {})
1011
11- var (
12- Default PrintFunc = color .New (color .Reset ).FprintfFunc ()
13- Blue PrintFunc = color .New (color .FgBlue ).FprintfFunc ()
14- Green PrintFunc = color .New (color .FgGreen ).FprintfFunc ()
15- Cyan PrintFunc = color .New (color .FgCyan ).FprintfFunc ()
16- Yellow PrintFunc = color .New (color .FgYellow ).FprintfFunc ()
17- Magenta PrintFunc = color .New (color .FgMagenta ).FprintfFunc ()
18- Red PrintFunc = color .New (color .FgRed ).FprintfFunc ()
19- )
12+ func Default () PrintFunc { return color .New (color .Reset ).FprintfFunc () }
13+ func Blue () PrintFunc { return color .New (color .FgBlue ).FprintfFunc () }
14+ func Green () PrintFunc { return color .New (color .FgGreen ).FprintfFunc () }
15+ func Cyan () PrintFunc { return color .New (color .FgCyan ).FprintfFunc () }
16+ func Yellow () PrintFunc { return color .New (color .FgYellow ).FprintfFunc () }
17+ func Magenta () PrintFunc { return color .New (color .FgMagenta ).FprintfFunc () }
18+ func Red () PrintFunc { return color .New (color .FgRed ).FprintfFunc () }
2019
2120// Logger is just a wrapper that prints stuff to STDOUT or STDERR,
2221// with optional color.
@@ -28,37 +27,39 @@ type Logger struct {
2827}
2928
3029// Outf prints stuff to STDOUT.
31- func (l * Logger ) Outf (print PrintFunc , s string , args ... interface {}) {
30+ func (l * Logger ) Outf (color Color , s string , args ... interface {}) {
3231 if len (args ) == 0 {
3332 s , args = "%s" , []interface {}{s }
3433 }
3534 if ! l .Color {
36- print = Default
35+ color = Default
3736 }
37+ print := color ()
3838 print (l .Stdout , s + "\n " , args ... )
3939}
4040
4141// VerboseOutf prints stuff to STDOUT if verbose mode is enabled.
42- func (l * Logger ) VerboseOutf (print PrintFunc , s string , args ... interface {}) {
42+ func (l * Logger ) VerboseOutf (color Color , s string , args ... interface {}) {
4343 if l .Verbose {
44- l .Outf (print , s , args ... )
44+ l .Outf (color , s , args ... )
4545 }
4646}
4747
4848// Errf prints stuff to STDERR.
49- func (l * Logger ) Errf (print PrintFunc , s string , args ... interface {}) {
49+ func (l * Logger ) Errf (color Color , s string , args ... interface {}) {
5050 if len (args ) == 0 {
5151 s , args = "%s" , []interface {}{s }
5252 }
5353 if ! l .Color {
54- print = Default
54+ color = Default
5555 }
56+ print := color ()
5657 print (l .Stderr , s + "\n " , args ... )
5758}
5859
5960// VerboseErrf prints stuff to STDERR if verbose mode is enabled.
60- func (l * Logger ) VerboseErrf (print PrintFunc , s string , args ... interface {}) {
61+ func (l * Logger ) VerboseErrf (color Color , s string , args ... interface {}) {
6162 if l .Verbose {
62- l .Errf (print , s , args ... )
63+ l .Errf (color , s , args ... )
6364 }
6465}
0 commit comments