config

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const PresetKey = "preset"

PresetKey is the Viper config key to use in viper.Viper.Set.

Variables

View Source
var (
	PresetDefault = PresetDark

	// AllPresets is used in parsing and places like the
	// internal/cmd/configschema package to show all available options.
	AllPresets = []Preset{

		PresetNone,

		PresetDark,
		PresetLight,

		PresetProtDark,
		PresetProtLight,
		PresetDeutDark,
		PresetDeutLight,
		PresetTritDark,
		PresetTritLight,

		PresetPre030Dark,
		PresetPre030Light,

		PresetPre0021Dark,
		PresetPre0021Light,
	}
)

Functions

func ApplyThemePreset

func ApplyThemePreset(v *viper.Viper) error

func LoadViper

func LoadViper() (*viper.Viper, error)

func NewViper

func NewViper() *viper.Viper

Types

type Color

type Color struct {
	Source string
	Code   string
}

func MustParseColor

func MustParseColor(s string) Color

func ParseColor

func ParseColor(s string) (Color, error)

func (Color) MarshalText

func (c Color) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler.

func (Color) Render

func (c Color) Render(s string) string

Render returns the string wrapped in color codes from this color.

func (*Color) Set

func (c *Color) Set(text string) error

Set implements flag.Value.

func (Color) Sprint

func (c Color) Sprint(args ...any) string

Sprint returns the stringified args (concatenated right after each other) wrapped in color codes from this color.

func (Color) Sprintf

func (c Color) Sprintf(format string, args ...any) string

Sprintf returns the formatted string wrapped in color codes from this color.

func (Color) Sprintln

func (c Color) Sprintln(args ...any) string

Sprintln returns the stringified args (concatenated right after each other) wrapped in color codes from this color, as well as a trailing newline. The newline character is added after the color reset.

func (Color) String

func (c Color) String() string

String returns the display name of this color.

func (*Color) UnmarshalText

func (c *Color) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type ColorSlice

type ColorSlice []Color

func MustParseColorSlice

func MustParseColorSlice(s string) ColorSlice

func ParseColorSlice

func ParseColorSlice(s string) (ColorSlice, error)

func (ColorSlice) MarshalText

func (s ColorSlice) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler.

func (ColorSlice) String

func (s ColorSlice) String() string

func (*ColorSlice) UnmarshalText

func (s *ColorSlice) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Config

type Config struct {
	Debug             bool          `jsonschema:"-"`
	Kubectl           string        `jsonschema:"default=kubectl,example=kubectl1.19,example=oc"` // Which kubectl executable to use
	ObjFreshThreshold time.Duration // Ages below this uses theme.data.durationfresh coloring
	Preset            Preset        // Color theme preset
	Theme             Theme
}

func Unmarshal

func Unmarshal(v *viper.Viper) (*Config, error)

type Preset

type Preset string
const (

	// "Zero value", i.e empty theme selected
	PresetNone Preset = ""

	// Default themes
	PresetDark  Preset = "dark"
	PresetLight Preset = "light"

	// Color blind focused themes
	PresetProtDark  Preset = "protanopia-dark"
	PresetProtLight Preset = "protanopia-light"
	PresetDeutDark  Preset = "deuteranopia-dark"
	PresetDeutLight Preset = "deuteranopia-light"
	PresetTritDark  Preset = "tritanopia-dark"
	PresetTritLight Preset = "tritanopia-light"

	// Pre-v0.3.0
	PresetPre030Dark  Preset = "pre-0.3.0-dark"
	PresetPre030Light Preset = "pre-0.3.0-light"

	// Pre-v0.0.21
	PresetPre0021Dark  Preset = "pre-0.0.21-dark"
	PresetPre0021Light Preset = "pre-0.0.21-light"
)

func ParsePreset

func ParsePreset(s string) (Preset, error)

func (Preset) MarshalText

func (p Preset) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler.

func (Preset) String

func (p Preset) String() string

func (*Preset) UnmarshalText

func (p *Preset) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Theme

type Theme struct {
	// Base colors must be first so they're applied first
	Base ThemeBase // base colors for themes

	Default Color // default when no specific mapping is found for the command

	Data   ThemeData   // colors for representing data
	Status ThemeStatus // generic status coloring (e.g "Ready", "Terminating")
	Table  ThemeTable  // used in table output, e.g "kubectl get" and parts of "kubectl describe"
	Stderr ThemeStderr // used in kubectl's stderr output

	Describe ThemeDescribe // used in "kubectl describe"
	Apply    ThemeApply    // used in "kubectl apply"
	Explain  ThemeExplain  // used in "kubectl explain"
	Options  ThemeOptions  // used in "kubectl options"
	Version  ThemeVersion  // used in "kubectl version"
}

Theme is the root theme config.

func NewBaseTheme

func NewBaseTheme(preset Preset) *Theme

NewBaseTheme returns the base color schema depending on the dark/light setting

type ThemeApply

type ThemeApply struct {
	Created    Color `defaultFrom:"theme.base.success"`   // used on "deployment.apps/foo created"
	Configured Color `defaultFrom:"theme.base.warning"`   // used on "deployment.apps/bar configured"
	Unchanged  Color `defaultFrom:"theme.base.primary"`   // used on "deployment.apps/quux unchanged"
	DryRun     Color `defaultFrom:"theme.base.secondary"` // used on "deployment.apps/quux created (dry-run)"
	Fallback   Color `defaultFrom:"theme.base.success"`   // used when "kubectl apply" outputs unknown format
}

ThemeApply holds colors for the "kubectl apply" output.

type ThemeBase

type ThemeBase struct {
	Info      Color // general color for when things are informational
	Primary   Color // general color for when things are focus
	Secondary Color // general color for when things are secondary focus
	Success   Color // general color for when things are good
	Warning   Color // general color for when things are wrong
	Danger    Color // general color for when things are bad
	Muted     Color // general color for when things are less relevant

	Key ColorSlice `defaultFromMany:"theme.base.secondary"` // general color for keys
}

ThemeBase contains base colors that other theme fields can default to, just to make overriding themes easier.

These fields should never be referenced in the printers. Instead, they should use the more specific fields, such as [ThemeApply.Created]

type ThemeData

type ThemeData struct {
	Key    ColorSlice `defaultFrom:"theme.base.key"`     // used for the key
	String Color      `defaultFrom:"theme.base.info"`    // used when value is a string
	True   Color      `defaultFrom:"theme.base.success"` // used when value is true
	False  Color      `defaultFrom:"theme.base.danger"`  // used when value is false
	Number Color      `defaultFrom:"theme.base.primary"` // used when the value is a number
	Null   Color      `defaultFrom:"theme.base.muted"`   // used when the value is null, nil, or none

	Quantity      Color `defaultFrom:"theme.data.number"`  // used when the value is a quantity, e.g "100m" or "5Gi"
	Duration      Color ``                                 // used when the value is a duration, e.g "12m" or "1d12h"
	DurationFresh Color `defaultFrom:"theme.base.success"` // color used when the time value is under a certain delay

	Ratio ThemeDataRatio
}

ThemeData holds colors for when representing parsed data. Such as in YAML, JSON, and even some "kubectl describe" values

type ThemeDataRatio

type ThemeDataRatio struct {
	Zero    Color `defaultFrom:"theme.base.muted"`   // used for "0/0"
	Equal   Color ``                                 // used for "n/n", e.g "1/1"
	Unequal Color `defaultFrom:"theme.base.warning"` // used for "n/m", e.g "0/1"
}

type ThemeDescribe

type ThemeDescribe struct {
	Key ColorSlice `defaultFrom:"theme.base.key"` // used on keys. The multiple colors are cycled based on indentation.
}

ThemeApply holds colors for the "kubectl apply" output.

type ThemeExplain

type ThemeExplain struct {
	Key      ColorSlice `defaultFrom:"theme.base.key"`    // used on keys. The multiple colors are cycled based on indentation.
	Required Color      `defaultFrom:"theme.base.danger"` // used on the trailing "-required-" string
}

ThemeExplain holds colors for the "kubectl explain" output.

type ThemeOptions

type ThemeOptions struct {
	Flag Color `defaultFrom:"theme.base.secondary"` // e.g "--kubeconfig"
}

ThemeOptions holds colors for the "kubectl options" output.

type ThemeStatus

type ThemeStatus struct {
	Success Color `defaultFrom:"theme.base.success"` // used in status keywords, e.g "Running", "Ready"
	Warning Color `defaultFrom:"theme.base.warning"` // used in status keywords, e.g "Terminating"
	Error   Color `defaultFrom:"theme.base.danger"`  // used in status keywords, e.g "Failed", "Unhealthy"
}

ThemeStatus holds colors for status texts, used in for example the "kubectl get" status column

type ThemeStderr

type ThemeStderr struct {
	Default Color `defaultFrom:"theme.base.info"`   // default when no specific mapping is found for the output line
	Error   Color `defaultFrom:"theme.base.danger"` // e.g when text contains "error"
}

ThemeStderr holds generic colors for kubectl's stderr output.

type ThemeTable

type ThemeTable struct {
	Header  Color      `defaultFrom:"theme.base.info"`                          // used on table headers
	Columns ColorSlice `defaultFromMany:"theme.base.info,theme.base.secondary"` // used on table columns when no other coloring applies such as status or duration coloring. The multiple colors are cycled based on column ID, from left to right.
}

ThemeTable holds colors for table output

type ThemeVersion

type ThemeVersion struct {
	Key ColorSlice `defaultFrom:"theme.base.key"` // used on the key
}

ThemeVersion holds colors for the "kubectl version" output.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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