-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
72 lines (55 loc) · 1.22 KB
/
options.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
package pager
// Option is an option for the page initialization
type Option func(*pager)
// PreSelect the given index in the data slice
func PreSelect(index uint) Option {
return func(pg *pager) {
pg.selected = int(index)
}
}
// FixPage always keeps the same pages (default)
func FixPage() Option {
return func(pg *pager) {
pg.style = func(p *pager) (from, to, selected int) {
page := p.currentPage()
if page > 0 {
from = page * p.height
}
to = from + p.height
if p.dataLen < to {
to = p.dataLen
}
return from, to, p.selected - from
}
}
}
// Top keeps the selected line at the top
func Top() Option {
return func(pg *pager) {
pg.style = func(p *pager) (from, to, selected int) {
from = p.selected
to = p.selected + p.height
if p.dataLen < to {
to = p.dataLen
}
return from, to, 0
}
}
}
// Bottom keeps the selected line at the bottom
func Bottom() Option {
return func(pg *pager) {
pg.style = func(p *pager) (from, to, selected int) {
if p.selected < p.height {
to = p.dataLen
if to > p.height {
to = p.height
}
return 0, to, p.selected
}
to = p.selected + 1
from = to - p.height
return from, to, p.selected - from
}
}
}