palette

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const CountSpecialColors int = 1

Number of colors with which we occupy the initial bits of the first mask. The color SpecialColorTransparent is zero, so it is not counted.

View Source
const SpecialColorRemover uint64 = 1 << 0

@color remover works so: C + remover = transparent.

View Source
const SpecialColorTransparent uint64 = 0

All functions without any colors are transparent: C + transparent = C.

Variables

View Source
var MaxColorsInMask = 64

MaxColorsInMask stores the maximum number of colors in the mask. Used in tests. It cannot be more than 64.

Functions

This section is empty.

Types

type Color

type Color struct {
	// Val is the mask of the current color.
	// A one bit determines the number of the current color.
	Val uint64

	// Index is the ordinal number of the mask,
	// in which this color is indicated by bit one.
	Index int
}

Color structure describes a color. The color is represented by two components. The first component is a mask, which contains single one bit that defines the color number. The second component is the index of the mask in which this one bit is.

The length of the mask in any color cannot be more than MaxColorsInMask.

So, for example, if the number of colors in the mask can be a maximum of 3, then if you need to keep the fourth color, then for this you need to use the following mask, so the mask Index will be 1, and the Val in the mask will be

1 << 4 % MaxColorsInMask,

then there is 0b01.

func NewColor

func NewColor(val uint64, index int) Color

type ColorContainer

type ColorContainer struct {
	Colors []Color
}

ColorContainer is class containing colors after @color parsing above each function (order is important).

func (*ColorContainer) Add

func (c *ColorContainer) Add(color Color)

func (*ColorContainer) Contains

func (c *ColorContainer) Contains(needColor Color) bool

func (*ColorContainer) Empty

func (c *ColorContainer) Empty() bool

func (*ColorContainer) String

func (c *ColorContainer) String(palette *Palette, withHighlights ColorMasks) string

type ColorMask

type ColorMask Color

type ColorMasks

type ColorMasks []ColorMask

func NewColorMasks

func NewColorMasks(colors []Color) ColorMasks

func NewEmptyColorMasks

func NewEmptyColorMasks() ColorMasks

func (ColorMasks) Add

func (masks ColorMasks) Add(color Color) ColorMasks

func (ColorMasks) Contains

func (masks ColorMasks) Contains(color Color) bool

type Config

type Config struct {
	Palette [][]map[string]string `json:"palette"`
}

Config is a structure for storing a palette of colors as a config.

type Palette

type Palette struct {
	Rulesets          []Ruleset
	ColorNamesMapping map[string]Color
}

Palette is a group of rulesets. All colors are stored as Color struct, not as strings.

func NewPalette

func NewPalette() *Palette

NewPalette creates a new Palette.

func OpenPaletteFromFile

func OpenPaletteFromFile(path string) (*Palette, error)

OpenPaletteFromFile returns a ready-use palette from a file.

func ReadPaletteFileYAML

func ReadPaletteFileYAML(data []byte) (*Palette, error)

The ReadPaletteFileYAML function interprets the passed text as a config in YAML format and returns a ready-made palette.

func (*Palette) AddRuleset

func (p *Palette) AddRuleset(ruleset Ruleset)

func (*Palette) ColorExists

func (p *Palette) ColorExists(colorName string) bool

func (*Palette) GetColorByName

func (p *Palette) GetColorByName(colorName string) Color

func (*Palette) GetNameByColor

func (p *Palette) GetNameByColor(needColor Color) string

func (*Palette) RegisterColorName

func (p *Palette) RegisterColorName(colorName string) Color

type Rule

type Rule struct {
	Colors []Color
	Masks  ColorMasks
	Error  string
}

Rule are representation of human-written "api has-curl" => "error text" or "api allow-curl has-curl" => 1 All colors are pre-converted to numeric while reading strings.

func NewRule

func NewRule(colors []Color, error string) *Rule

NewRule creates a new Rule.

func (*Rule) ContainsIn

func (r *Rule) ContainsIn(colorMasks ColorMasks) bool

ContainsIn checks if the rule's colors are contained in the passed mask.

func (*Rule) IsError

func (r *Rule) IsError() bool

IsError checks if the rule describes an error.

func (*Rule) String

func (r *Rule) String(palette *Palette) string

type Ruleset

type Ruleset []*Rule

Ruleset is a group of rules, order is important. Typically, it looks like one error rule and some "exceptions" — more specific color chains with no error

func NewRuleset

func NewRuleset(rules ...*Rule) Ruleset

NewRuleset creates a new Ruleset.

Jump to

Keyboard shortcuts

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