2023-05-02 11:33:06 -04:00
|
|
|
// Copyright IBM Corp. 2014, 2026
|
2023-08-10 18:43:27 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-05-02 11:33:06 -04:00
|
|
|
|
2014-07-12 23:59:16 -04:00
|
|
|
package command
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2023-12-20 06:04:10 -05:00
|
|
|
"github.com/hashicorp/cli"
|
2014-07-12 23:59:16 -04:00
|
|
|
"github.com/mitchellh/colorstring"
|
|
|
|
|
)
|
|
|
|
|
|
2023-08-18 08:53:25 -04:00
|
|
|
// ColorizeUi is a Ui implementation that colors its output according
|
2014-07-12 23:59:16 -04:00
|
|
|
// to the given color schemes for the given type of output.
|
|
|
|
|
type ColorizeUi struct {
|
|
|
|
|
Colorize *colorstring.Colorize
|
|
|
|
|
OutputColor string
|
|
|
|
|
InfoColor string
|
|
|
|
|
ErrorColor string
|
2015-03-05 15:22:34 -05:00
|
|
|
WarnColor string
|
2014-07-12 23:59:16 -04:00
|
|
|
Ui cli.Ui
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (u *ColorizeUi) Ask(query string) (string, error) {
|
|
|
|
|
return u.Ui.Ask(u.colorize(query, u.OutputColor))
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-29 14:07:13 -04:00
|
|
|
func (u *ColorizeUi) AskSecret(query string) (string, error) {
|
|
|
|
|
return u.Ui.AskSecret(u.colorize(query, u.OutputColor))
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-12 23:59:16 -04:00
|
|
|
func (u *ColorizeUi) Output(message string) {
|
|
|
|
|
u.Ui.Output(u.colorize(message, u.OutputColor))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (u *ColorizeUi) Info(message string) {
|
|
|
|
|
u.Ui.Info(u.colorize(message, u.InfoColor))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (u *ColorizeUi) Error(message string) {
|
|
|
|
|
u.Ui.Error(u.colorize(message, u.ErrorColor))
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-05 15:22:34 -05:00
|
|
|
func (u *ColorizeUi) Warn(message string) {
|
|
|
|
|
u.Ui.Warn(u.colorize(message, u.WarnColor))
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-12 23:59:16 -04:00
|
|
|
func (u *ColorizeUi) colorize(message string, color string) string {
|
|
|
|
|
if color == "" {
|
|
|
|
|
return message
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return u.Colorize.Color(fmt.Sprintf("%s%s[reset]", color, message))
|
|
|
|
|
}
|