paginator

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: MIT Imports: 2 Imported by: 0

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

View Source
var NewModel = New

NewModel creates a new model with defaults.

Deprecated. Use New instead.

Functions

This section is empty.

Types

type Model

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

Model is the Bubble Tea model for this user interface.

func New

func New() Model

New creates a new model with defaults.

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

OnLastPage 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 calculating 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.

func (Model) Update

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

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

func (Model) View

func (m Model) View() string

View renders the pagination to a string.

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