Skip to main content

Theme

Struct Theme 

Source
pub struct Theme {
Show 14 fields pub palette: Palette, pub symbols: Symbols, pub text: Style, pub muted: Style, pub accent: Style, pub success: Style, pub warning: Style, pub error: Style, pub border: Style, pub focused_border: Style, pub title: Style, pub selected: Style, pub help_key: Style, pub help_desc: Style,
}
Expand description

Semantic style tokens and widget helpers for a Charm-like ratatui UI.

Fields§

§palette: Palette

Source palette used to build semantic styles.

§symbols: Symbols

Shared symbols used by helper methods.

§text: Style

Main text style.

§muted: Style

Muted secondary text style.

§accent: Style

Primary accent style.

§success: Style

Success style.

§warning: Style

Warning style.

§error: Style

Error style.

§border: Style

Normal border style.

§focused_border: Style

Focused border style.

§title: Style

Block title style.

§selected: Style

Selected row/item style.

§help_key: Style

Help key style.

§help_desc: Style

Help description style.

Implementations§

Source§

impl Theme

Source

pub fn new(palette: Palette, symbols: Symbols) -> Self

Builds a theme from a palette and symbol set.

Source

pub fn block<'a>(&self) -> Block<'a>

Creates a rounded bordered block using the theme’s default border and title styles.

Source

pub fn block_with_focus<'a>(&self, focused: bool) -> Block<'a>

Creates a rounded bordered block with focus-aware border styling.

Examples found in repository?
examples/themed-widgets.rs (line 17)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let theme = BubbleTheme::default();
8    let backend = TestBackend::new(48, 8);
9    let mut terminal = Terminal::new(backend)?;
10
11    terminal.draw(|frame| {
12        let area = frame.area();
13        let inner = area.inner(Margin::new(2, 1));
14
15        frame.render_widget(
16            theme
17                .block_with_focus(true)
18                .title(theme.title("ratatui-bubbletea")),
19            area,
20        );
21
22        frame.render_widget(
23            theme.paragraph(vec![
24                theme.bullet("Plain ratatui loop"),
25                theme.checked("Charm-like defaults"),
26                theme.help_line([("q", "quit"), ("?", "help")]),
27            ]),
28            inner,
29        );
30    })?;
31
32    Ok(())
33}
Source

pub fn titled_block<'a, T>(&self, title: T) -> Block<'a>
where T: Into<Line<'a>>,

Creates a rounded, titled block using the theme’s default title style.

Source

pub fn modal_block<'a>(&self) -> Block<'a>

Creates a modal-style block with the focused/accent border style.

This is intended for the common Clear + centered-popup pattern.

Source

pub fn titled_modal_block<'a, T>(&self, title: T) -> Block<'a>
where T: Into<Line<'a>>,

Creates a titled modal-style block with the focused/accent border style.

Source

pub fn paragraph<'a, T>(&self, text: T) -> Paragraph<'a>
where T: Into<Text<'a>>,

Creates a paragraph using the theme’s normal text style.

Examples found in repository?
examples/themed-widgets.rs (lines 23-27)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let theme = BubbleTheme::default();
8    let backend = TestBackend::new(48, 8);
9    let mut terminal = Terminal::new(backend)?;
10
11    terminal.draw(|frame| {
12        let area = frame.area();
13        let inner = area.inner(Margin::new(2, 1));
14
15        frame.render_widget(
16            theme
17                .block_with_focus(true)
18                .title(theme.title("ratatui-bubbletea")),
19            area,
20        );
21
22        frame.render_widget(
23            theme.paragraph(vec![
24                theme.bullet("Plain ratatui loop"),
25                theme.checked("Charm-like defaults"),
26                theme.help_line([("q", "quit"), ("?", "help")]),
27            ]),
28            inner,
29        );
30    })?;
31
32    Ok(())
33}
Source

pub fn paragraph_in_block<'a, T, L>(&self, text: T, title: L) -> Paragraph<'a>
where T: Into<Text<'a>>, L: Into<Line<'a>>,

Creates a paragraph with a themed block attached.

Source

pub fn span<'a, T>(&self, content: T) -> Span<'a>
where T: Into<Cow<'a, str>>,

Creates a normal text span.

Source

pub fn muted<'a, T>(&self, content: T) -> Span<'a>
where T: Into<Cow<'a, str>>,

Creates a muted text span.

Source

pub fn accent<'a, T>(&self, content: T) -> Span<'a>
where T: Into<Cow<'a, str>>,

Creates an accent text span.

Source

pub fn success<'a, T>(&self, content: T) -> Span<'a>
where T: Into<Cow<'a, str>>,

Creates a success text span.

Source

pub fn warning<'a, T>(&self, content: T) -> Span<'a>
where T: Into<Cow<'a, str>>,

Creates a warning text span.

Source

pub fn error<'a, T>(&self, content: T) -> Span<'a>
where T: Into<Cow<'a, str>>,

Creates an error text span.

Source

pub fn title<'a, T>(&self, content: T) -> Line<'a>
where T: Into<Cow<'a, str>>,

Creates a title line.

Examples found in repository?
examples/themed-widgets.rs (line 18)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let theme = BubbleTheme::default();
8    let backend = TestBackend::new(48, 8);
9    let mut terminal = Terminal::new(backend)?;
10
11    terminal.draw(|frame| {
12        let area = frame.area();
13        let inner = area.inner(Margin::new(2, 1));
14
15        frame.render_widget(
16            theme
17                .block_with_focus(true)
18                .title(theme.title("ratatui-bubbletea")),
19            area,
20        );
21
22        frame.render_widget(
23            theme.paragraph(vec![
24                theme.bullet("Plain ratatui loop"),
25                theme.checked("Charm-like defaults"),
26                theme.help_line([("q", "quit"), ("?", "help")]),
27            ]),
28            inner,
29        );
30    })?;
31
32    Ok(())
33}
Source

pub fn bullet<'a, T>(&self, content: T) -> Line<'a>
where T: Into<Cow<'a, str>>,

Creates a line prefixed with the default bullet symbol.

Examples found in repository?
examples/themed-widgets.rs (line 24)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let theme = BubbleTheme::default();
8    let backend = TestBackend::new(48, 8);
9    let mut terminal = Terminal::new(backend)?;
10
11    terminal.draw(|frame| {
12        let area = frame.area();
13        let inner = area.inner(Margin::new(2, 1));
14
15        frame.render_widget(
16            theme
17                .block_with_focus(true)
18                .title(theme.title("ratatui-bubbletea")),
19            area,
20        );
21
22        frame.render_widget(
23            theme.paragraph(vec![
24                theme.bullet("Plain ratatui loop"),
25                theme.checked("Charm-like defaults"),
26                theme.help_line([("q", "quit"), ("?", "help")]),
27            ]),
28            inner,
29        );
30    })?;
31
32    Ok(())
33}
Source

pub fn checked<'a, T>(&self, content: T) -> Line<'a>
where T: Into<Cow<'a, str>>,

Creates a success line prefixed with the default check symbol.

Examples found in repository?
examples/themed-widgets.rs (line 25)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let theme = BubbleTheme::default();
8    let backend = TestBackend::new(48, 8);
9    let mut terminal = Terminal::new(backend)?;
10
11    terminal.draw(|frame| {
12        let area = frame.area();
13        let inner = area.inner(Margin::new(2, 1));
14
15        frame.render_widget(
16            theme
17                .block_with_focus(true)
18                .title(theme.title("ratatui-bubbletea")),
19            area,
20        );
21
22        frame.render_widget(
23            theme.paragraph(vec![
24                theme.bullet("Plain ratatui loop"),
25                theme.checked("Charm-like defaults"),
26                theme.help_line([("q", "quit"), ("?", "help")]),
27            ]),
28            inner,
29        );
30    })?;
31
32    Ok(())
33}
Source

pub fn crossed<'a, T>(&self, content: T) -> Line<'a>
where T: Into<Cow<'a, str>>,

Creates an error line prefixed with the default cross symbol.

Source

pub fn help_line<'a, I, K, D>(&self, bindings: I) -> Line<'a>
where I: IntoIterator<Item = (K, D)>, K: Into<Cow<'a, str>>, D: Into<Cow<'a, str>>,

Creates a compact help line from (key, description) pairs.

Examples found in repository?
examples/themed-widgets.rs (line 26)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let theme = BubbleTheme::default();
8    let backend = TestBackend::new(48, 8);
9    let mut terminal = Terminal::new(backend)?;
10
11    terminal.draw(|frame| {
12        let area = frame.area();
13        let inner = area.inner(Margin::new(2, 1));
14
15        frame.render_widget(
16            theme
17                .block_with_focus(true)
18                .title(theme.title("ratatui-bubbletea")),
19            area,
20        );
21
22        frame.render_widget(
23            theme.paragraph(vec![
24                theme.bullet("Plain ratatui loop"),
25                theme.checked("Charm-like defaults"),
26                theme.help_line([("q", "quit"), ("?", "help")]),
27            ]),
28            inner,
29        );
30    })?;
31
32    Ok(())
33}

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Theme

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Theme

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 Eq for Theme

Source§

impl Hash for Theme

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Theme

Source§

fn eq(&self, other: &Theme) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Theme

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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.