Skip to content

smelt.text

Tier: UiHost — Requires a terminal UI; calling these from headless mode raises.

Visual-width measurement. UiHost-only.

smelt.text.fit

fun(s: string, width: integer, opts: table?): string

Force s to occupy exactly width display cells: truncate when too long (appending opts.suffix, default "…"), pad when too short (with opts.fill, default " "). opts.align is "left" (default), "right", or "center". Use this for fixed-width UI slots — handles multi-byte and wide chars correctly so the result is always exactly width cells wide regardless of content.

smelt.text.line_count

fun(s: string): integer

Return the number of lines in s. Counts \n separators and adds one if the last line is unterminated; an empty string returns 0. Matches the line count users see in a renderer that splits on \n without dropping the trailing partial line.

smelt.text.slugify

fun(s: string): string

Lowercase s, replace non-alphanumeric runs with -, drop empty segments. Same algorithm the title plugin uses for fallback slugs.

smelt.text.truncate

fun(s: string, max_bytes: integer, suffix: string?): string

Truncate s to at most max_bytes, snapping to the previous UTF-8 char boundary. Returns s unchanged when it already fits; appends suffix when provided and truncation actually occurred. Byte-based — use smelt.text.fit instead when you need to fit into a terminal-cell budget.

smelt.text.width

fun(s: string): integer

Return the visual column count of s. Lua's #s counts bytes; use this for sizing extmark ranges or computing column offsets so multi-byte and wide characters land correctly.