From bb1fa36a4794f665a377ce8fcc0dcd5fcee588bd Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Tue, 4 Dec 2018 16:58:32 -0800 Subject: [PATCH] Enable ANSI colorization in Windows terminal (#2269) Before the windows console will understand ANSI colorization codes the terminal must be put in a special mode by passing ENABLE_VIRTUAL_TERMINAL_PROCESSING to SetConsoleMode. This was happening as a side effect of term.StdStreams() from a docker package, which we did before displaying the update data. However, any colorization done before that call would just show the raw ANSI escape codes. Call this helper much earlier (i.e. as soon as the CLI starts up) so any messages that we print will have the correct colorization applied to them. Fixes #2214 --- CHANGELOG.md | 2 ++ cmd/pulumi.go | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15d8e8cc2..aed5fd635 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Configuration and stack commands now take a `--config-file` options. This option allows the user to override the file used to fetch and store config information for a stack during the execution of a command. +- Fix an issue where ANSI escape codes would appear in messages printed from the CLI when running on Windows. + - Fix an error about a bad icotl when trying to read sensitive input from the console and standard in was not connected to a terminal. ## 0.16.6 (Released November 28th, 2018) diff --git a/cmd/pulumi.go b/cmd/pulumi.go index 99b68cc30..c8f1e4100 100644 --- a/cmd/pulumi.go +++ b/cmd/pulumi.go @@ -28,6 +28,7 @@ import ( "github.com/blang/semver" "github.com/djherbis/times" + "github.com/docker/docker/pkg/term" "github.com/golang/glog" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -76,6 +77,10 @@ func NewPulumiCmd() *cobra.Command { "\n" + "For more information, please visit the project page: https://pulumi.io", PersistentPreRun: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error { + // We run this method for its side-effects. On windows, this will enable the windows terminal + // to understand ANSI escape codes. + _, _, _ = term.StdStreams() + // For all commands, attempt to grab out the --color value provided so we // can set the GlobalColorization value to be used by any code that doesn't // get DisplayOptions passed in.