4 "github.com/fatih/color"
11 // UiColor is a posix shell color code to use.
17 // A list of colors that are useful. These are all non-bolded by default.
19 UiColorNone UiColor = UiColor{noColor, false}
20 UiColorRed = UiColor{int(color.FgHiRed), false}
21 UiColorGreen = UiColor{int(color.FgHiGreen), false}
22 UiColorYellow = UiColor{int(color.FgHiYellow), false}
23 UiColorBlue = UiColor{int(color.FgHiBlue), false}
24 UiColorMagenta = UiColor{int(color.FgHiMagenta), false}
25 UiColorCyan = UiColor{int(color.FgHiCyan), false}
28 // ColoredUi is a Ui implementation that colors its output according
29 // to the given color schemes for the given type of output.
30 type ColoredUi struct {
38 func (u *ColoredUi) Ask(query string) (string, error) {
39 return u.Ui.Ask(u.colorize(query, u.OutputColor))
42 func (u *ColoredUi) AskSecret(query string) (string, error) {
43 return u.Ui.AskSecret(u.colorize(query, u.OutputColor))
46 func (u *ColoredUi) Output(message string) {
47 u.Ui.Output(u.colorize(message, u.OutputColor))
50 func (u *ColoredUi) Info(message string) {
51 u.Ui.Info(u.colorize(message, u.InfoColor))
54 func (u *ColoredUi) Error(message string) {
55 u.Ui.Error(u.colorize(message, u.ErrorColor))
58 func (u *ColoredUi) Warn(message string) {
59 u.Ui.Warn(u.colorize(message, u.WarnColor))
62 func (u *ColoredUi) colorize(message string, uc UiColor) string {
63 if uc.Code == noColor {
67 attr := []color.Attribute{color.Attribute(uc.Code)}
69 attr = append(attr, color.Bold)
72 return color.New(attr...).SprintFunc()(message)