pulumi/pkg/diag/colors/colors.go
joeduffy 7f0a97a4e3 Print configuration variables; etc.
This change does a few things:

* First and foremost, it tracks configuration variables that are
  initialized, and optionally prints them out as part of the
  prelude/header (based on --show-config), both in a dry-run (plan)
  and in an actual deployment (apply).

* It tidies up some of the colorization and messages, and includes
  nice banners like "Deploying changes:", etc.

* Fix an assertion.

* Issue a new error

      "One or more errors occurred while applying X's configuration"

  just to make it easier to distinguish configuration-specific
  failures from ordinary ones.

* Change config keys to tokens.Token, not tokens.ModuleMember,
  since it is legal for keys to represent class members (statics).
2017-02-28 10:32:24 -08:00

72 lines
2 KiB
Go

// Copyright 2016 Pulumi, Inc. All rights reserved.
package colors
import (
"fmt"
"github.com/reconquest/loreley"
"github.com/pulumi/coconut/pkg/util/contract"
)
const colorLeft = "<{%"
const colorRight = "%}>"
func init() {
// Change the Loreley delimiters from { and }, to something more complex, to avoid accidental collisions.
loreley.DelimLeft = colorLeft
loreley.DelimRight = colorRight
}
func Command(s string) string {
return colorLeft + s + colorRight
}
func Colorize(s fmt.Stringer) string {
txt := s.String()
return ColorizeText(txt)
}
func ColorizeText(s string) string {
c, err := loreley.CompileAndExecuteToString(s, nil, nil)
contract.Assertf(err == nil, "Expected no errors during string colorization; str=%v, err=%v", s, err)
return c
}
// Basic
var (
Black = Command("fg 0")
Red = Command("fg 1")
Green = Command("fg 2")
Yellow = Command("fg 3")
Blue = Command("fg 4")
Magenta = Command("fg 5")
Cyan = Command("fg 6")
White = Command("fg 7")
BrightBlack = Command("fg 8")
BrightRed = Command("fg 9")
BrightGreen = Command("fg 10")
BrightYellow = Command("fg 11")
BrightBlue = Command("fg 12")
BrightMagenta = Command("fg 13")
BrightCyan = Command("fg 14")
BrightWhite = Command("fg 15")
Reset = Command("reset")
)
// Special predefined colors for logical conditions.
var (
SpecInfo = Magenta // for information.
SpecError = Red // for errors.
SpecWarning = Yellow // for warnings.
SpecLocation = Cyan // for source locations.
SpecFatal = BrightRed // for fatal errors
SpecNote = White // for notes
SpecImportant = BrightYellow // for particularly noteworthy messages.
SpecUnimportant = BrightBlack // for notes that can be skimmed or aren't very important.
SpecAdded = Green // for adds (in the diff sense).
SpecChanged = Yellow // for changes (in the diff sense).
SpecDeleted = Red // for deletes (in the diff sense).
)