feat: make hashtag interactions more dynamic
This commit is contained in:
parent
cc1e9d4d69
commit
5dbea00562
|
@ -5,7 +5,6 @@ use log::info;
|
|||
use nostr_sdk::TagStandard::Hashtag;
|
||||
use nostr_sdk::{Alphabet, EventBuilder, EventId, Kind, Tag, TagKind, TagStandard};
|
||||
use std::borrow::Cow;
|
||||
use std::iter::once;
|
||||
|
||||
pub const TASK_KIND: Kind = Kind::GitIssue;
|
||||
pub const PROCEDURE_KIND_ID: u16 = 1639;
|
||||
|
@ -150,8 +149,10 @@ pub(crate) fn to_prio_tag(value: Prio) -> Tag {
|
|||
|
||||
#[test]
|
||||
fn test_extract_tags() {
|
||||
assert_eq!(extract_tags("Hello from #mars with #greetings *4 # yeah done-it"),
|
||||
assert_eq!(extract_tags("Hello from #mars with #greetings *4 # # yeah done-it"),
|
||||
("Hello from #mars with #greetings".to_string(),
|
||||
["mars", "greetings", "yeah", "done-it"].into_iter().map(to_hashtag)
|
||||
.chain(once(Tag::custom(TagKind::Custom(Cow::from(PRIO)), [40.to_string()]))).collect()))
|
||||
.chain(std::iter::once(Tag::custom(TagKind::Custom(Cow::from(PRIO)), [40.to_string()]))).collect()));
|
||||
assert_eq!(extract_tags("So tagless #"),
|
||||
("So tagless".to_string(), vec![]));
|
||||
}
|
16
src/main.rs
16
src/main.rs
|
@ -4,8 +4,7 @@ use std::env::{args, var};
|
|||
use std::fs;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader, Write};
|
||||
use std::iter::once;
|
||||
use std::ops::{Add, Sub};
|
||||
use std::ops::Sub;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
|
@ -28,7 +27,7 @@ use tokio::time::timeout;
|
|||
|
||||
use crate::helpers::*;
|
||||
use crate::kinds::{Prio, BASIC_KINDS, PROPERTY_COLUMNS, PROP_KINDS, TRACKING_KIND};
|
||||
use crate::task::{State, Task, TaskState, MARKER_DEPENDS};
|
||||
use crate::task::{State, Task, TaskState};
|
||||
use crate::tasks::{PropertyCollection, StateFilter, TasksRelay};
|
||||
|
||||
mod helpers;
|
||||
|
@ -621,18 +620,21 @@ async fn main() -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
Some('#') =>
|
||||
tasks.set_tags(arg_default.split_whitespace().map(|s| Hashtag(s.to_string()).into())),
|
||||
Some('#') => {
|
||||
if !tasks.update_tags(arg_default.split_whitespace().map(|s| Hashtag(s.to_string()).into())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Some('+') =>
|
||||
match arg {
|
||||
Some(arg) => tasks.add_tag(arg.to_string()),
|
||||
None => {
|
||||
println!("Hashtags of all known tasks:\n{}", tasks.all_hashtags().join(" ").italic());
|
||||
tasks.print_hashtags();
|
||||
if tasks.has_tag_filter() {
|
||||
println!("Use # to remove tag filters and . to remove all filters.")
|
||||
}
|
||||
continue 'repl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
21
src/tasks.rs
21
src/tasks.rs
|
@ -647,7 +647,26 @@ impl TasksRelay {
|
|||
!self.tags.is_empty() || !self.tags_excluded.is_empty()
|
||||
}
|
||||
|
||||
pub(crate) fn set_tags(&mut self, tags: impl IntoIterator<Item=Tag>) {
|
||||
pub(crate) fn print_hashtags(&self) {
|
||||
println!("Hashtags of all known tasks:\n{}", self.all_hashtags().join(" ").italic());
|
||||
}
|
||||
|
||||
/// Returns true if tags have been updated, false if it printed something
|
||||
pub(crate) fn update_tags(&mut self, tags: impl IntoIterator<Item=Tag>) -> bool {
|
||||
let mut peekable = tags.into_iter().peekable();
|
||||
if self.tags.is_empty() && peekable.peek().is_none() {
|
||||
if !self.tags_excluded.is_empty() {
|
||||
self.tags_excluded.clear();
|
||||
}
|
||||
self.print_hashtags();
|
||||
false
|
||||
} else {
|
||||
self.set_tags(peekable);
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
fn set_tags(&mut self, tags: impl IntoIterator<Item=Tag>) {
|
||||
self.tags.clear();
|
||||
self.tags.extend(tags);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue