Pause spinner ticks when not refreshing.
All checks were successful
Build & Test / Main (push) Successful in 59s
All checks were successful
Build & Test / Main (push) Successful in 59s
Also, add a quick-and-dirty model for displaying basic performance stats, currently just the number of calls to the root Update() and View() methods.
This commit is contained in:
24
tui/tui.go
24
tui/tui.go
@@ -6,25 +6,20 @@ import (
|
||||
"code.humancabbage.net/sam/moonmath/coindesk"
|
||||
"code.humancabbage.net/sam/moonmath/config"
|
||||
"code.humancabbage.net/sam/moonmath/tui/asset"
|
||||
"code.humancabbage.net/sam/moonmath/tui/perf"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
type Model struct {
|
||||
assets []asset.Model
|
||||
assets []asset.Model
|
||||
stats perf.Model
|
||||
displayStats bool
|
||||
}
|
||||
|
||||
func New(assets []coindesk.Asset, cfg config.All) (p *tea.Program) {
|
||||
model := newModel(assets, cfg)
|
||||
p = tea.NewProgram(
|
||||
model,
|
||||
tea.WithAltScreen(),
|
||||
tea.WithFPS(30),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
func newModel(assets []coindesk.Asset, cfg config.All) (m Model) {
|
||||
func New(assets []coindesk.Asset, cfg config.All, displayStats bool) (m Model) {
|
||||
m.stats = perf.New()
|
||||
m.displayStats = displayStats
|
||||
// construct models for each asset, but don't filter out dupes
|
||||
seen := map[coindesk.Asset]struct{}{}
|
||||
for _, a := range assets {
|
||||
@@ -52,6 +47,7 @@ func (m Model) Init() tea.Cmd {
|
||||
}
|
||||
|
||||
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.stats.AddUpdate()
|
||||
switch msg := msg.(type) {
|
||||
// handle keys for quitting
|
||||
case tea.KeyMsg:
|
||||
@@ -78,11 +74,15 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
|
||||
func (m Model) View() string {
|
||||
m.stats.AddView()
|
||||
var ss []string
|
||||
for i := range m.assets {
|
||||
s := m.assets[i].View()
|
||||
ss = append(ss, s)
|
||||
}
|
||||
if m.displayStats {
|
||||
ss = append(ss, m.stats.View())
|
||||
}
|
||||
r := lipgloss.JoinVertical(lipgloss.Center, ss...)
|
||||
return r
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user