color

package
v0.0.0-...-fb30631 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package color handles ANSI colors and colorization.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Color

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

Color stores a color definition: RGB composition and kind.

func NewHexBGColor

func NewHexBGColor(value string) Color

NewHexBGColor parses background hex color. Invalid provided values return KindUnknown color kind.

func NewHexFGColor

func NewHexFGColor(value string) Color

NewHexFGColor parses foreground hex color. Invalid provided values return KindUnknown color kind.

func NewRGBBGColor

func NewRGBBGColor(r, g, b uint8) Color

NewRGBBGColor creates a new background color from its RGB components.

func NewRGBFGColor

func NewRGBFGColor(r, g, b uint8) Color

NewRGBFGColor creates a new foreground color from its RGB components.

func (Color) Equal

func (c Color) Equal(cc Color) bool

Equal checks whenever two colors are the same.

func (Color) RGB

func (c Color) RGB() (uint8, uint8, uint8)

RGB returns the color composites.

func (Color) String

func (c Color) String() string

String returns the hex representation of a color.

type Colorizer

type Colorizer interface {
	Colorize(style Style, format string, args ...interface{}) string
}

Colorizer defines how to colorize something with style.

func NewColorizer

func NewColorizer(shell string) (Colorizer, error)

NewColorizer returns a new colorizer based on the provided shell.

type Config

type Config struct {
	Foreground *string `yaml:"fg"`
	Background *string `yaml:"bg"`
}

Config stores color configuration.

func (*Config) SetDefaultColor

func (c *Config) SetDefaultColor(def Config)

SetDefaultColor sets default to unsetted values.

func (Config) ToStyle

func (c Config) ToStyle() Style

ToStyle creates a Style from Config.

type Kind

type Kind int

Kind defines where the color applies.

const (
	// KindUnknown is the zero value for ColorKind, which is an invalid value.
	KindUnknown Kind = iota
	// KindForeground applies the color to the foreground.
	KindForeground
	// KindBackground applies the color to the background.
	KindBackground
)

type NoopColorizer

type NoopColorizer struct{}

NoopColorizer implements Colorizer without doing anything.

func (NoopColorizer) Colorize

func (NoopColorizer) Colorize(style Style, format string, args ...interface{}) string

Colorize does nothing.

type Style

type Style [2]Color

Style stores a foreground and background color.

func NewStyle

func NewStyle(fg, bg Color) Style

NewStyle creates a new Style based on both foreground and background color. Color are applied to the style only if they have the right kind.

func (Style) ANSISprintf

func (s Style) ANSISprintf(format string, args ...interface{}) string

ANSISprintf works the same as fmt.Sprintf but surround output with the ansi escape sequences the Style + reset, to apply colors.

func (Style) Colors

func (s Style) Colors() (Color, Color)

Colors splits back a Style to its components: a foreground and a background color.

Jump to

Keyboard shortcuts

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