beamtea_viewport (beamtea v0.1.2)

View Source

A bubble: a scrollable viewport over a block of text, mirroring the viewport package in charmbracelet/bubbles.

Give it content and a height; it shows a window into that content that the user can scroll with the arrows, PageUp/PageDown, Home/End (and j/k).

     V0 = beamtea_viewport:new(#{height => 10}),
     V1 = beamtea_viewport:set_content(BigText, V0),
     {V2, _} = beamtea_viewport:update({key, down}, V1),
     beamtea_viewport:view(V2).

Summary

Functions

Scroll down by N lines (clamped).

Scroll up by N lines (clamped).

Equivalent to new(#{}).

Options: height (visible rows, default 20), width (optional).

How far through the content we are scrolled, as 0.0–1.0.

Replace the content (split into lines on \n).

Scroll in response to a key.

The visible window of lines.

Types

model/0

-opaque model()

Functions

at_bottom(M)

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

at_top(_)

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

line_down(N, M)

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

Scroll down by N lines (clamped).

line_up(N, M)

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

Scroll up by N lines (clamped).

new()

-spec new() -> model().

Equivalent to new(#{}).

new(Opts)

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

Options: height (visible rows, default 20), width (optional).

offset(_)

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

scroll_percent(M)

-spec scroll_percent(model()) -> float().

How far through the content we are scrolled, as 0.0–1.0.

set_content(Content, M)

-spec set_content(iodata(), model()) -> model().

Replace the content (split into lines on \n).

total_lines(_)

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

update(Msg, M)

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

Scroll in response to a key.

view(_)

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

The visible window of lines.