forked from janek/mostr
1
0
Fork 0

feat: enable setting specific state with label

This commit is contained in:
xeruf 2024-08-29 11:06:56 +03:00
parent 1a1f23007b
commit c5a2872534
3 changed files with 25 additions and 11 deletions

View File

@ -530,9 +530,20 @@ async fn main() -> Result<()> {
Some('!') => Some('!') =>
match tasks.get_position() { match tasks.get_position() {
None => warn!("First select a task to set its state!"), None => {
warn!("First select a task to set its state!");
info!("Usage: ![(Open|Procedure|Pending|Done|Closed): ][Statename]");
}
Some(id) => { Some(id) => {
'block: {
if let Some((left, right)) = arg_default.split_once(": ") {
if let Ok(state) = left.try_into() {
tasks.set_state_for(id, right, state);
break 'block;
}
}
tasks.set_state_for_with(id, arg_default); tasks.set_state_for_with(id, arg_default);
}
tasks.move_up(); tasks.move_up();
} }
} }

View File

@ -233,14 +233,17 @@ pub(crate) enum State {
/// Actionable ordered task list /// Actionable ordered task list
Procedure = PROCEDURE_KIND as isize, Procedure = PROCEDURE_KIND as isize,
} }
impl From<&str> for State { impl TryFrom<&str> for State {
fn from(value: &str) -> Self { type Error = ();
match value {
"Closed" => State::Closed, fn try_from(value: &str) -> Result<Self, Self::Error> {
"Done" => State::Done, match value.to_ascii_lowercase().as_str() {
"Pending" => State::Pending, "closed" => Ok(State::Closed),
"Proc" | "Procedure" | "List" => State::Procedure, "done" => Ok(State::Done),
_ => State::Open, "pending" => Ok(State::Pending),
"proc" | "procedure" | "list" => Ok(State::Procedure),
"open" => Ok(State::Open),
_ => Err(()),
} }
} }
} }

View File

@ -856,7 +856,7 @@ impl Tasks {
} }
pub(crate) fn set_state_for_with(&mut self, id: EventId, comment: &str) { pub(crate) fn set_state_for_with(&mut self, id: EventId, comment: &str) {
self.set_state_for(id, comment, comment.into()); self.set_state_for(id, comment, comment.try_into().unwrap_or(State::Open));
} }
pub(crate) fn set_state_for(&mut self, id: EventId, comment: &str, state: State) -> EventId { pub(crate) fn set_state_for(&mut self, id: EventId, comment: &str, state: State) -> EventId {