github.com/arvindram03/terraform@v0.3.7-0.20150212015210-408f838db36d/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  	Ui          cli.Ui
    18  }
    19  
    20  func (u *ColorizeUi) Ask(query string) (string, error) {
    21  	return u.Ui.Ask(u.colorize(query, u.OutputColor))
    22  }
    23  
    24  func (u *ColorizeUi) Output(message string) {
    25  	u.Ui.Output(u.colorize(message, u.OutputColor))
    26  }
    27  
    28  func (u *ColorizeUi) Info(message string) {
    29  	u.Ui.Info(u.colorize(message, u.InfoColor))
    30  }
    31  
    32  func (u *ColorizeUi) Error(message string) {
    33  	u.Ui.Error(u.colorize(message, u.ErrorColor))
    34  }
    35  
    36  func (u *ColorizeUi) colorize(message string, color string) string {
    37  	if color == "" {
    38  		return message
    39  	}
    40  
    41  	return u.Colorize.Color(fmt.Sprintf("%s%s[reset]", color, message))
    42  }