Documentation
¶
Overview ¶
Package theme manages viewkit's process-global palette, styles, and screen background rendering.
Index ¶
- Constants
- func Activate(key string) bool
- func AppMargin(body string) string
- func Bullet(msg string) string
- func DisplayName(key string) string
- func FillLine(c lipgloss.TerminalColor, width int) string
- func Generation() uint64
- func Icon(icon string, hue int) string
- func IconBlank() string
- func Keys() []string
- func PadBlock(c lipgloss.TerminalColor, width, rows int, lines ...string) string
- func Register(key, name string, p Palette)
- func Screen(body string, width, height int) string
- func SeverityColor(s glyph.Severity) lipgloss.TerminalColor
- func SeverityStyle(s glyph.Severity) lipgloss.Style
- func StripBg() lipgloss.TerminalColor
- func StripBlock(width int, lines ...string) string
- func StripBold(fg lipgloss.TerminalColor, s string) string
- func StripText(fg lipgloss.TerminalColor, s string) string
- func Success(msg string) string
- func Use(t Theme)
- type Palette
- type Theme
Examples ¶
Constants ¶
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.
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
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
AppMargin indents body by the standard horizontal app margin (AppMarginX columns each side), adding no vertical margin.
func Bullet ¶ added in v0.0.4
Bullet renders an accent-colored bullet followed by msg in the body text style.
func DisplayName ¶
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
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
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. Safe for concurrent use.
func Screen ¶
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
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
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
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)
}
Output:
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 Default ¶
func Default() Theme
Default returns the theme built from the built-in default palette.