diff --git a/nba/global.go b/nba/global.go new file mode 100644 index 0000000..e0bd879 --- /dev/null +++ b/nba/global.go @@ -0,0 +1,7 @@ +package nba + +var ( + Gm *BoxScoreRepository + Sb *ScoreboardRepository + St *StandingsRepository +) diff --git a/nba/scoreboard.go b/nba/scoreboard.go index ec6988a..85fd31a 100644 --- a/nba/scoreboard.go +++ b/nba/scoreboard.go @@ -9,7 +9,7 @@ import ( "github.com/nleeper/goment" "github.com/dylantientcheu/nbacli/nag" - "github.com/dylantientcheu/nbacli/styles" + "github.com/dylantientcheu/nbacli/ui/constants" ) type BoxScoreSummary struct { @@ -40,15 +40,15 @@ func (g BoxScoreSummary) Description() string { // show time from now desc = fmt.Sprintf("Tip-off %s | %s", moment.From(now), g.ArenaName) - desc = styles.DescStyle(desc) + desc = constants.DescStyle(desc) } else if status == "Final" { // passed game // gameDate := GetDateFromString(g.GameDate).Format("2006-01-02") - desc = fmt.Sprintf("%s %s", styles.ScoreStyle(g.HomeTeamScore, g.VisitorTeamScore), styles.DescStyle(g.ArenaName)) + desc = fmt.Sprintf("%s %s", constants.ScoreStyle(g.HomeTeamScore, g.VisitorTeamScore), constants.DescStyle(g.ArenaName)) } else { // live game - desc = fmt.Sprintf("%s %s - %s | %s", styles.LiveStyle(), styles.ScoreStyle(g.HomeTeamScore, g.VisitorTeamScore), styles.DescStyle(status), styles.DescStyle(g.ArenaName)) - desc = styles.DescText.Render(desc) + desc = fmt.Sprintf("%s %s - %s | %s", constants.LiveStyle(), constants.ScoreStyle(g.HomeTeamScore, g.VisitorTeamScore), constants.DescStyle(status), constants.DescStyle(g.ArenaName)) + desc = constants.DescText.Render(desc) } return desc diff --git a/styles/constants.go b/styles/constants.go deleted file mode 100644 index 1c5a3f6..0000000 --- a/styles/constants.go +++ /dev/null @@ -1,83 +0,0 @@ -package styles - -import ( - "strconv" - "time" - - "github.com/charmbracelet/bubbles/spinner" - "github.com/charmbracelet/lipgloss" -) - -var EmphasisText = lipgloss.NewStyle().Bold(true) -var PrimaryText = lipgloss.NewStyle().Bold(true) -var SecondaryText = lipgloss.NewStyle().Foreground(lipgloss.Color("#808080")) - -var LiveText = lipgloss.NewStyle().Background(lipgloss.AdaptiveColor{Light: "#ef2929", Dark: "#ef2929"}).Foreground(lipgloss.AdaptiveColor{Light: "#ffffff", Dark: "#ffffff"}).Bold(true) -var FinalText = lipgloss.NewStyle().Background(lipgloss.Color("#9356DF")).Foreground(lipgloss.Color("#ffffff")).Bold(true) -var DescText = lipgloss.NewStyle().Foreground(lipgloss.Color("#818181")) -var ScoreText = lipgloss.NewStyle().Background(lipgloss.AdaptiveColor{Light: "214", Dark: "#181818"}).Foreground(lipgloss.AdaptiveColor{Light: "0", Dark: "214"}) - -const ( - magentaDark = "200" - yellowDark = "214" - blueDark = "33" - pinkDark = "219" - - logoBgDark = "#0f1429" - headerBgDark = "#2d3454" - unselectedItemFgDark = "251" - paginatorBgDark = logoBgDark - selectedPageFgDark = unselectedItemFgDark - unselectedPageFgDark = "239" - - magentaLight = magentaDark - yellowLight = "208" - blueLight = blueDark - pinkLight = pinkDark - - logoBgLight = "252" - headerBgLight = "254" - unselectedItemFgLight = "235" - paginatorBgLight = logoBgLight - selectedPageFgLight = unselectedItemFgLight - unselectedPageFgLight = "247" -) - -func GetSpinner() spinner.Spinner { - normal := lipgloss.NewStyle(). - Foreground(lipgloss.AdaptiveColor{Light: selectedPageFgLight, Dark: selectedPageFgDark}). - Background(lipgloss.AdaptiveColor{Light: unselectedPageFgLight, Dark: unselectedPageFgDark}). - Faint(false) - - color := normal.Copy() - - magenta := lipgloss.AdaptiveColor{Light: magentaLight, Dark: magentaDark} - yellow := lipgloss.AdaptiveColor{Light: yellowLight, Dark: yellowDark} - blue := lipgloss.AdaptiveColor{Light: blueLight, Dark: blueDark} - - return spinner.Spinner{ - Frames: []string{ - normal.Render("fetching" + color.Foreground(magenta).Render(".") + color.Foreground(yellow).Render(".") + color.Foreground(blue).Render(".")), - normal.Render("fetching "), - normal.Render("fetching" + color.Foreground(magenta).Render(".") + normal.Render(" ")), - normal.Render("fetching" + color.Foreground(magenta).Render(".") + color.Foreground(yellow).Render(".") + normal.Render(" ")), - }, - FPS: 1500 * time.Millisecond, - } -} - -func LiveStyle() string { - return LiveText.Render(" LIVE ") -} - -func FinalStyle() string { - return FinalText.Render(" FINAL ") -} - -func ScoreStyle(homeScore int, awayScore int) string { - return ScoreText.Render(" " + strconv.Itoa(homeScore) + " - " + strconv.Itoa(awayScore) + " ") -} - -func DescStyle(desc string) string { - return DescText.Render(desc) -} diff --git a/ui/constants/consts.go b/ui/constants/consts.go index 6571840..ab8da62 100644 --- a/ui/constants/consts.go +++ b/ui/constants/consts.go @@ -1,7 +1,8 @@ package constants import ( - "github.com/dylantientcheu/nbacli/nba" + "strconv" + "github.com/evertras/bubble-table/table" "github.com/charmbracelet/bubbles/key" @@ -13,16 +14,12 @@ import ( var BaseStyle = lipgloss.NewStyle(). BorderStyle(lipgloss.RoundedBorder()). - BorderForeground(Accent) + BorderForeground(Secondary) var ( // P the current tea program P *tea.Program - Gm *nba.BoxScoreRepository - Sb *nba.ScoreboardRepository - St *nba.StandingsRepository - // WindowSize store the size of the terminal window WindowSize tea.WindowSizeMsg @@ -46,11 +43,21 @@ var ( InnerDivider: "│", } - Accent = lipgloss.AdaptiveColor{Light: "#874BFD", Dark: "#7D56F4"} + LiveText = lipgloss.NewStyle().Background(lipgloss.AdaptiveColor{Light: "#ef2929", Dark: "#ef2929"}).Foreground(lipgloss.AdaptiveColor{Light: "#ffffff", Dark: "#ffffff"}).Bold(true) + + FinalText = lipgloss.NewStyle().Background(lipgloss.Color("#9356DF")).Foreground(lipgloss.Color("#ffffff")).Bold(true) + DescText = lipgloss.NewStyle().Foreground(lipgloss.Color("#818181")) + + ScoreText = lipgloss.NewStyle().Background(lipgloss.AdaptiveColor{Light: "214", Dark: "#181818"}).Foreground(lipgloss.AdaptiveColor{Light: "0", Dark: "214"}) + + Accent = lipgloss.AdaptiveColor{Light: "#5b1b7b", Dark: "#5b1b7b"} + AccentDarker = lipgloss.AdaptiveColor{Light: "#5b1b7b", Dark: "#5b1b7b"} + Secondary = lipgloss.AdaptiveColor{Light: "#ed2265", Dark: "#ed2265"} + Tertiary = lipgloss.AdaptiveColor{Light: "#f69053", Dark: "#f69053"} activeTabBorder = lipgloss.Border{ + Bottom: "─", Top: "─", - Bottom: " ", Left: "│", Right: "│", TopLeft: "╭", @@ -60,24 +67,29 @@ var ( } tabBorder = lipgloss.Border{ - Top: "─", - Bottom: "─", - Left: "│", - Right: "│", - TopLeft: "╭", - TopRight: "╮", - BottomLeft: "┴", - BottomRight: "┴", + Bottom: "─", + // Top: "─", + // Left: "│", + // Right: "│", + // TopLeft: "╭", + // TopRight: "╮", + BottomLeft: "─", + BottomRight: "─", } TabStyle = lipgloss.NewStyle(). Border(tabBorder, true). BorderForeground(Accent). + Background(Accent). + Foreground(lipgloss.Color("#FFFFFF")). Padding(0, 1) ActiveTabStyle = lipgloss.NewStyle(). Border(activeTabBorder, true). - BorderForeground(Accent). + BorderForeground(Secondary). + Background(Secondary). + Foreground(lipgloss.Color("#FFFFFF")). + Bold(true). Padding(0, 1) BleedSpaceWidth = 4 @@ -138,3 +150,19 @@ func Max(a, b int) int { } return b } + +func LiveStyle() string { + return LiveText.Render(" LIVE ") +} + +func FinalStyle() string { + return FinalText.Render(" FINAL ") +} + +func ScoreStyle(homeScore int, awayScore int) string { + return ScoreText.Render(" " + strconv.Itoa(homeScore) + " - " + strconv.Itoa(awayScore) + " ") +} + +func DescStyle(desc string) string { + return DescText.Render(desc) +} diff --git a/ui/game.go b/ui/game.go index 53da42f..5047105 100644 --- a/ui/game.go +++ b/ui/game.go @@ -107,7 +107,7 @@ func InitGameView(activeGameID string, activeGame nba.BoxScoreSummary, previousM table.NewFlexColumn("PTS", "PTS", 3), } - rows := newStatsBoard(constants.Gm, activeGameID) + rows := newStatsBoard(nba.Gm, activeGameID) t := table.New(columns).WithRows(rows). Focused(true). @@ -126,7 +126,9 @@ func statsToRows(gameStats []nba.GameStat) []table.Row { var rows []table.Row areBenchers := false - rows = append(rows, table.NewRow(renderTeamRow("AWAY TEAM")).WithStyle(lipgloss.NewStyle().AlignHorizontal(lipgloss.Center).Background(lipgloss.AdaptiveColor{Light: "0", Dark: "214"}))) + rows = append(rows, table.NewRow(renderTeamRow("AWAY TEAM")). + WithStyle(lipgloss.NewStyle().AlignHorizontal(lipgloss.Center). + Background(constants.Secondary))) for idx, stat := range gameStats { // format plus minus @@ -166,7 +168,9 @@ func statsToRows(gameStats []nba.GameStat) []table.Row { } if idx < len(gameStats)-1 && gameStats[idx].TeamID != gameStats[idx+1].TeamID { - rows = append(rows, table.NewRow(renderTeamRow("HOME TEAM")).WithStyle(lipgloss.NewStyle().AlignHorizontal(lipgloss.Center).Background(lipgloss.AdaptiveColor{Light: "0", Dark: "214"}))) + rows = append(rows, table.NewRow(renderTeamRow("HOME TEAM")).WithStyle(lipgloss.NewStyle(). + AlignHorizontal(lipgloss.Center). + Background(constants.Secondary))) } } return rows @@ -175,7 +179,7 @@ func statsToRows(gameStats []nba.GameStat) []table.Row { func renderBenchRow() table.RowData { return table.RowData{ "POS": "", - "NAME": table.NewStyledCell("B E N C H", lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "0", Dark: "214"}).Padding(0)), + "NAME": table.NewStyledCell("B E N C H", lipgloss.NewStyle().Foreground(constants.Tertiary).Padding(0)), "MIN": "", "FG": "", "3PT": "", @@ -193,7 +197,7 @@ func renderBenchRow() table.RowData { func renderTeamRow(team string) table.RowData { return table.RowData{ "POS": "", - "NAME": table.NewStyledCell(team, lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "214", Dark: "0"})), + "NAME": table.NewStyledCell(team, lipgloss.NewStyle().Foreground(lipgloss.Color("#FFFFFF"))), "MIN": "", "FG": "", "3PT": "", diff --git a/ui/scoreboards.go b/ui/scoreboards.go index 71ebf7e..01fde68 100644 --- a/ui/scoreboards.go +++ b/ui/scoreboards.go @@ -31,7 +31,7 @@ type Model struct { } func InitScoreboard(date time.Time) tea.Model { - items := newScoreboardList(constants.Sb, date) + items := newScoreboardList(nba.Sb, date) m := Model{mode: nav, currentDate: date, list: list.NewModel(items, list.NewDefaultDelegate(), 8, 8)} if constants.WindowSize.Height != 0 { top, right, bottom, left := constants.DocStyle.GetMargin() diff --git a/ui/standings.go b/ui/standings.go index ca26a84..8f593ec 100644 --- a/ui/standings.go +++ b/ui/standings.go @@ -127,7 +127,7 @@ func InitStandingsView() *StandingsModel { table.NewFlexColumn("L10", "L10", 3), } - easternRows, westernRows := newStandingsBoard(constants.St) + easternRows, westernRows := newStandingsBoard(nba.St) tEast := table.New(columns).WithRows(easternRows).Focused(true).Border(constants.CustomTableBorder).WithBaseStyle(constants.BaseStyle).WithPageSize(10) tWest := table.New(columns).WithRows(westernRows).Border(constants.CustomTableBorder).WithBaseStyle(constants.BaseStyle).WithPageSize(10) diff --git a/ui/ui.go b/ui/ui.go index a228e82..ce85842 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -26,7 +26,7 @@ func StartTea(date time.Time) { } }() } - constants.Sb = &scbrd + nba.Sb = &scbrd m := InitScoreboard(date) UpdateTeaView(m)