TSS (Terminal Style Sheets)

Overview & Terminology

This document defines the behavior of term.tss (src/term/term/tss.lua):

TSS is a style system for terminal output.

A style sheet is defined as a Lua table with style definition, and is referred as rss (raw style sheet). tss is an instantiated object of a particular rss, with methods to apply it:

local tss_mod = require("term.tss")
local rss = { fg = "white" }
local tss = tss_mod.new(rss)

Styles are resolved by dot-path (for example: table.border.top_line), then applied through tss:apply() or tss:apply_sized().

TSS is used directly by terminal widgets and by markdown renderers.

Supported Core Properties

These properties are understood by term.tss itself:

PropertyTypeBehavior
fgstring / number / {r,g,b}Foreground color
bgstring / number / {r,g,b}Background color
sstringComma-separated style list (bold,italic,...)
alignstringleft, right, center, none
clipnumber0 auto-clip to configured width, >0 explicit clip position, <0 disable clipping
text_indentnumberText-level indentation added by tss:apply()
block_indentnumberBlock-level indentation hint for renderers (not applied by tss:apply())
wnumberElement width (fractional or absolute; see width semantics below)
tsstring / tableKitty text sizing configuration (non-cascading)
beforestringPrefix decorator added before content
afterstringSuffix decorator added after content

Leaf-Object Properties

The following are read from the final resolved style object (leaf), not from cascaded props:

PropertyTypeBehavior
contentstringOverrides input content
fillbooleanRepeats content to configured width

Because these are leaf-object properties, define them at the style you apply directly.

Cascading Rules

Property cascade

Multiple elements in one apply call

tss:apply(elements, content) accepts one element or an array of elements. When multiple elements are passed, TSS resolves them in order and merges style state left-to-right.

Width (w) Semantics

w rules are strict:

Important consequence:

For full-width behavior, use an absolute width that will clamp to max (for example, a very large value).

Text Sizing (ts) Semantics

ts supports:

Validation:

Runtime gate:

Public API

term.tss exports:

TSS object methods:

apply() return value

apply() and apply_sized() return a table:

Use .text, .width, and .height explicitly.

Renderer-Specific Style Fields

Some style fields used in markdown renderers are not interpreted by term.tss directly (for example list.indent_per_level). They are consumed by renderer code and may coexist with core TSS properties.

PathTypeValuesDefaultBehavior
list.indent_per_levelnumbernon-negative number (renderer uses floored integer)4Controls nesting indentation step for markdown list rendering (spaces per nesting level after level 1).
table.overflowstringwrap, clipwrapControls terminal table cell overflow handling in markdown renderers. wrap expands row height and wraps cell content within fitted column width. clip preserves legacy single-line truncation with ellipsis when needed.

Thematic break glyph customization uses core TSS fields: