UI & Themes
Charming::UI is the low-level styling and layout toolkit: immutable Style builders, ANSI-aware measurement and joining, color capability detection, and gradients. Themes sit on top — named token sets (title, muted, border, …) that resolve to styles so app code never hard-codes colors. For a guided tour of the Style builder, colors, and borders, see Styling; for theme registration, see Application & Configuration.
Layout helpers
Charming::UI provides ANSI-aware layout helpers:
Charming::UI.styleCharming::UI.adaptive(light:, dark:)— a color resolved against the terminal background at render timeCharming::UI.join_horizontal(*blocks, gap: 0, align: :top)—align:is:top/:center/:bottomor a 0.0–1.0 fractionCharming::UI.join_vertical(*blocks, gap: 0, align: :left)— pads narrower blocks to the widest;align:is:left/:center/:rightor a fractionCharming::UI.center(block, width:, height:)Charming::UI.place(block, width:, height:, top: 0, left: 0, background: nil)— positions take integers,:center, or fractionsCharming::UI.overlay(base, overlay, top: :center, left: :center)Charming::UI.visible_slice(line, start_column, width)Charming::UI::Width.measure(value)/pad_to(line, width)/widest(lines)Charming::UI::Width.strip_ansi(value)Charming::UI::Truncate.tail(text, width, ellipsis: "…")Charming::UI::TextWrapper.new(width:).wrap(value)Charming::UI::Gradient.blend(from, to, amount)/steps(from, to, count)/colorize(text, from:, to:)
Color capability
Color capability (Charming::UI::ColorSupport):
level— the active capability::truecolor,:color256,:color16, or:none(auto-detected fromNO_COLOR,COLORTERM,TERM).level = value— force a level;nilre-enables detection.at_least?(:color256)— capability comparison.- Hex colors in styles and themes downconvert automatically to the active level.
Terminal background (Charming::UI::Background):
dark?— whether the background is dark (OSC 11 query at runtime startup,COLORFGBGfallback, dark default).assume = :dark | :light | nil— override or re-enable detection.
Styles
Styles are immutable builders:
style.foreground(:cyan).bold.border(:rounded).padding(1, 2).width(40)
Common style methods:
foreground/fgbackground/bgbold,faint,italic,underline,reverse,strikethroughpadding,margin(CSS shorthand; per-side setters likepadding_left,margin_top)border(style, sides:, foreground:, background:)— style name or a customUI::Border;foreground:takes a color or per-side hashwidth,height,max_width,max_heightalign,align_verticalwrap,truncate(ellipsis: "…")— overflow fit modes at a fixed width (default is clip)render(value)
Themes
Theme tokens return Charming::UI::Style objects:
texttitlemutedborderselectedinfowarn
Themes can be loaded with theme name, built_in: or theme name, from: on the application class.