Skip to content

Commit 9add6ce

Browse files
committed
Colored output now works on Windows
1 parent 84283eb commit 9add6ce

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

commands/root/root.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import (
2121
"io/ioutil"
2222
"os"
2323

24+
"golang.org/x/crypto/ssh/terminal"
25+
26+
"github.com/mattn/go-colorable"
27+
2428
"github.com/arduino/go-paths-helper"
2529

2630
"github.com/arduino/arduino-cli/commands"
@@ -75,7 +79,13 @@ func preRun(cmd *cobra.Command, args []string) {
7579
logrus.SetOutput(ioutil.Discard)
7680
} else {
7781
// Else print on stderr.
78-
commands.ErrLogrus.Out = os.Stderr
82+
83+
// Workaround to get colored output on windows
84+
if terminal.IsTerminal(int(os.Stdout.Fd())) {
85+
logrus.SetFormatter(&logrus.TextFormatter{ForceColors: true})
86+
}
87+
logrus.SetOutput(colorable.NewColorableStdout())
88+
commands.ErrLogrus.Out = colorable.NewColorableStderr()
7989
formatter.SetLogger(commands.ErrLogrus)
8090
}
8191
initConfigs()

0 commit comments

Comments
 (0)