Support colors on Windows (#1312)

mine
mattn 2021-11-27 06:12:03 +09:00 committed by GitHub
parent 6b6a490c73
commit 256441692a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -31,7 +31,7 @@ func printInfo() {
func printLogo(c color.Paint) { func printLogo(c color.Paint) {
for _, l := range ui.LogoSmall { for _, l := range ui.LogoSmall {
fmt.Println(color.Colorize(l, c)) fmt.Fprintln(out, color.Colorize(l, c))
} }
fmt.Println() fmt.Fprintln(out)
} }

View File

@ -8,6 +8,7 @@ import (
"github.com/derailed/k9s/internal/color" "github.com/derailed/k9s/internal/color"
"github.com/derailed/k9s/internal/config" "github.com/derailed/k9s/internal/config"
"github.com/derailed/k9s/internal/view" "github.com/derailed/k9s/internal/view"
"github.com/mattn/go-colorable"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -33,6 +34,8 @@ var (
Long: longAppDesc, Long: longAppDesc,
Run: run, Run: run,
} }
out = colorable.NewColorableStdout()
) )
func init() { func init() {

View File

@ -41,8 +41,8 @@ func printVersion(short bool) {
func printTuple(fmat, section, value string, outputColor color.Paint) { func printTuple(fmat, section, value string, outputColor color.Paint) {
if outputColor != -1 { if outputColor != -1 {
fmt.Printf(fmat, color.Colorize(section+":", outputColor), color.Colorize(value, color.LightGray)) fmt.Fprintf(out, fmat, color.Colorize(section+":", outputColor), color.Colorize(value, color.LightGray))
return return
} }
fmt.Printf(fmat, section, value) fmt.Fprintf(out, fmat, section, value)
} }