From 31847d0995a571920054b525ae5fcf5b972af280 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Mon, 10 Jan 2022 14:46:40 -0500 Subject: [PATCH] Expose IDs on spinners and spinner tick messages --- spinner/spinner.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/spinner/spinner.go b/spinner/spinner.go index d3b21ee0..a22d1a6a 100644 --- a/spinner/spinner.go +++ b/spinner/spinner.go @@ -146,6 +146,11 @@ func (m *Model) Finish() { } } +// ID returns the spinner's unique ID. +func (m Model) ID() int { + return m.id +} + // advancedMode returns whether or not the user is making use of HideFor and // MinimumLifetime properties. func (m Model) advancedMode() bool { @@ -200,7 +205,7 @@ func NewModel() Model { type TickMsg struct { Time time.Time tag int - id int + ID int } // Update is the Tea update function. This will advance the spinner one frame @@ -211,7 +216,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { case TickMsg: // If an ID is set, and the ID doesn't belong to this spinner, reject // the message. - if msg.id > 0 && msg.id != m.id { + if msg.ID > 0 && msg.ID != m.id { return m, nil } @@ -257,7 +262,7 @@ func (m Model) View() string { func (m Model) Tick() tea.Msg { return TickMsg{ Time: time.Now(), - id: m.id, + ID: m.id, tag: m.tag, } } @@ -266,7 +271,7 @@ func (m Model) tick(id, tag int) tea.Cmd { return tea.Tick(m.Spinner.FPS, func(t time.Time) tea.Msg { return TickMsg{ Time: t, - id: id, + ID: id, tag: tag, } })