summaryrefslogtreecommitdiff
path: root/internal/switcher
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2024-11-24 01:07:05 -0500
committerBenjamin Chausse <benjamin@chausse.xyz>2024-11-24 01:07:05 -0500
commitec84a4f1dca36a18c93b9f96e262cca34853c086 (patch)
treefbc4e9f13736c387df71683c8c2a69890337c4c7 /internal/switcher
parent7005459db8824695ded8aa755f6c7bb89e123fa0 (diff)
Implement clipboard
Diffstat (limited to 'internal/switcher')
-rw-r--r--internal/switcher/keys.go20
-rw-r--r--internal/switcher/switcher.go16
2 files changed, 33 insertions, 3 deletions
diff --git a/internal/switcher/keys.go b/internal/switcher/keys.go
index 94eb6fb..e019ba1 100644
--- a/internal/switcher/keys.go
+++ b/internal/switcher/keys.go
@@ -3,7 +3,7 @@ package switcher
import "github.com/charmbracelet/bubbles/key"
type keybinds struct {
- next, prev, quit key.Binding
+ next, prev, cpHex, cpRgb, cpHsl, cpCmyk, quit key.Binding
}
func newKeybinds() keybinds {
@@ -16,6 +16,22 @@ func newKeybinds() keybinds {
key.WithKeys("shift+tab"),
key.WithHelp("shift+tab", "previous picker"),
),
+ cpHex: key.NewBinding(
+ key.WithKeys("x"),
+ key.WithHelp("x", "yank/copy hex value"),
+ ),
+ cpRgb: key.NewBinding(
+ key.WithKeys("r"),
+ key.WithHelp("r", "yank/copy RGB value"),
+ ),
+ cpHsl: key.NewBinding(
+ key.WithKeys("s"),
+ key.WithHelp("s", "yank/copy HSL value"),
+ ),
+ cpCmyk: key.NewBinding(
+ key.WithKeys("c"),
+ key.WithHelp("c", "yank/copy CMYK value"),
+ ),
quit: key.NewBinding(
key.WithKeys("q", "ctrl+c"),
key.WithHelp("q", "quit"),
@@ -25,7 +41,7 @@ func newKeybinds() keybinds {
func Keys() []key.Binding {
k := newKeybinds()
- return []key.Binding{k.next, k.prev}
+ return []key.Binding{k.next, k.prev, k.cpHex, k.cpRgb, k.cpHsl, k.cpCmyk, k.quit}
}
func (m Model) AllKeys() []key.Binding {
diff --git a/internal/switcher/switcher.go b/internal/switcher/switcher.go
index 0680996..7ff7164 100644
--- a/internal/switcher/switcher.go
+++ b/internal/switcher/switcher.go
@@ -9,6 +9,7 @@ import (
"github.com/charmbracelet/bubbletea-app-template/internal/picker"
"github.com/charmbracelet/bubbletea-app-template/internal/preview"
"github.com/charmbracelet/bubbletea-app-template/internal/quit"
+ "github.com/charmbracelet/bubbletea-app-template/internal/util"
)
type Model struct {
@@ -74,9 +75,22 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
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
- // return m, tea.Quit
default:
// Update the picker
newActive, cmd := m.pickers[m.active].Update(msg)