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('!') =>
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) => {
tasks.set_state_for_with(id, arg_default);
'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.move_up();
}
}

View File

@ -233,14 +233,17 @@ pub(crate) enum State {
/// Actionable ordered task list
Procedure = PROCEDURE_KIND as isize,
}
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<&str> for State {
type Error = ();
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.to_ascii_lowercase().as_str() {
"closed" => Ok(State::Closed),
"done" => Ok(State::Done),
"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) {
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 {