From 0716720b77bc7d93443a917ca203626909b0a69a Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Thu, 18 Jan 2024 23:50:04 +0100 Subject: [PATCH] feat: display date --- config | 2 +- src/main.rs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/config b/config index 0641e37..8e3954d 100644 --- a/config +++ b/config @@ -14,7 +14,7 @@ fps=30 # Which color mode to use # Value: "term", "hex" or "ansi" -color_mode=ansi +color_mode=term # Loaded if color_mode is set to "term" # Value: 0-15 diff --git a/src/main.rs b/src/main.rs index ced1e62..ffa3806 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ use crossterm::{ cursor, event::{self, Event, KeyCode, KeyModifiers}, execute, queue, - style::{self, Color}, + style::{self, Attribute, Color}, terminal::{self, ClearType}, }; @@ -102,6 +102,21 @@ fn render_frame(config: &Config) -> io::Result<()> { } draw_symbol(minute.chars().last().unwrap(), x - 2 + 4 * 7, y, color)?; + // Display date + let date = time.date_naive().format("%Y-%m-%d").to_string(); + let mut stdout = io::stdout(); + + let x = width / 2 - (date.len() as u16) / 2; + let y = height / 2 + text_height / 2 + 2; + + queue!( + stdout, + cursor::MoveTo(x, y), + style::SetForegroundColor(color), + style::SetAttribute(Attribute::Bold) + )?; + write!(stdout, "{}", date)?; + return Ok(()); }