mirror of
https://github.com/go-task/task.git
synced 2025-11-23 22:24:45 +02:00
Enforce NO_COLOR=1 on tests to make sure it passes
Closes #459 Fixes #480 Ref #343 Ref fatih/color#137
This commit is contained in:
@@ -6,17 +6,16 @@ import (
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
type Color func() PrintFunc
|
||||
type PrintFunc func(io.Writer, string, ...interface{})
|
||||
|
||||
var (
|
||||
Default PrintFunc = color.New(color.Reset).FprintfFunc()
|
||||
Blue PrintFunc = color.New(color.FgBlue).FprintfFunc()
|
||||
Green PrintFunc = color.New(color.FgGreen).FprintfFunc()
|
||||
Cyan PrintFunc = color.New(color.FgCyan).FprintfFunc()
|
||||
Yellow PrintFunc = color.New(color.FgYellow).FprintfFunc()
|
||||
Magenta PrintFunc = color.New(color.FgMagenta).FprintfFunc()
|
||||
Red PrintFunc = color.New(color.FgRed).FprintfFunc()
|
||||
)
|
||||
func Default() PrintFunc { return color.New(color.Reset).FprintfFunc() }
|
||||
func Blue() PrintFunc { return color.New(color.FgBlue).FprintfFunc() }
|
||||
func Green() PrintFunc { return color.New(color.FgGreen).FprintfFunc() }
|
||||
func Cyan() PrintFunc { return color.New(color.FgCyan).FprintfFunc() }
|
||||
func Yellow() PrintFunc { return color.New(color.FgYellow).FprintfFunc() }
|
||||
func Magenta() PrintFunc { return color.New(color.FgMagenta).FprintfFunc() }
|
||||
func Red() PrintFunc { return color.New(color.FgRed).FprintfFunc() }
|
||||
|
||||
// Logger is just a wrapper that prints stuff to STDOUT or STDERR,
|
||||
// with optional color.
|
||||
@@ -28,37 +27,39 @@ type Logger struct {
|
||||
}
|
||||
|
||||
// Outf prints stuff to STDOUT.
|
||||
func (l *Logger) Outf(print PrintFunc, s string, args ...interface{}) {
|
||||
func (l *Logger) Outf(color Color, s string, args ...interface{}) {
|
||||
if len(args) == 0 {
|
||||
s, args = "%s", []interface{}{s}
|
||||
}
|
||||
if !l.Color {
|
||||
print = Default
|
||||
color = Default
|
||||
}
|
||||
print := color()
|
||||
print(l.Stdout, s+"\n", args...)
|
||||
}
|
||||
|
||||
// VerboseOutf prints stuff to STDOUT if verbose mode is enabled.
|
||||
func (l *Logger) VerboseOutf(print PrintFunc, s string, args ...interface{}) {
|
||||
func (l *Logger) VerboseOutf(color Color, s string, args ...interface{}) {
|
||||
if l.Verbose {
|
||||
l.Outf(print, s, args...)
|
||||
l.Outf(color, s, args...)
|
||||
}
|
||||
}
|
||||
|
||||
// Errf prints stuff to STDERR.
|
||||
func (l *Logger) Errf(print PrintFunc, s string, args ...interface{}) {
|
||||
func (l *Logger) Errf(color Color, s string, args ...interface{}) {
|
||||
if len(args) == 0 {
|
||||
s, args = "%s", []interface{}{s}
|
||||
}
|
||||
if !l.Color {
|
||||
print = Default
|
||||
color = Default
|
||||
}
|
||||
print := color()
|
||||
print(l.Stderr, s+"\n", args...)
|
||||
}
|
||||
|
||||
// VerboseErrf prints stuff to STDERR if verbose mode is enabled.
|
||||
func (l *Logger) VerboseErrf(print PrintFunc, s string, args ...interface{}) {
|
||||
func (l *Logger) VerboseErrf(color Color, s string, args ...interface{}) {
|
||||
if l.Verbose {
|
||||
l.Errf(print, s, args...)
|
||||
l.Errf(color, s, args...)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user