manidator

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2017 License: BSD-3-Clause Imports: 8 Imported by: 1

README

go-manidator

Build Status GitHub license Go Documentation

Manidator is a utility to display the last line of output from one or more "dators".

A "dator" (from "updater") is simply something that can provide live line-based output by implementing the manidator.Dator interface.

Why does manidator exist?

I wanted to provide output from multiple commands at the same time, but I didn't want the output of each command to get mixed up with the output of the others.

See go-aws-lanes for details on that.

Where does the name come from?

The name manidator is a sort of portmanteau of "many" and "updater".

Documentation

Index

Constants

View Source
const ESC = 27

Variables

View Source
var (
	// DefaultInterval is the default amount of time to wait between each update to the screen.
	DefaultInterval = 50 * time.Millisecond

	// DefaultTerminalWidth is the default size of the output window when it cannot be determined automatically.
	DefaultTerminalWidth = 80
)

Functions

This section is empty.

Types

type Dator

type Dator interface {
	io.WriteCloser

	// GetName returns the name of the Dator.
	GetName() string

	// GetLastLine returns the last line of output from the Dator, with leading and trailing spaces trimmed off.
	GetLastLine() string

	// IsClosed indicates that the Dator is closed and will provide no additional output.
	IsClosed() bool
}

Dator provides an interface for an object that can provide the last line of output from, say, a command or event stream.

func NewDator

func NewDator(name string) Dator

NewDator creates a new DefaultDator with the specified name.

type DefaultDator

type DefaultDator struct {
	*bytes.Buffer
	// contains filtered or unexported fields
}

DefaultDator is the default implementation of the Dator interface.

func (*DefaultDator) Close

func (this *DefaultDator) Close() error

Close marks the Dator as closed.

func (*DefaultDator) GetLastLine

func (this *DefaultDator) GetLastLine() string

GetLastLine returns the last line of output from the Dator, with leading and trailing spaces trimmed off.

func (*DefaultDator) GetName

func (this *DefaultDator) GetName() string

GetName returns the name of the Dator.

func (*DefaultDator) IsClosed

func (this *DefaultDator) IsClosed() bool

IsClosed indicates that the Dator is closed and will provide no additional output.

type Manidator

type Manidator struct {
	// Interval is the amount of time to wait between each update to the screen. By default it is 50ms.
	Interval time.Duration
	// contains filtered or unexported fields
}

func New

func New(dators ...Dator) *Manidator

New creates a new Manidator, optionally adding one or more Dators immediately.

func (*Manidator) Add

func (this *Manidator) Add(dators ...Dator)

Add includes one or more additional Dators in the Manidator's output.

func (*Manidator) Begin

func (this *Manidator) Begin(ctx context.Context)

Begin launches the Manidator and displays the output from each registered Dator. The loop runs in its own goroutine, so this function returns immediately.

func (*Manidator) Done

func (this *Manidator) Done() chan struct{}

Done allows the Manidator owner to know when all Dators have finished providing output.

func (*Manidator) Stop

func (this *Manidator) Stop()

Stop allows the Manidator owner to request that all output come to a halt.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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