beamtea_list (beamtea v0.1.2)

View Source

A bubble: a scrollable, selectable list.

Arrow keys (or j/k) move the selection; the visible window scrolls to keep the cursor in view. Forward key messages to update/2 and read the choice back with selected/1.

     L = beamtea_list:new([<<"Tea">>, <<"Coffee">>, <<"Water">>], #{title => <<"Pick one">>}),
     {L1, _} = beamtea_list:update({key, down}, L),
     {1, <<"Coffee">>} = beamtea_list:selected(L1).

Summary

Functions

Equivalent to new(Items, #{}).

Options: title, height (visible rows, default 10), cursor_glyph (default "> "), color (selection accent).

{Index, Item} currently under the cursor (or none if empty).

Replace the items; the cursor is clamped into range.

Move the selection in response to a key; ignore everything else.

Render the (optional) title and the visible window of items.

Types

model/0

-opaque model()

Functions

cursor(_)

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

items(_)

-spec items(model()) -> [iodata()].

new(Items)

-spec new([iodata()]) -> model().

Equivalent to new(Items, #{}).

new(Items, Opts)

-spec new([iodata()], map()) -> model().

Options: title, height (visible rows, default 10), cursor_glyph (default "> "), color (selection accent).

selected(_)

-spec selected(model()) -> {non_neg_integer(), iodata()} | none.

{Index, Item} currently under the cursor (or none if empty).

set_items(Items, M)

-spec set_items([iodata()], model()) -> model().

Replace the items; the cursor is clamped into range.

update(Msg, M)

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

Move the selection in response to a key; ignore everything else.

view(_)

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

Render the (optional) title and the visible window of items.