-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathhelp_page.go
79 lines (72 loc) · 1.54 KB
/
help_page.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
package jiraui
import (
ui "gopkg.in/gizak/termui.v2"
)
type HelpPage struct {
BaseListPage
CommandBarFragment
StatusBarFragment
}
func (p *HelpPage) Search() {
s := p.ActiveSearch
n := len(p.cachedResults)
if s.command == "" {
return
}
increment := 1
if s.directionUp {
increment = -1
}
// we use modulo here so we can loop through every line.
// adding 'n' means we never have '-1 % n'.
startLine := (p.uiList.Cursor + n + increment) % n
for i := startLine; i != p.uiList.Cursor; i = (i + increment + n) % n {
if s.re.MatchString(p.cachedResults[i]) {
p.uiList.SetCursorLine(i)
p.Update()
break
}
}
}
func (p *HelpPage) GoBack() {
currentPage, previousPages = previousPages[len(previousPages)-1], previousPages[:len(previousPages)-1]
changePage()
}
func (p *HelpPage) Refresh() {
pDeref := &p
q := *pDeref
q.cachedResults = make([]string, 0)
helpPage = q
currentPage = helpPage
changePage()
q.Create()
}
func (p *HelpPage) Update() {
ls := p.uiList
ui.Render(ls)
p.statusBar.Update()
p.commandBar.Update()
}
func (p *HelpPage) Create() {
ui.Clear()
ls := NewScrollableList()
p.uiList = ls
if p.statusBar == nil {
p.statusBar = new(StatusBar)
}
if p.commandBar == nil {
p.commandBar = commandBar
}
if len(p.cachedResults) == 0 {
p.cachedResults = HelpTextAsStrings(nil, "jira_ui_help")
}
ls.Items = p.cachedResults
ls.ItemFgColor = ui.ColorYellow
ls.BorderLabel = "Help"
ls.Height = ui.TermHeight() - 2
ls.Width = ui.TermWidth()
ls.Y = 0
p.statusBar.Create()
p.commandBar.Create()
p.Update()
}