diff --git a/cmd/game.go b/cmd/game.go index c9a9b3c..3a2c21a 100644 --- a/cmd/game.go +++ b/cmd/game.go @@ -13,7 +13,8 @@ import ( // args var date = "" -var gameID = "" + +// var gameID = "" var hasYesterday = false var hasTomorrow = false @@ -54,10 +55,10 @@ var StandingCmd = &cobra.Command{ func init() { rootCmd.AddCommand(gameCmd) - rootCmd.AddCommand(StandingCmd) rootCmd.PersistentFlags().StringVarP(&date, "date", "d", "", "Date to get the schedule for (YYYYMMDD)") rootCmd.PersistentFlags().BoolVarP(&hasYesterday, "yesterday", "y", false, "Get yesterday's games") rootCmd.PersistentFlags().BoolVarP(&hasTomorrow, "tomorrow", "t", false, "Get tomorrow's games") - rootCmd.MarkFlagsMutuallyExclusive("yesterday", "tomorrow", "date") + + rootCmd.AddCommand(StandingCmd) } diff --git a/ui/constants/consts.go b/ui/constants/consts.go index ea6d60e..6571840 100644 --- a/ui/constants/consts.go +++ b/ui/constants/consts.go @@ -13,7 +13,7 @@ import ( var BaseStyle = lipgloss.NewStyle(). BorderStyle(lipgloss.RoundedBorder()). - BorderForeground(lipgloss.Color("#874BFD")) + BorderForeground(Accent) var ( // P the current tea program @@ -45,6 +45,42 @@ var ( InnerDivider: "│", } + + Accent = lipgloss.AdaptiveColor{Light: "#874BFD", Dark: "#7D56F4"} + + activeTabBorder = lipgloss.Border{ + Top: "─", + Bottom: " ", + Left: "│", + Right: "│", + TopLeft: "╭", + TopRight: "╮", + BottomLeft: "┘", + BottomRight: "└", + } + + tabBorder = lipgloss.Border{ + Top: "─", + Bottom: "─", + Left: "│", + Right: "│", + TopLeft: "╭", + TopRight: "╮", + BottomLeft: "┴", + BottomRight: "┴", + } + + TabStyle = lipgloss.NewStyle(). + Border(tabBorder, true). + BorderForeground(Accent). + Padding(0, 1) + + ActiveTabStyle = lipgloss.NewStyle(). + Border(activeTabBorder, true). + BorderForeground(Accent). + Padding(0, 1) + + BleedSpaceWidth = 4 ) /* STYLING */ @@ -52,8 +88,11 @@ var ( // DocStyle styling for viewports var DocStyle = lipgloss.NewStyle().Margin(1, 2) +// TitleStyle styling for titles +var TitleStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#FFFFFF")).Background(Accent).Padding(0, 2) + // HelpStyle styling for help context menu -var HelpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")).Render +var HelpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")) // ErrStyle provides styling for error messages var ErrStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#bd534b")).Render @@ -92,3 +131,10 @@ var Keymap = keymap{ key.WithHelp("ctrl+c/q", "quit"), ), } + +func Max(a, b int) int { + if a > b { + return a + } + return b +} diff --git a/ui/game.go b/ui/game.go index 98b1735..53da42f 100644 --- a/ui/game.go +++ b/ui/game.go @@ -17,29 +17,7 @@ import ( var baseStyle = lipgloss.NewStyle(). BorderStyle(lipgloss.RoundedBorder()). - BorderForeground(lipgloss.Color("#874BFD")) - -var ( - customBorder = table.Border{ - Top: "─", - Left: "│", - Right: "│", - Bottom: "─", - - TopRight: "╮", - TopLeft: "╭", - BottomRight: "╯", - BottomLeft: "╰", - - TopJunction: "┬", - LeftJunction: "├", - RightJunction: "┤", - BottomJunction: "┴", - InnerJunction: "┼", - - InnerDivider: "│", - } -) + BorderForeground(constants.Accent) type keyMap struct { Down key.Binding @@ -101,6 +79,7 @@ func (m GameModel) View() string { Up: key.NewBinding(key.WithKeys("up"), key.WithHelp("↑", "highlight previous row")), Previous: key.NewBinding(key.WithKeys("esc", "q"), key.WithHelp("q/esc", "back to games list")), } + helpContainer := lipgloss.NewStyle(). SetString(m.help.View(keyMap)). Width(m.width). @@ -108,7 +87,6 @@ func (m GameModel) View() string { PaddingTop(1). String() - // helpText := return scoretext.RenderScoreText(m.activeGame.ArenaName, m.activeGame.GameDate, m.activeGame.HomeTeamScore, m.activeGame.VisitorTeamScore, m.activeGame.HomeTeamName, m.activeGame.VisitorTeamName) + table + helpContainer } @@ -133,7 +111,7 @@ func InitGameView(activeGameID string, activeGame nba.BoxScoreSummary, previousM t := table.New(columns).WithRows(rows). Focused(true). - Border(customBorder).WithBaseStyle(baseStyle).WithPageSize(constants.WindowSize.Height / 3) + Border(constants.CustomTableBorder).WithBaseStyle(baseStyle).WithPageSize(constants.WindowSize.Height / 3) m := GameModel{t, activeGameID, activeGame, previousModel, help.New(), constants.WindowSize.Height, constants.WindowSize.Width, 3} return &m diff --git a/ui/gameboard/scoretext/scoretext.go b/ui/gameboard/scoretext/scoretext.go index d004cbb..9a59bb3 100644 --- a/ui/gameboard/scoretext/scoretext.go +++ b/ui/gameboard/scoretext/scoretext.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/charmbracelet/lipgloss" + "github.com/dylantientcheu/nbacli/ui/constants" "golang.org/x/term" ) @@ -13,7 +14,7 @@ var ( subtle = lipgloss.AdaptiveColor{Light: "#D9DCCF", Dark: "#212121"} dialogBoxStyle = lipgloss.NewStyle(). Border(lipgloss.RoundedBorder()). - BorderForeground(lipgloss.Color("#874BFD")). + BorderForeground(constants.Accent). Padding(1, 1). BorderTop(true). BorderLeft(true). diff --git a/ui/standings.go b/ui/standings.go index 4427447..ca26a84 100644 --- a/ui/standings.go +++ b/ui/standings.go @@ -1,6 +1,9 @@ package ui import ( + "strings" + + "github.com/dylantientcheu/nbacli/nag/params" "github.com/dylantientcheu/nbacli/nba" "github.com/dylantientcheu/nbacli/ui/constants" @@ -16,12 +19,13 @@ type StandingsModel struct { easternConfTable table.Model westernConfTable table.Model help help.Model + selectedTab int width, height, margin int } func (m *StandingsModel) recalculateTable() { - m.easternConfTable = m.easternConfTable.WithTargetWidth(m.width) - m.westernConfTable = m.westernConfTable.WithTargetWidth(m.width) + m.easternConfTable = m.easternConfTable.WithTargetWidth(m.width - constants.BleedSpaceWidth) + m.westernConfTable = m.westernConfTable.WithTargetWidth(m.width - constants.BleedSpaceWidth) } func (m StandingsModel) Init() tea.Cmd { return nil } @@ -31,13 +35,22 @@ func (m StandingsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: switch msg.String() { + case "tab": + m.selectedTab = (m.selectedTab + 1) % 2 + if (m.selectedTab) == 0 { + m.easternConfTable = m.easternConfTable.Focused(true) + m.westernConfTable = m.westernConfTable.Focused(false) + } else { + m.easternConfTable = m.easternConfTable.Focused(false) + m.westernConfTable = m.westernConfTable.Focused(true) + } case "q", "esc": return m, tea.Quit case "ctrl+c": return m, tea.Quit case "enter": // TODO: to team view - return m, tea.Batch() + // return m, tea.Batch() } case tea.WindowSizeMsg: m.width = msg.Width @@ -59,6 +72,7 @@ func (m StandingsModel) View() string { Up: key.NewBinding(key.WithKeys("up"), key.WithHelp("↑", "highlight previous row")), Previous: key.NewBinding(key.WithKeys("esc", "q"), key.WithHelp("q/esc", "back to games list")), } + helpContainer := lipgloss.NewStyle(). SetString(m.help.View(keyMap)). Width(m.width). @@ -66,10 +80,36 @@ func (m StandingsModel) View() string { PaddingTop(1). String() - easternConfText := lipgloss.NewStyle().AlignHorizontal(lipgloss.Center).Padding(1, 3).Background(lipgloss.AdaptiveColor{Light: "214", Dark: "#181818"}).Render("EASTERN CONFERENCE") - westernConfText := lipgloss.NewStyle().AlignHorizontal(lipgloss.Center).Padding(1, 3).Background(lipgloss.AdaptiveColor{Light: "214", Dark: "#181818"}).Render("WESTERN CONFERENCE") + tabGap := constants.TabStyle.Copy(). + BorderTop(false). + BorderLeft(false). + BorderRight(false) + + tabRow := lipgloss.JoinHorizontal( + lipgloss.Top, + constants.ActiveTabStyle.Render("EASTERN CONFERENCE"), + constants.TabStyle.Render("WESTERN CONFERENCE"), + ) + + renderedTable := easternTable + + if m.selectedTab == 1 { + tabRow = lipgloss.JoinHorizontal( + lipgloss.Top, + constants.TabStyle.Render("EASTERN CONFERENCE"), + constants.ActiveTabStyle.Render("WESTERN CONFERENCE"), + ) + renderedTable = westernTable + } + + gap := tabGap.Render(strings.Repeat(" ", constants.Max(0, m.width-lipgloss.Width(tabRow)))) + + tabRow = lipgloss.JoinHorizontal(lipgloss.Bottom, tabRow, gap) + + // title + title := constants.TitleStyle.Render("NBA Standings: " + params.CurrentSeason) - return easternConfText + "\n" + easternTable + "\n" + westernConfText + "\n" + westernTable + "\n" + helpContainer + return constants.DocStyle.Render(title + "\n\n" + tabRow + "\n" + renderedTable + "\n" + helpContainer) } func InitStandingsView() *StandingsModel { @@ -89,10 +129,10 @@ func InitStandingsView() *StandingsModel { easternRows, westernRows := newStandingsBoard(constants.St) - tEast := table.New(columns).WithRows(easternRows).Focused(true).Border(constants.CustomTableBorder).WithBaseStyle(constants.BaseStyle).WithPageSize(constants.WindowSize.Height / 3) - tWest := table.New(columns).WithRows(westernRows).Border(constants.CustomTableBorder).WithBaseStyle(constants.BaseStyle).WithPageSize(constants.WindowSize.Height / 3) + 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) - m := StandingsModel{tEast, tWest, help.New(), constants.WindowSize.Height, constants.WindowSize.Width, 3} + m := StandingsModel{tEast, tWest, help.New(), 0, constants.WindowSize.Height, constants.WindowSize.Width, 3} return &m }