Initial configuration support.

This commit is contained in:
2024-03-19 21:44:11 -07:00
parent bf50ba4539
commit 60a4574c5a
11 changed files with 550 additions and 64 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"time"
"code.humancabbage.net/sam/moonmath/config"
"code.humancabbage.net/sam/moonmath/moon"
"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
@@ -22,13 +23,17 @@ type Model struct {
projections table.Model
}
func New() Model {
math := moon.NewMath(nil, nil)
func New(cfg config.Data) Model {
math := moon.NewMath(
cfg.Asset,
cfg.Goals,
config.GetBases(&cfg))
tableStyle := table.DefaultStyles()
tableStyle.Selected = lipgloss.NewStyle()
prices := table.New(
table.WithColumns([]table.Column{
{Title: "Asset", Width: 6},
{Title: "Price", Width: 9},
}),
table.WithHeight(1),
@@ -40,7 +45,7 @@ func New() Model {
}
for i := range math.Columns {
projectionCols = append(projectionCols, table.Column{
Title: math.Columns[i].Base.Name(),
Title: math.Columns[i].Base.Label(),
Width: 10,
})
}
@@ -51,7 +56,7 @@ func New() Model {
projectionRows[0][0] = "Starting"
projectionRows[1][0] = "CDPR"
for i := range math.Goals {
projectionRows[i+2][0] = fmt.Sprintf("$%.0f", math.Goals[i])
projectionRows[i+2][0] = fmt.Sprintf("$%.0f", math.Goals[i].Value)
}
projections := table.New(
table.WithColumns(projectionCols),
@@ -95,7 +100,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func refillPrice(m *Model) {
rows := []table.Row{
[]string{fmt.Sprintf("$%0.2f", m.math.CurrentPrice)},
[]string{string(m.math.Asset), fmt.Sprintf("$%0.2f", m.math.CurrentPrice)},
}
m.prices.SetRows(rows)
}