Disable colors if we're not in an interactive session.
@@ -17,6 +17,8 @@ package cmdutil
import (
"os"
+ "golang.org/x/crypto/ssh/terminal"
+
"github.com/pulumi/pulumi/pkg/diag"
"github.com/pulumi/pulumi/pkg/diag/colors"
"github.com/pulumi/pulumi/pkg/util/contract"
@@ -33,6 +35,14 @@ func GetGlobalColorization() colors.Colorization {
return colors.Never
}
+ // Only have colors when we're in an interactive session. If we're non-interactive (i.e.
+ // redirecting stdout), then disable colors as well. We don't want to put color tags into the
+ // stream. We only do this if the color is set to be on. If it was set to 'raw' then we don't
+ // touch it.
+ if globalColorization == colors.Always && !terminal.IsTerminal(int(os.Stdout.Fd())) {
+ return colors.Never
+ }
+
return globalColorization
}
