beamtea_paginator (beamtea v0.1.2)

View Source

A bubble: a paginator (dots or "N/M"), mirroring the paginator package in charmbracelet/bubbles.

Tracks the current page over a total item count and helps you slice the items for the visible page.

     P0 = beamtea_paginator:new(#{total_items => 42, per_page => 10}),
     {P1, _} = beamtea_paginator:update({key, right}, P0),
     {Start, End} = beamtea_paginator:slice_bounds(P1, 42),
     Page = lists:sublist(Items, Start + 1, End - Start).

Summary

Functions

Equivalent to new(#{}).

Options: per_page (default 10), total_items (default 0), kind (dots | arabic, default dots), glyphs and colours.

Recompute the page count for a new item total, clamping the page.

{StartIndex, EndIndex} (0-based, half-open) for the current page over TotalItems — feed straight into lists:sublist/3.

Move between pages with ←/→, h/l, or PageUp/PageDown.

Render the paginator.

Types

model/0

-opaque model()

Functions

new()

-spec new() -> model().

Equivalent to new(#{}).

new(Opts)

-spec new(map()) -> model().

Options: per_page (default 10), total_items (default 0), kind (dots | arabic, default dots), glyphs and colours.

on_last_page(_)

-spec on_last_page(model()) -> boolean().

page(_)

-spec page(model()) -> non_neg_integer().

per_page(_)

-spec per_page(model()) -> pos_integer().

set_total_items(Total, M)

-spec set_total_items(non_neg_integer(), model()) -> model().

Recompute the page count for a new item total, clamping the page.

slice_bounds(_, TotalItems)

-spec slice_bounds(model(), non_neg_integer()) -> {non_neg_integer(), non_neg_integer()}.

{StartIndex, EndIndex} (0-based, half-open) for the current page over TotalItems — feed straight into lists:sublist/3.

total_pages(_)

-spec total_pages(model()) -> pos_integer().

update(Msg, M)

-spec update(term(), model()) -> {model(), beamtea:cmd()}.

Move between pages with ←/→, h/l, or PageUp/PageDown.

view(_)

-spec view(model()) -> iodata().

Render the paginator.