From 8a72aa0637ed265b2434f6126c6d592b50e9dffe Mon Sep 17 00:00:00 2001 From: ardevd Date: Thu, 8 Feb 2024 22:55:15 +0100 Subject: [PATCH] refactor: unify spinner instantiation --- internal/tui/loading.go | 6 +----- internal/tui/pay_invoice.go | 5 +---- internal/tui/styling.go | 11 ++++++++++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/internal/tui/loading.go b/internal/tui/loading.go index 2747a8f..2b3b467 100644 --- a/internal/tui/loading.go +++ b/internal/tui/loading.go @@ -7,7 +7,6 @@ import ( "github.com/ardevd/flash/internal/lnd" "github.com/charmbracelet/bubbles/spinner" tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/lipgloss" "github.com/lightninglabs/lndclient" ) @@ -21,10 +20,7 @@ type LoadingModel struct { } func InitLoading(service *lndclient.GrpcLndServices) LoadingModel { - s := spinner.New() - s.Spinner = spinner.Dot - s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205")) - return LoadingModel{spinner: s, lndService: service, ctx: context.Background()} + return LoadingModel{spinner: getSpinner(), lndService: service, ctx: context.Background()} } func (m LoadingModel) Init() tea.Cmd { diff --git a/internal/tui/pay_invoice.go b/internal/tui/pay_invoice.go index 2f58915..cd1b788 100644 --- a/internal/tui/pay_invoice.go +++ b/internal/tui/pay_invoice.go @@ -58,10 +58,7 @@ func newPayInvoiceModel(service *lndclient.GrpcLndServices, base *BaseModel) *Pa m.base.pushView(&m) m.form = getInvoicePaymentForm() m.invoiceState = PaymentStateNone - s := spinner.New() - s.Spinner = spinner.Dot - s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205")) - m.spinner = s + m.spinner = getSpinner() return &m } diff --git a/internal/tui/styling.go b/internal/tui/styling.go index 0a131b3..f69a6ff 100644 --- a/internal/tui/styling.go +++ b/internal/tui/styling.go @@ -1,6 +1,7 @@ package tui import ( + "github.com/charmbracelet/bubbles/spinner" "github.com/charmbracelet/lipgloss" "github.com/muesli/termenv" ) @@ -71,5 +72,13 @@ func NewStyles(lg *lipgloss.Renderer) *Styles { // Return a function that will colorize the foreground of a given string. func makeFgStyle(color string) func(string) string { return termenv.Style{}.Foreground(term.Color(color)). - Styled + Styled +} + +// Return a standardized spinner +func getSpinner() spinner.Model { + s := spinner.New() + s.Spinner = spinner.Dot + s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205")) + return s }