From 059ad9f66b38f2ea963bd735963102a38eedc7a8 Mon Sep 17 00:00:00 2001 From: Jan Willems Date: Sun, 18 Feb 2024 15:41:40 +0100 Subject: [PATCH] feat: Added running clock: #1. --- Cargo.lock | 3 +++ Cargo.toml | 1 + src/main.rs | 11 +++++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ad7f137..4d1520e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,6 +70,7 @@ name = "brt" version = "0.1.0" dependencies = [ "anyhow", + "chrono", "crossterm", "dirs", "itertools", @@ -122,7 +123,9 @@ checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" dependencies = [ "android-tzdata", "iana-time-zone", + "js-sys", "num-traits", + "wasm-bindgen", "windows-targets 0.52.0", ] diff --git a/Cargo.toml b/Cargo.toml index 45c9152..3be0f41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,4 @@ itertools = "0.12.1" log = "0.4.20" dirs = "5.0.1" log4rs = "1.3.0" +chrono = "0.4.34" diff --git a/src/main.rs b/src/main.rs index 50054f5..f03cca4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use chrono::{DateTime, Utc}; use std::path::PathBuf; use std::{ error::Error, @@ -11,7 +12,7 @@ use crossterm::{ execute, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, }; -use log::{debug, info, LevelFilter}; +use log::{info, LevelFilter}; use log4rs::append::file::FileAppender; use log4rs::config::{Appender, Logger, Root}; use log4rs::encode::pattern::PatternEncoder; @@ -22,6 +23,8 @@ use ratatui::{ }; const LOG_PATTERN: &str = "{d(%Y-%m-%d %H:%M:%S)} | {l} | {f}:{L} | {m}{n}"; +const NAME: &str = env!("CARGO_PKG_NAME"); +const VERSION: &str = env!("CARGO_PKG_VERSION"); // These type aliases are used to make the code more readable by reducing repetition of the generic // types. They are not necessary for the functionality of the code. @@ -30,8 +33,7 @@ type Result = std::result::Result>; fn main() -> Result<()> { initialize_logging(); - debug!("Hello there!"); - info!("This is brt. Version yokemebob."); + info!("This is {NAME}. Version {}.", VERSION); let mut terminal = setup_terminal()?; let result = run(&mut terminal); restore_terminal(terminal)?; @@ -125,6 +127,7 @@ fn ui(frame: &mut Frame) { .borders(Borders::ALL) .border_style(Style::default().fg(Color::White)) .border_type(BorderType::Rounded); - let paragraph = Paragraph::new(Line::from("The clock comes here.").centered()).block(block); + let now: DateTime = Utc::now(); + let paragraph = Paragraph::new(Line::from(now.to_string()).centered()).block(block); frame.render_widget(paragraph, layout[0]); }