63 lines
1 KiB
Go
63 lines
1 KiB
Go
|
package rank
|
||
|
|
||
|
import (
|
||
|
"github.com/charmbracelet/bubbles/key"
|
||
|
"github.com/remogatto/sugarfoam/components/group"
|
||
|
"github.com/remogatto/sugarfoam/components/table"
|
||
|
"github.com/remogatto/sugarfoam/components/viewport"
|
||
|
)
|
||
|
|
||
|
type keyBindings struct {
|
||
|
group *group.Model
|
||
|
|
||
|
quit, enter key.Binding
|
||
|
}
|
||
|
|
||
|
func (k *keyBindings) ShortHelp() []key.Binding {
|
||
|
keys := make([]key.Binding, 0)
|
||
|
|
||
|
current := k.group.Current()
|
||
|
|
||
|
switch item := current.(type) {
|
||
|
case *table.Model:
|
||
|
keys = append(
|
||
|
keys,
|
||
|
item.KeyMap.LineUp,
|
||
|
item.KeyMap.LineDown,
|
||
|
)
|
||
|
|
||
|
case *viewport.Model:
|
||
|
keys = append(
|
||
|
keys,
|
||
|
item.KeyMap.Up,
|
||
|
item.KeyMap.Down,
|
||
|
)
|
||
|
}
|
||
|
|
||
|
keys = append(
|
||
|
keys,
|
||
|
k.group.KeyMap.FocusNext,
|
||
|
k.group.KeyMap.FocusPrev,
|
||
|
k.quit,
|
||
|
)
|
||
|
|
||
|
return keys
|
||
|
}
|
||
|
|
||
|
func (k keyBindings) FullHelp() [][]key.Binding {
|
||
|
return [][]key.Binding{
|
||
|
{
|
||
|
k.quit,
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func newBindings(g *group.Model) *keyBindings {
|
||
|
return &keyBindings{
|
||
|
group: g,
|
||
|
quit: key.NewBinding(
|
||
|
key.WithKeys("esc"), key.WithHelp("esc", "quit app"),
|
||
|
),
|
||
|
}
|
||
|
}
|