From d73724c31a87b69fd53e6fcef87bd2b0bbb21115 Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 17 Oct 2024 23:40:47 -0700 Subject: [PATCH 1/5] Remove unneeded write for clippy --- src/csv.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/csv.rs b/src/csv.rs index 0706b86..5cf95f8 100644 --- a/src/csv.rs +++ b/src/csv.rs @@ -98,7 +98,7 @@ impl Writer for CSVWriter { let lines = writables.map(|c| c.to_csv()).collect::(); // Open file in append mode - let mut file = match OpenOptions::new().write(true).append(true).open(&self.path) { + let mut file = match OpenOptions::new().append(true).open(&self.path) { Ok(file) => file, Err(..) => { logger.log("Could not open file for writing.", logger::Severity::Error); From 0fe21234536aeca550e340b7af7a44161436c86c Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 17 Oct 2024 23:43:56 -0700 Subject: [PATCH 2/5] Change format collect to string function --- src/daemon.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/daemon.rs b/src/daemon.rs index 48cea28..302251d 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -380,8 +380,12 @@ impl Checker for Daemon { fn preprint_render(&mut self) -> String { let message = format!("{}\n", self.message); let title = "Name\tMax\tMin\tFreq\tTemp\tUsage\tGovernor\n"; + // Render each line of cpu core - let cpus = &self.cpus.iter().map(|c| format!("{c}")).collect::(); + let mut cpus = String::new(); + for c in &self.cpus { + cpus.push_str(&c.to_string()); + } // Prints battery percent or N/A if not let battery_status = print_battery_status(&self.battery); From f8563b5839460a3e16b909b64af546d4ffbae640 Mon Sep 17 00:00:00 2001 From: pibiba Date: Fri, 22 Nov 2024 13:33:15 +0700 Subject: [PATCH 3/5] Add chrono to dependencies list --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 664d45c..25d575b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ cached = "0.42.0" rand = "0.8.5" globset = "0.4" time = { version = "0.3", features = ["local-offset", "formatting"]} +chrono = "0.4.38" [dev-dependencies] criterion = { version = "0.4", features = ["html_reports"] } From 429bf263d98992ed62225aa27349ff3b42981dc2 Mon Sep 17 00:00:00 2001 From: pibiba Date: Fri, 22 Nov 2024 13:40:19 +0700 Subject: [PATCH 4/5] Update time handling to rely solely on chrono --- src/logger.rs | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/logger.rs b/src/logger.rs index 6b8a336..798dfc2 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -3,13 +3,12 @@ //! It allows the program to log messages with different severity levels (error, warning, log) and display them in a human-readable format. //! //! The log messages contain a timestamp, a severity level and the message. The logs are stored in a vector and are serializable and deserializable. The logs can also be displayed in a human-readable format. -extern crate time; use efcl::{color, Color}; use serde::{Deserialize, Serialize}; use std::fmt; use std::time::SystemTime; -use time::{format_description, OffsetDateTime}; +use chrono::{DateTime, Local}; #[derive(Debug, Eq, PartialEq, Serialize, Deserialize)] /// The Severity enum is used to represent the different levels of severity of a log message. It has three possible values: @@ -44,22 +43,9 @@ impl fmt::Display for Log { Severity::Log => color!(Color::BLUE, "notice:"), }; - let date_time_fmt = - format_description::parse("[year]-[month]-[day] [hour]:[minute]:[second]") - .expect("Invalid time format."); + let local_time: DateTime = DateTime::::from(self.timestamp); - let mut time = OffsetDateTime::from(self.timestamp) - .format(&date_time_fmt) - .unwrap(); - - if OffsetDateTime::now_local().is_ok() { - time = OffsetDateTime::now_local() - .expect("IndeterminateOffset") - .format(&date_time_fmt) - .unwrap(); - } - - write!(f, "{} {} -> {}", severity, time, self.message) + write!(f, "{} {} -> {}", severity, local_time.format("%Y-%m-%d %H:%M:%S"), self.message) } } From 8e7e94607db2ac2cc25292a0df2e1b7f13909735 Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 26 Nov 2024 23:21:57 -0800 Subject: [PATCH 5/5] Format --- src/logger.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/logger.rs b/src/logger.rs index 798dfc2..d75a178 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -4,11 +4,11 @@ //! //! The log messages contain a timestamp, a severity level and the message. The logs are stored in a vector and are serializable and deserializable. The logs can also be displayed in a human-readable format. +use chrono::{DateTime, Local}; use efcl::{color, Color}; use serde::{Deserialize, Serialize}; use std::fmt; use std::time::SystemTime; -use chrono::{DateTime, Local}; #[derive(Debug, Eq, PartialEq, Serialize, Deserialize)] /// The Severity enum is used to represent the different levels of severity of a log message. It has three possible values: @@ -45,7 +45,13 @@ impl fmt::Display for Log { let local_time: DateTime = DateTime::::from(self.timestamp); - write!(f, "{} {} -> {}", severity, local_time.format("%Y-%m-%d %H:%M:%S"), self.message) + write!( + f, + "{} {} -> {}", + severity, + local_time.format("%Y-%m-%d %H:%M:%S"), + self.message + ) } }