beamtea_paginator (beamtea v0.1.2)
View SourceA 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
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
Functions
-spec new() -> model().
Equivalent to new(#{}).
Options: per_page (default 10), total_items (default 0), kind (dots | arabic, default dots), glyphs and colours.
-spec page(model()) -> non_neg_integer().
-spec per_page(model()) -> pos_integer().
-spec set_total_items(non_neg_integer(), model()) -> model().
Recompute the page count for a new item total, clamping the page.
-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.
-spec total_pages(model()) -> pos_integer().
-spec update(term(), model()) -> {model(), beamtea:cmd()}.
Move between pages with ←/→, h/l, or PageUp/PageDown.
Render the paginator.