events

package
v0.0.0-...-7149754 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package events provides functionalities for packages to log their states as events for others to consume and display to end users in meaningful ways.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

type Bus struct {
	// contains filtered or unexported fields
}

Bus is a send/receive event bus.

func NewBus

func NewBus(options ...BusOption) Bus

NewBus creates a new event bus to send/receive events.

func (*Bus) Events

func (b *Bus) Events() <-chan Event

Events returns go channel with Event accessible only for read.

func (Bus) Send

func (b Bus) Send(e Event)

Send sends a new event to bus.

func (Bus) Shutdown

func (b Bus) Shutdown()

Shutdown shutdowns event bus.

type BusOption

type BusOption func(*Bus)

Bus is a send/receive event bus.

func WithCustomBufferSize

func WithCustomBufferSize(size int) BusOption

WithCustomBufferSize configures buffer size of underlying bus channel

func WithWaitGroup

func WithWaitGroup(wg *sync.WaitGroup) BusOption

WithWaitGroup sets wait group which is blocked if events bus is not empty.

type Event

type Event struct {
	// Description of the state.
	Description string

	// Status shows the current status of event.
	Status Status

	// TextColor of the text.
	TextColor color.Color

	// Icon of the text.
	Icon string
}

Event represents a state.

func New

func New(status Status, description string, options ...Option) Event

New creates a new event with given config.

func NewDone

func NewDone(description, icon string) Event

NewDone creates a new StatusDone event.

func NewNeutral

func NewNeutral(description string) Event

NewNeutral creates a new StatusNeutral event.

func NewOngoing

func NewOngoing(description string) Event

NewOngoing creates a new StatusOngoing event.

func (Event) IsOngoing

func (e Event) IsOngoing() bool

IsOngoing checks if state change that triggered this event is still ongoing.

func (Event) Text

func (e Event) Text() string

Text returns the text state of event.

type Option

type Option func(*Event)

Option event options

func Icon

func Icon(icon string) Option

Icon sets the text icon prefix.

func TextColor

func TextColor(c color.Color) Option

TextColor sets the text color

type Status

type Status int

Status shows if state is ongoing or completed.

const (
	StatusOngoing Status = iota
	StatusDone
	StatusNeutral
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL