theme

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package theme holds the colour schemes the board and the interface are drawn with, and remembers which one the player chose.

Colours are stored as data rather than as styles so that this package does not depend on the rendering layer: the interface maps these roles onto whatever style type it uses. A role left empty means "do not colour this", which is how the monochrome theme works and how a terminal that reports no colour support is handled without a second code path.

Index

Constants

View Source
const Default = "classic"

Default is the theme used when the player has not chosen one.

Variables

This section is empty.

Functions

func Names

func Names() []string

Names returns the theme names in a stable order.

Types

type Background

type Background uint8

Background says which terminal a scheme is drawn for.

No scheme paints a background: pegs and links sit on whatever colour the player's terminal already is. A scheme is therefore only legible against one end of the range, and saying which one is what stops a scheme being written that is legible against neither. The default scheme used to be exactly that: its darker player was near-black, invisible on a dark terminal, while its panel text was near-white, invisible on a light one.

const (
	// AnyBackground sets no colours at all, so it cannot clash with either.
	AnyBackground Background = iota
	// DarkBackground is drawn to be read against a dark terminal.
	DarkBackground
	// LightBackground is drawn to be read against a light terminal.
	LightBackground
)

Which terminal a scheme suits.

type Theme

type Theme struct {
	Name    string
	Summary string

	// Suits is the terminal this scheme is legible against.
	Suits Background
	// VerticalPeg and HorizontalPeg colour the two players' pegs, and their
	// links take the matching link colour. These two must stay clearly distinct
	// from each other in every theme.
	VerticalPeg  string
	VerticalLink string

	HorizontalPeg  string
	HorizontalLink string

	// Grid is the empty holes and the board frame.
	Grid string
	// BorderRow tints the border rows so a player can see which edges are theirs.
	BorderRow string

	// Cursor is the hole the player is pointing at.
	Cursor string
	// Highlight marks holes the interface is calling out, such as a hint or a
	// tutorial step.
	Highlight string
	// LastMove marks the move just played.
	LastMove string

	// Text, Dim and Warning are the information panel's foreground colours.
	Text    string
	Dim     string
	Warning string
}

Theme names the colour of every role the interface draws.

func All

func All() []Theme

All returns every built-in theme.

func Get

func Get(name string) (Theme, error)

Get returns the named theme.

func Select

func Select(dir, name string) (Theme, error)

Select records the player's choice. The write is atomic so an interrupted save cannot leave an unreadable settings file behind.

func Selected

func Selected(dir string) (Theme, error)

Selected returns the theme the player chose, falling back to the default when nothing has been chosen or the stored name is no longer known. A corrupt or unreadable settings file is not worth failing a game over, so it degrades to the default and reports the reason.

func (Theme) Monochrome

func (t Theme) Monochrome() bool

Monochrome reports whether the theme asks for no colour at all.

Jump to

Keyboard shortcuts

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