Documentation ¶
Overview ¶
Package paginator provides a Bubble Tea package for calculating 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 ¶
- Variables
- type KeyMap
- type Model
- func (m *Model) GetSliceBounds(length int) (start int, end int)
- func (m Model) ItemsOnPage(totalItems int) int
- func (m *Model) NextPage()
- func (m Model) OnFirstPage() bool
- func (m Model) OnLastPage() bool
- func (m *Model) PrevPage()
- func (m *Model) SetTotalPages(items int) int
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m Model) View() string
- type Option
- type Type
Constants ¶
This section is empty.
Variables ¶
var DefaultKeyMap = KeyMap{ PrevPage: key.NewBinding(key.WithKeys("pgup", "left", "h")), NextPage: key.NewBinding(key.WithKeys("pgdown", "right", "l")), }
DefaultKeyMap is the default set of key bindings for navigating and acting upon the paginator.
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 configures how the pagination is rendered (Arabic, Dots). Type Type // Page is the current page number. Page int // PerPage is the number of items per page. PerPage int // TotalPages is the total number of pages. TotalPages int // ActiveDot is used to mark the current page under the Dots display type. ActiveDot string // InactiveDot is used to mark inactive pages under the Dots display type. InactiveDot string // ArabicFormat is the printf-style format to use for the Arabic display type. ArabicFormat string // KeyMap encodes the keybindings recognized by the widget. KeyMap KeyMap // Deprecated: customize [KeyMap] instead. UsePgUpPgDownKeys bool // Deprecated: customize [KeyMap] instead. UseLeftRightKeys bool // Deprecated: customize [KeyMap] instead. UseUpDownKeys bool // Deprecated: customize [KeyMap] instead. UseHLKeys bool // Deprecated: customize [KeyMap] instead. UseJKKeys bool }
Model is the Bubble Tea model for this user interface.
func (*Model) GetSliceBounds ¶
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 to the pagination. For example:
bunchOfStuff := []stuff{...} start, end := model.GetSliceBounds(len(bunchOfStuff)) sliceToRender := bunchOfStuff[start:end]
func (Model) ItemsOnPage ¶
ItemsOnPage is a helper function for returning the number of items on the current page given the total number 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) OnFirstPage ¶
OnFirstPage returns whether or not we're on the first page.
func (Model) OnLastPage ¶
OnLastPage returns whether or not we're on the last page.
func (*Model) PrevPage ¶
func (m *Model) PrevPage()
PrevPage is a helper function for navigating one page backward. It will not page beyond the first page (i.e. page 0).
func (*Model) SetTotalPages ¶
SetTotalPages is a helper function for calculating the total number of pages from a given number of items. Its 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 Option ¶
type Option func(*Model)
Option is used to set options in New.
func WithTotalPages ¶
WithTotalPages sets the total pages.