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
This commit is contained in:
Matt Ellis 2018-12-04 16:58:32 -08:00 committed by GitHub
parent 84ea2f0df7
commit bb1fa36a47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View file

@ -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)

View file

@ -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.