From 638be7b7b0c086c691f4d0defb6d3a07584ce7aa Mon Sep 17 00:00:00 2001 From: Danielle Tomlinson Date: Wed, 20 Feb 2019 13:56:15 +0100 Subject: [PATCH 1/2] vendor: Update to latest go-colorable --- .../mattn/go-colorable/colorable_appengine.go | 29 +++++++++++++++++++ vendor/vendor.json | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 vendor/github.com/mattn/go-colorable/colorable_appengine.go diff --git a/vendor/github.com/mattn/go-colorable/colorable_appengine.go b/vendor/github.com/mattn/go-colorable/colorable_appengine.go new file mode 100644 index 000000000000..1f28d773d748 --- /dev/null +++ b/vendor/github.com/mattn/go-colorable/colorable_appengine.go @@ -0,0 +1,29 @@ +// +build appengine + +package colorable + +import ( + "io" + "os" + + _ "github.com/mattn/go-isatty" +) + +// NewColorable return new instance of Writer which handle escape sequence. +func NewColorable(file *os.File) io.Writer { + if file == nil { + panic("nil passed instead of *os.File to NewColorable()") + } + + return file +} + +// NewColorableStdout return new instance of Writer which handle escape sequence for stdout. +func NewColorableStdout() io.Writer { + return os.Stdout +} + +// NewColorableStderr return new instance of Writer which handle escape sequence for stderr. +func NewColorableStderr() io.Writer { + return os.Stderr +} diff --git a/vendor/vendor.json b/vendor/vendor.json index 6856a72452b0..0c78974b1987 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -240,7 +240,7 @@ {"path":"github.com/jmespath/go-jmespath","checksumSHA1":"3/Bhy+ua/DCv2ElMD5GzOYSGN6g=","comment":"0.2.2-2-gc01cf91","revision":"c01cf91b011868172fdcd9f41838e80c9d716264"}, {"path":"github.com/kr/pretty","checksumSHA1":"eOXF2PEvYLMeD8DSzLZJWbjYzco=","revision":"cfb55aafdaf3ec08f0db22699ab822c50091b1c4","revisionTime":"2016-08-23T17:07:15Z"}, {"path":"github.com/kr/text","checksumSHA1":"uulQHQ7IsRKqDudBC8Go9J0gtAc=","revision":"7cafcd837844e784b526369c9bce262804aebc60","revisionTime":"2016-05-04T02:26:26Z"}, - {"path":"github.com/mattn/go-colorable","checksumSHA1":"iRRp6PUlGXJgudZ3FD5jySI0Ukk=","revision":"efa589957cd060542a26d2dd7832fd6a6c6c3ade","revisionTime":"2018-03-10T13:32:14Z"}, + {"path":"github.com/mattn/go-colorable","checksumSHA1":"SEnjvwVyfuU2xBaOfXfwPD5MZqk=","revision":"efa589957cd060542a26d2dd7832fd6a6c6c3ade","revisionTime":"2018-03-10T13:32:14Z"}, {"path":"github.com/mattn/go-isatty","checksumSHA1":"AZO2VGorXTMDiSVUih3k73vORHY=","revision":"6ca4dbf54d38eea1a992b3c722a76a5d1c4cb25c","revisionTime":"2017-11-07T05:05:31Z"}, {"path":"github.com/mattn/go-shellwords","checksumSHA1":"ajImwVZHzsI+aNwsgzCSFSbmJqs=","revision":"f4e566c536cf69158e808ec28ef4182a37fdc981","revisionTime":"2015-03-21T17:42:21Z"}, {"path":"github.com/matttproud/golang_protobuf_extensions/pbutil","checksumSHA1":"bKMZjd2wPw13VwoE7mBeSv5djFA=","revision":"c12348ce28de40eed0136aa2b644d0ee0650e56c","revisionTime":"2016-04-24T11:30:07Z"}, From ed9818a5705d3d773f441cbb88f0e1f7c522e38f Mon Sep 17 00:00:00 2001 From: Danielle Tomlinson Date: Wed, 20 Feb 2019 14:01:35 +0100 Subject: [PATCH 2/2] 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. --- command/commands.go | 5 +++-- main.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/command/commands.go b/command/commands.go index 37291f8b32b8..ab2173904e60 100644 --- a/command/commands.go +++ b/command/commands.go @@ -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(), } } diff --git a/main.go b/main.go index 5f7169670501..9637c774202f 100644 --- a/main.go +++ b/main.go @@ -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