beamtea_table (beamtea v0.1.2)

View Source

A bubble: a scrollable, row-selectable data table, mirroring the table package in charmbracelet/bubbles.

     Cols = [{<<"Name">>, 12}, {<<"Lang">>, 8}, {<<"Stars">>, 6}],
     Rows = [[<<"beamtea">>, <<"Erlang">>, <<"1.2k">>], ...],
     T = beamtea_table:new(Cols, Rows, #{height => 6}),
     {T1, _} = beamtea_table:update({key, down}, T),
     beamtea_table:selected_row(T1).

Summary

Functions

Options: height (visible rows, default 10), header_color, select_color.

The currently selected row (or none if the table is empty).

Replace the rows; the cursor is clamped into range.

Move the selected row with the arrows (or j/k) and scroll to follow.

Render the header and the visible rows.

Types

column/0

-type column() :: {Title :: iodata(), Width :: pos_integer()}.

model/0

-opaque model()

Functions

cursor(_)

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

new(Columns, Rows)

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

Equivalent to new(Columns, Rows, #{}).

new(Columns, Rows, Opts)

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

Options: height (visible rows, default 10), header_color, select_color.

rows(_)

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

selected_row(_)

-spec selected_row(model()) -> {non_neg_integer(), [iodata()]} | none.

The currently selected row (or none if the table is empty).

set_rows(Rows, M)

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

Replace the rows; the cursor is clamped into range.

update(Msg, M)

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

Move the selected row with the arrows (or j/k) and scroll to follow.

view(_)

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

Render the header and the visible rows.