Skip to content

Commit 9639ea5

Browse files
committed
make countdown shows on terminal title
1 parent d7db964 commit 9639ea5

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/main.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
io,
2+
io::{self, Write},
33
time::{Duration, Instant},
44
};
55

@@ -48,6 +48,11 @@ struct PomodoroSession {
4848
const HIGHLIGHT_COLOR: Color = Color::Rgb(0, 255, 150);
4949
const PRIMARY_COLOR: Color = Color::Rgb(144, 255, 161); //Color::Rgb(80,250,123);
5050

51+
fn set_terminal_title(title: &str) {
52+
print!("\x1b]0;{}\x07", title);
53+
io::stdout().flush().unwrap_or(());
54+
}
55+
5156
struct PomodoroTimer {
5257
current_session: PomodoroSession,
5358
mode: TimerMode,
@@ -275,6 +280,20 @@ impl PomodoroTimer {
275280
}
276281

277282
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+
278297
// If Mario animation is active, show it fullscreen
279298
if timer.show_mario_animation {
280299
let mario_canvas = timer.mario_animation.render(f.area());
@@ -540,6 +559,9 @@ fn run_timer() -> Result<(), Box<dyn std::error::Error>> {
540559
disable_raw_mode()?;
541560
execute!(terminal.backend_mut(), LeaveAlternateScreen)?;
542561
terminal.show_cursor()?;
562+
563+
// Restore terminal title
564+
set_terminal_title("Terminal");
543565

544566
result
545567
}

0 commit comments

Comments
 (0)