Skip to content

Commit

Permalink
refactor: unify spinner instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
ardevd committed Feb 8, 2024
1 parent e941d3d commit 8a72aa0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
6 changes: 1 addition & 5 deletions internal/tui/loading.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions internal/tui/pay_invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 10 additions & 1 deletion internal/tui/styling.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tui

import (
"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/termenv"
)
Expand Down Expand Up @@ -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
}

0 comments on commit 8a72aa0

Please sign in to comment.