sanpii/todo-txt

Feature: access subject stripped of contexts/projects/hashtags

Closed this issue · 2 comments

Would it be possible to add a subject_stripped field to the Task struct that would contain the subject but without contexts, projects or hashtags ? This stripped subject can be more relevant than the full subject line in certain situations, since the contexts/... are already gathered in separate fields of the Task struct.
My particular use case is to compare tasks in order to diff two todo.txt files.

I don’t like this idea. I think it’s a special usecase for your application, you can create a trait to extend task funtionnalities.

trait Orderable {
    fn text() -> String;

    fn order(self, other: Self) -> ::std::cmp::Ordering{
        self.text().cmp(other.text())
    }
}

impl Orderable for Task {
    fn text() -> String {
        self.subject // strip the task subject if you want
    }
}

But it’s maybe a good idea to implement the ::std::cmp::Ord trait for Task? Is ordering rule clear enough to implement its for everyone?

Ok, I was mostly concerned about avoiding to parse contexts/projects again since this lib does it once already.
To answer your question though, I do not believe there is a clear ordering on tasks since a lot of different orderings (by completion, by due date, by priority, ...) make sense.