theme

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 5 Imported by: 4 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package theme manages viewkit's process-global palette, styles, and screen background rendering.

Index

Examples

Constants

View Source
const (
	BodyWidth    = 81
	MinBodyWidth = 24

	MinScreenWidth     = 80
	MinBodyHeight      = 35
	TallBodyHeight     = 46
	AppMarginY         = 1
	AppMarginX         = 2
	ListItemGapY       = 1
	ScreenPaddingWidth = AppMarginX*2 + 4
	MinScreenBodyWidth = MinScreenWidth - ScreenPaddingWidth

	RuleWidth = BodyWidth + 4
)

Layout metrics shared by every viewkit screen. BodyWidth is the content column that panels and cards wrap (they add their own border and padding); the Min*/Tall* values are the terminal sizes screens are designed against, and RuleWidth is the horizontal-rule span covering body plus panel chrome.

View Source
const (
	DefaultTooNarrowTitle = "TERMINAL TOO NARROW"
	DefaultTooNarrowNeed  = "Need at least %d columns."
	DefaultTooNarrowBody  = "Current width: %s columns. Resize the terminal to at least %d characters wide to use this screen."
)

Default text for the too-narrow-terminal screen. TooNarrowNeed takes the required column count; TooNarrowBody takes the current width (as a string) and the required column count.

Variables

This section is empty.

Functions

func Activate added in v0.2.0

func Activate(key string) bool

Activate looks up the named theme and makes it active, replacing the Named-then-Use two-step. It reports whether key was registered; the active theme is left unchanged when it was not.

func AppMargin added in v0.0.3

func AppMargin(body string) string

AppMargin indents body by the standard horizontal app margin (AppMarginX columns each side), adding no vertical margin.

func Bullet added in v0.0.4

func Bullet(msg string) string

Bullet renders an accent-colored bullet followed by msg in the body text style.

func DisplayName

func DisplayName(key string) string

DisplayName returns the human-readable name registered for key, or key itself when it is not registered.

func FillLine added in v0.0.3

func FillLine(c lipgloss.TerminalColor, width int) string

FillLine returns a width-column run of spaces painted with background c. Negative widths yield an empty line.

func Generation added in v0.2.0

func Generation() uint64

Generation returns a counter incremented by every Use. Views that cache theme-derived render state compare generations instead of theme identity to detect a theme change.

func Icon added in v0.0.4

func Icon(icon string, hue int) string

Icon renders icon as a fixed-width lead colored by the theme's Series style at index hue, falling back to Accent when hue is out of range. An empty icon yields an empty string.

func IconBlank added in v0.1.16

func IconBlank() string

IconBlank returns glyph.LeadWidth spaces, aligning rows that have no icon with rows rendered by Icon.

func Keys

func Keys() []string

Keys returns the registered palette keys in registration order, built-ins first.

func PadBlock added in v0.0.3

func PadBlock(c lipgloss.TerminalColor, width, rows int, lines ...string) string

PadBlock joins lines with rows blank filler lines above and below, each width columns of background c, giving the block vertical breathing room on a colored strip.

func Register added in v0.0.1

func Register(key, name string, p Palette)

Register adds palette p to the registry under key with the given display name. A later call with the same key replaces the earlier name and palette in place, so apps can override the built-ins — deliberately unlike the first-wins glyph/panels/deck registries, where overriding is a collision. Safe for concurrent use.

func Screen

func Screen(body string, width, height int) string

Screen paints the active theme's background across a width-by-height area behind body. Every ANSI reset inside body is re-followed by the background sequence so embedded styles do not punch holes in the fill. When the theme has no background color, body is returned unchanged.

func SeverityColor added in v0.0.4

func SeverityColor(s glyph.Severity) lipgloss.TerminalColor

SeverityColor maps glyph.Severity to the active theme's terminal color. glyph.Severity is the sole severity vocabulary; theme only supplies color.

func SeverityStyle added in v0.1.6

func SeverityStyle(s glyph.Severity) lipgloss.Style

SeverityStyle maps glyph.Severity to the active theme's style for that severity. Use it when rendering text; use SeverityColor when only the foreground color is needed.

func StripBg added in v0.0.4

func StripBg() lipgloss.TerminalColor

StripBg returns the background color for status strips: the active theme's panel border color, cached when the theme is installed.

func StripBlock added in v0.0.4

func StripBlock(width int, lines ...string) string

StripBlock wraps lines in one strip-background filler line above and below, each width columns wide.

func StripBold added in v0.0.4

func StripBold(fg lipgloss.TerminalColor, s string) string

StripBold renders s bold in foreground fg on the strip background.

func StripText added in v0.0.4

func StripText(fg lipgloss.TerminalColor, s string) string

StripText renders s in foreground fg on the strip background.

func Success added in v0.0.4

func Success(msg string) string

Success renders a success-colored check mark followed by msg in the body text style.

func Use

func Use(t Theme)

Use makes t the active theme. Safe to call while other goroutines render.

Example
package main

import (
	"github.com/codyconfer/viewkit/theme"
)

func main() {
	defer theme.Use(theme.Default())

	if th, ok := theme.Named("monokai"); ok {
		theme.Use(th)
	}

	body := theme.Cur().Accent.Render("ready")
	_ = theme.Screen(body, theme.MinScreenWidth, theme.MinBodyHeight)
}

Types

type Palette

type Palette struct {
	Accent   lipgloss.Color
	Border   lipgloss.Color
	Muted    lipgloss.Color
	Text     lipgloss.Color
	Selected lipgloss.Color
	Success  lipgloss.Color
	Warning  lipgloss.Color
	Failure  lipgloss.Color
	Info     lipgloss.Color
	Series2  lipgloss.Color
	Series3  lipgloss.Color
	Bg       lipgloss.Color
}

Palette is the twelve-color input to New: semantic roles (Accent, Success, Failure, ...) plus extra chart series colors and the screen background. Registering a Palette is all a custom theme needs; New derives every style.

type Theme

type Theme struct {
	Title  lipgloss.Style
	Accent lipgloss.Style
	Dim    lipgloss.Style
	Val    lipgloss.Style
	Key    lipgloss.Style
	Can    lipgloss.Style
	Cant   lipgloss.Style

	Panel      lipgloss.Style
	PanelFocus lipgloss.Style
	PanelTitle lipgloss.Style
	Card       lipgloss.Style
	AppFrame   lipgloss.Style

	NotifPositive lipgloss.Style
	NotifNeutral  lipgloss.Style
	NotifWarning  lipgloss.Style
	NotifNegative lipgloss.Style
	NotifIdle     lipgloss.Style
	NotifTitle    lipgloss.Style

	Series []lipgloss.Style

	Bg lipgloss.Color

	TooNarrowTitle string
	TooNarrowNeed  string
	TooNarrowBody  string
	// contains filtered or unexported fields
}

Theme is a bundle of ready-to-use lipgloss styles: text roles, panel and notification frames, chart Series styles, the screen background color, and the too-narrow-screen message templates. Build one with New and install it with Use; read the active theme with Cur.

func Cur

func Cur() Theme

Cur returns the active theme by value (matching keys.Cur).

func Default

func Default() Theme

Default returns the theme built from the built-in default palette.

func Named

func Named(key string) (Theme, bool)

Named builds a Theme from the palette registered under key. When key is not registered it returns Default() and false.

func New

func New(p Palette) Theme

New derives a full Theme from p: text styles, panel/card borders, notification frames, and a seven-entry Series ramp, with the too-narrow messages set to their defaults.

Jump to

Keyboard shortcuts

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