Terminal Style Sheets — CSS-inspired cascading style system for
terminal output with text sizing support. An rss (raw style sheet)
is a plain Lua table defining styles; a tss is the object returned
by new() that wraps an rss with cascading resolution, window-aware
layout, and text sizing methods.
| Name | Signature |
|---|---|
tss:get | tss:get(el, base_props) -> props, obj |
tss:apply | tss:apply(elements, content, position) -> result |
tss:set_property | tss:set_property(path, property, value) |
tss:get_property | tss:get_property(path, property) -> value |
tss:get_style | tss:get_style(path) -> style |
tss:style_snapshot | tss:style_snapshot() -> snapshot |
tss:get_window_width | tss:get_window_width() -> width |
tss:set_window_width | tss:set_window_width(width) |
tss:get_window_size | tss:get_window_size() -> size |
tss:set_window_size | tss:set_window_size(height, width) |
tss:get_supports_ts | tss:get_supports_ts() -> enabled |
tss:set_supports_ts | tss:set_supports_ts(enabled) |
tss:apply_sized | tss:apply_sized(base_elements, content, position, opts) -> result |
tss:resolve_scale | tss:resolve_scale(elements) -> scale |
tss:scope | tss:scope(overrides) -> child |
new | new(rss, opts) -> tss |
merge | merge(rss_1, rss_2, opts) -> tss |
tss:get(
el,base_props) ->props,obj
Resolve cascading style properties for an element path
Traverses the dot-separated element path (e.g. "heading.h1")
and merges properties from each level. Returns the merged
properties table and the innermost style object.
tss:apply(
elements,content,position) ->result
Apply styling to content using cascading element selectors
Resolves styles, applies width, alignment, clipping, decorators,
text sizing, and ANSI colors/styles. The elements argument may
also be a table of element strings. Returns a table with text
(styled string), width, and height fields.
tss:set_property(
path,property,value)
Set a style property at the given element path
tss:get_property(
path,property) ->value
Get a style property value at the given element path
tss:get_style(
path) ->style
Get a copy of the style subtree at the given path
tss:style_snapshot() ->
snapshot
Return a deep copy of the entire style sheet
tss:get_window_width() ->
width
Return the current window width used for layout calculations
tss:set_window_width(
width)
Set the window width used for layout calculations
tss:get_window_size() ->
size
Return the current window dimensions
tss:set_window_size(
height,width)
Set the window dimensions used for layout calculations
tss:get_supports_ts() ->
enabled
Check whether text sizing protocol support is enabled
tss:set_supports_ts(
enabled)
Enable or disable text sizing protocol support
tss:apply_sized(
base_elements,content,position,opts) ->result
Apply styling with inline formatting ranges and text sizing
Handles content with inline style ranges (bold, italic, etc.)
combined with text sizing. The content table must have a plain
field (text without ANSI codes) and a ranges list of
{start, stop, elements} inline style ranges. The base_elements
argument may also be a table. The optional opts table supports
skip_before and skip_after booleans to suppress decorators.
Returns a table with text, width, and height fields.
tss:resolve_scale(
elements) ->scale
Resolve the effective text-sizing scale factor for style elements
Returns the integer scale factor (ts.s) for the given element(s).
Accepts a single element string or a table of elements (cascaded
left to right). Returns 1 when no text sizing is configured or
the terminal does not support it.
tss:scope(
overrides) ->child
Create a child TSS instance with overridden style properties
Deep-merges overrides on top of the parent's style sheet and returns
a new TSS instance. The child inherits the parent's window size and
supports_ts setting. Useful for rendering themed sub-sections (e.g.
a widget inside a pane) without mutating the parent TSS.
new(
rss,opts) ->tss
Create a new TSS instance from a raw style sheet
Creates a TSS object with cascading style resolution, text sizing,
and window-aware layout. The opts table may contain
supports_ts (default true) to gate text sizing features.
merge(
rss_1,rss_2,opts) ->tss
Merge two raw style sheets and return a new TSS instance
Deep-merges rss_2 into rss_1 and passes the result to new().
opts is forwarded to new() unchanged (e.g. supports_ts).