style

package
v0.0.0-...-a7186bf Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0, MIT Imports: 6 Imported by: 0

Documentation

Overview

Package style describes terminal text styling — foreground and background colours together with text attributes — as composable values that authors declare directly and reuse to build themes.

Index

Constants

This section is empty.

Variables

View Source
var (
	Black   = named(30)
	Red     = named(31)
	Green   = named(32)
	Yellow  = named(33)
	Blue    = named(34)
	Magenta = named(35)
	Cyan    = named(36)
	White   = named(37)

	BrightBlack   = named(90)
	BrightRed     = named(91)
	BrightGreen   = named(92)
	BrightYellow  = named(93)
	BrightBlue    = named(94)
	BrightMagenta = named(95)
	BrightCyan    = named(96)
	BrightWhite   = named(97)
)

The sixteen named ANSI colours.

View Source
var ErrUnknownAttribute = errors.New("unknown attribute")

ErrUnknownAttribute reports that a text-attribute name could not be resolved.

View Source
var ErrUnknownColour = errors.New("unknown colour")

ErrUnknownColour reports that a colour name could not be resolved.

Functions

This section is empty.

Types

type Attribute

type Attribute uint

Attribute is a bitfield of text attributes. The zero value is no attributes, and values combine with bitwise OR.

const (
	Bold Attribute = 1 << iota
	Faint
	Italic
	Underline
	Blink
	Reverse
	Strike
)

func AttributeByName

func AttributeByName(name string) (Attribute, bool)

AttributeByName resolves a single named attribute ("bold", "italic"). The second result reports whether the name was recognised.

func (*Attribute) UnmarshalText

func (a *Attribute) UnmarshalText(b []byte) error

UnmarshalText resolves a single named attribute, returning ErrUnknownAttribute for an unrecognised name.

type Colour

type Colour struct {
	// contains filtered or unexported fields
}

Colour is a foreground or background colour. Its zero value is unset, meaning it contributes no styling and is overridable by Style.Merge.

A Colour is either one of the sixteen named ANSI colours (see the package preset variables) or a 24-bit value produced by RGB.

func ColourByName

func ColourByName(name string) (Colour, bool)

ColourByName resolves one of the sixteen named ANSI colours. The second result reports whether the name was recognised.

func RGB

func RGB(r, g, b uint8) Colour

RGB returns a 24-bit true-colour.

func (*Colour) UnmarshalText

func (c *Colour) UnmarshalText(b []byte) error

UnmarshalText resolves a named colour ("red", "brightred") or a true-colour in "rgb(r,g,b)" form with each component in the range 0-255. It returns ErrUnknownColour for any other input.

type Style

type Style struct {
	Foreground Colour
	Background Colour
	Attributes Attribute
}

Style is a complete set of terminal styling: foreground colour, background colour, and text attributes. Its zero value applies no styling and renders as an empty string.

func (Style) Merge

func (s Style) Merge(other Style) Style

Merge overlays other onto s and returns the result. A set colour in other replaces the corresponding colour in s; attributes combine with bitwise OR.

func (Style) String

func (s Style) String() string

String returns the SGR escape sequence for s, without a leading reset. The zero Style returns the empty string.

Jump to

Keyboard shortcuts

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