Documentation
¶
Overview ¶
Package style provides terminal styling with ANSI colors and text attributes.
Index ¶
- Variables
- type Attribute
- type Color
- type ColorSystem
- type ColorType
- type Style
- func (s Style) Add(other Style) Style
- func (s Style) Background() *Color
- func (s Style) Foreground() *Color
- func (s Style) IsBold() bool
- func (s Style) IsDim() bool
- func (s Style) IsEmpty() bool
- func (s Style) IsItalic() bool
- func (s Style) IsStrike() bool
- func (s Style) IsUnderline() bool
- func (s Style) Link() string
- func (s Style) Render(text string, colorSystem ColorSystem) string
- func (s Style) String() string
- func (s Style) WithBackground(c Color) Style
- func (s Style) WithBlink(on bool) Style
- func (s Style) WithBold(on bool) Style
- func (s Style) WithConceal(on bool) Style
- func (s Style) WithDim(on bool) Style
- func (s Style) WithForeground(c Color) Style
- func (s Style) WithItalic(on bool) Style
- func (s Style) WithLink(url string) Style
- func (s Style) WithOverline(on bool) Style
- func (s Style) WithReverse(on bool) Style
- func (s Style) WithStrike(on bool) Style
- func (s Style) WithUnderline(on bool) Style
Constants ¶
This section is empty.
Variables ¶
var ( Bold = New().WithBold(true) Dim = New().WithDim(true) Italic = New().WithItalic(true) Underline = New().WithUnderline(true) Blink = New().WithBlink(true) Reverse = New().WithReverse(true) Strike = New().WithStrike(true) Conceal = New().WithConceal(true) Overline = New().WithOverline(true) )
var ( Red = New().WithForeground(StandardColor(1)) Green = New().WithForeground(StandardColor(2)) Yellow = New().WithForeground(StandardColor(3)) Blue = New().WithForeground(StandardColor(4)) Magenta = New().WithForeground(StandardColor(5)) Cyan = New().WithForeground(StandardColor(6)) White = New().WithForeground(StandardColor(7)) Black = New().WithForeground(StandardColor(0)) )
Functions ¶
This section is empty.
Types ¶
type Color ¶
type Color struct {
// contains filtered or unexported fields
}
Color represents a terminal color.
func ParseColor ¶
ParseColor parses a color from a string. Supported formats:
- Named colors: "red", "bright_blue", etc.
- Hex: "#ff0000" or "#f00"
- RGB: "rgb(255,0,0)"
- 256-color: "color(123)"
- Default: "default"
func StandardColor ¶
StandardColor creates a color from the standard 16-color palette. Numbers 0-7 are normal colors, 8-15 are bright variants.
func (Color) ANSICodes ¶
ANSICodes returns the ANSI SGR parameters for this color. foreground=true for foreground color, false for background.
func (Color) Downgrade ¶
func (c Color) Downgrade(system ColorSystem) Color
Downgrade returns a color suitable for the given color system.
type ColorSystem ¶
type ColorSystem int
ColorSystem represents the color capability of a terminal.
const ( ColorSystemNone ColorSystem = 0 // No color support ColorSystemStandard ColorSystem = 1 // 16 colors (standard ANSI) ColorSystem256 ColorSystem = 2 // 256 colors ColorSystemTrueColor ColorSystem = 3 // 24-bit true color )
type Style ¶
type Style struct {
// contains filtered or unexported fields
}
Style represents terminal text styling with colors and attributes. It uses a three-state system for attributes:
- Not set (will inherit from parent)
- Explicitly on
- Explicitly off
func (Style) Add ¶
Add combines two styles, with the other style taking precedence for any attributes that are explicitly set.
func (Style) Background ¶
Background returns the background color, or nil if not set.
func (Style) Foreground ¶
Foreground returns the foreground color, or nil if not set.
func (Style) IsUnderline ¶
IsUnderline returns true if underline is explicitly set to on.
func (Style) Render ¶
func (s Style) Render(text string, colorSystem ColorSystem) string
Render wraps text with ANSI escape codes for this style.
func (Style) WithBackground ¶
WithBackground returns a new style with the given background color.
func (Style) WithConceal ¶
WithConceal returns a new style with conceal set.
func (Style) WithForeground ¶
WithForeground returns a new style with the given foreground color.
func (Style) WithItalic ¶
WithItalic returns a new style with italic set.
func (Style) WithOverline ¶
WithOverline returns a new style with overline set.
func (Style) WithReverse ¶
WithReverse returns a new style with reverse set.
func (Style) WithStrike ¶
WithStrike returns a new style with strikethrough set.
func (Style) WithUnderline ¶
WithUnderline returns a new style with underline set.