Something went wrong. Try again.
a collection of games playable over ssh!
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869package selector
import ( "fmt" "math" "strings" "unicode"
common "github.com/CelestialCrafter/games/common" "github.com/CelestialCrafter/games/styles" "github.com/charmbracelet/lipgloss")
func (m Model) View() string { greeting := lipgloss.NewStyle(). BorderForeground(styles.Colors.Accent). Border(lipgloss.NormalBorder()). BorderLeft(false). BorderRight(false). BorderTop(false). Padding(0, 2). Render("welcome back!! <3") greeting = lipgloss.Place(m.width, 2, lipgloss.Center, lipgloss.Top, greeting)
selectedBar := fmt.Sprintf( "\n%v", lipgloss.NewStyle(). Margin(0, 1). Foreground(styles.Colors.Secondary). Render(strings.Repeat("─", common.ICON_WIDTH+2)), )
rowAmount := int(math.Ceil(float64(len(common.Games)) / float64(m.rowLength))) menu := make([][]string, rowAmount) for i := range menu { menu[i] = make([]string, m.rowLength) }
menuRows := make([]string, rowAmount)
for i := 0; i < len(common.Games); i++ { currentRow := i / m.rowLength currentColumn := i % m.rowLength current := &menu[currentRow][currentColumn]
*current = common.Games[uint(i)].Icon if m.selectedGame == i { *current = strings.TrimRightFunc(*current, unicode.IsSpace) + selectedBar } }
for i := 0; i < len(menu); i++ { menuRows[i] = lipgloss.JoinHorizontal(lipgloss.Top, menu[i]...) }
menuJoined := lipgloss.JoinVertical(lipgloss.Left, menuRows...) help := m.help.View(m.keys)
availableHeight := m.height availableHeight -= lipgloss.Height(greeting) availableHeight -= lipgloss.Height(help)
return lipgloss.JoinVertical( lipgloss.Top, greeting, lipgloss.NewStyle().Height(availableHeight).Render(menuJoined), help, )}