From 084d0acefd44d81347133b4cdf72022878bd1ef9 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Mon, 24 Aug 2020 21:07:45 -0400 Subject: [PATCH] Fix comments + minimum lifetime should work in conjunction with HideFor --- spinner/spinner.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/spinner/spinner.go b/spinner/spinner.go index 18fd001..213eb9f 100644 --- a/spinner/spinner.go +++ b/spinner/spinner.go @@ -44,8 +44,13 @@ type Model struct { // (per github.com/muesli/termenv). BackgroundColor string - // Minimum amount of time the spinner can run. Any logic around this can - // be implemented in view that implements this spinner. Optional. + // MinimumLifetime is the minimum amount of time the spinner can run. Any + // 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 // HideFor can be used to wait to show the spinner until a certain amount @@ -54,7 +59,8 @@ type Model struct { // Optional. 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 frame int @@ -78,7 +84,7 @@ func (m Model) MinimumLifetimeReached() bool { if m.MinimumLifetime == 0 { 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