From 8b4d17786425b63ec45f6df189eab1ea7dcbf6a7 Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Sun, 24 Nov 2024 04:01:37 -0500 Subject: Freaking hsl doesn't reset to cyan everytime --- internal/colors/hsl.go | 4 ++++ internal/picker/picker.go | 5 +++++ internal/switcher/switcher.go | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/internal/colors/hsl.go b/internal/colors/hsl.go index 51a1785..5a6a66c 100644 --- a/internal/colors/hsl.go +++ b/internal/colors/hsl.go @@ -92,6 +92,10 @@ func (h HSL) FromPrecise(p PreciseColor) ColorSpace { hue = (r-g)/delta + 4 } hue /= 6 + hue = math.Mod(hue, 1) + if hue < 0 { + hue += 1 + } } return HSL{ diff --git a/internal/picker/picker.go b/internal/picker/picker.go index 13b04a5..14ada59 100644 --- a/internal/picker/picker.go +++ b/internal/picker/picker.go @@ -91,6 +91,11 @@ func (m Model) SetColor(c colors.ColorSpace) { m.sliders[1].Set(cmyk.M) m.sliders[2].Set(cmyk.Y) m.sliders[3].Set(cmyk.K) + case "HSL": + hsl := colors.HSL{}.FromPrecise(p).(colors.HSL) + m.sliders[0].Set(hsl.H) + m.sliders[1].Set(hsl.S) + m.sliders[2].Set(hsl.L) } } diff --git a/internal/switcher/switcher.go b/internal/switcher/switcher.go index b534e54..c470557 100644 --- a/internal/switcher/switcher.go +++ b/internal/switcher/switcher.go @@ -73,26 +73,33 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cs := m.pickers[m.active].GetColor() m.Next() m.pickers[m.active].SetColor(cs) + case key.Matches(msg, keys.prev): cs := m.pickers[m.active].GetColor() m.Prev() m.pickers[m.active].SetColor(cs) + case key.Matches(msg, keys.cpHex): util.Copy(colors.Hex(m.pickers[m.active].GetColor())) + case key.Matches(msg, keys.cpRgb): pc := m.pickers[m.active].GetColor().ToPrecise() rgb := colors.RGB{}.FromPrecise(pc).(colors.RGB) util.Copy(rgb.String()) + case key.Matches(msg, keys.cpHsl): pc := m.pickers[m.active].GetColor().ToPrecise() hsl := colors.HSL{}.FromPrecise(pc).(colors.HSL) util.Copy(hsl.String()) + case key.Matches(msg, keys.cpCmyk): pc := m.pickers[m.active].GetColor().ToPrecise() cmyk := colors.CMYK{}.FromPrecise(pc).(colors.CMYK) util.Copy(cmyk.String()) + case key.Matches(msg, keys.quit): return quit.Model{}, tea.Quit + default: // Update the picker newActive, cmd := m.pickers[m.active].Update(msg) -- cgit v1.2.3