bar

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewModel = New

NewModel returns a model with default values.

Deprecated: use New instead.

Functions

This section is empty.

Types

type DownloadBar

type DownloadBar struct {
	Program *tea.Program
	// contains filtered or unexported fields
}

func NewDownloadBar

func NewDownloadBar(opts ...Option) (bar *DownloadBar)

func (*DownloadBar) CheckDownloaded

func (bar *DownloadBar) CheckDownloaded() bool

func (*DownloadBar) Copy

func (bar *DownloadBar) Copy(bodyReader io.Reader, storageFile *os.File) (n int64)

func (*DownloadBar) Run

func (bar *DownloadBar) Run()

func (*DownloadBar) SetSweep

func (bar *DownloadBar) SetSweep(sweep func())

func (*DownloadBar) SetTotal

func (bar *DownloadBar) SetTotal(total int64)

func (*DownloadBar) Write

func (bar *DownloadBar) Write(p []byte) (int, error)

type DownloadModel

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

func (*DownloadModel) Init

func (dm *DownloadModel) Init() tea.Cmd

func (*DownloadModel) SetSweep

func (dm *DownloadModel) SetSweep(sweep func())

func (*DownloadModel) Update

func (dm *DownloadModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*DownloadModel) View

func (dm *DownloadModel) View() string

type ErrorMsg

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

type ExtraMsg

type ExtraMsg string

type FrameMsg

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

FrameMsg indicates that an animation step should occur.

type Model

type Model struct {

	// Total width of the progress bar, including percentage, if set.
	Width int

	// "Filled" sections of the progress bar.
	Full      string
	FullColor string

	// "Empty" sections of the progress bar.
	Empty      string
	EmptyColor string

	// Settings for rendering the numeric percentage.
	ShowPercentage  bool
	PercentFormat   string // a fmt string for a float
	PercentageStyle lipgloss.Style
	// contains filtered or unexported fields
}

Model stores values we'll use when rendering the progress bar.

func New

func New(opts ...Option) Model

New returns a model with default values.

func (*Model) DecrPercent

func (m *Model) DecrPercent(v float64) tea.Cmd

DecrPercent decrements the percentage by a given amount, returning a command necessary to animate the progress bar to the new percentage.

If you're rendering with ViewAs you won't need this.

func (*Model) IncrPercent

func (m *Model) IncrPercent(v float64) tea.Cmd

IncrPercent increments the percentage by a given amount, returning a command necessary to animate the progress bar to the new percentage.

If you're rendering with ViewAs you won't need this.

func (Model) Init

func (m Model) Init() tea.Cmd

Init exists to satisfy the tea.Model interface.

func (Model) Percent

func (m Model) Percent() float64

Percent returns the current visible percentage on the model. This is only relevant when you're animating the progress bar.

If you're rendering with ViewAs you won't need this.

func (*Model) SetExtra

func (m *Model) SetExtra(extra string)

func (*Model) SetPercent

func (m *Model) SetPercent(p float64) tea.Cmd

SetPercent sets the percentage state of the model as well as a command necessary for animating the progress bar to this new percentage.

If you're rendering with ViewAs you won't need this.

func (*Model) SetSpringOptions

func (m *Model) SetSpringOptions(frequency, damping float64)

SetSpringOptions sets the frequency and damping for the current spring. Frequency corresponds to speed, and damping to bounciness. For details see:

https://github.com/charmbracelet/harmonica

func (*Model) SetTitle

func (m *Model) SetTitle(title string)

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update is used to animate the progress bar during transitions. Use SetPercent to create the command you'll need to trigger the animation.

If you're rendering with ViewAs you won't need this.

func (Model) View

func (m Model) View() string

View renders an animated progress bar in its current state. To render a static progress bar based on your own calculations use ViewAs instead.

func (Model) ViewAs

func (m Model) ViewAs(percent float64) string

ViewAs renders the progress bar with a given percentage.

type Option

type Option func(*Model)

Option is used to set options in New. For example:

    progress := New(
	       WithRamp("#ff0000", "#0000ff"),
	       WithoutPercentage(),
    )

func WithColorProfile

func WithColorProfile(p termenv.Profile) Option

WithColorProfile sets the color profile to use for the progress bar.

func WithDefaultGradient

func WithDefaultGradient() Option

WithDefaultGradient sets a gradient fill with default colors.

func WithDefaultScaledGradient

func WithDefaultScaledGradient() Option

WithDefaultScaledGradient sets a gradient with default colors, and scales the gradient to fit the filled portion of the ramp.

func WithGradient

func WithGradient(colorA, colorB string) Option

WithGradient sets a gradient fill blending between two colors.

func WithScaledGradient

func WithScaledGradient(colorA, colorB string) Option

WithScaledGradient scales the gradient to fit the width of the filled portion of the progress bar.

func WithSolidFill

func WithSolidFill(color string) Option

WithSolidFill sets the progress to use a solid fill with the given color.

func WithSpringOptions

func WithSpringOptions(frequency, damping float64) Option

WithSpringOptions sets the initial frequency and damping options for the progress bar's built-in spring-based animation. Frequency corresponds to speed, and damping to bounciness. For details see:

https://github.com/charmbracelet/harmonica

func WithTitle

func WithTitle(title string) Option

func WithWidth

func WithWidth(w int) Option

WithWidth sets the initial width of the progress bar. Note that you can also set the width via the Width property, which can come in handy if you're waiting for a tea.WindowSizeMsg.

func WithoutPercentage

func WithoutPercentage() Option

WithoutPercentage hides the numeric percentage.

type OrdinaryBar

type OrdinaryBar struct {
	Program *tea.Program
	// contains filtered or unexported fields
}

func NewOrdinaryBar

func NewOrdinaryBar(opts ...Option) (bar *OrdinaryBar)

func (*OrdinaryBar) Add

func (bar *OrdinaryBar) Add(processed, succeeded int)

func (*OrdinaryBar) AddOnlyProcessed

func (bar *OrdinaryBar) AddOnlyProcessed(processed int)

func (*OrdinaryBar) EnableSucceeded

func (bar *OrdinaryBar) EnableSucceeded()

func (*OrdinaryBar) Run

func (bar *OrdinaryBar) Run()

func (*OrdinaryBar) SetTotal

func (bar *OrdinaryBar) SetTotal(total int64)

type ProgressMsg

type ProgressMsg float64

Jump to

Keyboard shortcuts

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