From 1cbcf1453c0b9a85ac9254816162d3e621342251 Mon Sep 17 00:00:00 2001 From: Ernaldis Date: Fri, 15 Sep 2023 13:43:58 -0500 Subject: [PATCH] format code --- src/controller/list.rs | 6 ++++-- src/data/activity.rs | 9 ++++++--- src/data/getter.rs | 18 +++++++++--------- src/view/table.rs | 14 +++++++------- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/controller/list.rs b/src/controller/list.rs index 337a648..3e5dbad 100644 --- a/src/controller/list.rs +++ b/src/controller/list.rs @@ -115,8 +115,10 @@ fn print_activity_with_line(activity: &Activity, line_number: usize) { "{} (Started: {}, Ended: {}, Line: {})\n", activity.description, activity.start.format(conf::FORMAT_DATETIME), - activity - .end.map_or_else(|| String::from("--"), |end| end.format(conf::FORMAT_DATETIME).to_string()), + activity.end.map_or_else( + || String::from("--"), + |end| end.format(conf::FORMAT_DATETIME).to_string() + ), line_number ) } diff --git a/src/data/activity.rs b/src/data/activity.rs index 7dce2a9..837269a 100644 --- a/src/data/activity.rs +++ b/src/data/activity.rs @@ -23,7 +23,8 @@ pub enum ActivityError { } impl Activity { - #[must_use] pub fn start(project: String, description: String, time: Option) -> Self { + #[must_use] + pub fn start(project: String, description: String, time: Option) -> Self { Self { start: time.unwrap_or_else(|| Local::now().naive_local()), end: None, @@ -36,11 +37,13 @@ impl Activity { self.end = time.or_else(|| Some(Local::now().naive_local())); } - #[must_use] pub fn is_stopped(&self) -> bool { + #[must_use] + pub fn is_stopped(&self) -> bool { self.end.is_some() } - #[must_use] pub fn get_duration(&self) -> Duration { + #[must_use] + pub fn get_duration(&self) -> Duration { if let Some(end) = self.end { end.signed_duration_since(self.start) } else { diff --git a/src/data/getter.rs b/src/data/getter.rs index 6fbd981..d3a3a08 100644 --- a/src/data/getter.rs +++ b/src/data/getter.rs @@ -13,7 +13,8 @@ pub struct ActivityFilter<'a> { pub project: Option<&'a str>, } -#[must_use] pub fn get_descriptions_and_projects( +#[must_use] +pub fn get_descriptions_and_projects( file_content: &[bartib_file::Line], ) -> Vec<(&String, &String)> { let mut activities: Vec<&activity::Activity> = get_activities(file_content).collect(); @@ -49,7 +50,8 @@ fn get_descriptions_and_projects_from_activities<'a>( descriptions_and_projects } -#[must_use] pub fn get_running_activities(file_content: &[bartib_file::Line]) -> Vec<&activity::Activity> { +#[must_use] +pub fn get_running_activities(file_content: &[bartib_file::Line]) -> Vec<&activity::Activity> { get_activities(file_content) .filter(|activity| !activity.is_stopped()) .collect() @@ -91,14 +93,11 @@ pub fn filter_activities<'a>( .filter(move |activity| { activity.start.date() >= from_date && activity.start.date() <= to_date }) - .filter(move |activity| { - filter - .project - .map_or(true, |p| activity.project == *p) - }) + .filter(move |activity| filter.project.map_or(true, |p| activity.project == *p)) } -#[must_use] pub fn get_last_activity_by_end(file_content: &[bartib_file::Line]) -> Option<&activity::Activity> { +#[must_use] +pub fn get_last_activity_by_end(file_content: &[bartib_file::Line]) -> Option<&activity::Activity> { get_activities(file_content) .filter(|activity| activity.is_stopped()) .max_by_key(|activity| { @@ -108,7 +107,8 @@ pub fn filter_activities<'a>( }) } -#[must_use] pub fn get_last_activity_by_start( +#[must_use] +pub fn get_last_activity_by_start( file_content: &[bartib_file::Line], ) -> Option<&activity::Activity> { get_activities(file_content).max_by_key(|activity| activity.start) diff --git a/src/view/table.rs b/src/view/table.rs index bf2cc87..02c4289 100644 --- a/src/view/table.rs +++ b/src/view/table.rs @@ -190,8 +190,7 @@ impl Table { impl fmt::Display for Table { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let terminal_width = term_size::dimensions_stdout() - .map_or(conf::DEFAULT_WIDTH, |d| d.0); + let terminal_width = term_size::dimensions_stdout().map_or(conf::DEFAULT_WIDTH, |d| d.0); let column_width = self.get_column_width(terminal_width - self.columns.len()); @@ -249,7 +248,11 @@ fn write_cells + std::fmt::Display>( }) .collect(); - let most_lines: usize = wrapped_cells.iter().map(std::vec::Vec::len).max().unwrap_or(1); + let most_lines: usize = wrapped_cells + .iter() + .map(std::vec::Vec::len) + .max() + .unwrap_or(1); for line in 0..most_lines { for (width, wrapped_cell) in column_width.iter().zip(wrapped_cells.iter()) { @@ -279,10 +282,7 @@ fn write_with_width_and_style( // cells are filled with non-breaking white space. Contrary to normal spaces non-breaking white // space will be styled (e.g. underlined) - write!( - f, - "{style_prefix}{content:\u{a0}