-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathbase_list_page.go
127 lines (108 loc) · 2.45 KB
/
base_list_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package jiraui
import (
"fmt"
"regexp"
ui "gopkg.in/gizak/termui.v2"
)
type Search struct {
command string
directionUp bool
re *regexp.Regexp
}
type BaseListPage struct {
uiList *ScrollableList
cachedResults []string
isPopulated bool
ActiveSearch Search
}
func (p *BaseListPage) SetSearch(searchCommand string) {
if len(searchCommand) < 2 {
// must be '/a' minimum
return
}
direction := []byte(searchCommand)[0]
regex := "(?i)" + string([]byte(searchCommand)[1:])
s := new(Search)
s.command = searchCommand
if direction == '?' {
s.directionUp = true
} else if direction == '/' {
s.directionUp = false
} else {
// bad command
return
}
if re, err := regexp.Compile(regex); err != nil {
// bad regex
return
} else {
s.re = re
p.ActiveSearch = *s
}
}
func (p *BaseListPage) IsPopulated() bool {
if len(p.cachedResults) > 0 || p.isPopulated {
return true
} else {
return false
}
}
func (p *BaseListPage) PreviousLine(n int) {
p.uiList.CursorUpLines(n)
}
func (p *BaseListPage) NextLine(n int) {
p.uiList.CursorDownLines(n)
}
func (p *BaseListPage) PreviousPara() {
p.PreviousLine(5)
}
func (p *BaseListPage) NextPara() {
p.NextLine(5)
}
func (p *BaseListPage) PreviousPage() {
p.uiList.PageUp()
}
func (p *BaseListPage) NextPage() {
p.uiList.PageDown()
}
func (p *BaseListPage) PageLines() int {
return p.uiList.Height - 2
}
func (p *BaseListPage) TopOfPage() {
p.uiList.Cursor = 0
p.uiList.ScrollToTop()
}
func (p *BaseListPage) BottomOfPage() {
p.uiList.Cursor = len(p.uiList.Items) - 1
p.uiList.ScrollToBottom()
}
func (p *BaseListPage) Id() string {
return fmt.Sprintf("BaseListPage(%p)", p)
}
func (p *BaseListPage) Update() {
log.Debugf("BaseListPage.Update(): self: %s (%p)", p.Id(), p)
log.Debugf("BaseListPage.Update(): currentPage: %s (%p)", currentPage.Id(), currentPage)
ui.Render(p.uiList)
}
func (p *BaseListPage) Refresh() {
pDeref := &p
q := *pDeref
q.cachedResults = make([]string, 0)
changePage()
q.Create()
}
func (p *BaseListPage) Create() {
log.Debugf("BaseListPage.Create(): self: %s (%p)", p.Id(), p)
log.Debugf("BaseListPage.Create(): currentPage: %s (%p)", currentPage.Id(), currentPage)
ui.Clear()
ls := NewScrollableList()
p.uiList = ls
p.cachedResults = make([]string, 0)
ls.Items = p.cachedResults
ls.ItemFgColor = ui.ColorYellow
ls.BorderLabel = "Updating, please wait"
ls.Height = ui.TermHeight()
ls.Width = ui.TermWidth()
ls.Y = 0
p.Update()
}