Compare commits

..

No commits in common. "7a8a048d6c1f4d545d089fbbe736687fc8a71a1f" and "b62ec6fd399e74aa1646fbd83df937e2148fcc30" have entirely different histories.

5 changed files with 47 additions and 120 deletions

View File

@ -94,7 +94,6 @@ To stop time-tracking completely, simply move to the root of all tasks.
+ no match: create & activate task
- `.2` - set view depth to `2`, which can be substituted for any number (how many subtask levels to show, default 1)
- `/[TEXT]` - like `.`, but never creates a task
- `|[TASK]` - (un)mark current task as procedure or create and activate a new task procedure (where subtasks automatically depend on the previously created task)
Dots can be repeated to move to parent tasks.
@ -133,7 +132,6 @@ An active tag or state filter will also set that attribute for newly created tas
- `rtime` - time tracked on this tasks and all recursive subtasks
- `progress` - recursive subtask completion in percent
- `subtasks` - how many direct subtasks are complete
- TBI `depends`
For debugging: `props`, `alltags`, `descriptions`
@ -153,7 +151,6 @@ Considering to use Calendar: https://github.com/nostr-protocol/nips/blob/master/
## Plans
- Remove state filter when moving up?
- Task markdown support? - colored
- Time tracking: Ability to postpone task and add planned timestamps (calendar entry)
- Parse Hashtag tags from task name
@ -171,8 +168,6 @@ The following features are not ready to be implemented
because they need conceptualization.
Suggestions welcome!
- Task Dependencies
- Task Templates
- Task Ownership
- Combined formatting and recursion specifiers
+ progress count/percentage and recursive or not

View File

@ -3,9 +3,8 @@ use log::info;
use nostr_sdk::{Alphabet, EventBuilder, EventId, Kind, Tag, TagStandard};
pub const TASK_KIND: u16 = 1621;
pub const PROCEDURE_KIND: u16 = 1639;
pub const TRACKING_KIND: u16 = 1650;
pub const KINDS: [u16; 8] = [1, TASK_KIND, TRACKING_KIND, PROCEDURE_KIND, 1630, 1631, 1632, 1633];
pub const KINDS: [u16; 7] = [1, TASK_KIND, TRACKING_KIND, 1630, 1631, 1632, 1633];
pub const PROPERTY_COLUMNS: &str = "Available properties:
- `id`

View File

@ -294,7 +294,7 @@ async fn main() {
continue;
},
Some(',') =>
Some(',') => {
match arg {
None => {
tasks.get_current_task().map_or_else(
@ -305,6 +305,7 @@ async fn main() {
}
Some(arg) => tasks.make_note(arg),
}
}
Some('>') => {
tasks.update_state(&arg_default, State::Done);
@ -320,41 +321,18 @@ async fn main() {
tasks.undo();
}
Some('|') =>
match arg {
None => match tasks.get_position() {
None => {
tasks.set_filter(
tasks.current_tasks().into_iter()
.filter(|t| t.pure_state() == State::Procedure)
.map(|t| t.event.id)
.collect()
);
}
Some(id) => {
tasks.set_state_for(id, "", State::Procedure);
}
},
Some(arg) => {
let id = tasks.make_task(arg);
tasks.set_state_for(id, "", State::Procedure);
tasks.move_to(Some(id));
}
}
Some('?') => {
tasks.set_state_filter(arg.map(|s| s.to_string()));
}
Some('!') =>
match tasks.get_position() {
Some('!') => match tasks.get_position() {
None => warn!("First select a task to set its state!"),
Some(id) => {
tasks.set_state_for_with(id, arg_default);
}
}
},
Some('#') =>
Some('#') => {
match arg {
Some(arg) => tasks.set_tag(arg.to_string()),
None => {
@ -362,21 +340,23 @@ async fn main() {
continue;
}
}
}
Some('+') =>
Some('+') => {
match arg {
Some(arg) => tasks.add_tag(arg.to_string()),
None => tasks.clear_filter()
}
}
Some('-') =>
Some('-') => {
match arg {
Some(arg) => tasks.remove_tag(arg),
None => tasks.clear_filter()
}
}
Some('*') =>
match arg {
Some('*') => match arg {
Some(arg) => {
if let Ok(num) = arg.parse::<i64>() {
tasks.track_at(Timestamp::from(Timestamp::now().as_u64().saturating_add_signed(num)));
@ -388,7 +368,7 @@ async fn main() {
}
None => {
println!("{}", tasks.times_tracked());
continue;
continue
}
}
@ -442,7 +422,7 @@ async fn main() {
}
}
_ =>
_ => {
if Regex::new("^wss?://").unwrap().is_match(&input) {
tasks.move_to(None);
let mut new_relay = relays.keys().find(|key| key.as_str().starts_with(&input)).cloned();
@ -466,6 +446,7 @@ async fn main() {
tasks.filter_or_create(&input);
}
}
}
or_print(tasks.print_tasks());
}
Some(Err(e)) => warn!("{}", e),

View File

@ -1,5 +1,4 @@
use fmt::Display;
use std::cmp::Ordering;
use std::collections::{BTreeSet, HashSet};
use std::fmt;
@ -9,47 +8,29 @@ use log::{debug, error, info, trace, warn};
use nostr_sdk::{Event, EventBuilder, EventId, Kind, Tag, TagStandard, Timestamp};
use crate::helpers::some_non_empty;
use crate::kinds::{is_hashtag, PROCEDURE_KIND};
use crate::kinds::is_hashtag;
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct Task {
/// Event that defines this task
pub(crate) event: Event,
/// Cached sorted tags of the event with references remove - do not modify!
pub(crate) tags: Option<BTreeSet<Tag>>,
/// Parent task references derived from the event tags
parents: Vec<EventId>,
/// Reference to children, populated dynamically
pub(crate) children: HashSet<EventId>,
/// Events belonging to this task, such as state updates and notes
pub(crate) props: BTreeSet<Event>,
}
impl PartialOrd<Self> for Task {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.event.partial_cmp(&other.event)
}
}
impl Ord for Task {
fn cmp(&self, other: &Self) -> Ordering {
self.event.cmp(&other.event)
}
/// Cached sorted tags of the event
pub(crate) tags: Option<BTreeSet<Tag>>,
parents: Vec<EventId>,
}
impl Task {
pub(crate) fn new(event: Event) -> Task {
let (refs, tags) = event.tags.iter().partition_map(|tag| match tag.as_standardized() {
let (parents, tags) = event.tags.iter().partition_map(|tag| match tag.as_standardized() {
Some(TagStandard::Event { event_id, .. }) => return Left(event_id),
_ => Right(tag.clone()),
});
// Separate refs for dependencies
Task {
children: Default::default(),
props: Default::default(),
tags: Some(tags).filter(|t: &BTreeSet<Tag>| !t.is_empty()),
parents: refs,
parents,
event,
}
}
@ -136,7 +117,6 @@ impl Task {
"hashtags" => self.filter_tags(|tag| { is_hashtag(tag) }),
"tags" => self.filter_tags(|_| true),
"alltags" => Some(format!("{:?}", self.tags)),
"parents" => Some(format!("{:?}", self.parents.iter().map(|id| id.to_string()).collect_vec())),
"props" => Some(format!(
"{:?}",
self.props
@ -192,20 +172,18 @@ impl Display for TaskState {
pub(crate) enum State {
Closed,
Open,
Procedure,
Pending,
Active,
Done,
}
impl TryFrom<Kind> for State {
type Error = ();
fn try_from(value: Kind) -> Result<Self, Self::Error> {
match value.as_u16() {
match value.as_u32() {
1630 => Ok(State::Open),
1631 => Ok(State::Done),
1632 => Ok(State::Closed),
1633 => Ok(State::Pending),
PROCEDURE_KIND => Ok(State::Procedure),
1633 => Ok(State::Active),
_ => Err(()),
}
}
@ -213,7 +191,7 @@ impl TryFrom<Kind> for State {
impl State {
pub(crate) fn is_open(&self) -> bool {
match self {
State::Open | State::Procedure => true,
State::Open | State::Active => true,
_ => false,
}
}
@ -223,8 +201,7 @@ impl State {
State::Open => 1630,
State::Done => 1631,
State::Closed => 1632,
State::Pending => 1633,
State::Procedure => PROCEDURE_KIND,
State::Active => 1633,
}
}
}

View File

@ -11,9 +11,8 @@ use chrono::LocalResult::Single;
use colored::Colorize;
use itertools::Itertools;
use log::{debug, error, info, trace, warn};
use nostr_sdk::{Event, EventBuilder, EventId, Keys, Kind, PublicKey, Tag, TagStandard, Timestamp, UncheckedUrl, Url};
use nostr_sdk::{Event, EventBuilder, EventId, Keys, Kind, PublicKey, Tag, TagStandard, Timestamp, Url};
use nostr_sdk::base64::write::StrConsumer;
use nostr_sdk::prelude::Marker;
use TagStandard::Hashtag;
use crate::{Events, EventSender};
@ -307,7 +306,7 @@ impl Tasks {
// TODO apply filters in transit
let state = t.pure_state();
self.state.as_ref().map_or_else(|| {
state.is_open() || (
state == State::Open || (
state == State::Done &&
t.parent_id() != None
)
@ -383,13 +382,13 @@ impl Tasks {
.map_or(String::new(), |p| format!("{:2.0}%", p * 100.0)),
"path" => self.get_task_path(Some(task.event.id)),
"rpath" => self.relative_path(task.event.id),
// TODO format strings configurable
// TODO format strings as config
"time" => display_time("MMMm", self.time_tracked(*task.get_id())),
"rtime" => {
let time = self.total_time_tracked(*task.get_id());
total_time += time;
display_time("HH:MM", time)
}
},
prop => task.get(prop).unwrap_or(String::new()),
})
.collect::<Vec<String>>()
@ -541,31 +540,7 @@ impl Tasks {
/// Sanitizes input
pub(crate) fn make_task(&mut self, input: &str) -> EventId {
let tag: Option<Tag> = self.get_current_task()
.and_then(|t| {
println!("{:?}", t);
if t.pure_state() == State::Procedure {
t.children.iter()
.filter_map(|id| self.get_by_id(id))
.max()
.map(|t| {
Tag::from(
TagStandard::Event {
event_id: t.event.id,
relay_url: self.sender.url.as_ref().map(|url| UncheckedUrl::new(url.as_str())),
marker: Some(Marker::Custom("depends".to_string())),
public_key: Some(t.event.pubkey),
}
)
})
} else {
None
}
});
let id = self.submit(
self.parse_task(input.trim())
.add_tags(tag.into_iter())
);
let id = self.submit(self.parse_task(input.trim()));
self.state.clone().inspect(|s| self.set_state_for_with(id, s));
id
}
@ -629,7 +604,7 @@ impl Tasks {
t.children.insert(event.id);
});
if self.tasks.contains_key(&event.id) {
debug!("Did not insert duplicate event {}", event.id); // TODO warn in next sdk version
warn!("Did not insert duplicate event {}", event.id);
} else {
self.tasks.insert(event.id, Task::new(event));
}