pulumi/pkg/diag/colors/colors.go
joeduffy a626dcf6a3 Prettify the CLI in a few places
This changes a few things in the CLI, mostly just prettying it up:

    * Label all steps more clearly with the kind of step.  Also
      unify the way we present this during planning and deployment.

    * Summarize the changes that *did not* get made just as clearly
      as those that did.  In other words, stuff like this:

        info: 2 resources changed:
            +1 resource created
            -1 resource deleted
            5 resources unchanged

      and

        info: no resources required
            5 resources unchanged

    * Always print output properties when they are pertinent.
      This includes creates, replacements, and updates.

    * Show replacement creates and deletes very distinctly.  The
      create parts show up minty green and the delete parts show up
      rosey red.  These are the "physical" steps, compared to the
      "logical" step of replacement (which remains marigold).

      I still don't love where we are here.  The asymmetry between
      planning and deployment bugs me, and could be surprising.
      ("Hey, my deploy doesn't look like my plan!")  I don't know
      what developers will want to see here and I feel like in
      general we are spewing far too much into the CLI to make it
      even useful for anything but diagnosing failures afterwards.

      I propose that we should do a deep dive on this during the
      CLI epic, pulumi/pulumi-service#2.

This resolves pulumi/pulumi-fabric#305.
2017-08-06 10:05:51 -07:00

79 lines
2.5 KiB
Go

// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
package colors
import (
"fmt"
"github.com/reconquest/loreley"
"github.com/pulumi/pulumi-fabric/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 (
SpecImportant = BrightYellow // for particularly noteworthy messages.
SpecUnimportant = BrightBlack // for notes that can be skimmed or aren't very important.
SpecDebug = SpecUnimportant // for debugging.
SpecInfo = Magenta // for information.
SpecError = Red // for errors.
SpecWarning = Yellow // for warnings.
SpecLocation = Cyan // for source locations.
SpecAttention = BrightRed // for messages that are meant to grab attention.
SpecNote = White // for simple notes.
SpecCreate = Green // for adds (in the diff sense).
SpecUpdate = BrightYellow // for changes (in the diff sense).
SpecRead = BrightWhite // for reads (relatively unimportant).
SpecReplace = Yellow // for replacements (in the diff sense).
SpecDelete = Red // for deletes (in the diff sense).
SpecCreateReplacement = BrightGreen // for replacement creates (in the diff sense).
SpecDeleteReplaced = BrightRed // for replacement deletes (in the diff sense).
)