subsonic-tui/internal/tui/views/help.go

114 lines
1.9 KiB
Go
Raw Normal View History

package views
import (
"git.dayanhub.com/sagi/subsonic-tui/internal/config"
"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. Use [shift] for moving panes",
},
{
"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()
view.SetBackgroundColor(config.ColorBackground)
height := 16
width := 100
view.SetBorder(true)
view.SetTitle(" Keybindings ")
view.SetTitleAlign(tview.AlignCenter)
for i, km := range keyMaps {
odd := i%2 != 0
txtColor := config.ColorText
if odd {
txtColor = config.ColorTextAccent
}
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)
}
innerFlex := tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(EmptyBox, 0, 1, false).
AddItem(view, height, 1, true).
AddItem(EmptyBox, 0, 1, false)
innerFlex.SetBackgroundColor(config.ColorBackground)
wrapper := tview.NewFlex().
AddItem(EmptyBox, 0, 1, false).
AddItem(innerFlex, width, 1, true).
AddItem(EmptyBox, 0, 1, false)
wrapper.SetBackgroundColor((config.ColorBackground))
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
}