Skip to content

Commit

Permalink
update taskprogress model to implement VisibleModel
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman committed Nov 15, 2023
1 parent 137905a commit 129116f
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions bubbles/taskprogress/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/wagoodman/go-progress"

"github.com/anchore/bubbly"
)

const (
checkMark = "✔"
xMark = "✘"
)

var _ bubbly.VisibleModel = (*Model)(nil)

type Model struct {
// ui components (view models)
Spinner spinner.Model
Expand Down Expand Up @@ -147,10 +151,6 @@ func (m Model) Init() tea.Cmd {
m.ProgressBar.Init(),
}

// if m.progressor != nil {
// cmds = append(cmds, m.ProgressBar.Init())
//}

return tea.Batch(
cmds...,
)
Expand All @@ -161,7 +161,7 @@ func (m Model) ID() int {
return m.id
}

// ID returns the spinner's unique ID.
// Sequence returns the spinner's current sequence number.
func (m Model) Sequence() int {
return m.sequence
}
Expand Down Expand Up @@ -234,9 +234,21 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}

func (m Model) IsVisible() bool {
isDoneAndHidden := m.completed && m.HideOnSuccess
if isDoneAndHidden {
// it might be that the consumer will not invoke View() again based on
// this response, in which case we need to ensure that the done() function
// in invoked to release resources
m.done()
}

return !(isDoneAndHidden)
}

// View renders the model's view.
func (m Model) View() string {
if m.completed && m.HideOnSuccess {
if !m.IsVisible() {
m.done()
return ""
}
Expand Down

0 comments on commit 129116f

Please sign in to comment.