Skip to content
Merged

2.0.1 #307

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<img src="https://img.shields.io/github/actions/workflow/status/digitalghost-dev/poke-cli/rust_test.yml?style=flat-square&logo=rust&logoColor=D34516&label=Tests&labelColor=EEE&color=D34516" alt="rust-tests-label">
<img src="https://img.shields.io/badge/dynamic/toml?url=https://raw.githubusercontent.com/digitalghost-dev/poke-cli/main/services/Cargo.toml&query=%24.package%5B%27rust-version%27%5D&style=flat-square&logo=rust&logoColor=D34516&label=Rust&labelColor=EEE&color=D34516" alt="rust-version"/>
</div>

`poke-cli` is a hybrid of a classic CLI and a modern TUI tool for viewing VG and TCG data about Pokémon!

View the [documentation](https://docs.poke-cli.com) on the data infrastructure in [data_platform/](https://github.com/digitalghost-dev/poke-cli/tree/main/data_platform) if you're interested.
Expand Down
8 changes: 4 additions & 4 deletions cmd/berry/berry.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (m model) View() tea.View {
Width(52).
Height(29).
Border(lipgloss.RoundedBorder()).
BorderForeground(styling.YellowColor).
BorderForeground(styling.ThemeColor).
Padding(1).
Render(selectedBerry)

Expand Down Expand Up @@ -158,11 +158,11 @@ func tableGeneration() error {
s := table.DefaultStyles()
s.Header = s.Header.
BorderStyle(lipgloss.NormalBorder()).
BorderForeground(styling.YellowColor).
BorderForeground(styling.ThemeColor).
BorderBottom(true)
s.Selected = s.Selected.
Foreground(lipgloss.Color("#000")).
Background(styling.YellowColor)
Background(styling.ThemeColor)
t.SetStyles(s)

m := model{table: t}
Expand All @@ -185,7 +185,7 @@ func berryContainers(name string) string {
boxStyle := lipgloss.NewStyle().
Padding(1, 2).
BorderStyle(lipgloss.ThickBorder()).
BorderForeground(styling.YellowColor).
BorderForeground(styling.ThemeColor).
Width(34)

// Render both without height constraints to measure natural heights.
Expand Down
4 changes: 2 additions & 2 deletions cmd/berry/berry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ func createTestModel() model {
s := table.DefaultStyles()
s.Header = s.Header.
BorderStyle(lipgloss.NormalBorder()).
BorderForeground(styling.YellowColor).
BorderForeground(styling.ThemeColor).
BorderBottom(true)
s.Selected = s.Selected.
Foreground(lipgloss.Color("#000")).
Background(styling.YellowColor)
Background(styling.ThemeColor)
t.SetStyles(s)

return model{table: t}
Expand Down
10 changes: 5 additions & 5 deletions cmd/card/cardlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ type cardDataMsg struct {
}

var (
activeTableSelectedBg color.Color = styling.YellowColor
activeTableSelectedBg color.Color = styling.ThemeColor
inactiveTableSelectedBg color.Color = lipgloss.Color("#808080")
)

func cardTableStyles(selectedBg color.Color) table.Styles {
s := table.DefaultStyles()
s.Header = s.Header.
BorderStyle(lipgloss.NormalBorder()).
BorderForeground(styling.YellowColor).
BorderForeground(styling.ThemeColor).
BorderBottom(true)
s.Selected = s.Selected.
Foreground(lipgloss.Color("#000")).
Foreground(styling.ContrastText(selectedBg)).
Background(selectedBg)
return s
}
Expand Down Expand Up @@ -297,7 +297,7 @@ func (m cardsModel) View() tea.View {
Width(42).
Height(29).
Border(lipgloss.RoundedBorder()).
BorderForeground(styling.YellowColor).
BorderForeground(styling.ThemeColor).
Padding(1).
Render(selectedCard)

Expand Down Expand Up @@ -327,7 +327,7 @@ type cardData struct {
func CardsList(setID string) (cardsModel, error) {
s := spinner.New()
s.Spinner = spinner.Dot
s.Style = styling.Yellow
s.Style = styling.Theme

return cardsModel{
SetID: setID,
Expand Down
4 changes: 2 additions & 2 deletions cmd/card/imageviewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (m imageModel) View() tea.View {
content = lipgloss.NewStyle().
Padding(2).
BorderStyle(lipgloss.RoundedBorder()).
BorderForeground(styling.YellowColor).
BorderForeground(styling.ThemeColor).
Render(styling.Red.Render(m.Error.Error()))
} else {
content = m.ImageData
Expand All @@ -97,7 +97,7 @@ func (m imageModel) View() tea.View {
func ImageRenderer(cardName string, imageURL string) imageModel {
s := spinner.New()
s.Spinner = spinner.Dot
s.Style = styling.Yellow
s.Style = styling.Theme

return imageModel{
CardName: cardName,
Expand Down
2 changes: 1 addition & 1 deletion cmd/card/setslist.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ type setData struct {
func SetsList(seriesID string) (setsModel, error) {
s := spinner.New()
s.Spinner = spinner.Dot
s.Style = styling.Yellow
s.Style = styling.Theme

return setsModel{
SeriesName: seriesID,
Expand Down
6 changes: 3 additions & 3 deletions cmd/comp/champions/tab_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func renderPokemonDetail(row compInfoRow, width int) string {
teammates := renderStatColumn("Common Teammates", row.CommonTeammates, colWidth)

var b strings.Builder
b.WriteString(styling.Yellow.Render(row.Pokemon))
b.WriteString(styling.Theme.Render(row.Pokemon))
b.WriteString("\n\n")
b.WriteString(lipgloss.JoinHorizontal(lipgloss.Top, moves, " ", items))
b.WriteString("\n\n")
Expand Down Expand Up @@ -231,7 +231,7 @@ func renderTeamDetail(team teamRow, width int) string {
var b strings.Builder

title := fmt.Sprintf("%s (%s)", team.Player, team.Record)
b.WriteString(styling.Yellow.Render("Selected Team"))
b.WriteString(styling.Theme.Render("Selected Team"))
b.WriteString("\n")
b.WriteString(styling.StyleBold.Render(title))
b.WriteString("\n")
Expand Down Expand Up @@ -392,7 +392,7 @@ func selectedSpeedTier(speedTable table.Model, rows []speedTierRow) speedTierRow

func renderSpeedDetail(row speedTierRow) string {
var b strings.Builder
b.WriteString(styling.Yellow.Render("Selected Pokémon"))
b.WriteString(styling.Theme.Render("Selected Pokémon"))
b.WriteString("\n")

b.WriteString(styling.StyleBold.Render(row.Pokemon))
Expand Down
3 changes: 2 additions & 1 deletion cmd/comp/shell/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"charm.land/bubbles/v2/table"
tea "charm.land/bubbletea/v2"
"github.com/digitalghost-dev/poke-cli/cmd/utils"
"github.com/digitalghost-dev/poke-cli/styling"
)

type dashboardModel struct {
Expand Down Expand Up @@ -139,7 +140,7 @@ func (m dashboardModel) renderTab(contentWidth int) string {
}
switch m.activeTab {
case 0:
return m.decoded.Overview(contentWidth, m.styles.HighlightColor)
return m.decoded.Overview(contentWidth, styling.ThemeColor)
case 1:
return m.table.View()
case 2:
Expand Down
8 changes: 4 additions & 4 deletions cmd/comp/shell/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *Styles) Render(tabs []string, activeTab, width int, renderContent func(

fillWidth := windowWidth - lipgloss.Width(row)
if fillWidth > 0 {
fill := lipgloss.NewStyle().Foreground(s.HighlightColor).
fill := lipgloss.NewStyle().Foreground(styling.ThemeColor).
Render(strings.Repeat("─", fillWidth-1) + "┐")
row = row + fill
}
Expand All @@ -65,11 +65,11 @@ func TableStyles() table.Styles {
s := table.DefaultStyles()
s.Header = s.Header.
BorderStyle(lipgloss.NormalBorder()).
BorderForeground(styling.YellowColor).
BorderForeground(styling.ThemeColor).
BorderBottom(true).
Bold(true)
s.Selected = s.Selected.
Foreground(lipgloss.Color("#000")).
Background(styling.YellowColor)
Foreground(styling.ContrastText(styling.ThemeColor)).
Background(styling.ThemeColor)
Comment thread
digitalghost-dev marked this conversation as resolved.
return s
}
3 changes: 0 additions & 3 deletions cmd/comp/shell/frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ func TestNewStyles(t *testing.T) {
if s == nil {
t.Fatal("expected non-nil styles")
}
if s.HighlightColor == nil {
t.Error("expected highlight color to be set")
}
}

func TestRender_ContainsTabsContentAndMenu(t *testing.T) {
Expand Down
14 changes: 11 additions & 3 deletions cmd/comp/shell/picker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type pickerModel struct {
tournaments []TournamentRef
selected *TournamentRef
error error
goBack bool
list list.Model
loading bool
spinner spinner.Model
Expand Down Expand Up @@ -52,7 +53,7 @@ func fetchTournaments(listURL string, conn ConnFunc) tea.Cmd {
func newPicker(spec Spec, conn ConnFunc) pickerModel {
s := spinner.New()
s.Spinner = spinner.Dot
s.Style = styling.Yellow
s.Style = styling.Theme

return pickerModel{
conn: conn,
Expand All @@ -76,6 +77,9 @@ func (m pickerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "ctrl+c", "esc":
m.quitting = true
return m, tea.Quit
case "b":
m.goBack = true
return m, tea.Quit
case "w":
return m, utils.Open("https://web.poke-cli.com/")
case "enter":
Expand Down Expand Up @@ -112,12 +116,16 @@ func (m pickerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
l.Styles.PaginationStyle = styling.PaginationStyle
l.Styles.HelpStyle = styling.HelpStyle

backBinding := key.NewBinding(
key.WithKeys("b"),
key.WithHelp("b", "back"),
)
webBinding := key.NewBinding(
key.WithKeys("w"),
key.WithHelp("w", "web"),
)
l.AdditionalShortHelpKeys = func() []key.Binding { return []key.Binding{webBinding} }
l.AdditionalFullHelpKeys = func() []key.Binding { return []key.Binding{webBinding} }
l.AdditionalShortHelpKeys = func() []key.Binding { return []key.Binding{backBinding, webBinding} }
l.AdditionalFullHelpKeys = func() []key.Binding { return []key.Binding{backBinding, webBinding} }

m.list = l
m.loading = false
Expand Down
16 changes: 6 additions & 10 deletions cmd/comp/shell/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,32 @@ func Run(spec Spec, conn ConnFunc) (back bool, err error) {
return result, nil
}

if err := loop(spec, conn, runPicker, runDashboard); err != nil {
return false, err
}
return true, nil
return loop(spec, conn, runPicker, runDashboard)
}

func loop(
spec Spec,
conn ConnFunc,
runPicker func(pickerModel) (pickerModel, error),
runDashboard func(dashboardModel) (dashboardModel, error),
) error {
) (back bool, err error) {
for {
result, err := runPicker(newPicker(spec, conn))
if err != nil {
return fmt.Errorf("error running tournament selection program: %w", err)
return false, fmt.Errorf("error running tournament selection program: %w", err)
}
if result.selected == nil {
break
return result.goBack, nil
}

dash, err := runDashboard(newDashboard(spec, conn, result.selected.Location))
if err != nil {
return fmt.Errorf("error running dashboard program: %w", err)
return false, fmt.Errorf("error running dashboard program: %w", err)
}
if !dash.goBack {
break
return false, nil
}
}
return nil
}

func FormatInt(n int) string {
Expand Down
23 changes: 18 additions & 5 deletions cmd/comp/shell/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,29 @@ func TestLoop_NoTournamentSelected(t *testing.T) {
dashCalled = true
return dashboardModel{}, nil
}
err := loop(testSpec(), noopConn, runPicker, runDashboard)
back, err := loop(testSpec(), noopConn, runPicker, runDashboard)
require.NoError(t, err)
require.False(t, back, "esc/quit from the picker should not return to the selection menu")
require.False(t, dashCalled, "dashboard should not launch when no tournament is selected")
}

func TestLoop_PickerGoBack_ReturnsBack(t *testing.T) {
runPicker := func(_ pickerModel) (pickerModel, error) { return pickerModel{selected: nil, goBack: true}, nil }
back, err := loop(testSpec(), noopConn, runPicker, nil)
require.NoError(t, err)
require.True(t, back, "pressing b in the picker should return to the selection menu")
}

func TestLoop_TournamentSelected_DashboardExits(t *testing.T) {
td := TournamentRef{Location: "London"}
runPicker := func(_ pickerModel) (pickerModel, error) { return pickerModel{selected: &td}, nil }
runDashboard := func(m dashboardModel) (dashboardModel, error) {
assert.Equal(t, "London", m.tournament)
return dashboardModel{goBack: false}, nil
}
assert.NoError(t, loop(testSpec(), noopConn, runPicker, runDashboard))
back, err := loop(testSpec(), noopConn, runPicker, runDashboard)
require.NoError(t, err)
assert.False(t, back, "quitting the dashboard should not return to the selection menu")
}

func TestLoop_GoBack_LoopsToPicker(t *testing.T) {
Expand All @@ -92,13 +102,15 @@ func TestLoop_GoBack_LoopsToPicker(t *testing.T) {
return pickerModel{selected: nil}, nil
}
runDashboard := func(_ dashboardModel) (dashboardModel, error) { return dashboardModel{goBack: true}, nil }
require.NoError(t, loop(testSpec(), noopConn, runPicker, runDashboard))
back, err := loop(testSpec(), noopConn, runPicker, runDashboard)
require.NoError(t, err)
require.False(t, back)
require.Equal(t, 2, calls, "expected the picker to run twice")
}

func TestLoop_PickerError(t *testing.T) {
runPicker := func(_ pickerModel) (pickerModel, error) { return pickerModel{}, errors.New("boom") }
err := loop(testSpec(), noopConn, runPicker, nil)
_, err := loop(testSpec(), noopConn, runPicker, nil)
assert.ErrorContains(t, err, "tournament selection")
}

Expand All @@ -108,5 +120,6 @@ func TestLoop_DashboardError(t *testing.T) {
runDashboard := func(_ dashboardModel) (dashboardModel, error) {
return dashboardModel{}, errors.New("boom")
}
assert.ErrorContains(t, loop(testSpec(), noopConn, runPicker, runDashboard), "dashboard")
_, err := loop(testSpec(), noopConn, runPicker, runDashboard)
assert.ErrorContains(t, err, "dashboard")
}
19 changes: 6 additions & 13 deletions cmd/comp/shell/styles.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package shell

import (
"image/color"

"charm.land/lipgloss/v2"
"github.com/digitalghost-dev/poke-cli/styling"
)

type Styles struct {
Doc lipgloss.Style
InactiveTab lipgloss.Style
ActiveTab lipgloss.Style
Window lipgloss.Style
HighlightColor color.Color
Doc lipgloss.Style
InactiveTab lipgloss.Style
ActiveTab lipgloss.Style
Window lipgloss.Style
}

func tabBorderWithBottom(left, middle, right string) lipgloss.Border {
Expand All @@ -26,24 +23,20 @@ func tabBorderWithBottom(left, middle, right string) lipgloss.Border {
func NewStyles() *Styles {
inactiveTabBorder := tabBorderWithBottom("┴", "─", "┴")
activeTabBorder := tabBorderWithBottom("┘", " ", "└")
isDark := styling.HasDarkBackground()
ld := lipgloss.LightDark(isDark)
highlightColor := ld(lipgloss.Color("#874BFD"), lipgloss.Color("#7D56F4"))

s := new(Styles)
s.Doc = lipgloss.NewStyle().
Padding(1, 2, 1, 2)
s.InactiveTab = lipgloss.NewStyle().
Border(inactiveTabBorder, true).
BorderForeground(highlightColor).
BorderForeground(styling.ThemeColor).
Padding(0, 1)
s.ActiveTab = s.InactiveTab.
Border(activeTabBorder, true)
s.Window = lipgloss.NewStyle().
BorderForeground(highlightColor).
BorderForeground(styling.ThemeColor).
Padding(2, 0).
Border(lipgloss.NormalBorder()).
UnsetBorderTop()
s.HighlightColor = highlightColor
return s
}
Loading
Loading