render

package
v0.0.0-...-21f8229 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NumberOfCharacters       = 66
	NumberOfCharactersBuffer = 12
)

NumberOfCharacters is the number of characters that the pbar display takes up NumberOfCharactersBuffer is the number of characters to leave out (for large numbers)

Variables

View Source
var (
	DefaultDescription              = ""
	DefaultFinishedIterationSymbol  = "\u2588"
	DefaultCurrentIterationSymbol   = "\u2588"
	DefaultRemainingIterationSymbol = " "
	DefaultLParen                   = "|"
	DefaultRParen                   = "|"
	DefaultMaxLineSize              = 80
	DefaultLineSize                 = 10
	DefaultSuffix                   = "\n"
)

The default values for all the parameter settings

View Source
var (
	TerminalSize = terminal.GetSize
	GetTerminal  = os.Stdin.Fd
)

Terminal and os functions used to examine terminal size

View Source
var DefaultWriter = os.Stdout

DefaultWriter is the standard place to write to

View Source
var NowTime = time.Now

NowTime allows us to stub out time.Now() easily

Functions

This section is empty.

Types

type Clock

type Clock interface {
	Now()
	Subtract() time.Duration
	SetStartTime()
	Start() time.Time
	Seconds(time.Duration) float64
	Remaining(float64) time.Duration
	Format(time.Duration) string
	IsStartTimeSet() error

	CreateSpeedMeter(float64, float64, float64) string
}

Clock enables various operations relating to time to be performed easily.

func NewClock

func NewClock() Clock

NewClock returns an instance of a real-time clock.

type ClockVal

type ClockVal struct {
	StartTime   time.Time
	CurrentTime time.Time
}

ClockVal implements a real-time clock by wrapping functions from the time module. It also contains a start time relating to when the Pbar object was initialized.

func (*ClockVal) CreateSpeedMeter

func (c *ClockVal) CreateSpeedMeter(start, stop, current float64) string

CreateSpeedMeter forms the part of the progress bar relating to the elapsed and remaining time, as well as the rate of iterations per second.

func (*ClockVal) Format

func (c *ClockVal) Format(d time.Duration) string

Format enables a time.Duration object to be formatted into a string format that can be easily integrated into the progress bar.

func (*ClockVal) IsStartTimeSet

func (c *ClockVal) IsStartTimeSet() error

IsStartTimeSet checks if the start time is set and returns an error if not

func (*ClockVal) Now

func (c *ClockVal) Now()

Now returns the current time (from the time module).

func (*ClockVal) Remaining

func (c *ClockVal) Remaining(fraction float64) time.Duration

Remaining returns a time.Duration object equating to the fraction of progress that has been performed.

func (*ClockVal) Seconds

func (c *ClockVal) Seconds(d time.Duration) float64

Seconds returns the number of seconds in a time.Duration object

func (*ClockVal) SetStartTime

func (c *ClockVal) SetStartTime()

SetStartTime enables the StartTime value to be set in the clock object.

func (*ClockVal) Start

func (c *ClockVal) Start() time.Time

Start returns the StartTime for the clock object

func (*ClockVal) Subtract

func (c *ClockVal) Subtract() time.Duration

Subtract finds the difference between a passed in time and the start time.

type Set

type Set struct {
	Description              string
	FinishedIterationSymbol  string
	CurrentIterationSymbol   string
	RemainingIterationSymbol string
	LineSize                 int
	MaxLineSize              int
	LParen                   string
	RParen                   string
	Suffix                   string
}

Set holds the setting parameters

func (*Set) CreateBarString

func (s *Set) CreateBarString(numStepsCompleted int) string

CreateBarString creates the actual 'bar' within the progress bar

func (*Set) GetCurrentIterationSymbol

func (s *Set) GetCurrentIterationSymbol() string

GetCurrentIterationSymbol gets the CurrentIterationSymbol value

func (*Set) GetDescription

func (s *Set) GetDescription() string

GetDescription gets the Description value

func (*Set) GetFinishedIterationSymbol

func (s *Set) GetFinishedIterationSymbol() string

GetFinishedIterationSymbol gets the FinishedIterationSymbol value

func (*Set) GetLParen

func (s *Set) GetLParen() string

GetLParen gets the LParen value

func (*Set) GetLineSize

func (s *Set) GetLineSize() int

GetLineSize gets the LineSize value

func (*Set) GetMaxLineSize

func (s *Set) GetMaxLineSize() int

GetMaxLineSize gets the MaxLineSize value

func (*Set) GetRParen

func (s *Set) GetRParen() string

GetRParen gets the RParen value

func (*Set) GetRemainingIterationSymbol

func (s *Set) GetRemainingIterationSymbol() string

GetRemainingIterationSymbol gets the RemainingIterationSymbol value

func (*Set) GetSuffix

func (s *Set) GetSuffix() string

GetSuffix gets the Retain value

func (*Set) SetCurrentIterationSymbol

func (s *Set) SetCurrentIterationSymbol(str string)

SetCurrentIterationSymbol sets the CurrentIterationSymbol value

func (*Set) SetDescription

func (s *Set) SetDescription(str string)

SetDescription sets the Description value

func (*Set) SetFinishedIterationSymbol

func (s *Set) SetFinishedIterationSymbol(str string)

SetFinishedIterationSymbol sets the FinishedIterationSymbol value

func (*Set) SetIdealLineSize

func (s *Set) SetIdealLineSize() error

SetIdealLineSize sets the line size to be almost the same size as the current terminal

func (*Set) SetLParen

func (s *Set) SetLParen(str string)

SetLParen sets the LParen value

func (*Set) SetLineSize

func (s *Set) SetLineSize(i int)

SetLineSize sets the LineSize value

func (*Set) SetMaxLineSize

func (s *Set) SetMaxLineSize(i int)

SetMaxLineSize sets the MaxLineSize value

func (*Set) SetRParen

func (s *Set) SetRParen(str string)

SetRParen sets the RParen value

func (*Set) SetRemainingIterationSymbol

func (s *Set) SetRemainingIterationSymbol(str string)

SetRemainingIterationSymbol sets the RemainingIterationSymbol value

func (*Set) SetSuffix

func (s *Set) SetSuffix(value string)

SetSuffix sets the Retain value

type Settings

type Settings interface {
	SetDescription(string)
	SetFinishedIterationSymbol(string)
	SetCurrentIterationSymbol(string)
	SetRemainingIterationSymbol(string)
	SetLineSize(int)
	SetMaxLineSize(int)
	SetLParen(string)
	SetRParen(string)
	SetSuffix(string)
	SetIdealLineSize() error

	GetDescription() string
	GetFinishedIterationSymbol() string
	GetCurrentIterationSymbol() string
	GetRemainingIterationSymbol() string
	GetLineSize() int
	GetMaxLineSize() int
	GetLParen() string
	GetRParen() string
	GetSuffix() string

	CreateBarString(int) string
}

Settings enables the setting and getting the setting parameters for the progress bar. It also enables the creation of the bar string

func NewSettings

func NewSettings() Settings

NewSettings creates a Settings interface

type Vals

type Vals struct {
	Start    float64
	Stop     float64
	Step     float64
	Current  float64
	IsObject bool
}

Vals holds the Start, Stop, Step and Current values

func (*Vals) GetCurrent

func (v *Vals) GetCurrent() float64

GetCurrent gets the Current value

func (*Vals) GetIsObject

func (v *Vals) GetIsObject() bool

GetIsObject gets the IsObject value

func (*Vals) GetStart

func (v *Vals) GetStart() float64

GetStart gets the Start value

func (*Vals) GetStep

func (v *Vals) GetStep() float64

GetStep gets the Step value

func (*Vals) GetStop

func (v *Vals) GetStop() float64

GetStop gets the Stop value

func (*Vals) SetCurrent

func (v *Vals) SetCurrent(s float64)

SetCurrent sets the Current value

func (*Vals) SetIsObject

func (v *Vals) SetIsObject(value bool)

SetIsObject sets the IsObject value

func (*Vals) SetStart

func (v *Vals) SetStart(s float64)

SetStart sets the Start value

func (*Vals) SetStep

func (v *Vals) SetStep(s float64)

SetStep sets the Step value

func (*Vals) SetStop

func (v *Vals) SetStop(s float64)

SetStop sets the Stop value

func (*Vals) Statistics

func (v *Vals) Statistics(linesize int) (string, int)

Statistics calculates all the numerical values relating to the progression of the progress bar. These are then formed and returned in a string, alongside the number of steps that have been completed.

type Values

type Values interface {
	SetStart(float64)
	SetStop(float64)
	SetStep(float64)
	SetCurrent(float64)
	SetIsObject(bool)

	GetStart() float64
	GetStop() float64
	GetStep() float64
	GetCurrent() float64
	GetIsObject() bool

	Statistics(int) (string, int)
}

Values holds the start, stop, step and current values for the progress bar. It also enables statistics to be calculated for these values relating to the ratio of completion.

func NewValues

func NewValues() Values

NewValues generates a NewValues interface

type Write

type Write interface {
	WriteString(string) error
	SetWriter(io.Writer)
	GetWriter() io.Writer
}

Write wraps the WriteString method

func NewWrite

func NewWrite() Write

NewWrite creates a new Write interface object

type Writing

type Writing struct {
	W io.Writer
}

Writing is struct holding an io.Writer

func (*Writing) GetWriter

func (w *Writing) GetWriter() io.Writer

GetWriter gets the underlying writer object

func (*Writing) SetWriter

func (w *Writing) SetWriter(writer io.Writer)

SetWriter sets the underlying writer object

func (*Writing) WriteString

func (w *Writing) WriteString(s string) error

WriteString writes the given string to the underlying io.Writer object

Jump to

Keyboard shortcuts

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