feat: nicely format current task information

This commit is contained in:
xeruf 2024-07-30 09:00:39 +03:00
parent f8f0cf7570
commit b519d459db
4 changed files with 104 additions and 3 deletions

78
Cargo.lock generated
View File

@ -65,6 +65,21 @@ version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"
[[package]]
name = "android-tzdata"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]]
name = "anstream"
version = "0.6.15"
@ -353,6 +368,20 @@ dependencies = [
"zeroize",
]
[[package]]
name = "chrono"
version = "0.4.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
dependencies = [
"android-tzdata",
"iana-time-zone",
"js-sys",
"num-traits",
"wasm-bindgen",
"windows-targets 0.52.5",
]
[[package]]
name = "cipher"
version = "0.4.4"
@ -391,6 +420,12 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]]
name = "cpufeatures"
version = "0.2.12"
@ -747,6 +782,29 @@ dependencies = [
"tracing",
]
[[package]]
name = "iana-time-zone"
version = "0.1.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"windows-core",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]
[[package]]
name = "idna"
version = "0.5.0"
@ -900,7 +958,9 @@ dependencies = [
name = "mostr"
version = "0.2.0"
dependencies = [
"chrono",
"colog",
"colored",
"itertools",
"log",
"nostr-sdk",
@ -1019,6 +1079,15 @@ dependencies = [
"thiserror",
]
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.16.0"
@ -1899,6 +1968,15 @@ dependencies = [
"rustls-pki-types",
]
[[package]]
name = "windows-core"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
dependencies = [
"windows-targets 0.52.5",
]
[[package]]
name = "windows-sys"
version = "0.48.0"

View File

@ -15,7 +15,9 @@ default-run = "mostr"
xdg = "2.5.2"
itertools = "0.12.1"
log = "0.4.21"
chrono = "0.4.38"
colog = "1.3.0"
colored = "2.1.0"
nostr-sdk = "0.30"
tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros"] }
once_cell = "1.19.0"

View File

@ -8,6 +8,7 @@ use std::str::FromStr;
use std::sync::mpsc;
use std::sync::mpsc::Sender;
use colored::Colorize;
use log::{debug, error, info, trace, warn};
use nostr_sdk::prelude::*;
use xdg::BaseDirectories;
@ -190,9 +191,12 @@ async fn main() {
tasks.print_tasks();
print!(
"{}",
format!(
" {}{}) ",
tasks.get_task_path(tasks.get_position()),
tasks.get_prompt_suffix()
).italic()
);
stdout().flush().unwrap();
match lines.next() {

View File

@ -2,6 +2,10 @@ use std::collections::{BTreeSet, HashMap};
use std::io::{Error, stdout, Write};
use std::iter::once;
use chrono::{Datelike, DateTime, Local, LocalResult, MappedLocalTime, NaiveDate, TimeZone, Utc};
use chrono::format::DelayedFormat;
use chrono::LocalResult::Single;
use colored::Colorize;
use itertools::Itertools;
use log::{debug, error, info, trace, warn};
use nostr_sdk::{Event, EventBuilder, EventId, Keys, Kind, Tag};
@ -199,15 +203,28 @@ impl Tasks {
if let Some(state) = t.state() {
writeln!(
lock,
"{} since {} (total time {}m)",
"{} since {} (total tracked time {}m)",
state.get_label(),
state.time.to_human_datetime(),
match Local.timestamp_opt(state.time.as_i64(), 0) {
Single(time) => {
let date = time.date_naive();
let prefix = match Local::now().date_naive().signed_duration_since(date).num_days() {
0 => "".into(),
1 => "yesterday ".into(),
2..=6 => date.format("%a ").to_string(),
_ => date.format("%y-%m-%d ").to_string(),
};
format!("{}{}", prefix, time.format("%H:%M"))
}
_ => state.time.to_human_datetime(),
},
t.time_tracked() / 60
)?;
}
writeln!(lock, "{}", t.descriptions().join("\n"))?;
}
writeln!(lock, "{}", self.properties.join("\t"))?; // TODO proper columns
// TODO proper columns
writeln!(lock, "{}", self.properties.join("\t").bold())?;
for task in self.current_tasks() {
writeln!(
lock,