tui

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinWidth  = 60
	MinHeight = 28
)

Variables

This section is empty.

Functions

func RenderBoard

func RenderBoard(engine *game.Engine, styles Styles, showGhost, showGrid bool, rainbow *theme.RainbowState) string

RenderBoard renders the visible portion of the board with the active and ghost pieces.

func RenderHoldPanel

func RenderHoldPanel(holdPiece *game.PieceType, holdUsed bool, styles Styles, rainbow *theme.RainbowState) string

RenderHoldPanel renders the hold piece panel.

func RenderNextPanel

func RenderNextPanel(pieces []game.PieceType, styles Styles, rainbow *theme.RainbowState) string

RenderNextPanel renders the next pieces preview panel.

func RenderPiecePreview

func RenderPiecePreview(pt game.PieceType, t theme.Theme, rainbow *theme.RainbowState) string

RenderPiecePreview renders a small preview of a piece type.

func RenderStatsPanel

func RenderStatsPanel(scorer *game.Scorer, styles Styles) string

RenderStatsPanel renders the score/level/lines panel.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App is the root Bubble Tea model.

func NewApp

func NewApp(cfg *config.Config, keys *config.KeyBindings, hs *config.HighScores) App

NewApp creates the root application model.

func (App) Init

func (a App) Init() tea.Cmd

func (App) Update

func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (App) View

func (a App) View() string

type GameModel

type GameModel struct {
	// contains filtered or unexported fields
}

GameModel handles the gameplay screen.

func NewGameModel

func NewGameModel(cfg *config.Config, keys *config.KeyBindings, rainbow *theme.RainbowState) GameModel

NewGameModel creates a new gameplay model.

func (GameModel) Init

func (g GameModel) Init() tea.Cmd

Init returns the initial commands for the game.

func (GameModel) Update

func (g GameModel) Update(msg tea.Msg, keys *config.KeyBindings) (GameModel, tea.Cmd)

Update processes messages for the game screen.

func (GameModel) View

func (g GameModel) View(s Styles, cfg *config.Config, rainbow *theme.RainbowState) string

View renders the gameplay screen.

type GameOverModel

type GameOverModel struct {
	// contains filtered or unexported fields
}

GameOverModel represents the game over screen.

func NewGameOverModel

func NewGameOverModel(engine *game.Engine, hs *config.HighScores) GameOverModel

NewGameOverModel creates a game over model and saves the score.

func (GameOverModel) View

func (m GameOverModel) View(s Styles) string

View renders the game over screen.

type HighScoresModel

type HighScoresModel struct {
	// contains filtered or unexported fields
}

HighScoresModel displays the high scores table.

func NewHighScoresModel

func NewHighScoresModel(hs *config.HighScores, s Styles) HighScoresModel

NewHighScoresModel creates a new high scores model.

func (HighScoresModel) View

func (m HighScoresModel) View(s Styles) string

View renders the high scores table.

type KeyBindsModel

type KeyBindsModel struct {
	// contains filtered or unexported fields
}

KeyBindsModel handles the key binding configuration screen.

func NewKeyBindsModel

func NewKeyBindsModel(keys *config.KeyBindings, s Styles) KeyBindsModel

NewKeyBindsModel creates a new key bindings model.

func (KeyBindsModel) HandleKey

func (m KeyBindsModel) HandleKey(msg tea.KeyMsg, keys *config.KeyBindings) KeyBindsModel

HandleKey processes a key press while listening for a new binding.

func (KeyBindsModel) Update

func (m KeyBindsModel) Update(msg tea.KeyMsg, keys *config.KeyBindings) KeyBindsModel

Update handles navigation input.

func (KeyBindsModel) View

func (m KeyBindsModel) View(s Styles) string

View renders the key bindings screen.

type LockTickMsg

type LockTickMsg struct {
	Time time.Time
}

LockTickMsg checks lock delay expiration.

type MenuModel struct {
	// contains filtered or unexported fields
}

MenuModel represents the main menu.

func NewMenuModel

func NewMenuModel(s Styles) MenuModel

NewMenuModel creates a new menu.

func (m *MenuModel) Next()

Next moves the cursor down.

func (m *MenuModel) Prev()

Prev moves the cursor up.

func (m *MenuModel) Selected() int

Selected returns the currently selected menu index.

func (m MenuModel) View(s Styles) string

View renders the menu.

type PauseModel

type PauseModel struct{}

PauseModel represents the pause overlay.

func NewPauseModel

func NewPauseModel() PauseModel

NewPauseModel creates a new pause model.

func (PauseModel) View

func (p PauseModel) View(s Styles) string

View renders the pause screen.

type RainbowTickMsg

type RainbowTickMsg struct {
	Time time.Time
}

RainbowTickMsg advances the rainbow theme animation.

type Screen

type Screen int

Screen represents the active screen.

const (
	ScreenMenu Screen = iota
	ScreenGame
	ScreenPause
	ScreenGameOver
	ScreenSettings
	ScreenHighScores
	ScreenKeyBinds
)

type SettingsModel

type SettingsModel struct {
	// contains filtered or unexported fields
}

SettingsModel handles the settings screen.

func NewSettingsModel

func NewSettingsModel(cfg *config.Config, s Styles) SettingsModel

NewSettingsModel creates a new settings model.

func (SettingsModel) Update

func (m SettingsModel) Update(msg tea.KeyMsg, cfg *config.Config) SettingsModel

Update handles settings input.

func (SettingsModel) View

func (m SettingsModel) View(s Styles) string

View renders the settings screen.

type Styles

type Styles struct {
	Theme theme.Theme

	// Base styles.
	Background lipgloss.Style
	Title      lipgloss.Style
	Subtitle   lipgloss.Style
	Text       lipgloss.Style
	Dim        lipgloss.Style
	Highlight  lipgloss.Style
	Selected   lipgloss.Style

	// Board styles.
	BoardBorder lipgloss.Style
	Cell        lipgloss.Style
	EmptyCell   lipgloss.Style
	GridCell    lipgloss.Style
	GhostCell   lipgloss.Style

	// Panel styles.
	Panel      lipgloss.Style
	PanelTitle lipgloss.Style

	// Menu styles.
	MenuItem         lipgloss.Style
	MenuItemSelected lipgloss.Style
}

Styles holds all Lipgloss styles derived from the active theme.

func NewStyles

func NewStyles(t theme.Theme) Styles

NewStyles creates styles from a theme.

func (*Styles) CellStyle

func (s *Styles) CellStyle(c lipgloss.Color) lipgloss.Style

CellStyle returns the style for a cell with the given color.

type TickMsg

type TickMsg struct {
	Time time.Time
}

TickMsg is sent on every game gravity tick.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL