feat: enhance display of task history

This commit is contained in:
xeruf 2024-11-20 19:34:40 +01:00
parent 9eb6138852
commit ca50bdf3bb
3 changed files with 34 additions and 16 deletions

View file

@ -146,6 +146,11 @@ pub fn format_timestamp_local(stamp: &Timestamp) -> String {
format_timestamp(stamp, "%y-%m-%d %a %H:%M")
}
/// Format nostr timestamp with seconds precision.
pub fn format_timestamp_full(stamp: &Timestamp) -> String {
format_timestamp(stamp, "%y-%m-%d %a %H:%M:%S")
}
pub fn format_timestamp_relative_to(stamp: &Timestamp, reference: &Timestamp) -> String {
// Rough difference in days
match (stamp.as_u64() as i64 - reference.as_u64() as i64) / 80_000 {

View file

@ -132,12 +132,16 @@ pub fn to_hashtag(tag: &str) -> Tag {
TagStandard::Hashtag(tag.to_string()).into()
}
fn format_tag(tag: &Tag) -> String {
pub fn format_tag(tag: &Tag) -> String {
if let Some(et) = match_event_tag(tag) {
return format!("{}: {:.8}",
et.marker.as_ref().map(|m| m.to_string()).unwrap_or(MARKER_PARENT.to_string()),
et.id);
}
format_tag_basic(tag)
}
pub fn format_tag_basic(tag: &Tag) -> String {
match tag.as_standardized() {
Some(TagStandard::PublicKey {
public_key,
@ -150,12 +154,12 @@ fn format_tag(tag: &Tag) -> String {
}
}
pub(crate) fn is_hashtag(tag: &Tag) -> bool {
pub fn is_hashtag(tag: &Tag) -> bool {
tag.single_letter_tag()
.is_some_and(|letter| letter.character == Alphabet::T)
}
pub(crate) fn to_prio_tag(value: Prio) -> Tag {
pub fn to_prio_tag(value: Prio) -> Tag {
Tag::custom(TagKind::Custom(Cow::from(PRIO)), [value.to_string()])
}

View file

@ -10,7 +10,7 @@ use std::time::Duration;
use crate::event_sender::MostrMessage;
use crate::helpers::*;
use crate::kinds::{join_tags, match_event_tag, Prio, BASIC_KINDS, PROPERTY_COLUMNS, PROP_KINDS};
use crate::kinds::{format_tag_basic, match_event_tag, Prio, BASIC_KINDS, PROPERTY_COLUMNS, PROP_KINDS};
use crate::task::{State, Task, TaskState, MARKER_PROPERTY};
use crate::tasks::{PropertyCollection, StateFilter, TasksRelay};
use chrono::Local;
@ -385,8 +385,11 @@ async fn main() -> Result<()> {
match arg {
None => {
if let Some(task) = tasks.get_current_task() {
println!("Change History:");
for e in once(&task.event).chain(task.props.iter().rev()) {
let content = match State::try_from(e.kind) {
println!("{} {} [{}]",
format_timestamp_full(&e.created_at),
match State::try_from(e.kind) {
Ok(state) => {
format!("State: {state}{}",
if e.content.is_empty() { String::new() } else { format!(" - {}", e.content) })
@ -394,11 +397,17 @@ async fn main() -> Result<()> {
Err(_) => {
e.content.to_string()
}
};
println!("{} {} [{}]",
format_timestamp_local(&e.created_at),
content,
join_tags(e.tags.iter().filter(|t| match_event_tag(t).is_some_and(|e| e.marker.as_ref().is_none_or(|m| m != MARKER_PROPERTY)))));
},
e.tags.iter().filter_map(|t| {
match match_event_tag(t) {
Some(et) =>
Some(et).take_if(|et| et.marker.as_ref().is_some_and(|m| m != MARKER_PROPERTY))
.map(|et| format!("{}: {}", et.marker.as_ref().unwrap(), tasks.get_relative_path(et.id))),
None =>
Some(format_tag_basic(t)),
}
}).join(", ")
)
}
continue 'repl;
} else {