|
1 | 1 | // Copyright © 2025 Huly Labs. Use of this source code is governed by the MIT license. |
2 | 2 | use std::collections::{HashMap, HashSet}; |
3 | 3 | use std::io::Write; |
4 | | -use std::path::PathBuf; |
| 4 | +use std::path::{Path, PathBuf}; |
| 5 | +use std::time::SystemTime; |
5 | 6 | use std::{fs, vec}; |
6 | 7 |
|
7 | 8 | use crate::agent::event::{AgentCommandStatus, AgentState, ConfirmToolResponse}; |
@@ -105,6 +106,7 @@ pub struct App<'a> { |
105 | 106 | pub theme: Theme, |
106 | 107 | pub model: ModelState, |
107 | 108 | pub ui: UiState<'a>, |
| 109 | + pub autoreload_theme: bool, |
108 | 110 | } |
109 | 111 |
|
110 | 112 | impl UiState<'_> { |
@@ -144,16 +146,19 @@ impl App<'_> { |
144 | 146 | sender: mpsc::UnboundedSender<agent::AgentControlEvent>, |
145 | 147 | receiver: mpsc::UnboundedReceiver<agent::AgentOutputEvent>, |
146 | 148 | messages: Vec<Message>, |
| 149 | + autoreload_theme: bool, |
147 | 150 | ) -> Self { |
| 151 | + let theme = Theme::load(&config.appearance.theme).unwrap(); |
148 | 152 | Self { |
149 | 153 | ui: UiState::new(config.workspace.clone()), |
150 | 154 | config, |
151 | 155 | data_dir, |
152 | 156 | running: true, |
153 | 157 | events: UiEventMultiplexer::new(receiver), |
154 | 158 | agent_sender: sender, |
155 | | - theme: Theme::default(), |
| 159 | + theme, |
156 | 160 | model: ModelState::new(messages, model_info), |
| 161 | + autoreload_theme, |
157 | 162 | } |
158 | 163 | } |
159 | 164 |
|
@@ -223,7 +228,20 @@ impl App<'_> { |
223 | 228 | if !self.model.messages.is_empty() { |
224 | 229 | self.ui.history_follow_last = true; |
225 | 230 | } |
| 231 | + let autoload_theme = |
| 232 | + self.autoreload_theme && Path::new(&self.config.appearance.theme).exists(); |
| 233 | + let mut last_theme_modified = SystemTime::now(); |
226 | 234 | while self.running { |
| 235 | + if autoload_theme { |
| 236 | + let current_theme_modified = |
| 237 | + std::fs::metadata(&self.config.appearance.theme)?.modified()?; |
| 238 | + if current_theme_modified != last_theme_modified { |
| 239 | + if let Ok(theme) = Theme::load(&self.config.appearance.theme) { |
| 240 | + self.theme = theme; |
| 241 | + } |
| 242 | + last_theme_modified = current_theme_modified; |
| 243 | + } |
| 244 | + } |
227 | 245 | terminal.draw(|frame| frame.render_widget(&mut self, frame.area()))?; |
228 | 246 |
|
229 | 247 | match self.events.next().await? { |
|
0 commit comments