pager
provides a simple data neutral paging solution for Go.
- This package does not depend on external packages.
- All versions of Go are supported.
Stable
package main
import (
"fmt"
"github.com/metakeule/pager"
)
var data = []string{"one", "two", "three", "four", "five", "six"}
func print(pg pager.Pager) {
from, to, selected := pg.Indexes()
// we got data
if from > -1 {
for i, line := range data[from:to] {
prefix := " "
if i == selected {
prefix = "> "
}
fmt.Println(prefix + line)
}
}
}
func main() {
pg := pager.New(3, len(data), pager.PreSelect(5))
// do the paging stuff here
// when height or data changes, create a new pager
pg.Prev()
// print the paged data
print(pg)
// Output:
// four
// > five
// six
}
There are three display variants available:
- FixPage (default)
- Top
- Bottom
see http://godoc.org/github.com/metakeule/pager
BenchmarkFixPage-4 26.7 ns/op 0 B/op 0 allocs/op
BenchmarkTop-4 9.08 ns/op 0 B/op 0 allocs/op
BenchmarkBottom-4 8.17 ns/op 0 B/op 0 allocs/op
BenchmarkNext-4 4.04 ns/op 0 B/op 0 allocs/op
BenchmarkPrev-4 4.54 ns/op 0 B/op 0 allocs/op
BenchmarkPageDown-4 20.6 ns/op 0 B/op 0 allocs/op
BenchmarkPageUp-4 21.3 ns/op 0 B/op 0 allocs/op