Documentation
¶
Overview ¶
Package theme manages viewkit's process-global palette, styles, and screen background rendering.
Index ¶
- Constants
- func AppMargin(body string) string
- func DisplayName(key string) string
- func FillLine(c lipgloss.TerminalColor, width 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)
- type Palette
- type Theme
- func (t Theme) Icon(icon string, hue int) string
- func (t Theme) Screen(body string, width, height int) string
- func (t Theme) SeverityColor(s glyph.Severity) lipgloss.TerminalColor
- func (t Theme) SeverityStyle(s glyph.Severity) lipgloss.Style
- func (t Theme) StripBg() lipgloss.TerminalColor
- func (t Theme) StripBlock(width int, lines ...string) string
- func (t Theme) StripBold(fg lipgloss.TerminalColor, s string) string
- func (t Theme) StripText(fg lipgloss.TerminalColor, s string) string
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 AppMargin ¶ added in v0.0.3
AppMargin indents body by the standard horizontal app margin (AppMarginX columns each side), adding no vertical margin.
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 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 — deliberately unlike the first-wins glyph/panels/deck registries, where overriding is a collision. Safe for concurrent use.
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 carry it in a ui.Scope.
func Default ¶
func Default() Theme
Default returns the (memoized) theme built from the built-in default palette.
func Named ¶
Named builds a Theme from the palette registered under key. When key is not registered it returns Default() and false.
Example ¶
package main
import (
"github.com/codyconfer/viewkit/theme"
)
func main() {
th := theme.Default()
if named, ok := theme.Named("monokai"); ok {
th = named
}
body := th.Accent.Render("ready")
_ = th.Screen(body, theme.MinScreenWidth, theme.MinBodyHeight)
}
Output:
func New ¶
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.
func (Theme) Icon ¶ added in v0.2.2
Icon renders icon as a fixed-width lead colored by Series[hue], falling back to Accent when hue is out of range. Empty icon yields "".
func (Theme) Screen ¶ added in v0.2.2
Screen paints this 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 (Theme) SeverityColor ¶ added in v0.2.2
func (t Theme) SeverityColor(s glyph.Severity) lipgloss.TerminalColor
SeverityColor maps glyph.Severity to this theme's terminal color.
func (Theme) SeverityStyle ¶ added in v0.2.2
SeverityStyle maps glyph.Severity to this theme's style for it.
func (Theme) StripBg ¶ added in v0.2.2
func (t Theme) StripBg() lipgloss.TerminalColor
StripBg returns this theme's status-strip background color.
func (Theme) StripBlock ¶ added in v0.2.2
StripBlock wraps lines in one strip-background filler line above and below, each width columns wide.