summaryrefslogtreecommitdiff
path: root/internal/slider/keys.go
blob: 026ea1bcd4287a8e61afe0b383e3851a9410838b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package slider

import "github.com/charmbracelet/bubbles/key"

type keybinds struct {
	incRegular key.Binding
	decRegular key.Binding
	incPrecise key.Binding
	decPrecise key.Binding
}

func newKeybinds() keybinds {
	return keybinds{
		incRegular: key.NewBinding(
			key.WithKeys("right", "l"),
			key.WithHelp("l", "inc. (coarse)"),
		),
		decRegular: key.NewBinding(
			key.WithKeys("left", "h"),
			key.WithHelp("h", "dec. (coarse)"),
		),
		incPrecise: key.NewBinding(
			key.WithKeys("shift+right", "L"),
			key.WithHelp("L", "inc. (fine)"),
		),
		decPrecise: key.NewBinding(
			key.WithKeys("shift+left", "H"),
			key.WithHelp("H", "dec. (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 [][]key.Binding{Keys()}
}