github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/cli_ui.go (about) 1 package command 2 3 import ( 4 "fmt" 5 6 "github.com/mitchellh/cli" 7 "github.com/mitchellh/colorstring" 8 ) 9 10 // ColoredUi is a Ui implementation that colors its output according 11 // to the given color schemes for the given type of output. 12 type ColorizeUi struct { 13 Colorize *colorstring.Colorize 14 OutputColor string 15 InfoColor string 16 ErrorColor string 17 WarnColor string 18 Ui cli.Ui 19 } 20 21 func (u *ColorizeUi) Ask(query string) (string, error) { 22 return u.Ui.Ask(u.colorize(query, u.OutputColor)) 23 } 24 25 func (u *ColorizeUi) AskSecret(query string) (string, error) { 26 return u.Ui.AskSecret(u.colorize(query, u.OutputColor)) 27 } 28 29 func (u *ColorizeUi) Output(message string) { 30 u.Ui.Output(u.colorize(message, u.OutputColor)) 31 } 32 33 func (u *ColorizeUi) Info(message string) { 34 u.Ui.Info(u.colorize(message, u.InfoColor)) 35 } 36 37 func (u *ColorizeUi) Error(message string) { 38 u.Ui.Error(u.colorize(message, u.ErrorColor)) 39 } 40 41 func (u *ColorizeUi) Warn(message string) { 42 u.Ui.Warn(u.colorize(message, u.WarnColor)) 43 } 44 45 func (u *ColorizeUi) colorize(message string, color string) string { 46 if color == "" { 47 return message 48 } 49 50 return u.Colorize.Color(fmt.Sprintf("%s%s[reset]", color, message)) 51 }