Documentation
¶
Overview ¶
Package ttyprogress contains utilities to visualize work progress on terminals. Context is the container covering some lines at the end of an output stream directed to a terminal. It can be used to add an arbitrary number of progress indicators.
Package github.com/mandelsoft/ttyprogress/ppi provides some support types, which can be used to provide own progress indicators to enrich the set of indicators provided by this package.
Index ¶
- Variables
- func AddElement[T Element](p Container, definition types.ElementDefinition[T]) (T, error)
- func GeneralizedRunner[E Element](r func(E)) func(Element)
- func New[T Dupper[T]](d Dupper[T]) T
- func PercentTerminalSize(p uint) uint
- func ReserveTerminalSize(r uint) uint
- func RunWith[E Element, D ElementDefinition[E], A Element](c Container, def D, runner func(e A)) (E, error)
- func RunWithS[E Element, D ElementDefinition[E]](c Container, def D, runner func(e E)) (E, error)
- func SimpleProgress[T Element](w io.Writer, e ElementDefinition[T]) T
- func SpecializedRunner[E Element](r func(Element)) func(E)
- type AnonymousGroup
- type AnonymousGroupDefinition
- type Bar
- type BarConfig
- type BarDefinition
- type Brackets
- type Container
- type Context
- type DecoratorFunc
- type Dupper
- type Element
- type ElementDefinition
- type ElementSpecification
- type ElementState
- type Estimated
- type EstimatedDefinition
- type EstimatedInterface
- type Group
- type GroupDefinition
- type IntBarBase
- type IntBarBaseImpl
- type IntBarImpl
- type IntBarInterface
- type LineBar
- type LineBarDefinition
- type NestedStep
- type NestedSteps
- type NestedStepsDefinition
- type ProgressElement
- type ScrollingSpinner
- type ScrollingSpinnerDefinition
- type Spinner
- type SpinnerDefinition
- type Steps
- type StepsDefinition
- type Text
- type TextDefinition
- type TextSpinner
- type TextSpinnerDefinition
- type Ticker
Constants ¶
This section is empty.
Variables ¶
var ( BarTypes = specs.BarTypes BracketTypes = specs.BracketTypes // BarWidth is the default width of the progress bar BarWidth = specs.BarWidth // ErrMaxCurrentReached is error when trying to set current value that exceeds the total value ErrMaxCurrentReached = errors.New("errors: current value is greater total value") )
Functions ¶
func AddElement ¶
func AddElement[T Element](p Container, definition types.ElementDefinition[T]) (T, error)
func GeneralizedRunner ¶
GeneralizedRunner converts a type specific runner to a general runner.
func PercentTerminalSize ¶
PercentTerminalSize return a width relative to to the terminal size.
func ReserveTerminalSize ¶
ReserveTerminalSize provide a reasonable width reserving an amount of characters for predefined fixed content.
func RunWith ¶
func RunWith[E Element, D ElementDefinition[E], A Element](c Container, def D, runner func(e A)) (E, error)
RunWith asynchronously executes a function for progressing a progress indication given by its definition. If the function exists the indicator is closed The runner must accept an Element interface matching the created element type.
func RunWithS ¶
func RunWithS[E Element, D ElementDefinition[E]](c Container, def D, runner func(e E)) (E, error)
func SimpleProgress ¶
func SimpleProgress[T Element](w io.Writer, e ElementDefinition[T]) T
SimpleProgress creates and displays a single progress element according to the given specification.
func SpecializedRunner ¶
SpecializedRunner converts a generic runner to a type specific runner.
Types ¶
type AnonymousGroup ¶
type AnonymousGroup interface {
specs.GroupBaseInterface
Gap() string
Close() error
}
AnonymousGroup is a plain indicator group and itself no indicator. It can be used group indicator with common handling for gaps and hiding.
type AnonymousGroupDefinition ¶
type AnonymousGroupDefinition struct {
specs.GroupBaseDefinition[*AnonymousGroupDefinition]
}
func NewAnonymousGroup ¶
func NewAnonymousGroup() *AnonymousGroupDefinition
func (*AnonymousGroupDefinition) Add ¶
func (d *AnonymousGroupDefinition) Add(c Container) (AnonymousGroup, error)
func (*AnonymousGroupDefinition) Dup ¶
func (d *AnonymousGroupDefinition) Dup() *AnonymousGroupDefinition
type Bar ¶
type Bar interface {
specs.BarInterface
}
Bar is a progress bar used to visualize the progress of an action in relation to a known maximum of required work.
type BarDefinition ¶
type BarDefinition struct {
specs.BarDefinition[*BarDefinition]
}
func NewBar ¶
func NewBar(set ...int) *BarDefinition
func (*BarDefinition) AddWithTotal ¶
func (d *BarDefinition) AddWithTotal(c Container, total int) (Bar, error)
func (*BarDefinition) Dup ¶
func (d *BarDefinition) Dup() *BarDefinition
func (*BarDefinition) GetGroupNotifier ¶
func (d *BarDefinition) GetGroupNotifier() specs.GroupNotifier
type Context ¶
type Context interface {
Container
// GetTTYContext returns the underlying ttycolors.TTYContext.
GetTTYContext() ttycolors.TTYContext
IsColorsEnabled() bool
EnableColors(b ...bool) Context
// Blocks returns the underlying
// blocks.Blocks object used
// to display the progress elements.
// It can directly be used in combination
// with progress elements.
// But all active blocks will prohibit the
// progress object to complete.
Blocks() *blocks.Blocks
// Done returns the done channel.
// A Context is done, if it is closed and
// all progress elements are finished.
Done() <-chan struct{}
// Close closes the Context. No more
// progress elements can be added anymore.
Close() error
// Wait until the Context is Done.
// If a context.Context is given, Wait
// also returns if the context is canceled.
Wait(ctx context.Context) error
}
Context is a set of lines on a terminal used to display some live progress information. It can be used to display an arbitrary number of progress elements, which are independently. Leading elements will leave the text window used once they are finished.
func For ¶
For creates a new Context, which manages a terminal line range used to indicate progress of some actions. This line range is always at the end of the given writer, which must refer to a terminal device. Context indicators are added by explicitly calling the appropriate constructors. They take the Context they should be attached to as first argument.
type DecoratorFunc ¶
type DecoratorFunc = types.DecoratorFunc
DecoratorFunc is a function that can be prepended and appended to the progress bar
func Amount ¶
func Amount(unit ...units.Unit) DecoratorFunc
Amount is a decorator for Bar elements providing information about the current and total amount for the progress.
func Message ¶
func Message(m ...any) DecoratorFunc
Message is a decorator for progress elements providing a static message.
func Processed ¶
func Processed(unit ...units.Unit) DecoratorFunc
Processed is a decorator for Bar objects providing information about the current progress value (int).
type ElementDefinition ¶
type ElementDefinition[T Element] interface { types.ElementDefinition[T] }
func GenericDefinition ¶
func GenericDefinition[T ElementDefinition[E], E Element](d T) ElementDefinition[Element]
GenericDefinition converts a specific progress indicator definition into a generic one (providing just an Element instead of the specific type).
type ElementSpecification ¶
type ElementSpecification[T Element] interface { specs.ElementSpecification[T] }
type ElementState ¶
type ElementState = types.ElementState
type Estimated ¶
type Estimated interface {
specs.EstimatedInterface
}
type EstimatedDefinition ¶
type EstimatedDefinition struct {
specs.EstimatedDefinition[*EstimatedDefinition]
}
func NewEstimated ¶
func NewEstimated(total time.Duration) *EstimatedDefinition
func (*EstimatedDefinition) Dup ¶
func (d *EstimatedDefinition) Dup() *EstimatedDefinition
type EstimatedInterface ¶
type EstimatedInterface = specs.EstimatedInterface
type GroupDefinition ¶
type GroupDefinition[E specs.ProgressInterface] struct { specs.GroupDefinition[*GroupDefinition[E], E] }
func NewGroup ¶
func NewGroup[E specs.ProgressInterface](p specs.GroupProgressElementDefinition[E]) *GroupDefinition[E]
func (*GroupDefinition[E]) Dup ¶
func (d *GroupDefinition[E]) Dup() *GroupDefinition[E]
type IntBarBase ¶
type IntBarBase[T IntBarImpl] struct { *ppi.BarBase[T, int] // contains filtered or unexported fields }
func (*IntBarBase[T]) CompletedPercent ¶
func (b *IntBarBase[T]) CompletedPercent() float64
func (*IntBarBase[T]) Current ¶
func (b *IntBarBase[T]) Current() int
func (*IntBarBase[T]) Incr ¶
func (b *IntBarBase[T]) Incr() bool
func (*IntBarBase[T]) Set ¶
func (b *IntBarBase[T]) Set(n int) bool
type IntBarBaseImpl ¶
type IntBarBaseImpl[T IntBarImpl] struct { *ppi.BarBaseImpl[T, int] // contains filtered or unexported fields }
func (*IntBarBaseImpl[T]) CompletedPercent ¶
func (b *IntBarBaseImpl[T]) CompletedPercent() float64
CompletedPercent return the percent completed
func (*IntBarBaseImpl[T]) Current ¶
func (b *IntBarBaseImpl[T]) Current() int
Current returns the current progress of the bar
func (*IntBarBaseImpl[T]) Incr ¶
func (b *IntBarBaseImpl[T]) Incr() bool
Incr increments the current value by 1, time elapsed to current time and returns true. It returns false if the cursor has reached or exceeds total value.
func (*IntBarBaseImpl[T]) IsFinished ¶
func (b *IntBarBaseImpl[T]) IsFinished() bool
func (*IntBarBaseImpl[T]) Set ¶
func (b *IntBarBaseImpl[T]) Set(n int) bool
Set the current count of the bar. It returns ErrMaxCurrentReached when trying n exceeds the total value. This is atomic operation and concurrency safe.
type IntBarImpl ¶
type IntBarImpl interface {
ppi.BarImpl[int]
IntBarInterface
}
type IntBarInterface ¶
type LineBar ¶
type LineBar interface {
specs.BarInterface
}
LineBar is a progress bar used to visualize the progress of an action in relation to a known maximum of required work reversing the progress line according to the actual progress.
type LineBarDefinition ¶
type LineBarDefinition struct {
specs.LineBarDefinition[*LineBarDefinition, int]
}
func NewLineBar ¶
func NewLineBar() *LineBarDefinition
func (*LineBarDefinition) Dup ¶
func (d *LineBarDefinition) Dup() *LineBarDefinition
func (*LineBarDefinition) GetGroupNotifier ¶
func (d *LineBarDefinition) GetGroupNotifier() specs.GroupNotifier
type NestedStep ¶
type NestedStep = specs.NestedStep
func NewNestedStep ¶
func NewNestedStep[T Element](name string, definition ElementDefinition[T]) NestedStep
type NestedSteps ¶
type NestedSteps interface {
specs.NestedStepsInterface
}
NestedSteps can be used to visualize a sequence of steps represented by own progress indicators.
type NestedStepsDefinition ¶
type NestedStepsDefinition struct {
specs.NestedStepsDefinition[*NestedStepsDefinition]
}
func NewNestedSteps ¶
func NewNestedSteps(steps ...specs.NestedStep) *NestedStepsDefinition
func (*NestedStepsDefinition) Add ¶
func (d *NestedStepsDefinition) Add(c Container) (NestedSteps, error)
func (*NestedStepsDefinition) Dup ¶
func (d *NestedStepsDefinition) Dup() *NestedStepsDefinition
type ProgressElement ¶
type ProgressElement = types.ProgressElement
type ScrollingSpinner ¶
type ScrollingSpinner interface {
specs.ScrollingSpinnerInterface
}
ScrollingScrollingSpinner is a progress indicator without information about the concrete progress using a scrolling text to indicate the progress.
type ScrollingSpinnerDefinition ¶
type ScrollingSpinnerDefinition struct {
specs.ScrollingSpinnerDefinition[*ScrollingSpinnerDefinition]
}
func NewScrollingSpinner ¶
func NewScrollingSpinner(text string, length int) *ScrollingSpinnerDefinition
func (*ScrollingSpinnerDefinition) Add ¶
func (d *ScrollingSpinnerDefinition) Add(c Container) (Spinner, error)
func (*ScrollingSpinnerDefinition) Dup ¶
func (d *ScrollingSpinnerDefinition) Dup() *ScrollingSpinnerDefinition
func (*ScrollingSpinnerDefinition) GetGroupNotifier ¶
func (d *ScrollingSpinnerDefinition) GetGroupNotifier() specs.GroupNotifier
type Spinner ¶
type Spinner interface {
specs.SpinnerInterface
}
Spinner is a progress indicator without information about the concrete progress.
type SpinnerDefinition ¶
type SpinnerDefinition struct {
specs.SpinnerDefinition[*SpinnerDefinition]
}
func NewSpinner ¶
func NewSpinner(set ...int) *SpinnerDefinition
func (*SpinnerDefinition) Dup ¶
func (d *SpinnerDefinition) Dup() *SpinnerDefinition
func (*SpinnerDefinition) GetGroupNotifier ¶
func (d *SpinnerDefinition) GetGroupNotifier() specs.GroupNotifier
type Steps ¶
type Steps interface {
specs.StepsInterface
}
Steps can be used to visualize a sequence of steps.
type StepsDefinition ¶
type StepsDefinition struct {
specs.StepsDefinition[*StepsDefinition]
}
func NewSteps ¶
func NewSteps(steps ...string) *StepsDefinition
func (*StepsDefinition) Dup ¶
func (d *StepsDefinition) Dup() *StepsDefinition
type Text ¶
type Text interface {
specs.TextInterface
}
Text provides a range of lines of output until the action described by the element is calling Text.Close. The element can be used as writer to pass the intended output. After the writer is closed, the complete output is shown after earlier elements and outer containers are done.
type TextDefinition ¶
type TextDefinition struct {
specs.TextDefinition[*TextDefinition]
}
func NewText ¶
func NewText(v ...int) *TextDefinition
func (*TextDefinition) Dup ¶
func (d *TextDefinition) Dup() *TextDefinition
type TextSpinner ¶
type TextSpinner interface {
specs.TextSpinnerInterface
}
type TextSpinnerDefinition ¶
type TextSpinnerDefinition struct {
specs.TextSpinnerDefinition[*TextSpinnerDefinition]
}
func NewTextSpinner ¶
func NewTextSpinner(set ...int) *TextSpinnerDefinition
func (*TextSpinnerDefinition) Add ¶
func (d *TextSpinnerDefinition) Add(c Container) (TextSpinner, error)
func (*TextSpinnerDefinition) Dup ¶
func (d *TextSpinnerDefinition) Dup() *TextSpinnerDefinition
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
blocks/hide
command
|
|
|
blocks/mixed
command
|
|
|
blocks/multiblock
command
|
|
|
blocks/multiline
command
|
|
|
blocks/scroll
command
|
|
|
blocks/simple
command
|
|
|
progress/anongroup
command
|
|
|
progress/bar
command
|
|
|
progress/bar2
command
|
|
|
progress/bargroup
command
|
|
|
progress/colors
command
|
|
|
progress/complex
command
|
|
|
progress/def
command
|
|
|
progress/estimated
command
|
|
|
progress/group
command
|
|
|
progress/group2
command
|
|
|
progress/linebar
command
|
|
|
progress/multi
command
|
|
|
progress/nestedsteps
command
|
|
|
progress/scrollingspinner
command
|
|
|
progress/spinner
command
|
|
|
progress/steps
command
|
|
|
progress/text
command
|
|
|
progress/text0
command
|
|
|
progress/textspinner
command
|
|
|
progress/variables
command
|
|