Help us shape the future of Go! Take the 2026 Go Developer Survey

ui

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Themes lists every theme in presentation order.

Functions

func Run

func Run(opts Options) error

Run starts the TUI program.

Types

type KeyMap

type KeyMap struct {
	Up, Down, Left, Right    key.Binding
	Reveal, Flag, Chord      key.Binding
	New, Restart, Difficulty key.Binding
	Menu, Stats, Help        key.Binding
	Quit                     key.Binding
}

KeyMap defines key bindings.

func DefaultKeyMap

func DefaultKeyMap() KeyMap

DefaultKeyMap returns default bindings.

type Model

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

Model is the bubbletea model.

func NewModel

func NewModel(opts Options) Model

NewModel creates a new UI model.

func (Model) Init

func (m Model) Init() tea.Cmd

Init implements tea.Model. A resumed game arrives with its clock already running, so the tick has to start without waiting for a first move.

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements tea.Model.

func (Model) View

func (m Model) View() string

View renders the TUI.

type Options

type Options struct {
	Difficulty game.Difficulty
	Seed       game.Seed
	Config     storage.Config
	HighScores storage.HighScores
	Stats      storage.Stats
	NoColor    bool
	// Session, when set, is an unfinished game to pick up instead of dealing
	// a new board.
	Session *storage.Session
}

Options configures the UI run.

type Screen

type Screen int

Screen identifies the active UI screen.

const (
	ScreenPlaying Screen = iota
	ScreenMenu
	ScreenDifficultyMenu
	ScreenSettings
	ScreenStats
	ScreenHelp
	ScreenReplays
	ScreenReplayWatch
	ScreenGameOver
	ScreenWin
)

type Styles

type Styles struct {
	Hidden     lipgloss.Style
	Revealed   lipgloss.Style
	Flagged    lipgloss.Style
	Questioned lipgloss.Style
	Mine       lipgloss.Style
	Cursor     lipgloss.Style
	Digits     [9]lipgloss.Style
	HUD        lipgloss.Style
	StatusBar  lipgloss.Style
	Overlay    lipgloss.Style
	Title      lipgloss.Style
	Warning    lipgloss.Style
}

Styles holds lipgloss styles for rendering.

func NewStyles

func NewStyles(theme Theme, useColor bool) Styles

NewStyles builds the style set for a theme. The monochrome set carries cell state through bold and reverse so the board survives terminals without colour, which is also why no theme is consulted in that case.

type Theme added in v0.3.0

type Theme string

Theme names a colour palette. The board is readable without colour at all, so a theme only changes how pleasant it looks — never what it means.

const (
	// ThemeClassic is the light grey of the original Windows game.
	ThemeClassic Theme = "classic"
	// ThemeDark suits dark terminals, where the classic light cells glare.
	ThemeDark Theme = "dark"
	// ThemeColorblind swaps the red/green digits for the Okabe-Ito palette,
	// which stays distinguishable with the common forms of colour blindness.
	ThemeColorblind Theme = "colorblind"
)

func ParseTheme added in v0.3.0

func ParseTheme(s string) (Theme, bool)

ParseTheme resolves a theme name, reporting whether it was recognised. The caller decides what an unknown name means: a typo on the command line is worth an error, whereas a stale config file should just fall back.

Jump to

Keyboard shortcuts

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