Style: themes
lib/style/tui_style.sh, lib/tui_api.sh - resolves theme.css (.class, :focus, :hover, :border, :title, :checked, :unchecked) to fg/bg/mods per pane and widget. Guide: ../guide/markup.md. ← API index for the full module list and a task-oriented tour with examples.
STATE is one of normal (default), focus, border, title, hover, checked, unchecked (the last two for checkboxes); a state without rules falls back to normal. Colors are black red green yellow blue magenta cyan white default, br_black … br_white, or #rrggbb. Functions return 0 unless their entry says otherwise.
Functions that print (tui.ansi, tui.paint, …) need a subshell when captured. In code that runs every frame use the ones that set variables (tui.style.sgr, tui.class.sgr, tui.class.style, tui.class.names).
Styling and themes
| Function | Summary |
|---|---|
tui.load_theme |
Loads a stylesheet into the class table. <theme src="…"/> calls it. |
tui.class |
Applies a theme class to a widget or pane: its normal rules and every pseudo-state it defines (:focus, :border, :title, :hover, :checked, :unchecked). |
tui.restyle |
Gives a widget or pane the look of a theme class and redraws just it: the widget, or the pane’s border, title and widgets. What the id had before is cleared first, so a :hover the old class had does not linger. |
tui.style |
Sets the style of a widget or pane directly, without a theme class. |
tui.ansi |
Prints the ANSI escape prefix of a widget or pane style (no reset). A state without rules falls back to normal. |
tui.class.ansi |
Prints the ANSI escape prefix of a theme class, without a widget. |
tui.paint |
Prints TEXT in the style of a widget or pane, followed by a reset. No newline. |
tui.class.paint |
Prints TEXT in the style of a theme class, followed by a reset. No newline. |
tui.paint.reset |
Clears the rendering cache, forcing a full redraw on the next flush. |
tui.style.sgr |
Resolves the style of a widget or pane into variables, without a subshell. |
tui.class.style |
Resolves a theme class into variables, without a subshell. Sets TUI_FG, TUI_BG, TUI_MODS. |
tui.class.sgr |
Resolves a theme class into an escape prefix, without a subshell. |
tui.class.names |
Stores every class and pseudo-state key of the loaded theme, sorted, in the array TUI_CLASSES. Fork-free. |
tui.glyph.get |
Resolves a themeable glyph into TUI_GLYPH, without a subshell: the variant’s value, else the base type’s, else the built-in default. |
tui.glyph.set |
Sets a themeable glyph at run time, for apps that let the user pick a look. |
tui.glyph.user |
Sets one part of the user’s own design, custom, and keeps it across theme changes. The Settings page uses it; the choice is stored as glyph.TYPE.KEY in the app’s dabt.conf. |
tui.glyph.available |
Lists the glyphs the Settings page offers for a slot, without a subshell. Every slot of a group gets the same list, so a checked and an unchecked mark are picked from one set. |
tui.variant.default |
Sets the design widgets of one type use when they name no variant of their own. The Settings page uses it; the choice is stored as variant.TYPE in the app’s dabt.conf. |
tui.variant.list |
Lists the designs the loaded theme defines for one widget type, without a subshell. |
tui.cache.theme_clear |
Forgets every memoized stylesheet, so the next load parses the files again. |
tui.load_theme
tui.load_theme FILE
Loads a stylesheet into the class table. <theme src="…"/> calls it.
Returns: 1 and a message on stderr when FILE can’t be read or parsed.
Notes
- Rules merge into one table: a later file overrides the fields it sets, and nothing is removed. Classes from a theme loaded on an earlier page stay defined.
- Each file is parsed once per process and re-applied from memory until its mtime, or the mtime of a file it imports, changes.
@import "other.css";(or@import url("other.css");) applies another stylesheet at that line. The path is relative to the importing file, or absolute. Fields the importing file sets afterwards override the imported ones; the rest are kept. An unreadable file is skipped with a warning, and imports nested more than 8 deep (cycles) are cut off.- The app-wide overlay from
tui.theme.setis re-applied after every stylesheet, so it always wins. - Widgets already styled with
tui.classkeep their old colors; load themes before applying classes. - Class names that collide with a widget or pane style are logged as warnings.
See also: tui.class
tui.class
tui.class ID CLASS
Applies a theme class to a widget or pane: its normal rules and every pseudo-state it defines (:focus, :border, :title, :hover, :checked, :unchecked).
Parameters
CLASS: class name without the dot. Empty does nothing.
Notes
- Copies the class’s current values. Changing or reloading the theme afterwards does not restyle
ID; reloading the page does. - Several calls layer: a later class overrides only the fields it sets.
class="…"in markup calls this.
Example
tui.class btn_go nav_link
tui.restyle
tui.restyle ID CLASS
Gives a widget or pane the look of a theme class and redraws just it: the widget, or the pane’s border, title and widgets. What the id had before is cleared first, so a :hover the old class had does not linger.
Returns: 1 for an unknown id or an empty class.
Notes
tui.classonly bakes the style; without a redraw the old look stays on screen until something repaints it.
Example
tui.restyle health_box tile_err # the border and title turn red
tui.style
tui.style ID FG BG MODS [STATE]
Sets the style of a widget or pane directly, without a theme class.
Parameters
FG,BG:black red green yellow blue magenta cyan white default, the bright variantsbr_black…br_white, or#rrggbb.""leaves the field unchanged.MODS: space-separated, frombold dim italic underline blink reverse hidden strike.""leaves it unchanged.STATE:normal(default),focus,border,title,hover,checked,unchecked.
Notes
- A field can’t be cleared once set; set it to another value instead.
Example
tui.style status "" "#1e1e2e" bold
tui.style status yellow "" "" border
tui.ansi
tui.ansi ID [STATE]
Prints the ANSI escape prefix of a widget or pane style (no reset). A state without rules falls back to normal.
Notes
- Runs in a subshell when used as
$(tui.ansi ...); in loops prefertui.style.sgr.
tui.class.ansi
tui.class.ansi CLASS [STATE]
Prints the ANSI escape prefix of a theme class, without a widget.
Notes
- Fork-free alternative:
tui.class.sgr.
tui.paint
tui.paint ID TEXT [STATE]
Prints TEXT in the style of a widget or pane, followed by a reset. No newline.
Example
tui.output log "$(tui.paint log "ERROR" title) disk full"
tui.class.paint
tui.class.paint CLASS TEXT [STATE]
Prints TEXT in the style of a theme class, followed by a reset. No newline.
tui.paint.reset
tui.paint.reset
Clears the rendering cache, forcing a full redraw on the next flush.
Notes
- Use this after the terminal was resized drastically, taken over by another process, or when a full erase has blanked the physical screen.
- Comparing against old cached rows would be meaningless; the next flush must resend everything unconditionally.
See also: tui.render
tui.style.sgr
tui.style.sgr ID [STATE]
Resolves the style of a widget or pane into variables, without a subshell.
Sets: TUI_SGR (escape prefix), TUI_FG, TUI_BG. TUI_RESET always holds \e[0m.
Example
tui.style.sgr log title
tui.output_append log "${TUI_SGR}== section ==${TUI_RESET}"
tui.class.style
tui.class.style CLASS [STATE]
Resolves a theme class into variables, without a subshell. Sets TUI_FG, TUI_BG, TUI_MODS.
Notes
- A state the class does not define falls back to the plain class.
tui.class.sgr
tui.class.sgr CLASS [STATE]
Resolves a theme class into an escape prefix, without a subshell.
Sets: TUI_SGR, plus TUI_FG, TUI_BG, TUI_MODS.
Example
tui.class.sgr nav_link focus
printf '%s text%s' "$TUI_SGR" "$TUI_RESET"
tui.class.names
tui.class.names
Stores every class and pseudo-state key of the loaded theme, sorted, in the array TUI_CLASSES. Fork-free.
Notes
- Pseudo-states appear as
CLASS_focus,CLASS_hover, …
tui.glyph.get
tui.glyph.get TYPE KEY [VARIANT]
Resolves a themeable glyph into TUI_GLYPH, without a subshell: the variant’s value, else the base type’s, else the built-in default.
Parameters
TYPE,KEY- the slot, e.g.progressfill. Themes set it with.progress { fill: "█"; }.VARIANT- optional design name, set with.progress.thin { fill: "━"; }.
Notes
- A glyph is a quoted, single-cell string. Control characters, wide glyphs and
;are not accepted (an empty string only for the bracket slots below); the rule is skipped and a warning is logged. - Slots:
progress.fillprogress.empty;checkbox.leftcheckbox.oncheckbox.offcheckbox.right;select.leftselect.arrowselect.right;scrollbar.thumbscrollbar.track;panebar.vthumbpanebar.vtrackpanebar.hthumbpanebar.htrack(the vertical and horizontal scrollbars of scrolling panes; a blank thumb is drawn reversed). - The
leftandrightslots may be set to""for a look without brackets. Widgets pick their variant withtui.variant.
Sets: TUI_GLYPH
Example
tui.glyph.get progress fill thin
printf '%s' "$TUI_GLYPH"
tui.glyph.set
tui.glyph.set TYPE KEY GLYPH [VARIANT]
Sets a themeable glyph at run time, for apps that let the user pick a look.
Parameters
TYPE,KEY,VARIANT- the slot, as intui.glyph.get.GLYPH- one visible, single-cell character.
Returns: 1 for an unknown slot or an unusable glyph; nothing changes.
Notes
- A theme reload clears glyphs set this way. Set them again when your page is shown.
- Repaint afterwards (
tui.relayout PANE, ortui.progress.setfor a bar).
Example
tui.glyph.set progress fill "●"
tui.glyph.set progress empty "○"
tui.glyph.user
tui.glyph.user TYPE KEY [GLYPH]
Sets one part of the user’s own design, custom, and keeps it across theme changes. The Settings page uses it; the choice is stored as glyph.TYPE.KEY in the app’s dabt.conf.
Parameters
TYPE,KEY- the slot, as intui.glyph.get.GLYPH- one visible, single-cell character (a space is allowed). Missing removes the part. Empty removes it too, except for the bracket slots (checkboxandselectleft/right), where it blanks them.
Returns: 1 for an unknown slot or an unusable glyph; nothing changes.
Notes
- The parts only show on widgets whose design is
custom: set it withtui.variant.defaultorvariant="custom". Every other design keeps the theme’s glyphs, so it is always clear which one is in force. A part left out ofcustomcomes from the theme’s base look. - Unlike
tui.glyph.set, it is not cleared by a theme reload.
Example
tui.glyph.user progress fill "●"
tui.glyph.available
tui.glyph.available TYPE KEY
Lists the glyphs the Settings page offers for a slot, without a subshell. Every slot of a group gets the same list, so a checked and an unchecked mark are picked from one set.
Sets: TUI_GLYPHS (array; empty when the slot has no entry).
Notes
- The lists live in one file,
glyphs/available.txtof the defaults directory: an@group slot slot ...line, then the glyphs of that group. Add a glyph there and every slot of the group offers it. - It is read once per process. The words
none(a blank bracket) andspace(a blank cell) stand for glyphs that cannot be written in the list.
Example
tui.glyph.available checkbox on
printf '%s\n' "${TUI_GLYPHS[@]}"
tui.variant.default
tui.variant.default TYPE [NAME]
Sets the design widgets of one type use when they name no variant of their own. The Settings page uses it; the choice is stored as variant.TYPE in the app’s dabt.conf.
Parameters
TYPE-progress,checkbox,select,scrollbar(the list, table and textarea scroll indicator) orpanebar(the scrollbars of scrolling panes).NAME- a design the theme defines, orcustom: the user’s own parts set withtui.glyph.user. Empty or missing clears it.
Notes
- A widget’s own
variant=wins. A name the theme does not define draws the base look. - Takes effect on the next draw; call
tui.redrawto repaint at once.
Example
tui.variant.default progress thin
tui.redraw
tui.variant.list
tui.variant.list TYPE
Lists the designs the loaded theme defines for one widget type, without a subshell.
Sets: TUI_VARIANTS (array, sorted; empty when the type has none). The built-in base look, default, is not in it.
Example
tui.variant.list progress
printf '%s\n' "${TUI_VARIANTS[@]}" # ascii dots squares thin
tui.cache.theme_clear
tui.cache.theme_clear
Forgets every memoized stylesheet, so the next load parses the files again.
Notes
- Only needed when a file changed without a new mtime; normally edits are picked up automatically.
Border styles
| Function | Summary |
|---|---|
tui.border.register |
Adds a border style, usable as border="NAME" (and divider="NAME") in markup. |
tui.border.register
tui.border.register NAME TL TR BL BR HZ VT [CAP_L CAP_R]
Adds a border style, usable as border="NAME" (and divider="NAME") in markup.
Parameters
TL TR BL BR: the four corners.HZ,VT: the horizontal and vertical edge. One cell each.CAP_L CAP_R: the glyphs either side of a pane title, which the built-in styles draw as spaces.┐and┌give btop’s look:┌─┐title┌────┐. Default: a space each.
Returns: 1 with fewer than seven arguments.
Notes
- Call it before the page is validated (before
tui.start), or the validator rejectsborder="NAME". - Junctions where panes share an edge are drawn as
single.
Example
tui.border.register rounded ╭ ╮ ╰ ╯ ─ │
tui.border.register btop ┌ ┐ └ ┘ ─ │ ┐ ┌
| Function | Summary |
|---|---|
tui.theme.set |
Sets an app-wide stylesheet that is layered over every page’s own theme, and reloads the current page. |
tui.theme.clear |
Removes the app-wide stylesheet and reloads the current page. |
tui.theme.current |
Prints the path of the app-wide stylesheet (empty when none). |
tui.theme.reload |
Reloads the current page, keeping focus and cursor when the focused widget still exists. |
tui.theme.list |
Prints every selectable theme overlay as NAME<TAB>FILE, one per line, sorted by name. |
tui.theme.pick |
Applies the theme NAME from tui.theme.list to every page and remembers it for the next start. Without NAME it removes the overlay (page default). |
tui.theme.set
tui.theme.set FILE
Sets an app-wide stylesheet that is layered over every page’s own theme, and reloads the current page.
Notes
- Lasts for this run only. To keep it across restarts, also
tui.config.set theme FILE(the Settings page does both). - The reload runs the page’s
on_visitagain. FILEmay start withdabt:for a file of DABT’s defaults folder:tui.theme.set "dabt:themes/nord.css".- Returns 1 and keeps the current theme when
FILEcannot be read. The log names the caller (tui.theme.set at run.sh:21) and suggests a nearby ordabt:file when it finds one.
Example
tui.theme.set "$APP/themes/ocean.css"
See also: tui.theme.clear
tui.theme.clear
tui.theme.clear
Removes the app-wide stylesheet and reloads the current page.
Notes
- Classes the overlay defined stay in the class table until they are overridden, because rules are merged, not replaced.
tui.theme.current
tui.theme.current
Prints the path of the app-wide stylesheet (empty when none).
tui.theme.reload
tui.theme.reload
Reloads the current page, keeping focus and cursor when the focused widget still exists.
tui.theme.list
tui.theme.list
Prints every selectable theme overlay as NAME<TAB>FILE, one per line, sorted by name.
Notes
- Lists every
*.cssin DABT’s installed themes directory ($TUI_DEFAULTS_DIR/themes) plus the app’s ownTUI_THEMES_DIR(set bytui.startto<app dir>/themeswhen that folder exists). An app theme with the same name wins. - The Settings page and the command palette list exactly these, so a
.cssdropped into either directory shows up in both.
Example
while IFS=$'\t' read -r name file; do echo "$name -> $file"; done < <(tui.theme.list)
See also: tui.theme.pick
tui.theme.pick
tui.theme.pick [NAME]
Applies the theme NAME from tui.theme.list to every page and remembers it for the next start. Without NAME it removes the overlay (page default).
Returns: 1 when no theme is called NAME.
Notes
- Same as picking a theme on the Settings page or in the command palette:
tui.config.settheme FILE, thentui.theme.set, which reloads the current page.
Example
tui.theme.pick nord
tui.theme.pick # back to the page default
See also: tui.theme.set (this run only)
