|
1 | 1 | use std::{ |
2 | | - io, |
| 2 | + io::{self, Write}, |
3 | 3 | time::{Duration, Instant}, |
4 | 4 | }; |
5 | 5 |
|
@@ -48,6 +48,11 @@ struct PomodoroSession { |
48 | 48 | const HIGHLIGHT_COLOR: Color = Color::Rgb(0, 255, 150); |
49 | 49 | const PRIMARY_COLOR: Color = Color::Rgb(144, 255, 161); //Color::Rgb(80,250,123); |
50 | 50 |
|
| 51 | +fn set_terminal_title(title: &str) { |
| 52 | + print!("\x1b]0;{}\x07", title); |
| 53 | + io::stdout().flush().unwrap_or(()); |
| 54 | +} |
| 55 | + |
51 | 56 | struct PomodoroTimer { |
52 | 57 | current_session: PomodoroSession, |
53 | 58 | mode: TimerMode, |
@@ -275,6 +280,20 @@ impl PomodoroTimer { |
275 | 280 | } |
276 | 281 |
|
277 | 282 | fn ui(f: &mut Frame, timer: &PomodoroTimer) { |
| 283 | + // Update terminal title with countdown |
| 284 | + let (elapsed, total) = timer.get_timer_progress(); |
| 285 | + let remaining = if total > elapsed { total - elapsed } else { Duration::from_secs(0) }; |
| 286 | + let remaining_minutes = remaining.as_secs() / 60; |
| 287 | + let remaining_seconds = remaining.as_secs() % 60; |
| 288 | + |
| 289 | + let session_type = match timer.current_session.timer_type { |
| 290 | + TimerType::Work => "Work", |
| 291 | + TimerType::Break => "Break", |
| 292 | + }; |
| 293 | + |
| 294 | + let title = format!("CYBER TOMATO - {} {:02}:{:02}", session_type, remaining_minutes, remaining_seconds); |
| 295 | + set_terminal_title(&title); |
| 296 | + |
278 | 297 | // If Mario animation is active, show it fullscreen |
279 | 298 | if timer.show_mario_animation { |
280 | 299 | let mario_canvas = timer.mario_animation.render(f.area()); |
@@ -540,6 +559,9 @@ fn run_timer() -> Result<(), Box<dyn std::error::Error>> { |
540 | 559 | disable_raw_mode()?; |
541 | 560 | execute!(terminal.backend_mut(), LeaveAlternateScreen)?; |
542 | 561 | terminal.show_cursor()?; |
| 562 | + |
| 563 | + // Restore terminal title |
| 564 | + set_terminal_title("Terminal"); |
543 | 565 |
|
544 | 566 | result |
545 | 567 | } |
|
0 commit comments