forked from wildeyedskies/stmp
-
Notifications
You must be signed in to change notification settings - Fork 6
/
widget_help.go
82 lines (62 loc) · 1.78 KB
/
widget_help.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2023 The STMPS Authors
// SPDX-License-Identifier: GPL-3.0-only
package main
import (
"strings"
"github.com/rivo/tview"
)
type HelpWidget struct {
Root *tview.Flex
helpBook *tview.Flex
leftColumn, rightColumn *tview.TextView
// visible reflects whether the modal is shown
visible bool
// external references
ui *Ui
}
func (ui *Ui) createHelpWidget() (m *HelpWidget) {
m = &HelpWidget{
ui: ui,
}
// two help columns side by side
m.leftColumn = tview.NewTextView().
SetTextAlign(tview.AlignLeft).
SetDynamicColors(true)
m.rightColumn = tview.NewTextView().
SetTextAlign(tview.AlignLeft).
SetDynamicColors(true)
m.helpBook = tview.NewFlex().
SetDirection(tview.FlexColumn)
m.Root = tview.NewFlex().
SetDirection(tview.FlexRow).
AddItem(m.helpBook, 0, 1, false)
m.Root.Box.SetBorder(true).SetTitle(" Help ")
return
}
func (h *HelpWidget) RenderHelp(context string) {
leftText := "[::b]Playback[::-]\n" + tview.Escape(strings.TrimSpace(helpPlayback))
h.leftColumn.SetText(leftText)
rightText := ""
switch context {
case PageBrowser:
rightText = "[::b]Browser[::-]\n" + tview.Escape(strings.TrimSpace(helpPageBrowser))
case PageQueue:
rightText = "[::b]Queue[::-]\n" + tview.Escape(strings.TrimSpace(helpPageQueue))
case PagePlaylists:
rightText = "[::b]Playlists[::-]\n" + tview.Escape(strings.TrimSpace(helpPagePlaylists))
case PageSearch:
rightText = "[::b]Search[::-]\n" + tview.Escape(strings.TrimSpace(helpSearchPage))
case PageLog:
fallthrough
default:
// no text
}
h.rightColumn.SetText(rightText)
h.helpBook.Clear()
if rightText != "" {
h.helpBook.AddItem(h.leftColumn, 38, 0, false).
AddItem(h.rightColumn, 0, 1, true) // gets focus for scrolling
} else {
h.helpBook.AddItem(h.leftColumn, 0, 1, false)
}
}