Skip to content

Package theme ​

Go module github.com/bide-ai/bide; all packages.

github.com/bide-ai/bide/theme · pkg.go.dev · Stability: experimental

Package theme is the theme layer of bide's visual pages: a theme is a small JSON file of typed values (colours, enums, numbers in ranges), never CSS.

Constants

  • const MaxSize = 16 << 10: MaxSize is the largest theme file Parse reads.
  • const Version = 1: Version is the only value of the bide_theme key.

Functions

  • func Load(path string) (*Theme, Report, error): Load reads and checks a custom theme file: Parse on the file's bytes.
  • func Parse(data []byte) (*Theme, Report, error): Parse reads a custom theme: strict JSON of at most MaxSize bytes that names a shipped base and overrides some of its values.

type CheckError ​

go
type CheckError struct{ Report Report }

CheckError is the error of a theme that failed its checks; Report holds every measure.

Methods

  • func (e *CheckError) Error() string: Error lists every failed measure, one to a line.

type Measure ​

go
type Measure struct {
	Check     string
	Subject   string
	Value     float64
	Threshold float64
	Pass      bool
	Severity  Severity
}

Measure is one pair a check looked at: what was measured, the threshold, and whether it holds.

Methods

  • func (m Measure) String() string: String is the measure as a line says it: the value and the threshold it needs, as bide theme check prints it after the check and the subject.

type Report ​

go
type Report struct {
	Theme    string
	Measures []Measure
}

Report holds every measure of a theme.

Constructors and functions

  • func Check(t *Theme) Report: Check measures a resolved theme against every check (C1 to C6 and C8; C7, the ranges, is enforced while parsing) and returns all measures, passing and failing.

Methods

  • func (r Report) Err() error: Err returns a *CheckError if any measure failed as an error, and nil otherwise.
  • func (r Report) Failures(s Severity) []Measure: Failures returns the failed measures of the given severity.

type Severity ​

go
type Severity int

Severity is how a failed measure counts: an Error refuses the theme, a Warning is reported.

Constants

  • const Error Severity: Error refuses the theme.
  • const Warning Severity: Warning is reported and does not refuse.

Methods

  • func (s Severity) String() string: String is "error" or "warning".

type Theme ​

go
type Theme struct {
	// contains filtered or unexported fields
}

Theme is a parsed, resolved and checked theme: every token has a value.

Constructors and functions

  • func Lookup(name string) (*Theme, bool): Lookup returns the shipped theme called name.
  • func Shipped() []*Theme: Shipped returns the shipped themes (light, dark, high-contrast), in that order.

Methods

  • func (t *Theme) Dark() bool: Dark reports whether the theme's ground is dark: the relative luminance of its background is below 0.18.
  • func (t *Theme) Name() string: Name is the theme's name, the value of data-theme that selects it.
  • func (t *Theme) Report() Report: Report returns a copy of the theme's check report, which for a theme that parsed holds only warnings.
  • func (t *Theme) Shipped() bool: Shipped reports whether the theme is one of bide's own.

Apache-2.0 licensed.