ratatui_toolkit/services/theme/app_theme/
mod.rs

1//! Application theme module for comprehensive TUI theming.
2//!
3//! This module provides [`AppTheme`] which is the main theme struct that
4//! contains all colors needed for a complete TUI application, including
5//! UI colors, text colors, background colors, border colors, and specialized
6//! color sets for diffs, markdown, and syntax highlighting.
7//!
8//! # Color Categories
9//!
10//! The theme is organized into logical categories:
11//!
12//! - **UI Colors**: `primary`, `secondary`, `accent`, `error`, `warning`, `success`, `info`
13//! - **Text Colors**: `text`, `text_muted`, `selected_text`
14//! - **Background Colors**: `background`, `background_panel`, `background_element`, `background_menu`
15//! - **Border Colors**: `border`, `border_active`, `border_subtle`
16//! - **Specialized**: [`DiffColors`], [`MarkdownColors`], [`SyntaxColors`]
17//!
18//! # Loading Themes
19//!
20//! Themes can be loaded from JSON files in the opencode format using the
21//! [`loader`](crate::services::theme::loader) module.
22//!
23//! # Example
24//!
25//! ```rust
26//! use ratatui_toolkit::services::theme::{AppTheme, ThemeVariant};
27//!
28//! // Use default theme
29//! let theme = AppTheme::default();
30//!
31//! // Access UI colors
32//! let primary = theme.primary;
33//! let error = theme.error;
34//!
35//! // Access specialized colors
36//! let diff_added = theme.diff.added;
37//! let heading_color = theme.markdown.heading;
38//! ```
39
40use ratatui::style::Color;
41
42use crate::services::theme::diff_colors::DiffColors;
43use crate::services::theme::markdown_colors::MarkdownColors;
44use crate::services::theme::syntax_colors::SyntaxColors;
45
46/// Comprehensive application theme with all widget colors.
47///
48/// This struct provides a complete color scheme for TUI applications,
49/// covering all common UI elements and specialized widget colors.
50///
51/// # Theme Structure
52///
53/// The theme is organized into:
54///
55/// 1. **UI Colors** - Semantic colors for interactive elements
56/// 2. **Text Colors** - Colors for text content
57/// 3. **Background Colors** - Surface and container backgrounds
58/// 4. **Border Colors** - Border and divider colors
59/// 5. **Diff Colors** - Colors for diff rendering
60/// 6. **Markdown Colors** - Colors for markdown content
61/// 7. **Syntax Colors** - Colors for code syntax highlighting
62///
63/// # Loading from JSON
64///
65/// Use [`AppTheme::from_json`] or the loader module to load themes
66/// from opencode-format JSON files.
67#[derive(Debug, Clone, PartialEq, Eq)]
68pub struct AppTheme {
69    // ========== UI Colors ==========
70    /// Primary UI color for main interactive elements.
71    ///
72    /// Used for primary buttons, active selections, and key UI elements.
73    pub primary: Color,
74
75    /// Secondary UI color for supporting elements.
76    ///
77    /// Used for secondary buttons and less prominent interactive elements.
78    pub secondary: Color,
79
80    /// Accent color for highlighting and emphasis.
81    ///
82    /// Used to draw attention to specific UI elements.
83    pub accent: Color,
84
85    /// Error color for error states and messages.
86    ///
87    /// Used for error indicators, validation errors, and destructive actions.
88    pub error: Color,
89
90    /// Warning color for warning states and messages.
91    ///
92    /// Used for warnings and caution indicators.
93    pub warning: Color,
94
95    /// Success color for success states and messages.
96    ///
97    /// Used for success indicators and confirmation feedback.
98    pub success: Color,
99
100    /// Info color for informational elements.
101    ///
102    /// Used for help text, hints, and informational messages.
103    pub info: Color,
104
105    // ========== Text Colors ==========
106    /// Primary text color for main content.
107    ///
108    /// The default color for body text and content.
109    pub text: Color,
110
111    /// Muted text color for secondary content.
112    ///
113    /// Used for less important text, placeholders, and hints.
114    pub text_muted: Color,
115
116    /// Text color for selected items.
117    ///
118    /// Used for text within selected or highlighted regions.
119    pub selected_text: Color,
120
121    // ========== Background Colors ==========
122    /// Main background color.
123    ///
124    /// The primary application background.
125    pub background: Color,
126
127    /// Panel background color.
128    ///
129    /// Used for content panels and cards.
130    pub background_panel: Color,
131
132    /// Element background color.
133    ///
134    /// Used for interactive elements like buttons and inputs.
135    pub background_element: Color,
136
137    /// Menu background color.
138    ///
139    /// Used for dropdown menus and popover backgrounds.
140    pub background_menu: Color,
141
142    // ========== Border Colors ==========
143    /// Default border color.
144    ///
145    /// Used for container borders and dividers.
146    pub border: Color,
147
148    /// Active border color.
149    ///
150    /// Used for focused or active element borders.
151    pub border_active: Color,
152
153    /// Subtle border color.
154    ///
155    /// Used for subtle dividers and less prominent borders.
156    pub border_subtle: Color,
157
158    // ========== Specialized Color Sets ==========
159    /// Colors for diff rendering.
160    ///
161    /// Contains all colors needed for the CodeDiff widget.
162    pub diff: DiffColors,
163
164    /// Colors for markdown rendering.
165    ///
166    /// Contains all colors needed for the MarkdownWidget.
167    pub markdown: MarkdownColors,
168
169    /// Colors for syntax highlighting.
170    ///
171    /// Contains all colors needed for code syntax highlighting.
172    pub syntax: SyntaxColors,
173}
174
175mod constructors;
176mod methods;
177mod traits;