Skip to content

minimal pager in Go that can be used with any data type

License

Notifications You must be signed in to change notification settings

metakeule/pager

Repository files navigation

pager

Build Status Travis Build status Appveyor Go Report Coverage Status

pager provides a simple data neutral paging solution for Go.

  • This package does not depend on external packages.
  • All versions of Go are supported.

Status

Stable

Usage

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

Documentation

see http://godoc.org/github.com/metakeule/pager

Benchmarks

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

About

minimal pager in Go that can be used with any data type

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages