palette

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Color

type Color = uint64
const SpecialColorRemover Color = 1 << 63

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

const SpecialColorTransparent Color = 0

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

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 ColorMask) string

type ColorMask

type ColorMask = uint64

type Config

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

type Palette

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

Palette is a group of rulesets. All colors are stored as numbers, not as strings:

They are numbers 1 << n, as we want to use bitmasks
to quickly test whether to check a rule for callstack.

func NewPalette

func NewPalette() *Palette

func OpenPaletteFromFile

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

OpenPaletteFromFile returns a ready-use palette from a file.

func ReadPaletteFileJSON

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

func ReadPaletteFileYAML

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

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
	Mask   ColorMask
	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

func (*Rule) ContainsIn

func (r *Rule) ContainsIn(colorMask ColorMask) bool

func (*Rule) IsError

func (r *Rule) IsError() bool

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

Jump to

Keyboard shortcuts

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