From f34a3a68054eaad15d76c871eeabfa854df47dae Mon Sep 17 00:00:00 2001 From: Frank Szendzielarz <33515470+FrankSzendzielarz@users.noreply.github.com> Date: Thu, 25 Jul 2019 13:46:42 +0200 Subject: [PATCH] cmd/clef: fix colored output on Windows (#19889) * Fixes #19861 - coloured output * cmd/clef: minor formatting nit * cmd/clef: bleah, stupid github editor --- cmd/clef/main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/clef/main.go b/cmd/clef/main.go index 85ec5647cd..5567fb8f59 100644 --- a/cmd/clef/main.go +++ b/cmd/clef/main.go @@ -53,6 +53,8 @@ import ( "github.com/ethereum/go-ethereum/signer/fourbyte" "github.com/ethereum/go-ethereum/signer/rules" "github.com/ethereum/go-ethereum/signer/storage" + colorable "github.com/mattn/go-colorable" + "github.com/mattn/go-isatty" "gopkg.in/urfave/cli.v1" ) @@ -392,7 +394,13 @@ func initialize(c *cli.Context) error { } fmt.Println() } - log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(c.Int(logLevelFlag.Name)), log.StreamHandler(logOutput, log.TerminalFormat(true)))) + usecolor := (isatty.IsTerminal(os.Stderr.Fd()) || isatty.IsCygwinTerminal(os.Stderr.Fd())) && os.Getenv("TERM") != "dumb" + output := io.Writer(logOutput) + if usecolor { + output = colorable.NewColorable(logOutput) + } + log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(c.Int(logLevelFlag.Name)), log.StreamHandler(output, log.TerminalFormat(usecolor)))) + return nil }