summaryrefslogtreecommitdiff
path: root/internal/slider/keys.go
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2024-11-23 18:12:03 -0500
committerBenjamin Chausse <benjamin@chausse.xyz>2024-11-23 18:12:03 -0500
commit89094fecf4cb1c018f15c976641cd18c255eac28 (patch)
tree9f6e32c38013bc526399ab324891e0b3269e50dc /internal/slider/keys.go
Semi-working POC
Diffstat (limited to 'internal/slider/keys.go')
-rw-r--r--internal/slider/keys.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/internal/slider/keys.go b/internal/slider/keys.go
new file mode 100644
index 0000000..9f96903
--- /dev/null
+++ b/internal/slider/keys.go
@@ -0,0 +1,52 @@
+package slider
+
+import "github.com/charmbracelet/bubbles/key"
+
+type keybinds struct {
+ incRegular key.Binding
+ decRegular key.Binding
+ incPrecise key.Binding
+ decPrecise key.Binding
+ // quitApp key.Binding
+}
+
+func newKeybinds() keybinds {
+ return keybinds{
+ incRegular: key.NewBinding(
+ key.WithKeys("right", "l"),
+ key.WithHelp("l", "Increase (coarse)"),
+ ),
+ decRegular: key.NewBinding(
+ key.WithKeys("left", "h"),
+ key.WithHelp("h", "Decrease (coarse)"),
+ ),
+ incPrecise: key.NewBinding(
+ key.WithKeys("shift+right", "L"),
+ key.WithHelp("L", "Increase (fine)"),
+ ),
+ decPrecise: key.NewBinding(
+ key.WithKeys("shift+left", "H"),
+ key.WithHelp("H", "Decrease (fine)"),
+ ),
+ }
+}
+
+// Join all keybindings into a single slice
+// a parent can use to know what Keys
+// it's children have.
+func Keys() []key.Binding {
+ k := newKeybinds()
+ return []key.Binding{
+ k.incRegular,
+ k.decRegular,
+ k.incPrecise,
+ k.decPrecise,
+ }
+}
+
+// AllKeys returns key.Bindings for the Model
+// and all of its active children. The parent
+// can use this to generate help text.
+func (m Model) AllKeys() []key.Binding {
+ return Keys()
+}