Skip to content

Commit

Permalink
feat: support timer modifactions on Spinner and Progressbar (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinJWendt committed Apr 15, 2024
1 parent 1800c6e commit 397222c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions progressbar_printer.go
Expand Up @@ -132,6 +132,12 @@ func (p ProgressbarPrinter) WithShowPercentage(b ...bool) *ProgressbarPrinter {
return &p
}

// WithStartedAt sets the time when the ProgressbarPrinter started.
func (p ProgressbarPrinter) WithStartedAt(t time.Time) *ProgressbarPrinter {
p.startedAt = t
return &p
}

// WithTitleStyle sets the style of the title.
func (p ProgressbarPrinter) WithTitleStyle(style *Style) *ProgressbarPrinter {
p.TitleStyle = style
Expand Down Expand Up @@ -167,6 +173,16 @@ func (p *ProgressbarPrinter) SetWriter(writer io.Writer) {
p.Writer = writer
}

// SetStartedAt sets the time when the ProgressbarPrinter started.
func (p *ProgressbarPrinter) SetStartedAt(t time.Time) {
p.startedAt = t
}

// ResetTimer resets the timer of the ProgressbarPrinter.
func (p *ProgressbarPrinter) ResetTimer() {
p.startedAt = time.Now()
}

// Increment current value by one.
func (p *ProgressbarPrinter) Increment() *ProgressbarPrinter {
p.Add(1)
Expand Down
16 changes: 16 additions & 0 deletions spinner_printer.go
Expand Up @@ -92,6 +92,12 @@ func (s SpinnerPrinter) WithShowTimer(b ...bool) *SpinnerPrinter {
return &s
}

// WithStartedAt sets the time when the SpinnerPrinter started.
func (s SpinnerPrinter) WithStartedAt(t time.Time) *SpinnerPrinter {
s.startedAt = t
return &s
}

// WithTimerRoundingFactor sets the rounding factor for the timer.
func (s SpinnerPrinter) WithTimerRoundingFactor(factor time.Duration) *SpinnerPrinter {
s.TimerRoundingFactor = factor
Expand All @@ -115,6 +121,16 @@ func (p *SpinnerPrinter) SetWriter(writer io.Writer) {
p.Writer = writer
}

// ResetTimer resets the timer of the SpinnerPrinter.
func (s *SpinnerPrinter) ResetTimer() {
s.startedAt = time.Now()
}

// SetStartedAt sets the time when the SpinnerPrinter started.
func (s *SpinnerPrinter) SetStartedAt(t time.Time) {
s.startedAt = t
}

// UpdateText updates the message of the active SpinnerPrinter.
// Can be used live.
func (s *SpinnerPrinter) UpdateText(text string) {
Expand Down

0 comments on commit 397222c

Please sign in to comment.