tui-nuances 0.1.12

Shared theming for ratatui widget libraries: one Theme, 90 built-in palettes, semantic styles, contrast-aware color math and terminal color downgrade
Documentation

tui-nuances

Crates.io docs.rs tui-nuances installs CI License: MIT Audit Fuzz

Shared theming for ratatui widget libraries. Build one Theme, style every component of your app from it: tui-chart, tui-slider, tui-spinner, tui-rating, tui-piechart, tui-checkbox, tui-file-explorer and your own widgets.

gallery

Features

  • One Theme with ~30 named slots: UI (foreground, muted, border, border_focused, primary, selection_bg/fg …), status (success, warning, error, info) and data-viz (palette, bull, bear, axis, grid, crosshair, tooltip).
  • 104 built-in themes (Theme::names() lists them in cycling order). The cycle starts with default and 19 dark themes, then 20 light ones, then 20 dark, the remaining 9 light, and the rest dark, so light themes show up early without flashing on every step (catppuccin-mocha/catppuccin-latte, solarized-dark/solarized-light, github-dark/github-light, gruvbox/gruvbox-light, tokyo-night/tokyo-night-day …).
    • Light (29): default-light, catppuccin-latte, solarized-light, github-light, gruvbox-light, tokyo-night-day, rose-pine-dawn, atom-one-light, ayu-light, everforest-light, dayfox, kanagawa-lotus, flexoki-light, modus-operandi, alabaster, edge-light, selenized-light, bluloco-light, papercolor-light, synthwave-dawn, tokyo-night-light, light-owl, gruvbox-material-light, dawnfox, material-lighter, iceberg-light, clair-obscur-canvas, mario-overworld, meadow.
    • Synthwave: synthwave, synthwave-outrun, synthwave-dawn, retrowave, vaporwave, laserwave, fairyfloss, neon, cyberpunk.
    • Dark: dracula, nord, monokai, one-dark, rose-pine, kanagawa-wave, nightfox, night-owl, material-palenight, iceberg, horizon, oxocarbon and ~50 more, plus game-inspired ones (super-mario, mario-underground, pip-boy, hyrule, doom, tarnished, clair-obscur, test-chamber, cavern-hush, dojo, underworld, summit, rain-noir, blocky …) and porsche.
    • Accessibility: colorblind (Okabe–Ito), high-contrast, mono. Every theme (except the terminal-native default/mono) passes WCAG AA for text.
  • Derive a theme from what you have: Theme::from_base(..), Theme::from_palette(..).
  • Semantic styles: style(), muted_style(), border_style(focused), title_style(), selected_style(), disabled_style(), status_style(Status).
  • Color math (tui_nuances::color): mix / lighten / darken, relative luminance, contrast ratio, readable_on, ensure_contrast, 256/16-color quantisation.
  • Terminal aware: ColorSupport::detect() (COLORTERM, TERM, NO_COLOR) and Theme::downgrade(support).
  • Glue traits: Themed (widgets) and ThemeProvider (your app theme type).
  • ThemeSwitcher for demos and settings screens.
  • Optional serde feature: themes load from flat JSON/TOML-style maps of color strings.

Installation

cargo add tui-nuances
# with serde support:
cargo add tui-nuances --features serde

or in Cargo.toml:

[dependencies]
tui-nuances = "0.1"
# with serde support:
# tui-nuances = { version = "0.1", features = ["serde"] }

Quick start

use ratatui::widgets::{Block, Borders, Paragraph};
use tui_nuances::{Status, Theme};

let theme = Theme::by_name("tokyo-night").unwrap_or_default();

let panel = Block::default()
    .borders(Borders::ALL)
    .border_style(theme.border_style(true))      // focused border
    .title_style(theme.title_style())
    .style(theme.style());                       // fg + bg
let status = Paragraph::new("deploy ok").style(theme.status_style(Status::Success));

Derive from your own colors

use ratatui::style::Color;
use tui_nuances::Theme;

let theme = Theme::from_base(
    "app",
    Some(Color::Rgb(16, 16, 24)),   // background
    Color::Rgb(230, 230, 240),      // foreground
    Color::Rgb(213, 0, 28),         // accent
    Color::Green,                   // bull / success
    Color::Red,                     // bear / error
)
.warning(Color::Yellow);            // every slot has a builder setter

Plug in your app's theme type

use tui_nuances::{Theme, ThemeProvider};

struct AppTheme { /* ... */ }
impl ThemeProvider for AppTheme {
    fn nuance_theme(&self) -> Theme { Theme::nord() }
}

Widget crates implement Themed { fn apply_theme(self, &Theme) -> Self }; then widget.themed(&app_theme) or widget.apply_theme(&theme) works everywhere.

Adapt to the terminal

use tui_nuances::Theme;

let theme = Theme::dracula().downgrade_for_terminal(); // honours NO_COLOR / COLORTERM / TERM

Examples

Example Run Demo
gallery – all themes on paged tiles (dark first, then light), n/p page cargo run --example gallery gallery
semantic – mock UI using only semantic styles cargo run --example semantic semantic
switcher – ThemeSwitcher + color downgrade cargo run --example switcher switcher

Regenerate the GIFs with nu scripts/generate_all_tapes.nu (vhs required).

Migrating from tui-chart's Theme

All chart fields keep their names (background, foreground, muted, axis, grid, border, title, palette, bull, bear, neutral, accent, crosshair, tooltip_fg, tooltip_bg) and the helpers base_style, axis_style, label_style, grid_style, fill, color(i), next/prev, all are available.

Development

just check-all   # cargo test --all-features + nushell script tests
just fuzz-list # needs nightly + cargo-fuzz

See CONTRIBUTING.md. Licensed under MIT.