feat(tasks): print info on currently selected task
This commit is contained in:
parent
18fca1d0f3
commit
f8f0cf7570
|
@ -50,7 +50,7 @@ impl Task {
|
||||||
.unwrap_or_else(|| self.get_id().to_string())
|
.unwrap_or_else(|| self.get_id().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn descriptions(&self) -> impl Iterator<Item = &String> + '_ {
|
pub(crate) fn descriptions(&self) -> impl Iterator<Item = &String> + '_ {
|
||||||
self.props.iter().filter_map(|event| {
|
self.props.iter().filter_map(|event| {
|
||||||
if event.kind == Kind::TextNote {
|
if event.kind == Kind::TextNote {
|
||||||
Some(&event.content)
|
Some(&event.content)
|
||||||
|
@ -170,7 +170,7 @@ impl Task {
|
||||||
pub(crate) struct TaskState {
|
pub(crate) struct TaskState {
|
||||||
state: State,
|
state: State,
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
time: Timestamp,
|
pub(crate) time: Timestamp,
|
||||||
}
|
}
|
||||||
impl TaskState {
|
impl TaskState {
|
||||||
pub(crate) fn get_label(&self) -> String {
|
pub(crate) fn get_label(&self) -> String {
|
||||||
|
|
43
src/tasks.rs
43
src/tasks.rs
|
@ -1,6 +1,8 @@
|
||||||
use std::collections::{BTreeSet, HashMap};
|
use std::collections::{BTreeSet, HashMap};
|
||||||
|
use std::io::{Error, stdout, Write};
|
||||||
use std::iter::once;
|
use std::iter::once;
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
use nostr_sdk::{Event, EventBuilder, EventId, Keys, Kind, Tag};
|
use nostr_sdk::{Event, EventBuilder, EventId, Keys, Kind, Tag};
|
||||||
use nostr_sdk::Tag::Hashtag;
|
use nostr_sdk::Tag::Hashtag;
|
||||||
|
@ -159,13 +161,13 @@ impl Tasks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn current_task(&self) -> Option<&Task> {
|
||||||
|
self.position.and_then(|id| self.tasks.get(&id))
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn current_tasks(&self) -> Vec<&Task> {
|
pub(crate) fn current_tasks(&self) -> Vec<&Task> {
|
||||||
if self.depth == 0 {
|
if self.depth == 0 {
|
||||||
return self
|
return self.current_task().into_iter().collect();
|
||||||
.position
|
|
||||||
.and_then(|id| self.tasks.get(&id))
|
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
}
|
}
|
||||||
let res: Vec<&Task> = self.resolve_tasks(self.view.iter());
|
let res: Vec<&Task> = self.resolve_tasks(self.view.iter());
|
||||||
if res.len() > 0 {
|
if res.len() > 0 {
|
||||||
|
@ -191,10 +193,24 @@ impl Tasks {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn print_tasks(&self) {
|
pub(crate) fn print_tasks(&self) -> Result<(), Error> {
|
||||||
println!("{}", self.properties.join("\t"));
|
let mut lock = stdout().lock();
|
||||||
|
if let Some(t) = self.current_task() {
|
||||||
|
if let Some(state) = t.state() {
|
||||||
|
writeln!(
|
||||||
|
lock,
|
||||||
|
"{} since {} (total time {}m)",
|
||||||
|
state.get_label(),
|
||||||
|
state.time.to_human_datetime(),
|
||||||
|
t.time_tracked() / 60
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
writeln!(lock, "{}", t.descriptions().join("\n"))?;
|
||||||
|
}
|
||||||
|
writeln!(lock, "{}", self.properties.join("\t"))?; // TODO proper columns
|
||||||
for task in self.current_tasks() {
|
for task in self.current_tasks() {
|
||||||
println!(
|
writeln!(
|
||||||
|
lock,
|
||||||
"{}",
|
"{}",
|
||||||
self.properties
|
self.properties
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -209,9 +225,10 @@ impl Tasks {
|
||||||
})
|
})
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join(" \t")
|
.join(" \t")
|
||||||
);
|
)?;
|
||||||
}
|
}
|
||||||
println!();
|
writeln!(lock)?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Movement and Selection
|
// Movement and Selection
|
||||||
|
@ -231,11 +248,7 @@ impl Tasks {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn move_up(&mut self) {
|
pub(crate) fn move_up(&mut self) {
|
||||||
self.move_to(
|
self.move_to(self.current_task().and_then(|t| t.parent_id()))
|
||||||
self.position
|
|
||||||
.and_then(|id| self.tasks.get(&id))
|
|
||||||
.and_then(|t| t.parent_id()),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn move_to(&mut self, id: Option<EventId>) {
|
pub(crate) fn move_to(&mut self, id: Option<EventId>) {
|
||||||
|
|
Loading…
Reference in New Issue