state

package
v0.0.0-...-e15721f Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2020 License: MIT Imports: 5 Imported by: 51

Documentation

Overview

Package state implements state tracking for a task. Its progress from 0.0 to 1.0, log messages, etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnableBeepsForAdam

func EnableBeepsForAdam()

EnableBeepsForAdam is there for backwards compatibility, but mostly, fun

Types

type Consumer

type Consumer struct {
	OnProgress       ProgressCallback
	OnPauseProgress  VoidCallback
	OnResumeProgress VoidCallback
	OnProgressLabel  ProgressLabelCallback
	OnMessage        MessageCallback
}

Consumer holds callbacks for the various state changes one might want to consume (show progress to the user, store messages in a text file, etc.)

func (*Consumer) CountCallback

func (c *Consumer) CountCallback(totalSize int64) counter.CountCallback

CountCallback returns a function suitable for counter.NewWriterCallback or counter.NewReaderCallback

func (*Consumer) Debug

func (c *Consumer) Debug(msg string)

Debug logs debug-level messages

func (*Consumer) Debugf

func (c *Consumer) Debugf(msg string, args ...interface{})

Debugf is a formatted variant of Debug

func (*Consumer) Error

func (c *Consumer) Error(msg string)

Error logs error-level messages

func (*Consumer) Errorf

func (c *Consumer) Errorf(msg string, args ...interface{})

Errorf is a formatted version of Error

func (*Consumer) Info

func (c *Consumer) Info(msg string)

Info logs info-level messages

func (*Consumer) Infof

func (c *Consumer) Infof(msg string, args ...interface{})

Infof is a formatted variant of Info

func (*Consumer) Logf

func (c *Consumer) Logf(msg string, args ...interface{})

Logf is an alias of Infof

func (*Consumer) Opf

func (c *Consumer) Opf(msg string, args ...interface{})

Opf logs an "operation" message (prefixed by OpSign) For example, "Extracting (file.zip)"

func (*Consumer) PauseProgress

func (c *Consumer) PauseProgress()

PauseProgress temporarily stops updating progress bars

func (*Consumer) Progress

func (c *Consumer) Progress(progress float64)

Progress announces the degree of completion of a task, in the [0,1] interval

func (*Consumer) ProgressLabel

func (c *Consumer) ProgressLabel(label string)

ProgressLabel gives extra info about which task is currently being executed

func (*Consumer) ResumeProgress

func (c *Consumer) ResumeProgress()

ResumeProgress resumes updating progress bars

func (*Consumer) Statf

func (c *Consumer) Statf(msg string, args ...interface{})

Statf logs a "stat" message (prefixed by StatSign) For example, "Extracted 26 files"

func (*Consumer) Warn

func (c *Consumer) Warn(msg string)

Warn logs warning-level messages

func (*Consumer) Warnf

func (c *Consumer) Warnf(msg string, args ...interface{})

Warnf is a formatted version of Warn

type MessageCallback

type MessageCallback func(level, msg string)

MessageCallback is called when a log message has to be printed

type ProgressCallback

type ProgressCallback func(alpha float64)

ProgressCallback is called periodically to announce the degree of completeness of an operation

type ProgressLabelCallback

type ProgressLabelCallback func(label string)

ProgressLabelCallback is called when the progress label should be changed

type ProgressTheme

type ProgressTheme struct {
	BarStart        string
	BarEnd          string
	Current         string
	CurrentHalfTone string
	Empty           string
	OpSign          string
	StatSign        string
	Separator       string
}

ProgressTheme contains all the characters we need to show progress

func GetTheme

func GetTheme() *ProgressTheme

GetTheme returns the theme used to show progress

type VoidCallback

type VoidCallback func()

VoidCallback is the type of OnPauseProgress/OnResumeProgress callbacks

Jump to

Keyboard shortcuts

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