clone

fifteen puzzle games for the terminal, with daily puzzles, weekly ladders and xp, built on bubble tea

refactor/root-tui-model
puzzletea / app / view_helpers.go
view_helpers.go 1.6K
1package app23import (4 "github.com/FelineStateMachine/puzzletea/ui"56 "charm.land/lipgloss/v2"7)89func renderContinueView(cont continueState, width, height int, notice noticeState) string {10 if len(cont.games) == 0 {11 return renderPanelView(width, height, notice, "Saved Games", "No saved games yet.", "esc back")12 }1314 footer := "↑/↓ navigate • enter resume • esc back"15 if pg := ui.TablePagination(cont.table); pg != "" {16 footer = pg + " " + footer17 }18 return renderPanelView(width, height, notice, "Saved Games", cont.table.View(), footer)19}2021func (m model) renderGameView() string {22 if m.session.game == nil {23 return ""24 }2526 gameView := lipgloss.NewStyle().MaxWidth(m.width).Render(m.session.game.View())27 centered := gameView28 if m.debug.enabled {29 debugInfo := lipgloss.NewStyle().MaxWidth(m.width).Render(30 ui.DebugStyle().Render(m.debug.info),31 )32 centered = lipgloss.JoinVertical(lipgloss.Center, gameView, debugInfo)33 }34 return ui.CenterView(m.width, m.height, m.appendNotice(centered))35}3637func renderStatsView(stats statsState, width, height int, notice noticeState) string {38 statsWidth, _ := statsViewportSize(width, height, stats.cards)39 var statsBody string40 if len(stats.cards) == 0 {41 statsBody = stats.viewport.View()42 } else {43 banner := ui.RenderStatsBanner(stats.profile, statsWidth)44 statsBody = lipgloss.JoinVertical(lipgloss.Left,45 banner,46 "",47 stats.viewport.View(),48 )49 }50 statsBody = lipgloss.NewStyle().Width(statsWidth).Render(statsBody)51 return renderPanelView(width, height, notice, "Stats", statsBody, "↑/↓ scroll • esc back")52}