gleamtea/style

A composable styling layer, inspired by charmbracelet/lipgloss. New in beamtea 0.1.2.

Build a Style by piping setters from new, then render it onto text. A style bundles inline attributes (colour, bold, …) with block layout (width, alignment, padding, border, margin):

import gleamtea/style
import gleamtea/color

style.new()
|> style.foreground(style.Named(color.Charmple))
|> style.bold
|> style.padding(style.VH(0, 2))
|> style.border(style.Rounded)
|> style.border_foreground(style.Named(color.Purple))
|> style.render("Hello")

Types

A border style.

pub type Border {
  NoBorder
  Normal
  Rounded
  Thick
  Double
}

Constructors

  • NoBorder
  • Normal
  • Rounded
  • Thick
  • Double

Box spacing for padding / margin: the same value on all sides, a vertical/horizontal pair, or explicit top/right/bottom/left.

pub type Spacing {
  All(Int)
  VH(vertical: Int, horizontal: Int)
  Sides(top: Int, right: Int, bottom: Int, left: Int)
}

Constructors

  • All(Int)
  • VH(vertical: Int, horizontal: Int)
  • Sides(top: Int, right: Int, bottom: Int, left: Int)

An opaque style (a beamtea_style map).

pub type Style

A colour a style can use: a named palette colour, a raw xterm-256 index, or a 24-bit truecolor triple.

pub type StyleColor {
  Named(color.Color)
  Index(Int)
  Rgb(r: Int, g: Int, b: Int)
}

Constructors

  • Named(color.Color)
  • Index(Int)
  • Rgb(r: Int, g: Int, b: Int)

Values

pub fn align(style: Style, a: layout.HAlign) -> Style

Horizontally align content within its fixed width.

pub fn background(style: Style, color: StyleColor) -> Style

Set the background colour.

pub fn bold(style: Style) -> Style

Make text bold.

pub fn border(style: Style, b: Border) -> Style

Draw a border around the content.

pub fn border_foreground(
  style: Style,
  color: StyleColor,
) -> Style

Colour the border.

pub fn faint(style: Style) -> Style

Make text faint/dim.

pub fn foreground(style: Style, color: StyleColor) -> Style

Set the foreground colour.

pub fn height(style: Style, h: Int) -> Style

Fix the content height (rows), padded/truncated per the vertical alignment.

pub fn italic(style: Style) -> Style

Make text italic.

pub fn join_horizontal(
  valign: layout.VAlign,
  blocks: List(String),
) -> String

Place already-rendered blocks side by side, aligning their differing heights.

pub fn join_vertical(
  halign: layout.HAlign,
  blocks: List(String),
) -> String

Stack already-rendered blocks, aligning their differing widths.

pub fn margin(style: Style, spec: Spacing) -> Style

Outer spacing.

pub fn merge(base: Style, over: Style) -> Style

Layer over on top of base (over’s properties win).

pub fn new() -> Style

An empty style.

pub fn padding(style: Style, spec: Spacing) -> Style

Inner spacing.

pub fn render(style: Style, text: String) -> String

Apply the style to text, returning styled (possibly multi-line) output.

pub fn reverse(style: Style) -> Style

Reverse foreground/background.

pub fn underline(style: Style) -> Style

Underline text.

pub fn valign(style: Style, v: layout.VAlign) -> Style

Vertically align content within its fixed height.

pub fn width(style: Style, w: Int) -> Style

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

Search Document