AppTheme

Struct AppTheme 

Source
pub struct AppTheme {
Show 20 fields pub primary: Color, pub secondary: Color, pub accent: Color, pub error: Color, pub warning: Color, pub success: Color, pub info: Color, pub text: Color, pub text_muted: Color, pub selected_text: Color, pub background: Color, pub background_panel: Color, pub background_element: Color, pub background_menu: Color, pub border: Color, pub border_active: Color, pub border_subtle: Color, pub diff: DiffColors, pub markdown: MarkdownColors, pub syntax: SyntaxColors,
}
Available on crate feature theme only.
Expand description

Comprehensive application theme with all widget colors.

This struct provides a complete color scheme for TUI applications, covering all common UI elements and specialized widget colors.

§Theme Structure

The theme is organized into:

  1. UI Colors - Semantic colors for interactive elements
  2. Text Colors - Colors for text content
  3. Background Colors - Surface and container backgrounds
  4. Border Colors - Border and divider colors
  5. Diff Colors - Colors for diff rendering
  6. Markdown Colors - Colors for markdown content
  7. Syntax Colors - Colors for code syntax highlighting

§Loading from JSON

Use AppTheme::from_json or the loader module to load themes from opencode-format JSON files.

Fields§

§primary: Color

Primary UI color for main interactive elements.

Used for primary buttons, active selections, and key UI elements.

§secondary: Color

Secondary UI color for supporting elements.

Used for secondary buttons and less prominent interactive elements.

§accent: Color

Accent color for highlighting and emphasis.

Used to draw attention to specific UI elements.

§error: Color

Error color for error states and messages.

Used for error indicators, validation errors, and destructive actions.

§warning: Color

Warning color for warning states and messages.

Used for warnings and caution indicators.

§success: Color

Success color for success states and messages.

Used for success indicators and confirmation feedback.

§info: Color

Info color for informational elements.

Used for help text, hints, and informational messages.

§text: Color

Primary text color for main content.

The default color for body text and content.

§text_muted: Color

Muted text color for secondary content.

Used for less important text, placeholders, and hints.

§selected_text: Color

Text color for selected items.

Used for text within selected or highlighted regions.

§background: Color

Main background color.

The primary application background.

§background_panel: Color

Panel background color.

Used for content panels and cards.

§background_element: Color

Element background color.

Used for interactive elements like buttons and inputs.

§background_menu: Color

Menu background color.

Used for dropdown menus and popover backgrounds.

§border: Color

Default border color.

Used for container borders and dividers.

§border_active: Color

Active border color.

Used for focused or active element borders.

§border_subtle: Color

Subtle border color.

Used for subtle dividers and less prominent borders.

§diff: DiffColors

Colors for diff rendering.

Contains all colors needed for the CodeDiff widget.

§markdown: MarkdownColors

Colors for markdown rendering.

Contains all colors needed for the MarkdownWidget.

§syntax: SyntaxColors

Colors for syntax highlighting.

Contains all colors needed for code syntax highlighting.

Implementations§

Source§

impl AppTheme

Source

pub fn from_json(json: &str, variant: ThemeVariant) -> Result<Self, String>

Creates an AppTheme from a JSON string in opencode format.

This parses the JSON, resolves all color references from the defs section, and constructs a complete theme.

§Arguments
  • json - The JSON string in opencode theme format
  • variant - Which theme variant (dark/light) to use
§Returns

Ok(AppTheme) if parsing succeeds, Err with a description otherwise.

§Errors

Returns an error if:

  • The JSON is malformed
  • Color values cannot be resolved
§Example
use ratatui_toolkit::services::theme::{AppTheme, ThemeVariant};

let json = r#"{
  "defs": { "myBlue": "#0066ff" },
  "theme": { "primary": { "dark": "myBlue", "light": "myBlue" } }
}"#;

let theme = AppTheme::from_json(json, ThemeVariant::Dark)
    .expect("Failed to parse theme");
Source

pub fn from_json_file<P: AsRef<Path>>( path: P, variant: ThemeVariant, ) -> Result<Self, String>

Creates an AppTheme from a JSON file path.

Reads the file and parses it as an opencode theme.

§Arguments
  • path - Path to the JSON theme file
  • variant - Which theme variant (dark/light) to use
§Returns

Ok(AppTheme) if the file can be read and parsed, Err with a description otherwise.

§Errors

Returns an error if:

  • The file cannot be read
  • The JSON is malformed
  • Color values cannot be resolved
§Example
use ratatui_toolkit::services::theme::{AppTheme, ThemeVariant};

let theme = AppTheme::from_json_file("themes/gruvbox.json", ThemeVariant::Dark)
    .expect("Failed to load theme");
Source§

impl AppTheme

Source

pub fn new( primary: Color, secondary: Color, accent: Color, error: Color, warning: Color, success: Color, info: Color, text: Color, text_muted: Color, selected_text: Color, background: Color, background_panel: Color, background_element: Color, background_menu: Color, border: Color, border_active: Color, border_subtle: Color, diff: DiffColors, markdown: MarkdownColors, syntax: SyntaxColors, ) -> Self

Creates a new AppTheme with all colors specified.

This is a low-level constructor that requires all colors to be provided. For most use cases, prefer AppTheme::default() or AppTheme::from_json().

§Arguments
  • primary - Primary UI color
  • secondary - Secondary UI color
  • accent - Accent color
  • error - Error color
  • warning - Warning color
  • success - Success color
  • info - Info color
  • text - Primary text color
  • text_muted - Muted text color
  • selected_text - Selected text color
  • background - Main background color
  • background_panel - Panel background color
  • background_element - Element background color
  • background_menu - Menu background color
  • border - Default border color
  • border_active - Active border color
  • border_subtle - Subtle border color
  • diff - Diff colors
  • markdown - Markdown colors
  • syntax - Syntax colors
§Returns

A new AppTheme instance with all colors configured.

§Example
use ratatui::style::Color;
use ratatui_toolkit::services::theme::{AppTheme, DiffColors, MarkdownColors, SyntaxColors};

let theme = AppTheme::new(
    Color::Blue, Color::Magenta, Color::Cyan,
    Color::Red, Color::Yellow, Color::Green, Color::LightBlue,
    Color::White, Color::Gray, Color::White,
    Color::Black, Color::DarkGray, Color::DarkGray, Color::DarkGray,
    Color::Gray, Color::White, Color::DarkGray,
    DiffColors::default(),
    MarkdownColors::default(),
    SyntaxColors::default(),
);
Source§

impl AppTheme

Source

pub fn get_color(&self, name: &str) -> Option<Color>

Gets a semantic color by name.

This method allows looking up theme colors by their semantic name, which is useful for dynamic color resolution from configuration.

§Arguments
  • name - The semantic name of the color (e.g., “primary”, “error”)
§Returns

Some(Color) if the name matches a known semantic color, None otherwise.

§Supported Names
  • UI: primary, secondary, accent, error, warning, success, info
  • Text: text, text_muted, selected_text
  • Background: background, background_panel, background_element, background_menu
  • Border: border, border_active, border_subtle
§Example
use ratatui_toolkit::services::theme::AppTheme;

let theme = AppTheme::default();
let primary = theme.get_color("primary");
assert!(primary.is_some());

Trait Implementations§

Source§

impl Clone for AppTheme

Source§

fn clone(&self) -> AppTheme

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 AppTheme

Source§

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

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

impl Default for AppTheme

Source§

fn default() -> Self

Creates a default application theme based on the Gruvbox dark theme.

This provides a cohesive dark theme that works well in most terminals and provides good contrast and readability.

§Returns

An AppTheme instance with Gruvbox dark colors.

Source§

impl PartialEq for AppTheme

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Eq for AppTheme

Source§

impl StructuralPartialEq for AppTheme

Auto Trait Implementations§

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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

Checks if this value is equivalent to the given key. 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<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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