1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
use directories::BaseDirs;
use notify_rust::Notification;
use ratatui::{style::Color, widgets::ListState};
use serde::{Deserialize, Serialize};
use std::{fs, time::Duration};
#[derive(Clone, Copy)]
pub struct Theme {
pub primary: Color,
pub overlay0: Color,
pub surface0: Color,
pub text: Color,
}
/// Color format rendered by noctalia v5's matugen template system.
/// Pomoru reads this from `~/.cache/pomoru/colors.json` when available.
#[derive(Deserialize)]
struct MatugenColors {
primary: String,
on_surface_variant: String,
surface_container: String,
on_surface: String,
}
/// Legacy color format from `~/.config/noctalia/colors.json` (noctalia < v5).
/// Kept for backward compatibility.
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct LegacyNoctaliaColors {
m_primary: String,
m_on_surface_variant: String,
m_surface_variant: String,
m_on_surface: String,
}
fn parse_hex_color(hex: &str) -> Option<Color> {
let hex = hex.trim_start_matches('#');
if hex.len() == 6 {
let r = u8::from_str_radix(&hex[0..2], 16).ok()?;
let g = u8::from_str_radix(&hex[2..4], 16).ok()?;
let b = u8::from_str_radix(&hex[4..6], 16).ok()?;
Some(Color::Rgb(r, g, b))
} else {
None
}
}
impl Theme {
pub fn load_with_mtime() -> (Self, Option<std::time::SystemTime>) {
// Catppuccin Mocha defaults — used when no theme file is present.
let mut theme = Self {
primary: Color::Rgb(180, 190, 254),
overlay0: Color::Rgb(108, 112, 134),
surface0: Color::Rgb(49, 50, 68),
text: Color::Rgb(205, 214, 244),
};
if let Some(base_dirs) = BaseDirs::new() {
// --- Priority 1: matugen / noctalia v5 rendered colors ---
let matugen_path = base_dirs
.home_dir()
.join(".cache/pomoru/colors.json");
if let Ok(metadata) = fs::metadata(&matugen_path) {
if let Ok(content) = fs::read_to_string(&matugen_path)
&& let Ok(colors) = serde_json::from_str::<MatugenColors>(&content)
{
if let Some(c) = parse_hex_color(&colors.primary) {
theme.primary = c;
}
if let Some(c) = parse_hex_color(&colors.on_surface_variant) {
theme.overlay0 = c;
}
if let Some(c) = parse_hex_color(&colors.surface_container) {
theme.surface0 = c;
}
if let Some(c) = parse_hex_color(&colors.on_surface) {
theme.text = c;
}
return (theme, metadata.modified().ok());
}
}
// --- Priority 2: legacy noctalia colors.json (noctalia < v5) ---
let legacy_path = base_dirs
.home_dir()
.join(".config/noctalia/colors.json");
if let Ok(metadata) = fs::metadata(&legacy_path) {
if let Ok(content) = fs::read_to_string(&legacy_path)
&& let Ok(colors) = serde_json::from_str::<LegacyNoctaliaColors>(&content)
{
if let Some(c) = parse_hex_color(&colors.m_primary) {
theme.primary = c;
}
if let Some(c) = parse_hex_color(&colors.m_on_surface_variant) {
theme.overlay0 = c;
}
if let Some(c) = parse_hex_color(&colors.m_surface_variant) {
theme.surface0 = c;
}
if let Some(c) = parse_hex_color(&colors.m_on_surface) {
theme.text = c;
}
return (theme, metadata.modified().ok());
}
}
}
(theme, None)
}
}
impl Default for Theme {
fn default() -> Self {
Theme::load_with_mtime().0
}
}
#[derive(PartialEq, Clone, Copy)]
pub enum SessionMode {
Work,
ShortBreak,
LongBreak,
}
#[derive(PartialEq, Clone, Copy)]
pub enum AppScreen {
Timer,
Tasks,
}
#[derive(PartialEq, Clone, Copy)]
pub enum InputMode {
Normal,
Insert,
Edit,
TimerEdit,
}
#[derive(Serialize, Deserialize)]
pub struct Config {
pub work_time_mins: u64,
pub short_break_mins: u64,
pub long_break_mins: u64,
pub tasks: Vec<Task>,
#[serde(default = "default_auto_switch")]
pub auto_switch_sessions: bool,
}
fn default_auto_switch() -> bool {
true
}
#[derive(Serialize)]
pub struct CurrentStatus {
pub text: String,
pub tooltip: String,
pub class: String,
}
#[derive(Serialize, Deserialize, Clone)]
pub struct Task {
pub title: String,
pub is_done: bool,
}
pub struct Pomo {
pub screen: AppScreen,
pub mode: SessionMode,
pub input_mode: InputMode,
pub work_time: Duration,
pub short_break_time: Duration,
pub long_break_time: Duration,
pub time_remaining: Duration,
pub total_duration: Duration,
pub is_running: bool,
pub auto_switch_sessions: bool,
pub break_count: u32,
pub tasks: Vec<Task>,
pub task_state: ListState,
pub input_buffer: String,
pub should_quit: bool,
pub theme: Theme,
pub theme_mtime: Option<std::time::SystemTime>,
}
impl Pomo {
pub fn new() -> Self {
let work = Duration::from_secs(25 * 60);
let (theme, theme_mtime) = Theme::load_with_mtime();
Self {
screen: AppScreen::Timer,
mode: SessionMode::Work,
input_mode: InputMode::Normal,
work_time: work,
short_break_time: Duration::from_secs(5 * 60),
long_break_time: Duration::from_secs(15 * 60),
time_remaining: work,
total_duration: work,
is_running: false,
auto_switch_sessions: true,
break_count: 0,
tasks: Vec::new(),
task_state: ListState::default(),
input_buffer: String::new(),
should_quit: false,
theme,
theme_mtime,
}
}
pub fn tick(&mut self) {
if self.is_running && self.time_remaining.as_secs() > 0 {
self.time_remaining -= Duration::from_secs(1);
} else if self.is_running && self.time_remaining.as_secs() == 0 {
let focus_msg = [
"I'm tired, boss...",
"Congrats! You're him 🗿",
"Stand up. Touch grass.",
"Mission Passed! Respect+",
];
let break_msg = [
"Ah shit, here we go again.",
"Wake up, Samurai. We have code to burn.",
"Lock back in.",
"Ref! Do Something! The break's over!",
];
// Use the remaining duration/break count as a seed for simple 'random' selection
let idx = (self.break_count as usize) % 4;
let (title, msg) = match self.mode {
SessionMode::Work => ("Focus Block Complete", focus_msg[idx]),
_ => ("Break Over", break_msg[idx]),
};
self.send_notification(title, msg);
if self.auto_switch_sessions {
self.transition_next_session();
self.is_running = true;
} else {
self.is_running = false;
self.reset_timer_to_mode();
}
|