subsonic-tui/internal/tui/views/help.go
Sagi Dayan 99e8e299e4
Some checks failed
ci / check for spelling errors (pull_request) Failing after 22s
ci / Make sure build does not fail (pull_request) Successful in 2m52s
ci / code quality (lint/tests) (pull_request) Has been skipped
Added ci workflow + fixed linting issues
Signed-off-by: Sagi Dayan <sagidayan@gmail.com>
2024-12-18 17:29:16 +02:00

116 lines
1.9 KiB
Go

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
}