Sagi Dayan
92e3c4ea7d
All checks were successful
ci / check for spelling errors (pull_request) Successful in 21s
ci / code quality (lint/tests) (pull_request) Successful in 2m29s
ci / Make sure build does not fail (pull_request) Successful in 2m25s
ci / notify-fail (pull_request) Has been skipped
ci / check for spelling errors (push) Successful in 22s
ci / code quality (lint/tests) (push) Successful in 1m53s
ci / Make sure build does not fail (push) Successful in 2m55s
ci / notify-fail (push) Has been skipped
Signed-off-by: Sagi Dayan <sagidayan@gmail.com>
116 lines
1.9 KiB
Go
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
|
|
}
|