beamtea_style (beamtea v0.1.2)

View Source

A composable styling layer, inspired by charmbracelet/lipgloss.

A style is an immutable set of visual properties (colours, weight, padding, border, alignment, size). You build one up with chained setters — each returns a new style — and render/2 applies it to text:

     S = beamtea_style:border(
           beamtea_style:padding(
             beamtea_style:foreground(beamtea_style:new(), pink), {1, 2}),
           rounded),
     beamtea_style:render(S, <<"Hello">>).

Styles compose: merge/2 layers one over another, and join_horizontal/2 / join_vertical/2 arrange rendered blocks side-by-side or stacked — the building blocks for panels, button rows and modals. Colours may be a named beamtea_color atom, an xterm-256 integer, or a truecolor {R,G,B} triple.

Summary

Functions

Fix the content height (rows), padded/truncated per valign/2.

Place rendered blocks side by side, aligning their differing heights (top | middle | bottom).

Stack rendered blocks, aligning their differing widths (left | center | right).

Outer spacing (same shorthand as padding/2).

Layer Over on top of Base (Over's properties win).

An empty style.

A style from a property map (same keys the setters use).

Inner spacing. N for all sides, {V, H} for vertical/horizontal, or {Top, Right, Bottom, Left}.

Apply the style to Text, returning styled iodata() (possibly multiple lines). Order: inline SGR -> width/align -> height/valign -> padding -> border -> margin.

Fix the content width (columns); shorter lines are padded per align/2, longer ones truncated.

Types

box/0

color/0

-type color() :: beamtea_color:name() | 0..255 | {0..255, 0..255, 0..255}.

style/0

-type style() :: map().

Functions

align(S, A)

-spec align(style(), left | center | right) -> style().

background(S, Color)

-spec background(style(), color()) -> style().

bold(S)

-spec bold(style()) -> style().

border(S, B)

-spec border(style(), none | normal | rounded | thick | double) -> style().

border_foreground(S, Color)

-spec border_foreground(style(), color()) -> style().

faint(S)

-spec faint(style()) -> style().

foreground(S, Color)

-spec foreground(style(), color()) -> style().

height(S, H)

-spec height(style(), non_neg_integer()) -> style().

Fix the content height (rows), padded/truncated per valign/2.

italic(S)

-spec italic(style()) -> style().

join_horizontal(VAlign, Blocks)

-spec join_horizontal(top | middle | bottom, [iodata()]) -> iodata().

Place rendered blocks side by side, aligning their differing heights (top | middle | bottom).

join_vertical(HAlign, Blocks)

-spec join_vertical(left | center | right, [iodata()]) -> iodata().

Stack rendered blocks, aligning their differing widths (left | center | right).

margin(S, Spec)

-spec margin(style(), box()) -> style().

Outer spacing (same shorthand as padding/2).

merge(Base, Over)

-spec merge(style(), style()) -> style().

Layer Over on top of Base (Over's properties win).

new()

-spec new() -> style().

An empty style.

new(Map)

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

A style from a property map (same keys the setters use).

padding(S, Spec)

-spec padding(style(), box()) -> style().

Inner spacing. N for all sides, {V, H} for vertical/horizontal, or {Top, Right, Bottom, Left}.

render(S, Text)

-spec render(style(), iodata()) -> iodata().

Apply the style to Text, returning styled iodata() (possibly multiple lines). Order: inline SGR -> width/align -> height/valign -> padding -> border -> margin.

reverse(S)

-spec reverse(style()) -> style().

underline(S)

-spec underline(style()) -> style().

valign(S, V)

-spec valign(style(), top | middle | bottom) -> style().

width(S, W)

-spec width(style(), non_neg_integer()) -> style().

Fix the content width (columns); shorter lines are padded per align/2, longer ones truncated.