7 // UiColor is a posix shell color code to use.
13 // A list of colors that are useful. These are all non-bolded by default.
15 UiColorNone UiColor = UiColor{-1, false}
16 UiColorRed = UiColor{31, false}
17 UiColorGreen = UiColor{32, false}
18 UiColorYellow = UiColor{33, false}
19 UiColorBlue = UiColor{34, false}
20 UiColorMagenta = UiColor{35, false}
21 UiColorCyan = UiColor{36, false}
24 // ColoredUi is a Ui implementation that colors its output according
25 // to the given color schemes for the given type of output.
26 type ColoredUi struct {
34 func (u *ColoredUi) Ask(query string) (string, error) {
35 return u.Ui.Ask(u.colorize(query, u.OutputColor))
38 func (u *ColoredUi) AskSecret(query string) (string, error) {
39 return u.Ui.AskSecret(u.colorize(query, u.OutputColor))
42 func (u *ColoredUi) Output(message string) {
43 u.Ui.Output(u.colorize(message, u.OutputColor))
46 func (u *ColoredUi) Info(message string) {
47 u.Ui.Info(u.colorize(message, u.InfoColor))
50 func (u *ColoredUi) Error(message string) {
51 u.Ui.Error(u.colorize(message, u.ErrorColor))
54 func (u *ColoredUi) Warn(message string) {
55 u.Ui.Warn(u.colorize(message, u.WarnColor))
58 func (u *ColoredUi) colorize(message string, color UiColor) string {
68 return fmt.Sprintf("\033[%d;%dm%s\033[0m", attr, color.Code, message)