diff --git a/src/main.rs b/src/main.rs index e8c8cbb..3ef63e3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,9 +37,9 @@ struct Cli { enum Commands { Debug {}, Chrono {}, - Countdown { + Timer { #[arg(required = true)] - start: Vec, + duration: Vec, }, } @@ -104,9 +104,9 @@ fn main() -> io::Result<()> { match &cli.command { Some(Commands::Chrono {}) => modes::chrono::main_loop(&mut config)?, - Some(Commands::Countdown { start }) => { - let start = start.join(" "); - modes::countdown::main_loop(&mut config, &start)? + Some(Commands::Timer { duration }) => { + let duration = duration.join(" "); + modes::timer::main_loop(&mut config, &duration)? } Some(Commands::Debug {}) => unreachable!(), None => modes::clock::main_loop(&mut config)?, diff --git a/src/modes/mod.rs b/src/modes/mod.rs index 3b59ebd..cfeb73d 100644 --- a/src/modes/mod.rs +++ b/src/modes/mod.rs @@ -1,4 +1,4 @@ pub mod chrono; pub mod clock; -pub mod countdown; pub mod debug; +pub mod timer; diff --git a/src/modes/countdown.rs b/src/modes/timer.rs similarity index 85% rename from src/modes/countdown.rs rename to src/modes/timer.rs index 1f6a1a9..a3222b4 100644 --- a/src/modes/countdown.rs +++ b/src/modes/timer.rs @@ -16,16 +16,16 @@ use crate::{ rendering::{self, symbols}, }; -struct Countdown { +struct Timer { duration: Duration, end_time: Option, paused_duration: Duration, } -impl Countdown { +impl Timer { fn new(duration: Duration) -> Self { let end_time = Some(Instant::now() + duration + Duration::from_secs(1)); - Countdown { + Timer { duration, end_time, paused_duration: Duration::ZERO, @@ -71,11 +71,11 @@ impl Countdown { } } -pub fn main_loop(config: &mut Config, start: &str) -> io::Result<()> { +pub fn main_loop(config: &mut Config, duration: &str) -> io::Result<()> { let mut stdout = io::stdout(); - let duration = parse_duration::parse(start).unwrap(); - let mut countdown = Countdown::new(duration); + let duration = parse_duration::parse(duration).unwrap(); + let mut timer = Timer::new(duration); let mut quit = false; while !quit { @@ -91,11 +91,11 @@ pub fn main_loop(config: &mut Config, start: &str) -> io::Result<()> { } // Handle pause KeyCode::Char(' ') => { - countdown.toggle_pause(); + timer.toggle_pause(); } // Handle reset KeyCode::Char('r') => { - countdown.reset(); + timer.reset(); } _ => {} }, @@ -107,7 +107,7 @@ pub fn main_loop(config: &mut Config, start: &str) -> io::Result<()> { queue!(stdout, terminal::Clear(ClearType::All))?; // Render - render_frame(&config, &countdown)?; + render_frame(&config, &timer)?; config.color.update(); @@ -119,17 +119,17 @@ pub fn main_loop(config: &mut Config, start: &str) -> io::Result<()> { return Ok(()); } -fn render_frame(config: &Config, countdown: &Countdown) -> io::Result<()> { +fn render_frame(config: &Config, timer: &Timer) -> io::Result<()> { let color = config.color.get_value(); // Display time - let remaining = utils::format_duration(countdown.time_left()); + let remaining = utils::format_duration(timer.time_left()); rendering::draw_time(&remaining, color)?; // Display pause state let (width, height) = terminal::size()?; let y = height / 2 + symbols::SYMBOL_HEIGHT as u16 / 2 + 2; - if countdown.is_paused() { + if timer.is_paused() { let text = "[PAUSE]"; let x = width / 2 - (text.len() as u16) / 2; @@ -141,7 +141,7 @@ fn render_frame(config: &Config, countdown: &Countdown) -> io::Result<()> { )?; } // Display finish state - else if countdown.is_finished() { + else if timer.is_finished() { let text = "[FINISHED]"; let x = width / 2 - (text.len() as u16) / 2;