Fix comments + minimum lifetime should work in conjunction with HideFor

This commit is contained in:
Christian Rocha 2020-08-24 21:07:45 -04:00
parent e8526ec4ef
commit 084d0acefd
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018

View File

@ -44,8 +44,13 @@ type Model struct {
// (per github.com/muesli/termenv). // (per github.com/muesli/termenv).
BackgroundColor string BackgroundColor string
// Minimum amount of time the spinner can run. Any logic around this can // MinimumLifetime is the minimum amount of time the spinner can run. Any
// be implemented in view that implements this spinner. Optional. // logic around this can be implemented in view that implements this
// spinner. If HideFor is set MinimumLifetime will be added on top of
// HideFor. In other words, if HideFor is 100ms and MinimumLifetime is
// 200ms then MinimumLifetime will expire after 300ms.
//
// MinimumLifetime is optional.
MinimumLifetime time.Duration MinimumLifetime time.Duration
// HideFor can be used to wait to show the spinner until a certain amount // HideFor can be used to wait to show the spinner until a certain amount
@ -54,7 +59,8 @@ type Model struct {
// Optional. // Optional.
HideFor time.Duration HideFor time.Duration
// HiddenState is the // HiddenState is the state to render the spinner when HideFor is in effect.
// For more control you can also use Model.Hidden() in the parent view.
HiddenState string HiddenState string
frame int frame int
@ -78,7 +84,7 @@ func (m Model) MinimumLifetimeReached() bool {
if m.MinimumLifetime == 0 { if m.MinimumLifetime == 0 {
return true return true
} }
return m.startTime.Add(m.MinimumLifetime).Before(time.Now()) return m.startTime.Add(m.HideFor).Add(m.MinimumLifetime).Before(time.Now())
} }
// Hidden returns whether or not the view should be rendered. Works in // Hidden returns whether or not the view should be rendered. Works in