From 3eefbad6d50ccbc81ed9d306dd64c1f3c2b6af55 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Wed, 14 Aug 2024 19:42:58 +0300 Subject: [PATCH] feat: allow setting multiple tag filters at once --- README.md | 4 ++-- src/main.rs | 3 ++- src/tasks.rs | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d2af762..0b58640 100644 --- a/README.md +++ b/README.md @@ -120,9 +120,9 @@ Dots and slashes can be repeated to move to parent tasks. Property Filters: -- `#TAG` - set tag filter (empty: list all used tags) +- `#TAG1 TAG2` - set tag filter (empty: list all used tags) - `+TAG` - add tag filter -- `-TAG` - remove tag filters +- `-TAG` - remove tag filters by prefix - `?STATUS` - filter by status (type or description) - plain `?` to reset, `??` to show all - `@AUTHOR` - filter by author (`@` for self, id prefix, name prefix) - TBI: Filter by time diff --git a/src/main.rs b/src/main.rs index ce483f9..1ec7603 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,7 @@ use env_logger::Builder; use itertools::Itertools; use log::{debug, error, info, LevelFilter, trace, warn}; use nostr_sdk::prelude::*; +use nostr_sdk::TagStandard::Hashtag; use regex::Regex; use xdg::BaseDirectories; @@ -456,7 +457,7 @@ async fn main() { Some('#') => match arg { - Some(arg) => tasks.set_tag(arg.to_string()), + Some(arg) => tasks.set_tags(arg.split_whitespace().map(|s| Hashtag(s.to_string()).into())), None => { println!("Hashtags of all known tasks:\n{}", tasks.all_hashtags().join(" ")); continue; diff --git a/src/tasks.rs b/src/tasks.rs index eb70139..74bb71e 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -128,6 +128,7 @@ impl Tasks { ], sorting: VecDeque::from([ "state".into(), + "hashtags".into(), "rtime".into(), "name".into(), ]), @@ -485,10 +486,10 @@ impl Tasks { info!("Removed all filters"); } - pub(crate) fn set_tag(&mut self, tag: String) { + pub(crate) fn set_tags(&mut self, tags: impl IntoIterator) { self.tags_excluded.clear(); self.tags.clear(); - self.add_tag(tag); + self.tags.extend(tags); } pub(crate) fn add_tag(&mut self, tag: String) {