subsonic-tui/internal/tui/views/help.go
Sagi Dayan 09df967395
All checks were successful
ci / check for spelling errors (pull_request) Successful in 22s
ci / code quality (lint/tests) (pull_request) Successful in 2m56s
ci / Make sure build does not fail (pull_request) Successful in 3m3s
ci / notify-fail (pull_request) Has been skipped
ci / check for spelling errors (push) Successful in 21s
ci / code quality (lint/tests) (push) Successful in 2m32s
ci / Make sure build does not fail (push) Successful in 2m43s
ci / notify-fail (push) Has been skipped
NO-ISSUE: help page copy change
Signed-off-by: Sagi Dayan <sagidayan@gmail.com>
2024-12-18 19:50:48 +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 with SHIFT for swtching 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
}