From 0eac501b4a188365735246e0a7ccd30bae05badd Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 19 Jul 2024 09:59:18 +0200 Subject: [PATCH] refactor(uidata): change name of the struct and the idx --- src/clock.rs | 6 +++--- src/clock/ui.rs | 28 ++++++++++++++-------------- src/main.rs | 4 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/clock.rs b/src/clock.rs index 9f45cc9..99ad61b 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -20,7 +20,7 @@ use std::time::Instant; pub mod timebar; pub mod ui; use timebar::TimeBarLength; -use ui::UiData; +use ui::Data; /// Make your terminal into a big clock #[derive(Parser, Debug, Clone)] @@ -190,7 +190,7 @@ impl Clock { ) -> anyhow::Result<()> { let tick_rate = std::time::Duration::from_millis(100); let mut last_tick = Instant::now(); - let mut uidata: UiData = UiData::default(); + let mut uidata: Data = Data::default(); self.setup()?; loop { let raw_time = chrono::Local::now().round_subsecs(0); @@ -251,7 +251,7 @@ impl Clock { fn ui( &mut self, terminal: &mut Terminal>, - data: &UiData, + data: &Data, ) -> anyhow::Result<()> { terminal.draw(|frame| { debug!("rendering the ui"); diff --git a/src/clock/ui.rs b/src/clock/ui.rs index 91453b0..0aa3ebd 100644 --- a/src/clock/ui.rs +++ b/src/clock/ui.rs @@ -9,16 +9,16 @@ use crate::clock::timebar::TimeBarLength; use super::Clock; #[derive(Debug, Clone, PartialEq, Default)] -pub struct UiData { +pub struct Data { now: [DateTime; 2], fdate: [String; 2], ftime: [String; 2], timebar_ratio: [Option; 2], - data_idx: usize, + idx: usize, } -impl UiData { +impl Data { pub fn update( &mut self, now: DateTime, @@ -26,11 +26,11 @@ impl UiData { ftime: String, timebar_ratio: Option, ) { - self.data_idx ^= 1; - self.now[self.data_idx] = now; - self.fdate[self.data_idx] = fdate; - self.ftime[self.data_idx] = ftime; - self.timebar_ratio[self.data_idx] = timebar_ratio; + self.idx ^= 1; + self.now[self.idx] = now; + self.fdate[self.idx] = fdate; + self.ftime[self.idx] = ftime; + self.timebar_ratio[self.idx] = timebar_ratio; #[cfg(debug_assertions)] if self.changed() { trace!("update with change: {:#?}", self); @@ -49,32 +49,32 @@ impl UiData { #[must_use] #[inline] pub fn fdate(&self) -> &str { - &self.fdate[self.data_idx] + &self.fdate[self.idx] } #[must_use] #[inline] pub fn ftime(&self) -> &str { - &self.ftime[self.data_idx] + &self.ftime[self.idx] } #[must_use] #[inline] pub fn now(&self) -> &DateTime { - &self.now[self.data_idx] + &self.now[self.idx] } #[must_use] #[inline] #[allow(clippy::missing_const_for_fn)] // no it's not const pub fn timebar_ratio(&self) -> Option { - self.timebar_ratio[self.data_idx] + self.timebar_ratio[self.idx] } } pub fn timebarw<'a>( clock: &mut Clock, - data: &UiData, + data: &Data, timebarw_padding: &[u16], inner_rect: Rect, ) -> Option> { @@ -122,7 +122,7 @@ pub fn timebarw<'a>( pub fn timebarw_label<'a>( clock: &Clock, - data: &UiData, + data: &Data, timebarw_padding: &[u16], inner_rect: Rect, ) -> Option> { diff --git a/src/main.rs b/src/main.rs index 6f44694..2294a51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,7 +63,7 @@ fn mock_tests() { use chrono::{Local, Timelike}; use libpt::log::info; - use crate::clock::ui::UiData; + use crate::clock::ui::Data; info!("doing the mock tests"); { let mut c = Clock::parse_from(["some exec", "-mvvv"]); @@ -81,7 +81,7 @@ fn mock_tests() { info!("0s=0.0"); } { - let mut data = UiData::default(); + let mut data = Data::default(); let now = Local::now(); data.update(now, "date".to_owned(), "time".to_owned(), Some(0.1)); assert_eq!(data.timebar_ratio(), Some(0.1));