theme

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package theme loads hunk's color themes: two built-ins, plus TOML files a user writes locally or pulls from a GitHub repo.

Index

Constants

View Source
const DefaultName = "hunk-dark"

DefaultName is the theme hunk uses when nothing else is asked for.

Variables

This section is empty.

Functions

func Builtins

func Builtins() []string

Builtins lists the theme names that ship inside the binary.

func ConfigDir

func ConfigDir() string

ConfigDir is where hunk keeps user themes, including downloaded ones.

Types

type Diff

type Diff struct {
	AddedFg       string `toml:"added_fg"`
	AddedBg       string `toml:"added_bg"`
	RemovedFg     string `toml:"removed_fg"`
	RemovedBg     string `toml:"removed_bg"`
	ContextFg     string `toml:"context_fg"`
	AddedWordBg   string `toml:"added_word_bg"`
	RemovedWordBg string `toml:"removed_word_bg"`
}

Diff colors the changes themselves, including the intra-line emphasis that marks which words on a line actually moved.

type Loader

type Loader struct {
	// ConfigDir holds themes/ ; defaults to ConfigDir().
	ConfigDir string
	// BaseURL is where github.com/... references are fetched from. Tests point
	// this at an httptest server so no test ever touches the network.
	BaseURL string
	// Refresh re-downloads remote themes instead of using the cached copy.
	Refresh bool
}

Loader resolves a theme reference into a Theme.

func (*Loader) Load

func (l *Loader) Load(ref string) (*Theme, []string, error)

Load resolves a theme reference, in order: an existing file path, a theme in the user's themes directory, a built-in name, then a github.com/... reference.

type Theme

type Theme struct {
	Name string `toml:"name"`
	// Syntax is the chroma style name used for syntax highlighting. It is not a
	// color, so it sits outside UI/Diff and is skipped by the hex validation.
	Syntax string `toml:"syntax"`
	UI     UI     `toml:"ui"`
	Diff   Diff   `toml:"diff"`
}

Theme is the full set of colors hunk can paint with. Every field is a hex color string ("#rgb" or "#rrggbb"); the UI converts them to terminal colors.

func Decode

func Decode(data []byte, source string) (t *Theme, warnings []string, err error)

Decode parses TOML on top of the default theme, so a file that specifies only a few keys is a valid theme: everything it leaves out is inherited.

Unknown keys are reported as warnings rather than failing the load — a typo should cost you one color, not your diff.

func Default

func Default() *Theme

Default returns a copy of the built-in default theme. Every other theme is decoded on top of this copy, which is what makes partial theme files work.

func (*Theme) Validate

func (t *Theme) Validate(source string) error

Validate rejects a theme with a color hunk cannot paint. A bad color is worth an error: silently substituting one leaves a theme looking broken with no explanation of which key is wrong.

type UI

type UI struct {
	Background string `toml:"background"`
	Foreground string `toml:"foreground"`
	Border     string `toml:"border"`
	LineNumber string `toml:"line_number"`
	FileHeader string `toml:"file_header"`
	Accent     string `toml:"accent"`
	SidebarFg  string `toml:"sidebar_fg"`
}

UI colors the frame: panes, headers, sidebar, status bar.

Accent is the one highlight color: every place hunk points at something — the @@ line, the current hunk, a change block's outline, the status bar, the selected file — is painted with it, so a theme changes its highlight once.

Jump to

Keyboard shortcuts

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