Skip to content

nimterm/theme

This page is generated from the module’s exported API and ## documentation comments.

Small TUI palette: named tokens → SGR strings, compiled once per apply.

Built-in themes compile once per terminal color depth. Custom themes are JSON under the configured global and workspace roots. No hot reload, no OSC queries, no per-frame color math.

ColorDepth = enum
cdNone, cd16, cd256, cdTrue

View source

ThemeSpec = object
name*: string
accent*, success*, error*, warning*, code*, muted*, dim*, text*: string
heading*, model*, panelBg*, selectedBg*, selectedFg*: string

View source

Theme = object
name*: string
accent*, success*, error*, warning*, code*, muted*, dim*, text*: string
heading*, model*, panelBg*, selectedBg*, selectedFg*: string
boldAccent*, boldError*: string
reset*: string

View source

Dark256 = (name: "dark", accent: "\e[36m", success: "\e[32m", error: "\e[31m",
warning: "\e[33m", code: "\e[38;5;179m", muted: "\e[90m",
dim: "\e[2m", text: "\e[37m", heading: "\e[1;34m", model: "\e[35m",
panelBg: "\e[48;5;236m", selectedBg: "\e[48;5;81m",
selectedFg: "\e[30m", boldAccent: "\e[1;36m", boldError: "\e[1;31m",
reset: "\e[0m")

View source

DarkSpec = (name: "dark", accent: "#00afaf", success: "#00af00",
error: "#af0000", warning: "#afaf00", code: "#d7af5f", muted: "242",
dim: "dim", text: "#c6c6c6", heading: "#5f87ff", model: "#af00af",
panelBg: "#303030", selectedBg: "#5fd7ff", selectedFg: "#000000")

View source

LightSpec = (name: "light", accent: "#005f87", success: "#008700",
error: "#af0000", warning: "#af5f00", code: "#875f00",
muted: "245", dim: "dim", text: "#262626", heading: "#5f00af",
model: "#8700af", panelBg: "#e4e4e4", selectedBg: "#0087af",
selectedFg: "#ffffff")

View source

currentTheme = Dark256

View source

themeRevision = 0

View source

proc clearThemeNameCache() {.raises: [], tags: [], forbids: [].}

View source

proc colorsOn(t: Theme): bool {.raises: [], tags: [], forbids: [].}

Returns: bool.

Name Type Default
t Theme

View source

proc paint(t: Theme; code, text: string): string {.raises: [], tags: [],
forbids: [].}

Returns: string.

Name Type Default
t Theme
code string
text string

View source

Convert a compiled theme token back into Nimterm’s semantic style. Theme tokens are still serialized for the plain console path, while widgets consume semantic cells.

proc styleFromSgr(code: string): nimstyle.Style {.raises: [], tags: [],
forbids: [].}

Returns: nimstyle.Style.

Name Type Default
code string

View source

proc themedStyle(t: Theme; foreground = ""; background = "";
attributes: set[nimstyle.TextAttribute] = {}): nimstyle.Style {.
raises: [], tags: [], forbids: [].}

Returns: nimstyle.Style.

Name Type Default
t Theme
foreground inferred ""
background inferred ""
attributes set[nimstyle.TextAttribute] {}

View source

Prefer a single SGR for an italic heading; else prefix italic.

proc italicHeading(t: Theme): string {.raises: [], tags: [], forbids: [].}

Returns: string.

Name Type Default
t Theme

View source

proc detectDepth(): ColorDepth {.raises: [], tags: [ReadEnvEffect], forbids: [].}

Returns: ColorDepth.

View source

proc compileTheme(spec: ThemeSpec; depth: ColorDepth): Theme {.raises: [],
tags: [], forbids: [].}

Returns: Theme.

Name Type Default
spec ThemeSpec
depth ColorDepth

View source

proc parseThemeJson(doc: JsonNode): tuple[ok: bool, spec: ThemeSpec, err: string] {.
raises: [KeyError], tags: [], forbids: [].}

Returns: tuple[ok: bool, spec: ThemeSpec, err: string].

Name Type Default
doc JsonNode

View source

proc listThemeNames(workspace = ""; appDir = ".nimterm"; globalDir = ""): seq[
string] {.raises: [OSError], tags: [ReadEnvEffect, ReadIOEffect,
ReadDirEffect, WriteIOEffect],
forbids: [].}

Returns: seq[string].

Name Type Default
workspace inferred ""
appDir inferred ".nimterm"
globalDir inferred ""

View source

proc findUserTheme(name, workspace: string; appDir = ".nimterm"; globalDir = ""): tuple[
ok: bool, spec: ThemeSpec, err: string] {.raises: [OSError],
tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, WriteIOEffect],
forbids: [].}

Returns: tuple[ok: bool, spec: ThemeSpec, err: string].

Name Type Default
name string
workspace string
appDir inferred ".nimterm"
globalDir inferred ""

View source

proc compileNamedTheme(name: string; depth: ColorDepth; workspace = "";
appDir = ".nimterm"; globalDir = ""): tuple[ok: bool,
theme: Theme, err: string] {.raises: [OSError], tags: [ReadEnvEffect,
ReadIOEffect, ReadDirEffect, WriteIOEffect], forbids: [].}

Returns: tuple[ok: bool, theme: Theme, err: string].

Name Type Default
name string
depth ColorDepth
workspace inferred ""
appDir inferred ".nimterm"
globalDir inferred ""

View source

Compile and install currentTheme. Returns “” or an error message. Depth defaults to activeDepth so /theme|/new|/resume keep the startup capability (tests stay on cd256; non-TTY detectDepth would wipe colors).

proc applyTheme(name: string; depth = activeDepth; workspace = "";
appDir = ".nimterm"; globalDir = ""): string {.
raises: [OSError],
tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, WriteIOEffect],
forbids: [].}

Returns: string.

Name Type Default
name string
depth inferred activeDepth
workspace inferred ""
appDir inferred ".nimterm"
globalDir inferred ""

View source

Accent rail + optional panel background (OpenCode-style).

proc userRail(t: Theme = currentTheme): string {.raises: [], tags: [],
forbids: [].}

Returns: string.

Name Type Default
t Theme currentTheme

View source

proc toolRail(t: Theme; isError: bool): string {.raises: [], tags: [],
forbids: [].}

Returns: string.

Name Type Default
t Theme
isError bool

View source