ui: Support colored output on Windows

This commit uses the go-colorable library to enable support for coloured
UI output on Windows. This acts as a compatibility layer that takes
standard unix-y terminal codes and translates them into the requisite
windows calls as required.
This commit is contained in:
Danielle Tomlinson 2019-02-20 14:01:35 +01:00
parent 3ae58eba84
commit 91c300c310
2 changed files with 6 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/hashicorp/nomad/command/agent"
"github.com/hashicorp/nomad/drivers/docker/docklog"
"github.com/hashicorp/nomad/version"
colorable "github.com/mattn/go-colorable"
"github.com/mitchellh/cli"
)
@ -63,8 +64,8 @@ func Commands(metaPtr *Meta, agentUi cli.Ui) map[string]cli.CommandFactory {
if meta.Ui == nil {
meta.Ui = &cli.BasicUi{
Reader: os.Stdin,
Writer: os.Stdout,
ErrorWriter: os.Stderr,
Writer: colorable.NewColorableStdout(),
ErrorWriter: colorable.NewColorableStderr(),
}
}

View File

@ -12,6 +12,7 @@ import (
"github.com/hashicorp/nomad/command"
"github.com/hashicorp/nomad/drivers/docker/docklog"
"github.com/hashicorp/nomad/version"
"github.com/mattn/go-colorable"
"github.com/mitchellh/cli"
"github.com/sean-/seed"
"golang.org/x/crypto/ssh/terminal"
@ -91,8 +92,8 @@ func RunCustom(args []string) int {
isTerminal := terminal.IsTerminal(int(os.Stdout.Fd()))
metaPtr.Ui = &cli.BasicUi{
Reader: os.Stdin,
Writer: os.Stdout,
ErrorWriter: os.Stderr,
Writer: colorable.NewColorableStdout(),
ErrorWriter: colorable.NewColorableStderr(),
}
// The Nomad agent never outputs color