feat: display current time
This commit is contained in:
@@ -4,5 +4,6 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
chrono = "0.4.31"
|
||||||
crossterm = "0.27.0"
|
crossterm = "0.27.0"
|
||||||
|
|
||||||
|
|||||||
27
src/main.rs
27
src/main.rs
@@ -4,6 +4,7 @@ use std::{
|
|||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use chrono::{Local, Timelike};
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
cursor,
|
cursor,
|
||||||
event::{self, Event, KeyCode, KeyModifiers},
|
event::{self, Event, KeyCode, KeyModifiers},
|
||||||
@@ -65,7 +66,11 @@ fn main() -> io::Result<()> {
|
|||||||
fn render_frame() -> io::Result<()> {
|
fn render_frame() -> io::Result<()> {
|
||||||
let (width, height) = terminal::size()?;
|
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_width = 6 + 7 + 6 + 7 + 6;
|
||||||
let text_height = 5;
|
let text_height = 5;
|
||||||
let color = Color::White;
|
let color = Color::White;
|
||||||
@@ -73,11 +78,23 @@ fn render_frame() -> io::Result<()> {
|
|||||||
let x = width / 2 - text_width / 2;
|
let x = width / 2 - text_width / 2;
|
||||||
let y = height / 2 - text_height / 2;
|
let y = height / 2 - text_height / 2;
|
||||||
|
|
||||||
draw_symbol('1', x - 0 + 0 * 7, y, color)?;
|
// Hour
|
||||||
draw_symbol('6', x - 0 + 1 * 7, y, color)?;
|
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(':', 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(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user