diff --git a/src/task.rs b/src/task.rs index ee17711..aa078cf 100644 --- a/src/task.rs +++ b/src/task.rs @@ -219,6 +219,17 @@ pub(crate) enum State { Pending, Procedure, } +impl From<&str> for State { + fn from(value: &str) -> Self { + match value { + "Closed" => State::Closed, + "Done" => State::Done, + "Pending" => State::Pending, + "Proc" | "Procedure" | "List" => State::Procedure, + _ => State::Open, + } + } +} impl TryFrom for State { type Error = (); @@ -236,7 +247,7 @@ impl TryFrom for State { impl State { pub(crate) fn is_open(&self) -> bool { match self { - State::Open | State::Procedure => true, + State::Open | State::Pending | State::Procedure => true, _ => false, } } diff --git a/src/tasks.rs b/src/tasks.rs index 003fd22..0f799bf 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -712,11 +712,7 @@ impl Tasks { } pub(crate) fn set_state_for_with(&mut self, id: EventId, comment: &str) { - self.set_state_for(id, comment, match comment { - "Closed" => State::Closed, - "Done" => State::Done, - _ => State::Open, - }); + self.set_state_for(id, comment, comment.into()); } pub(crate) fn set_state_for(&mut self, id: EventId, comment: &str, state: State) -> EventId {