diff --git a/src/tasks/list.rs b/src/tasks/list.rs index a474e41..dfa074c 100644 --- a/src/tasks/list.rs +++ b/src/tasks/list.rs @@ -1,5 +1,24 @@ use async_std::prelude::FutureExt as _; +macro_rules! tags { + ($self:ident, $kind:ident) => {{ + let today = crate::date::today(); + let preferences = crate::application::preferences(); + + $self + .inner + .iter() + .filter(|x| { + (preferences.done || !x.finished) + && (preferences.defered + || x.threshold_date.is_none() + || x.threshold_date.unwrap() <= today) + }) + .collect::>() + .$kind() + }}; +} + #[derive(Clone, Debug, Default)] pub struct List { pub inner: todo_txt::task::List, @@ -60,27 +79,15 @@ impl List { } pub fn projects(&self) -> Vec { - let today = crate::date::today(); - - self.inner - .iter() - .filter(|x| { - !x.finished && (x.threshold_date.is_none() || x.threshold_date.unwrap() <= today) - }) - .collect::>() - .projects() + tags!(self, projects) } pub fn contexts(&self) -> Vec { - let today = crate::date::today(); + tags!(self, contexts) + } - self.inner - .iter() - .filter(|x| { - !x.finished && (x.threshold_date.is_none() || x.threshold_date.unwrap() <= today) - }) - .collect::>() - .contexts() + pub fn hashtags(&self) -> Vec { + tags!(self, hashtags) } pub fn write(&self) -> Result<(), String> {