diff --git a/cmd/tetrigo/subcommands.go b/cmd/tetrigo/subcommands.go index 35de244..1e5778c 100644 --- a/cmd/tetrigo/subcommands.go +++ b/cmd/tetrigo/subcommands.go @@ -2,12 +2,13 @@ package main import ( "fmt" - "github.com/Broderick-Westrope/tetrigo/internal/tui/starter" + + tea "github.com/charmbracelet/bubbletea" "github.com/Broderick-Westrope/tetrigo/internal/config" "github.com/Broderick-Westrope/tetrigo/internal/data" "github.com/Broderick-Westrope/tetrigo/internal/tui" - tea "github.com/charmbracelet/bubbletea" + "github.com/Broderick-Westrope/tetrigo/internal/tui/starter" ) type MenuCmd struct{} diff --git a/internal/tui/starter/model.go b/internal/tui/starter/model.go index 4d9d682..a997249 100644 --- a/internal/tui/starter/model.go +++ b/internal/tui/starter/model.go @@ -3,11 +3,11 @@ package starter import ( "database/sql" "errors" - "github.com/Broderick-Westrope/tetrigo/internal/tui/views" "reflect" "github.com/Broderick-Westrope/tetrigo/internal/config" "github.com/Broderick-Westrope/tetrigo/internal/tui" + "github.com/Broderick-Westrope/tetrigo/internal/tui/views" "github.com/charmbracelet/bubbles/key" tea "github.com/charmbracelet/bubbletea" ) diff --git a/internal/tui/utils.go b/internal/tui/utils.go index 470783a..bd4a0d9 100644 --- a/internal/tui/utils.go +++ b/internal/tui/utils.go @@ -1,11 +1,12 @@ package tui import ( - "errors" "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/x/ansi" "github.com/mattn/go-runewidth" + + "errors" "regexp" "strings" "unicode" @@ -43,7 +44,7 @@ func ConstructKeyBinding(keys []string, desc string) key.Binding { return key.NewBinding(key.WithKeys(keys...), key.WithHelp(buildHelpKeys(keys), desc)) } -// Window overlay (CREDIT: https://gist.github.com/ras0q/9bf5d81544b22302393f61206892e2cd) ------------------------------------ +// Window overlay (CREDIT: https://gist.github.com/ras0q/9bf5d81544b22302393f61206892e2cd) // OverlayCenter writes the overlay string onto the background string such that the middle of the // overlay string will be at the middle of the overlay will be at the middle of the background. @@ -95,7 +96,8 @@ func Overlay(bg, overlay string, row, col int, ignoreMarginWhitespace bool) (str } // removeMarginWhitespace preserves the background where the overlay line has leading or trailing whitespace. -// This is done by detecting those empty cells in the overlay string and replacing them with the corresponding background cells. +// This is done by detecting those empty cells in the overlay string and +// replacing them with the corresponding background cells. // //nolint:gocognit func removeMarginWhitespace(bgLine, overlayLine string, col int) string { diff --git a/internal/tui/views/menu.go b/internal/tui/views/menu.go index 2648704..3d6612d 100644 --- a/internal/tui/views/menu.go +++ b/internal/tui/views/menu.go @@ -2,9 +2,10 @@ package views import ( "fmt" - "github.com/Broderick-Westrope/tetrigo/internal/tui/components" "github.com/Broderick-Westrope/tetrigo/internal/tui" + "github.com/Broderick-Westrope/tetrigo/internal/tui/components" + "github.com/charmbracelet/bubbles/help" "github.com/charmbracelet/bubbles/key" tea "github.com/charmbracelet/bubbletea" @@ -149,6 +150,7 @@ func (m MenuModel) startGame() (tea.Cmd, error) { if !ok { return nil, errInvalidValue } + case "Mode": picker, ok := i.model.(*components.HPickerModel) if !ok { @@ -158,8 +160,14 @@ func (m MenuModel) startGame() (tea.Cmd, error) { if !ok { return nil, errInvalidValue } + case "Name": - playerName = i.model.(components.TextInputModel).Child.Value() + input, ok := i.model.(components.TextInputModel) + if !ok { + return nil, errInvalidModel + } + playerName = input.Child.Value() + default: return nil, fmt.Errorf("invalid item label: %q", i.label) } diff --git a/internal/tui/views/single.go b/internal/tui/views/single.go index 136e990..ff7444c 100644 --- a/internal/tui/views/single.go +++ b/internal/tui/views/single.go @@ -2,10 +2,11 @@ package views import ( "fmt" - "github.com/Broderick-Westrope/tetrigo/internal/tui/components" "strconv" "time" + "github.com/Broderick-Westrope/tetrigo/internal/tui/components" + "github.com/Broderick-Westrope/tetrigo/internal/config" "github.com/Broderick-Westrope/tetrigo/internal/data" "github.com/Broderick-Westrope/tetrigo/internal/tui"