forked from janek/mostr
feat: allow timetracking with date specifier
This commit is contained in:
parent
8c2c279238
commit
a2505e94fb
|
@ -100,9 +100,10 @@ when the application is terminated regularly.
|
||||||
Dots can be repeated to move to parent tasks.
|
Dots can be repeated to move to parent tasks.
|
||||||
|
|
||||||
- `:[IND][COL]` - add property column COL at IND or end, if it already exists remove property column COL or IND
|
- `:[IND][COL]` - add property column COL at IND or end, if it already exists remove property column COL or IND
|
||||||
- `>[TEXT]` - Complete active task and move to parent, with optional state description
|
- `*[TIME]` - add timetracking with the specified offset
|
||||||
- `<[TEXT]` - Close active task and move to parent, with optional state description
|
- `>[TEXT]` - complete active task and move to parent, with optional state description
|
||||||
- `!TEXT` - Set state for current task from text
|
- `<[TEXT]` - close active task and move to parent, with optional state description
|
||||||
|
- `!TEXT` - set state for current task from text
|
||||||
- `,TEXT` - add text note (comment / description)
|
- `,TEXT` - add text note (comment / description)
|
||||||
- `@` - undoes last action (moving in place or upwards or waiting a minute confirms pending actions)
|
- `@` - undoes last action (moving in place or upwards or waiting a minute confirms pending actions)
|
||||||
|
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -10,12 +10,13 @@ use std::str::FromStr;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
|
use chrono::DateTime;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use xdg::BaseDirectories;
|
use xdg::BaseDirectories;
|
||||||
|
|
||||||
use crate::kinds::{build_tracking, TRACKING_KIND};
|
use crate::kinds::TRACKING_KIND;
|
||||||
use crate::task::State;
|
use crate::task::State;
|
||||||
use crate::tasks::Tasks;
|
use crate::tasks::Tasks;
|
||||||
|
|
||||||
|
@ -352,7 +353,17 @@ async fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Some('-') => {
|
Some('-') => {
|
||||||
tasks.remove_tag(arg.to_string())
|
tasks.remove_tag(arg.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
Some('*') => {
|
||||||
|
if let Ok(num) = arg.parse::<i64>() {
|
||||||
|
tasks.track_at(Timestamp::now() + num);
|
||||||
|
} else if let Ok(date) = DateTime::parse_from_rfc3339(arg) {
|
||||||
|
tasks.track_at(Timestamp::from(date.to_utc().timestamp() as u64));
|
||||||
|
} else {
|
||||||
|
warn!("Cannot parse {arg}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Some('.') => {
|
Some('.') => {
|
||||||
|
|
12
src/tasks.rs
12
src/tasks.rs
|
@ -495,6 +495,18 @@ impl Tasks {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_task_title(&self, id: &EventId) -> String {
|
||||||
|
self.tasks.get(id).map_or(id.to_string(), |t| t.get_title())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn track_at(&mut self, time: Timestamp) -> EventId {
|
||||||
|
info!("Tracking \"{:?}\" from {}", self.position.map(|id| self.get_task_title(&id)), time.to_human_datetime());
|
||||||
|
self.submit(
|
||||||
|
build_tracking(self.get_position())
|
||||||
|
.custom_created_at(time)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fn submit(&mut self, builder: EventBuilder) -> EventId {
|
fn submit(&mut self, builder: EventBuilder) -> EventId {
|
||||||
let event = self.sender.submit(builder).unwrap();
|
let event = self.sender.submit(builder).unwrap();
|
||||||
let id = event.id;
|
let id = event.id;
|
||||||
|
|
Loading…
Reference in New Issue