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)
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 border_foreground(
style: Style,
color: StyleColor,
) -> Style
Colour the border.
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 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 render(style: Style, text: String) -> String
Apply the style to text, returning styled (possibly multi-line) output.
pub fn valign(style: Style, v: layout.VAlign) -> Style
Vertically align content within its fixed height.