packer: don't output colors if Windows and not Cygwin
This commit is contained in:
parent
e11b6617f3
commit
27a07cc9aa
|
@ -9,6 +9,7 @@ FEATURES:
|
||||||
|
|
||||||
IMPROVEMENTS:
|
IMPROVEMENTS:
|
||||||
|
|
||||||
|
* core: Colors won't be outputted on Windows unless in Cygwin.
|
||||||
* builder/amazon/all: Added `iam_instance_profile` to launch the source
|
* builder/amazon/all: Added `iam_instance_profile` to launch the source
|
||||||
image with a given IAM profile. [GH-226]
|
image with a given IAM profile. [GH-226]
|
||||||
|
|
||||||
|
|
19
packer/ui.go
19
packer/ui.go
|
@ -10,6 +10,7 @@ import (
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"runtime"
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -80,6 +81,10 @@ func (u *ColoredUi) Error(message string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *ColoredUi) colorize(message string, color UiColor, bold bool) string {
|
func (u *ColoredUi) colorize(message string, color UiColor, bold bool) string {
|
||||||
|
if !u.supportsColors() {
|
||||||
|
return message
|
||||||
|
}
|
||||||
|
|
||||||
attr := 0
|
attr := 0
|
||||||
if bold {
|
if bold {
|
||||||
attr = 1
|
attr = 1
|
||||||
|
@ -88,6 +93,20 @@ func (u *ColoredUi) colorize(message string, color UiColor, bold bool) string {
|
||||||
return fmt.Sprintf("\033[%d;%d;40m%s\033[0m", attr, color, message)
|
return fmt.Sprintf("\033[%d;%d;40m%s\033[0m", attr, color, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *ColoredUi) supportsColors() bool {
|
||||||
|
// For now, on non-Windows machine, just assume it does
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// On Windows, if we appear to be in Cygwin, then it does
|
||||||
|
cygwin := os.Getenv("CYGWIN") != "" ||
|
||||||
|
os.Getenv("OSTYPE") == "cygwin" ||
|
||||||
|
os.Getenv("TERM") == "cygwin"
|
||||||
|
|
||||||
|
return cygwin
|
||||||
|
}
|
||||||
|
|
||||||
func (u *PrefixedUi) Ask(query string) (string, error) {
|
func (u *PrefixedUi) Ask(query string) (string, error) {
|
||||||
return u.Ui.Ask(u.prefixLines(u.SayPrefix, query))
|
return u.Ui.Ask(u.prefixLines(u.SayPrefix, query))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue