solarized-emacs

a fork of Bozhidar Batsov's solarized-emacs
git clone https://git.trogloxene.org/solarized-emacs.git
Log | Files | Refs | README

commit 220e1a7963c059fc3fde5f3cc44f079d07178d93
parent 894ac002b3ea990dd01dfe6f48fadbfa861c6210
Author: Thomas Frössman <thomasf@jossystem.se>
Date:   Wed, 20 Nov 2019 11:38:12 +0100

colorlab: individual accent pair generator per output palette

Diffstat:
Mcolorlab/main.go | 85++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
Mcolorlab/pkg/colorlab/colrofinder.go | 38+++++++++++++++++++++++++++++++++-----
2 files changed, 87 insertions(+), 36 deletions(-)

diff --git a/colorlab/main.go b/colorlab/main.go @@ -49,52 +49,72 @@ func main() { var palettes = []Palette{ { - Name: "solarized-dark", - Solarized: solarized, + Name: "solarized-dark", + Solarized: solarized, + Accent1Pair: default1BgFg, + Accent2Pair: default2BgFg, }, { - Name: "solarized-light", - Solarized: solarized, - Inverse: true, + Name: "solarized-light", + Solarized: solarized, + Inverse: true, + Accent1Pair: default1BgFg, + Accent2Pair: default2BgFg, }, { - Name: "solarized-dark-high-contrast", - Solarized: solarizedDarkHighContrast, + Name: "solarized-dark-high-contrast", + Solarized: solarizedDarkHighContrast, + Accent1Pair: default1BgFg, + Accent2Pair: default2BgFg, }, { - Name: "solarized-light-high-contrast", - Solarized: solarizedLightHighContrast, - Inverse: true, + Name: "solarized-light-high-contrast", + Solarized: solarizedLightHighContrast, + Inverse: true, + Accent1Pair: default1BgFg, + Accent2Pair: default2BgFg, }, { - Name: "gruvbox-dark", - Solarized: gruvboxDark, + Name: "gruvbox-dark", + Solarized: gruvboxDark, + Accent1Pair: default1BgFg, + Accent2Pair: default2BgFg, }, { - Name: "gruvbox-light", - Solarized: gruvboxLight, - Inverse: true, + Name: "gruvbox-light", + Solarized: gruvboxLight, + Inverse: true, + Accent1Pair: default1BgFg, + Accent2Pair: default2BgFg, }, { - Name: "zenburn", - Solarized: zenburn, + Name: "zenburn", + Solarized: zenburn, + Accent1Pair: default1BgFg, + Accent2Pair: default2BgFg, }, { - Name: "monokai", - Solarized: monokai, + Name: "monokai", + Solarized: monokai, + Accent1Pair: default1BgFg, + Accent2Pair: default2BgFg, }, } var ( default1BgFg = AccentPairGenerator{ - BlendBackgroundAmout: 0.85, - BlendForegroundAmout: 0.3, - Gamma: 0.01, + BlendBackgroundAmout: 0.85, + BlendForegroundAmout: 0.3, + Gamma: 0.01, + ForegroundBlendFinder: colorlab.ExtremeColorFgFinder, + BackgroundBlendFinder: colorlab.ExtremeColorBgFinder, } default2BgFg = AccentPairGenerator{ - BlendBackgroundAmout: 0.6, - BlendForegroundAmout: 0.45, - Gamma: 0.04, + BlendBackgroundAmout: 0.6, + BlendForegroundAmout: 0.45, + Gamma: 0.04, + ForegroundBlendFinder: colorlab.ExtremeColorFgFinder, + BackgroundBlendFinder: colorlab.ExtremeColorBgFinder, } ) @@ -107,8 +127,8 @@ func (p Palette) Generate() colorlab.NamedColors { corrected = pal.Inverse() } - bgs, fgs := default1BgFg.Generate(corrected) - hbgs, hfgs := default2BgFg.Generate(corrected) + bgs, fgs := p.Accent1Pair.Generate(corrected) + hbgs, hfgs := p.Accent2Pair.Generate(corrected) cols := colorlab.Merge( pal.NamedColors(), fgs.NamedColors().WithSuffix("-1fg"), @@ -140,8 +160,8 @@ type AccentPairGenerator struct { BlendForegroundAmout float64 Gamma float64 - // BackgroundBlendColor ColorFinder - // ForegroundBlendColor ColorFinder + BackgroundBlendFinder colorlab.ColorFinder + ForegroundBlendFinder colorlab.ColorFinder } func (g *AccentPairGenerator) Generate(sol colorlab.Solarized) (backgrounds, foregrounds colorlab.Accents) { @@ -159,8 +179,8 @@ func (g *AccentPairGenerator) Generate(sol colorlab.Solarized) (backgrounds, for fmt.Println(" ") } - blendBgColor := colorlab.DefaultBlendColorBgFinder(sol) - blendFgColor := colorlab.DefaultBlendColorFgFinder(sol) + blendBgColor := g.BackgroundBlendFinder(sol) + blendFgColor := g.ForegroundBlendFinder(sol) bg := v.BlendLab(blendBgColor, g.BlendBackgroundAmout) fg := v.BlendLab(blendFgColor, g.BlendForegroundAmout) @@ -392,6 +412,9 @@ type Palette struct { Name string Inverse bool Solarized colorlab.Solarized + + Accent1Pair AccentPairGenerator + Accent2Pair AccentPairGenerator } func rewriteTheme(nc colorlab.NamedColors, paletteName string) { diff --git a/colorlab/pkg/colorlab/colrofinder.go b/colorlab/pkg/colorlab/colrofinder.go @@ -1,20 +1,48 @@ package colorlab -import "github.com/lucasb-eyer/go-colorful" +import ( + "log" + + "github.com/lucasb-eyer/go-colorful" +) // Find a specific color in a Solarized based on some preconditon type ColorFinder func(Solarized) colorful.Color -// DefaultBlendColorFgFinder finds the darkest base tone for light on dark or the lightest color for dark on light. -func DefaultBlendColorFgFinder(sol Solarized) colorful.Color { +// NamedColorFinder extracts a named color from a palette +func NamedColorFinder(name string) ColorFinder { + return func(sol Solarized) colorful.Color { + colors := sol.NamedColors() + c, ok := colors[name] + if !ok { + log.Fatalf("color %s not in list: %v", name, colors) + } + return c.Color() + } +} + +// BgFinder returns base03 from the input Solarized +func BgFinder(sol Solarized) colorful.Color { + return NamedColorFinder("base03")(sol) + +} + +// FgFinder finds base0 from the input Solarized +func FgFinder(sol Solarized) colorful.Color { + return NamedColorFinder("base0")(sol) + +} + +// ExtremeColorFgFinder finds the darkest base tone for light on dark or the lightest color for dark on light. +func ExtremeColorFgFinder(sol Solarized) colorful.Color { if sol.IsDarkOnBright() { return sol.Base.NamedColors().ColorList().ByLightnessDesc()[0] } return sol.Base.NamedColors().ColorList().ByLightness()[0] } -// DefaultBlendColorFgFinder finds the lightest base tone for light on dark or the darkest color for dark on light. -func DefaultBlendColorBgFinder(sol Solarized) colorful.Color { +// ExtremeColorFgFinder finds the lightest base tone for light on dark or the darkest color for dark on light. +func ExtremeColorBgFinder(sol Solarized) colorful.Color { if sol.IsDarkOnBright() { return sol.Base.NamedColors().ColorList().ByLightness()[0] }