paginator

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2020 License: MIT Imports: 2 Imported by: 101

Documentation

Overview

package paginator provides a Bubble Tea package for calulating pagination and rendering pagination info. Note that this package does not render actual pages: it's purely for handling keystrokes related to pagination, and rendering pagination status.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func View

func View(model tea.Model) string

View renders the pagination to a string.

Types

type Model

type Model struct {
	Type             Type
	Page             int
	PerPage          int
	TotalPages       int
	ActiveDot        string
	InactiveDot      string
	ArabicFormat     string
	UseLeftRightKeys bool
	UseUpDownKeys    bool
	UseHLKeys        bool
	UseJKKeys        bool
}

Model is the Tea model for this user interface.

func NewModel

func NewModel() Model

NewModel creates a new model with defaults.

func Update

func Update(msg tea.Msg, m Model) (Model, tea.Cmd)

Update is the Tea update function which binds keystrokes to pagination.

func (*Model) GetSliceBounds

func (m *Model) GetSliceBounds(length int) (start int, end int)

GetSliceBounds is a helper function for paginating slices. Pass the length of the slice you're rendering and you'll receive the start and end bounds corresponding the to pagination. For example:

bunchOfStuff := []stuff{...}
start, end := model.GetSliceBounds(len(bunchOfStuff))
sliceToRender := bunchOfStuff[start:end]

func (Model) ItemsOnPage

func (m Model) ItemsOnPage(totalItems int) int

ItemsOnPage is a helper function for returning the numer of items on the current page given the total numer of items passed as an argument.

func (*Model) NextPage

func (m *Model) NextPage()

NextPage is a helper function for navigating one page forward. It will not page beyond the last page (i.e. totalPages - 1).

func (Model) OnLastPage

func (m Model) OnLastPage() bool

LastPage returns whether or not we're on the last page.

func (*Model) PrevPage

func (m *Model) PrevPage()

PrevPage is a number function for navigating one page backward. It will not page beyond the first page (i.e. page 0).

func (*Model) SetTotalPages

func (m *Model) SetTotalPages(items int) int

SetTotalPages is a helper function for calculatng the total number of pages from a given number of items. It's use is optional since this pager can be used for other things beyond navigating sets. Note that it both returns the number of total pages and alters the model.

type Type

type Type int

Type specifies the way we render pagination.

const (
	Arabic Type = iota
	Dots
)

Pagination rendering options

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL