Merge pull request #125 from github/ansi-colorfunc
Make use of ansi.ColorFunc
This commit is contained in:
commit
15b76ce703
1 changed files with 11 additions and 24 deletions
|
|
@ -15,33 +15,20 @@ func NewColorable(f *os.File) io.Writer {
|
|||
}
|
||||
|
||||
func makeColorFunc(color string) func(string) string {
|
||||
cf := ansi.ColorFunc(color)
|
||||
return func(arg string) string {
|
||||
output := arg
|
||||
if isatty.IsTerminal(os.Stdout.Fd()) {
|
||||
output = ansi.Color(color+arg+ansi.Reset, "")
|
||||
return cf(arg)
|
||||
}
|
||||
|
||||
return output
|
||||
return arg
|
||||
}
|
||||
}
|
||||
|
||||
var Black = makeColorFunc(ansi.Black)
|
||||
var White = makeColorFunc(ansi.White)
|
||||
var Magenta = makeColorFunc(ansi.Magenta)
|
||||
var Cyan = makeColorFunc(ansi.Cyan)
|
||||
var Red = makeColorFunc(ansi.Red)
|
||||
var Yellow = makeColorFunc(ansi.Yellow)
|
||||
var Blue = makeColorFunc(ansi.Blue)
|
||||
var Green = makeColorFunc(ansi.Green)
|
||||
var Gray = makeColorFunc(ansi.LightBlack)
|
||||
|
||||
func Bold(arg string) string {
|
||||
output := arg
|
||||
if isatty.IsTerminal(os.Stdout.Fd()) {
|
||||
// This is really annoying. If you just define Bold as ColorFunc("+b") it will properly bold but
|
||||
// will not use the default color, resulting in black and probably unreadable text. This forces
|
||||
// the default color before bolding.
|
||||
output = ansi.Color(ansi.DefaultFG+arg+ansi.Reset, "+b")
|
||||
}
|
||||
return output
|
||||
}
|
||||
var Magenta = makeColorFunc("magenta")
|
||||
var Cyan = makeColorFunc("cyan")
|
||||
var Red = makeColorFunc("red")
|
||||
var Yellow = makeColorFunc("yellow")
|
||||
var Blue = makeColorFunc("blue")
|
||||
var Green = makeColorFunc("green")
|
||||
var Gray = makeColorFunc("black+h")
|
||||
var Bold = makeColorFunc("default+b")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue