Skip to main content

tui_nuances/
lib.rs

1//! # tui-nuances
2//!
3//! Shared theming for [ratatui](https://ratatui.rs) widget libraries
4//! (`tui-chart`, `tui-slider`, `tui-spinner`, `tui-rating`, `tui-piechart`,
5//! `tui-checkbox`, `tui-file-explorer`, …): build **one** [`Theme`] and style
6//! every component of your app from it.
7//!
8//! * [`Theme`] – ~30 named color slots (UI, status, selection, data-viz) with
9//!   90 built-ins: `default`, `catppuccin-mocha`, `catppuccin-latte`,
10//!   `dracula`, `nord`, `gruvbox`, `tokyo-night`, `solarized-dark`,
11//!   `solarized-light`, `one-dark`, `rose-pine`, `monokai`, `default-light`, `grape`, `ocean`, `sunset`, `forest`, `rose`, `neon`, `gruvbox-light`, `catppuccin-frappe`, `catppuccin-macchiato`, `tokyo-night-storm`, `tokyo-night-light`, `kanagawa-wave`, `kanagawa-dragon`, `kanagawa-lotus`, `moonfly`, `nightfly`, `oxocarbon`, `cyberpunk`, `rose-pine-moon`, `rose-pine-dawn`, `ayu-mirage`, `everforest-dark`, `atom-one-light`, `night-owl`, `poimandres`, `flexoki-dark`, `flexoki-light`, `carbonfox`, `andromeda`, `synthwave`,
12//!   `ayu-dark`, `github-dark`, `github-light`, `zenburn`, `super-mario`, `tokyo-night-moon`, `tokyo-night-day`, `gruvbox-material`, `nightfox`, `dawnfox`, `melange`, `material-palenight`, `tomorrow-night`, `snazzy`, `iceberg`, `papercolor-light`, `synthwave-outrun`, `cobalt`, `modus-vivendi`, `modus-operandi`, `horizon`, `sonokai`, `clair-obscur`, `clair-obscur-canvas`, `mario-overworld`, `mario-underground`, `pip-boy`, `tarnished`, `hyrule`, `doom`, `phantom`, `cavern-hush`, `test-chamber`, `ember`, `meadow`, `dojo`, `underworld`, `summit`, `rain-noir`, `blocky`, `everforest-light`, `ayu-light`, `duskfox`,
13//!   `porsche`, `colorblind`, `high-contrast`, `mono`.
14//! * [`Theme::from_base`] / [`Theme::from_palette`] – derive a full theme from a
15//!   few colors your app already has.
16//! * Semantic styles – [`Theme::style`], [`Theme::selected_style`],
17//!   [`Theme::border_style`], [`Theme::status_style`] …
18//! * [`color`] – mix / lighten / darken, WCAG contrast, [`color::readable_on`],
19//!   256/16-color quantisation.
20//! * [`ColorSupport`] + [`Theme::downgrade`] – adapt to the terminal
21//!   (`COLORTERM`, `TERM`, `NO_COLOR`).
22//! * [`Themed`] / [`ThemeProvider`] – glue for widget crates and app theme types.
23//! * [`ThemeSwitcher`] – cycle themes in demos.
24//!
25//! ```
26//! use ratatui::{style::Color, widgets::{Block, Borders, Paragraph}};
27//! use tui_nuances::{Status, Theme};
28//!
29//! let theme = Theme::by_name("tokyo-night").unwrap();
30//! let block = Block::default()
31//!     .borders(Borders::ALL)
32//!     .border_style(theme.border_style(true))
33//!     .title_style(theme.title_style())
34//!     .style(theme.style());
35//! let ok = Paragraph::new("all good").style(theme.status_style(Status::Success));
36//! # let _ = (block, ok);
37//! assert!(theme.palette.len() >= 8);
38//! ```
39//!
40//! # Features
41//!
42//! * `serde` – `Serialize`/`Deserialize` for [`Theme`] (flat map of color strings).
43//!
44//! # Depending on it
45//!
46//! ```toml
47//! tui-nuances = { git = "https://github.com/sorinirimies/tui-nuances" }
48//! ```
49
50#![warn(missing_docs)]
51
52#[macro_use]
53mod macros;
54
55mod builtin;
56pub mod color;
57mod provider;
58mod roles;
59mod style;
60mod support;
61mod switcher;
62mod theme;
63
64pub use provider::{ThemeProvider, Themed};
65pub use style::Status;
66pub use support::ColorSupport;
67pub use switcher::ThemeSwitcher;
68pub use theme::{Theme, DEFAULT_PALETTE};