110 lines
1.7 KiB
Go
110 lines
1.7 KiB
Go
|
package views
|
||
|
|
||
|
import (
|
||
|
"github.com/gdamore/tcell/v2"
|
||
|
"github.com/rivo/tview"
|
||
|
)
|
||
|
|
||
|
var _ View = &help{}
|
||
|
|
||
|
type help struct {
|
||
|
view *tview.Flex
|
||
|
keyPressedFunc func()
|
||
|
}
|
||
|
|
||
|
type keyMap struct {
|
||
|
key string
|
||
|
description string
|
||
|
}
|
||
|
|
||
|
var keyMaps = []keyMap{
|
||
|
{
|
||
|
"Arrows", "Navigation",
|
||
|
},
|
||
|
{
|
||
|
"h, j, k, l", "Navigation",
|
||
|
},
|
||
|
{
|
||
|
"g", "Jump to top",
|
||
|
},
|
||
|
{
|
||
|
"G", "Jump to bottom",
|
||
|
},
|
||
|
{
|
||
|
"p", "Toggle Play/Pause",
|
||
|
},
|
||
|
{
|
||
|
"s", "Stop",
|
||
|
},
|
||
|
{
|
||
|
"n", "Play next song",
|
||
|
},
|
||
|
{
|
||
|
"N", "Play previous song",
|
||
|
},
|
||
|
{
|
||
|
"c", "Stop and clear queue",
|
||
|
},
|
||
|
{
|
||
|
"r", "Start song radio",
|
||
|
},
|
||
|
{
|
||
|
"/", "Search",
|
||
|
},
|
||
|
{
|
||
|
"q", "Quit",
|
||
|
},
|
||
|
}
|
||
|
|
||
|
func NewHelp() *help {
|
||
|
h := &help{}
|
||
|
view := tview.NewTable()
|
||
|
height := 16
|
||
|
width := 100
|
||
|
view.SetBorder(true)
|
||
|
view.SetTitle(" Keybindings ")
|
||
|
view.SetTitleAlign(tview.AlignCenter)
|
||
|
|
||
|
for i, km := range keyMaps {
|
||
|
odd := i%2 != 0
|
||
|
txtColor := tcell.ColorWhite
|
||
|
if odd {
|
||
|
txtColor = tcell.ColorYellow
|
||
|
}
|
||
|
keyCell := tview.NewTableCell(km.key).
|
||
|
SetExpansion(1).
|
||
|
SetAlign(tview.AlignCenter).
|
||
|
SetTextColor(txtColor)
|
||
|
descCell := tview.NewTableCell(km.description).
|
||
|
SetExpansion(1).
|
||
|
SetAlign(tview.AlignCenter).
|
||
|
SetTextColor(txtColor)
|
||
|
view.SetCell(i, 0, keyCell)
|
||
|
view.SetCell(i, 1, descCell)
|
||
|
}
|
||
|
|
||
|
wrapper := tview.NewFlex().
|
||
|
AddItem(nil, 0, 1, false).
|
||
|
AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
|
||
|
AddItem(nil, 0, 1, false).
|
||
|
AddItem(view, height, 1, true).
|
||
|
AddItem(nil, 0, 1, false), width, 1, true).
|
||
|
AddItem(nil, 0, 1, false)
|
||
|
|
||
|
h.view = wrapper
|
||
|
|
||
|
return h
|
||
|
}
|
||
|
|
||
|
func (h *help) GetView() tview.Primitive {
|
||
|
return h.view
|
||
|
}
|
||
|
|
||
|
func (h *help) Update() {
|
||
|
|
||
|
}
|
||
|
|
||
|
func (h *help) SetKeyPressedFunc(f func()) {
|
||
|
h.keyPressedFunc = f
|
||
|
}
|