Skip to main content

Theme

Struct Theme 

Source
pub struct Theme { /* private fields */ }
Expand description

Semantic color palette for TUI rendering.

A Theme provides named colors for every visual role in the UI — text, backgrounds, status indicators, markdown rendering, and diffs. Components access colors through the ViewContext rather than hardcoding values, making the entire UI re-skinnable.

When the syntax feature is enabled, the theme also caches a parsed syntect theme for syntax highlighting.

§Construction

Use the builder for custom themes — every field is required:

use tui::{Theme, Color};

let theme = Theme::builder()
    .fg(Color::White)
    .bg(Color::Black)
    .accent(Color::Cyan)
    .highlight_bg(Color::DarkBlue)
    .highlight_fg(Color::White)
    .text_secondary(Color::Grey)
    .code_fg(Color::Green)
    .code_bg(Color::Rgb { r: 30, g: 30, b: 30 })
    .heading(Color::Yellow)
    .link(Color::Blue)
    .blockquote(Color::DarkGrey)
    .muted(Color::DarkGrey)
    .success(Color::Green)
    .warning(Color::Yellow)
    .error(Color::Red)
    .info(Color::Cyan)
    .secondary(Color::Magenta)
    .sidebar_bg(Color::Rgb { r: 20, g: 20, b: 20 })
    .diff_added_fg(Color::Green)
    .diff_removed_fg(Color::Red)
    .diff_added_bg(Color::Rgb { r: 0, g: 20, b: 0 })
    .diff_removed_bg(Color::Rgb { r: 20, g: 0, b: 0 })
    .build()
    .unwrap();

Theme::default() provides a dark-theme preset.

§Color categories

  • Basefg, bg, accent, highlight_bg, highlight_fg
  • Texttext_secondary, code_fg, code_bg
  • Markdownheading, link, blockquote, muted
  • Statussuccess, warning, error, info, secondary
  • Layoutsidebar_bg
  • Diffsdiff_added_fg, diff_removed_fg, diff_added_bg, diff_removed_bg

§Helper methods

  • selected_row_style() — Returns a Style with highlight_fg on highlight_bg, suitable for selected list rows.
  • selected_row_style_with_fg(color) — Same but with a custom foreground.

§See also

Implementations§

Source§

impl Theme

Source

pub fn catppuccin_mocha() -> Self

Catppuccin Mocha theme (dark, high contrast).

This is the default theme and is always available without any additional dependencies.

Source

pub fn light() -> Self

A minimal light theme.

Source§

impl Theme

Source

pub fn syntect_theme(&self) -> &Theme

Return the cached syntect theme for syntax highlighting.

Source

pub fn load_from_path(path: &Path) -> Self

Load theme from a .tmTheme file.

Source§

impl Theme

Source

pub fn builder() -> ThemeBuilder

Source

pub fn primary(&self) -> Color

Source

pub fn text_primary(&self) -> Color

Source

pub fn background(&self) -> Color

Source

pub fn code_fg(&self) -> Color

Source

pub fn code_bg(&self) -> Color

Source

pub fn sidebar_bg(&self) -> Color

Source

pub fn accent(&self) -> Color

Source

pub fn highlight_bg(&self) -> Color

Source

pub fn highlight_fg(&self) -> Color

Source

pub fn selected_row_style(&self) -> Style

Source

pub fn selected_row_style_with_fg(&self, fg: Color) -> Style

Source

pub fn secondary(&self) -> Color

Source

pub fn text_secondary(&self) -> Color

Source

pub fn success(&self) -> Color

Source

pub fn warning(&self) -> Color

Source

pub fn error(&self) -> Color

Source

pub fn info(&self) -> Color

Source

pub fn muted(&self) -> Color

Source

pub fn heading(&self) -> Color

Source

pub fn blockquote(&self) -> Color

Source

pub fn diff_added_bg(&self) -> Color

Source

pub fn diff_removed_bg(&self) -> Color

Source

pub fn diff_added_fg(&self) -> Color

Source

pub fn diff_removed_fg(&self) -> Color

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Theme

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Theme

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Theme

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<&Theme> for Theme

Source§

fn from(syntect: &Theme) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Theme

§

impl RefUnwindSafe for Theme

§

impl Send for Theme

§

impl Sync for Theme

§

impl Unpin for Theme

§

impl UnsafeUnpin for Theme

§

impl UnwindSafe for Theme

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more