The existing logic would flow colorization information into the engine, so depending on the settings in the CLI, the engine may or may not have emitted colorized events. This coupling is not great and we want to start moving to a world where the presentation happens exclusively at the CLI level. With this change, the engine will always produce strings that have the colorization formatting directives (i.e. the directives that reconquest/loreley understands) and the CLI will apply colorization (which could mean either running loreley to turn the directives into ANSI escape codes, or drop them or retain them, for debuging purposes). Fixes #742
107 lines
2 KiB
Go
107 lines
2 KiB
Go
// Copyright 2017, Pulumi Corporation. All rights reserved.
|
|
|
|
package engine
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/pulumi/pulumi/pkg/diag"
|
|
"github.com/pulumi/pulumi/pkg/diag/colors"
|
|
)
|
|
|
|
// Event represents an event generated by the engine during an operation. The underlying
|
|
// type for the `Payload` field will differ depending on the value of the `Type` field
|
|
type Event struct {
|
|
Type EventType
|
|
Payload interface{}
|
|
}
|
|
|
|
// EventType is the kind of event being emitted.
|
|
type EventType string
|
|
|
|
const (
|
|
CancelEvent EventType = "cancel"
|
|
StdoutColorEvent EventType = "stdoutcolor"
|
|
DiagEvent EventType = "diag"
|
|
)
|
|
|
|
func cancelEvent() Event {
|
|
return Event{Type: CancelEvent}
|
|
}
|
|
|
|
// DiagEventPayload is the payload for an event with type `diag`
|
|
type DiagEventPayload struct {
|
|
Message string
|
|
Color colors.Colorization
|
|
Severity diag.Severity
|
|
}
|
|
|
|
type StdoutEventPayload struct {
|
|
Message string
|
|
Color colors.Colorization
|
|
}
|
|
|
|
func stdOutEventWithColor(s fmt.Stringer) Event {
|
|
return Event{
|
|
Type: StdoutColorEvent,
|
|
Payload: StdoutEventPayload{
|
|
Message: s.String(),
|
|
Color: colors.Raw,
|
|
},
|
|
}
|
|
}
|
|
|
|
func diagDebugEvent(msg string) Event {
|
|
return Event{
|
|
Type: DiagEvent,
|
|
Payload: DiagEventPayload{
|
|
Message: msg,
|
|
Color: colors.Raw,
|
|
Severity: diag.Debug,
|
|
},
|
|
}
|
|
}
|
|
|
|
func diagInfoEvent(msg string) Event {
|
|
return Event{
|
|
Type: DiagEvent,
|
|
Payload: DiagEventPayload{
|
|
Message: msg,
|
|
Color: colors.Raw,
|
|
Severity: diag.Info,
|
|
},
|
|
}
|
|
}
|
|
|
|
func diagInfoerrEvent(msg string) Event {
|
|
return Event{
|
|
Type: DiagEvent,
|
|
Payload: DiagEventPayload{
|
|
Message: msg,
|
|
Color: colors.Raw,
|
|
Severity: diag.Infoerr,
|
|
},
|
|
}
|
|
}
|
|
|
|
func diagErrorEvent(msg string) Event {
|
|
return Event{
|
|
Type: DiagEvent,
|
|
Payload: DiagEventPayload{
|
|
Message: msg,
|
|
Color: colors.Raw,
|
|
Severity: diag.Error,
|
|
},
|
|
}
|
|
}
|
|
|
|
func diagWarningEvent(msg string) Event {
|
|
return Event{
|
|
Type: DiagEvent,
|
|
Payload: DiagEventPayload{
|
|
Message: msg,
|
|
Color: colors.Raw,
|
|
Severity: diag.Warning,
|
|
},
|
|
}
|
|
}
|