ui

package
Version: v0.0.0-...-51f9457 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewActivity

func NewActivity(ctx context.Context, group *ActivityGroup, kind string) (context.Context, context.CancelFunc)

NewActivity creates a new activity and sets it as current in the context.

Does nothing if the context is already associated with an activity.

This also replaces the logger with the one that logs into the activity. If `group` is not-nil, adds this activity into the group. Otherwise it stands on its own (whatever it means depends on the UI implementation).

If there's no Implementation in the context, sets up a primitive activity implementation that just logs into the logger.

The activity must be closed through the returned CancelFunc. Note that it will also close the associated context.

func SetImplementation

func SetImplementation(ctx context.Context, impl Implementation) context.Context

SetImplementation puts the Implementation into the context.

Types

type Activity

type Activity interface {
	// Progress updates the activity progress.
	Progress(ctx context.Context, title string, units Units, cur, total int64)
	// Log is called by the logging system when the activity is installed into the context.
	Log(ctx context.Context, level logging.Level, calldepth int, f string, args []interface{})
	// Done is called when the activity finishes.
	Done(ctx context.Context)
}

Activity is a single-threaded process with a progress indicator.

Once installed into a context it also acts as a logger sink in that context.

The progress is allowed to "jump back" (e.g. when a download is restarted).

func CurrentActivity

func CurrentActivity(ctx context.Context) Activity

CurrentActivity returns the current activity in the context.

Constructs a primitive implementation that just logs into the logger if there's no activity in the context.

type ActivityGroup

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

ActivityGroup is a group of related activities running at the same time.

Used to assign unique titles to them.

type FancyImplementation

type FancyImplementation struct {
	Out *os.File // where to write the output, should be a terminal
	// contains filtered or unexported fields
}

FancyImplementation implements activities UI using terminal escape sequences.

func (*FancyImplementation) NewActivity

func (impl *FancyImplementation) NewActivity(ctx context.Context, group *ActivityGroup, kind string) Activity

NewActivity is a part of Implementation interface.

type Implementation

type Implementation interface {
	// NewActivity creates a new activity, optionally putting it in a group.
	NewActivity(ctx context.Context, group *ActivityGroup, kind string) Activity
}

Implementation implements a UI that shows activities.

It lives in the context.

type Units

type Units string

Units is what kind of units to use for an activity progress.

const UnitBytes Units = "bytes"

UnitBytes indicates units passed to Progress are bytes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL