feat: allow setting multiple tag filters at once

This commit is contained in:
xeruf 2024-08-14 19:42:58 +03:00
parent b544616801
commit 3eefbad6d5
3 changed files with 7 additions and 5 deletions

View File

@ -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

View File

@ -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;

View File

@ -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<Item=Tag>) {
self.tags_excluded.clear();
self.tags.clear();
self.add_tag(tag);
self.tags.extend(tags);
}
pub(crate) fn add_tag(&mut self, tag: String) {