forked from janek/mostr
feat: enable setting specific state with label
This commit is contained in:
parent
1a1f23007b
commit
c5a2872534
13
src/main.rs
13
src/main.rs
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
19
src/task.rs
19
src/task.rs
|
@ -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(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue