diff --git a/Cargo.toml b/Cargo.toml index 94a4276..3873843 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,5 +4,6 @@ version = "0.1.0" edition = "2021" [dependencies] +chrono = "0.4.31" crossterm = "0.27.0" diff --git a/src/main.rs b/src/main.rs index aa16053..48b7dd1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use std::{ time::Duration, }; +use chrono::{Local, Timelike}; use crossterm::{ cursor, event::{self, Event, KeyCode, KeyModifiers}, @@ -65,7 +66,11 @@ fn main() -> io::Result<()> { fn render_frame() -> io::Result<()> { let (width, height) = terminal::size()?; - // Display centered 16:20 in white + let time = Local::now(); + let hour = time.hour().to_string(); + let minute = time.minute().to_string(); + + // Display current time let text_width = 6 + 7 + 6 + 7 + 6; let text_height = 5; let color = Color::White; @@ -73,11 +78,23 @@ fn render_frame() -> io::Result<()> { let x = width / 2 - text_width / 2; let y = height / 2 - text_height / 2; - draw_symbol('1', x - 0 + 0 * 7, y, color)?; - draw_symbol('6', x - 0 + 1 * 7, y, color)?; + // Hour + if hour.len() == 1 { + draw_symbol('0', x - 0 + 0 * 7, y, color)?; + } else { + draw_symbol(hour.chars().nth(0).unwrap(), x - 0 + 0 * 7, y, color)?; + } + draw_symbol(hour.chars().last().unwrap(), x - 0 + 1 * 7, y, color)?; + draw_symbol(':', x - 1 + 2 * 7, y, color)?; - draw_symbol('2', x - 2 + 3 * 7, y, color)?; - draw_symbol('0', x - 2 + 4 * 7, y, color)?; + + // Minutes + if minute.len() == 1 { + draw_symbol('0', x - 2 + 3 * 7, y, color)?; + } else { + draw_symbol(minute.chars().nth(0).unwrap(), x - 2 + 3 * 7, y, color)?; + } + draw_symbol(minute.chars().last().unwrap(), x - 2 + 4 * 7, y, color)?; return Ok(()); }