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,
}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:
- UI Colors - Semantic colors for interactive elements
- Text Colors - Colors for text content
- Background Colors - Surface and container backgrounds
- Border Colors - Border and divider colors
- Diff Colors - Colors for diff rendering
- Markdown Colors - Colors for markdown content
- 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: ColorPrimary UI color for main interactive elements.
Used for primary buttons, active selections, and key UI elements.
secondary: ColorSecondary UI color for supporting elements.
Used for secondary buttons and less prominent interactive elements.
accent: ColorAccent color for highlighting and emphasis.
Used to draw attention to specific UI elements.
error: ColorError color for error states and messages.
Used for error indicators, validation errors, and destructive actions.
warning: ColorWarning color for warning states and messages.
Used for warnings and caution indicators.
success: ColorSuccess color for success states and messages.
Used for success indicators and confirmation feedback.
info: ColorInfo color for informational elements.
Used for help text, hints, and informational messages.
text: ColorPrimary text color for main content.
The default color for body text and content.
text_muted: ColorMuted text color for secondary content.
Used for less important text, placeholders, and hints.
selected_text: ColorText color for selected items.
Used for text within selected or highlighted regions.
background: ColorMain background color.
The primary application background.
background_panel: ColorPanel background color.
Used for content panels and cards.
background_element: ColorElement background color.
Used for interactive elements like buttons and inputs.
Menu background color.
Used for dropdown menus and popover backgrounds.
border: ColorDefault border color.
Used for container borders and dividers.
border_active: ColorActive border color.
Used for focused or active element borders.
border_subtle: ColorSubtle border color.
Used for subtle dividers and less prominent borders.
diff: DiffColorsColors for diff rendering.
Contains all colors needed for the CodeDiff widget.
markdown: MarkdownColorsColors for markdown rendering.
Contains all colors needed for the MarkdownWidget.
syntax: SyntaxColorsColors for syntax highlighting.
Contains all colors needed for code syntax highlighting.
Implementations§
Source§impl AppTheme
impl AppTheme
Sourcepub fn from_json(json: &str, variant: ThemeVariant) -> Result<Self, String>
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 formatvariant- 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");Sourcepub fn from_json_file<P: AsRef<Path>>(
path: P,
variant: ThemeVariant,
) -> Result<Self, String>
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 filevariant- 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
impl AppTheme
Sourcepub 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
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 colorsecondary- Secondary UI coloraccent- Accent colorerror- Error colorwarning- Warning colorsuccess- Success colorinfo- Info colortext- Primary text colortext_muted- Muted text colorselected_text- Selected text colorbackground- Main background colorbackground_panel- Panel background colorbackground_element- Element background colorbackground_menu- Menu background colorborder- Default border colorborder_active- Active border colorborder_subtle- Subtle border colordiff- Diff colorsmarkdown- Markdown colorssyntax- 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
impl AppTheme
Sourcepub fn get_color(&self, name: &str) -> Option<Color>
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§
impl Eq for AppTheme
impl StructuralPartialEq for AppTheme
Auto Trait Implementations§
impl Freeze for AppTheme
impl RefUnwindSafe for AppTheme
impl Send for AppTheme
impl Sync for AppTheme
impl Unpin for AppTheme
impl UnwindSafe for AppTheme
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().