progress

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bar

type Bar interface {
	UpdateDisplay(newDisplay *DisplayProps)
}

Bar controls how a bar is displayed, for both single bar or multi bar item.

type DisplayProps

type DisplayProps struct {
	Prefix string
	Suffix string // If `Mode == Done / Error`, Suffix is not printed
	Mode   Mode
}

DisplayProps controls the display of the progress bar.

type Mode

type Mode int

Mode determines how the progress bar is rendered

const (
	// ModeSpinner renders a Spinner
	ModeSpinner Mode = iota
	// ModeProgress renders a ProgressBar. Not supported yet.
	ModeProgress
	// ModeDone renders as "Done" message.
	ModeDone
	// ModeError renders as "Error" message.
	ModeError
)

type MultiBar

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

MultiBar renders multiple progress bars.

func NewMultiBar

func NewMultiBar(prefix string) *MultiBar

NewMultiBar creates a new MultiBar.

func (*MultiBar) AddBar

func (b *MultiBar) AddBar(prefix string) *MultiBarItem

AddBar adds a new bar item. This function is not thread safe. Must be called before render loop is started.

func (*MultiBar) StartRenderLoop

func (b *MultiBar) StartRenderLoop()

StartRenderLoop starts the render loop. This function is thread safe.

func (*MultiBar) StopRenderLoop

func (b *MultiBar) StopRenderLoop()

StopRenderLoop stops the render loop. This function is thread safe.

type MultiBarItem

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

MultiBarItem controls a bar item inside MultiBar.

func (*MultiBarItem) UpdateDisplay

func (i *MultiBarItem) UpdateDisplay(newDisplay *DisplayProps)

UpdateDisplay updates the display property of this bar item. This function is thread safe.

type SingleBar

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

SingleBar renders single progress bar.

Example
package main

import (
	"strconv"
	"time"

	"github.com/luyomo/OhMyTiUP/pkg/tui/progress"
)

func main() {
	b := progress.NewSingleBar("Prefix")

	b.UpdateDisplay(&progress.DisplayProps{
		Prefix: "Prefix",
		Suffix: "Suffix",
	})

	n := 3

	go func() {
		time.Sleep(time.Second)
		for i := 0; i < n; i++ {
			b.UpdateDisplay(&progress.DisplayProps{
				Prefix: "Prefix" + strconv.Itoa(i),
				Suffix: "Suffix" + strconv.Itoa(i),
			})
			time.Sleep(time.Second)
		}
	}()

	b.StartRenderLoop()

	time.Sleep(time.Second * time.Duration(n+1))

	b.UpdateDisplay(&progress.DisplayProps{
		Mode: progress.ModeDone,
		// Mode:   progress.ModeError,
		Prefix: "Prefix",
	})

	b.StopRenderLoop()
}
Output:

func NewSingleBar

func NewSingleBar(prefix string) *SingleBar

NewSingleBar creates a new SingleBar.

func (*SingleBar) StartRenderLoop

func (b *SingleBar) StartRenderLoop()

StartRenderLoop starts the render loop. This function is thread safe.

func (*SingleBar) StopRenderLoop

func (b *SingleBar) StopRenderLoop()

StopRenderLoop stops the render loop. This function is thread safe.

func (*SingleBar) UpdateDisplay

func (b *SingleBar) UpdateDisplay(newDisplay *DisplayProps)

UpdateDisplay updates the display property of this single bar. This function is thread safe.

Jump to

Keyboard shortcuts

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