beamtea_layout (beamtea v0.1.2)

View Source

Position a block of content within the full terminal.

beamtea renders exactly what your view/1 returns, anchored at the top-left. To use the whole screen you place your content inside the terminal's {Cols, Rows} — centre it, pin it to a corner, etc. Widths are measured ignoring ANSI colour codes (via beamtea_util:visible_width/1), so coloured content still aligns.

The runtime can apply this for you: beamtea:start(Mod, Flags, #{layout => center}). Or call it yourself in view/1 when you track the size via the {resize, {Cols, Rows}} message.

Summary

Functions

Centre Content both horizontally and vertically.

Draw a bordered panel that fills the whole {Cols, Rows} terminal and place Content inside it (top-left, with one column of padding). This is what makes a small view "fit the terminal". Options: border_color (default charmple) and padding (inner columns/rows, default 1). Lines wider than the inner width are truncated; the panel is padded to full height.

Composite Fg on top of Bg at {Col, Row} (0-based) within a {Cols, Rows} area — the basis for a floating modal/popover. Both may be fully styled (ANSI is handled when slicing the background by column); Bg is padded to the full area first.

Centre Fg over Bg within {Cols, Rows}.

Place Content within a {Cols, Rows} area. Options: halign (left | center | right, default center) and valign (top | middle | bottom, default middle). The block keeps its internal left-alignment; it is positioned as a unit.

Centre horizontally, pinned to the top.

Types

halign/0

-type halign() :: left | center | right.

valign/0

-type valign() :: top | middle | bottom.

Functions

center(Content, Size)

-spec center(iodata(), {pos_integer(), pos_integer()}) -> iodata().

Centre Content both horizontally and vertically.

frame(Content, Size, Opts)

-spec frame(iodata(), {pos_integer(), pos_integer()}, map()) -> iodata().

Draw a bordered panel that fills the whole {Cols, Rows} terminal and place Content inside it (top-left, with one column of padding). This is what makes a small view "fit the terminal". Options: border_color (default charmple) and padding (inner columns/rows, default 1). Lines wider than the inner width are truncated; the panel is padded to full height.

overlay(Bg, Fg, _, _)

-spec overlay(iodata(),
              iodata(),
              {non_neg_integer(), non_neg_integer()},
              {pos_integer(), pos_integer()}) ->
                 iodata().

Composite Fg on top of Bg at {Col, Row} (0-based) within a {Cols, Rows} area — the basis for a floating modal/popover. Both may be fully styled (ANSI is handled when slicing the background by column); Bg is padded to the full area first.

overlay_center(Bg, Fg, _)

-spec overlay_center(iodata(), iodata(), {pos_integer(), pos_integer()}) -> iodata().

Centre Fg over Bg within {Cols, Rows}.

place(Content, _, Opts)

-spec place(iodata(), {pos_integer(), pos_integer()}, #{halign => halign(), valign => valign()}) ->
               iodata().

Place Content within a {Cols, Rows} area. Options: halign (left | center | right, default center) and valign (top | middle | bottom, default middle). The block keeps its internal left-alignment; it is positioned as a unit.

top_center(Content, Size)

-spec top_center(iodata(), {pos_integer(), pos_integer()}) -> iodata().

Centre horizontally, pinned to the top.