Compare commits

...

3 commits

Author SHA1 Message Date
xeruf
8655a21396 enhance(tasks): revamp time formatting 2025-05-20 20:47:33 +02:00
xeruf
d3039cee7f build(cargo): update simple dependencies 2025-05-19 21:01:37 +02:00
xeruf
a3befc87da build: update version to 0.10, rust 1.87, update Cargo.lock 2025-05-19 20:49:33 +02:00
4 changed files with 448 additions and 368 deletions

775
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,7 @@ repository = "https://forge.ftt.gmbh/janek/mostr"
readme = "README.md" readme = "README.md"
license = "GPL 3.0" license = "GPL 3.0"
authors = ["melonion"] authors = ["melonion"]
version = "0.9.3" version = "0.10.0"
rust-version = "1.82" rust-version = "1.82"
edition = "2021" edition = "2021"
default-run = "mostr" default-run = "mostr"
@ -21,15 +21,15 @@ regex = "1.11"
log = "0.4" log = "0.4"
env_logger = "0.11" env_logger = "0.11"
colog = "1.3" colog = "1.3"
colored = "2.2" colored = "3.0"
rustyline = { git = "https://github.com/xeruf/rustyline", rev = "5364854" } rustyline = { git = "https://github.com/xeruf/rustyline", rev = "5364854" }
# OS-Specific Abstractions # OS-Specific Abstractions
keyring = "3" keyring = "3"
directories = "5.0" directories = "6.0"
whoami = "1.5" whoami = "1.6"
# slint = "1.8" # slint = "1.8"
# Application Utils # Application Utils
itertools = "0.12" itertools = "0.14"
chrono = "0.4" chrono = "0.4"
parse_datetime = "0.5" parse_datetime = "0.5"
interim = { version = "0.1", features = ["chrono"] } interim = { version = "0.1", features = ["chrono"] }

View file

@ -1,2 +1,2 @@
[toolchain] [toolchain]
channel = "1.84.0" channel = "1.87"

View file

@ -736,8 +736,8 @@ impl TasksRelay {
"path" => self.get_task_path(Some(task.get_id())), "path" => self.get_task_path(Some(task.get_id())),
"rpath" => self.get_relative_path(task.get_id()), "rpath" => self.get_relative_path(task.get_id()),
// TODO format strings configurable // TODO format strings configurable
"time" => format_secs("MMMm", self.time_tracked(task.get_id())), "time" => format_secs("TTTT", self.time_tracked(task.get_id())),
"rtime" => format_secs("HHH:MM", self.total_time_tracked(task.get_id())), "rtime" => format_secs("TT:TT", self.total_time_tracked(task.get_id())),
prop => task.get(prop).unwrap_or_default(), prop => task.get(prop).unwrap_or_default(),
} }
} }
@ -1551,7 +1551,7 @@ impl Display for TasksRelay {
writeln!(lock, writeln!(lock,
"{count} visible tasks{}", "{count} visible tasks{}",
format_secs(" tracked a total of HHhMMm", total_time) format_secs(" tracked a total of T", total_time)
)?; )?;
Ok(()) Ok(())
} }
@ -1593,24 +1593,23 @@ where
} }
} }
/// Formats the given seconds according to the given format. /// Formats seconds using a formatting scheme.
/// - MMM - minutes
/// - MM - minutes of the hour
/// - HH - hours
///
/// Returns an empty string if under one minute. /// Returns an empty string if under one minute.
fn format_secs(format: &str, secs: u64) -> String { fn format_secs(format: &str, secs: u64) -> String {
// TODO format to only hours/days for large values
Some(secs / 60) Some(secs / 60)
.filter(|t| t > &0) .filter(|t| t > &0)
.map_or(String::new(), |mins| { .map_or(String::new(), |mins| {
let hours = mins / 60;
format format
.replace("MMM", &format!("{:3}", mins)) .replace("TTTT",
.replace("HHH", &format!("{:>3}", mins.div(60))) &(if mins > 999 { format!("h{:03}", hours) }
.replace("HH", &format!("{:>2}", mins.div(60))) else { format!("{:>3}m", mins) }))
.replace("H", &mins.div(60).to_string()) .replace("TT:TT",
.replace("MM", &format!("{:02}", mins.rem(60))) &(if hours > 99 { format!("h{:>4}", hours) }
.replace("M", &mins.to_string()) else { format!("{:>2}:{:02}", hours, mins.rem(60)) }))
.replace("T",
&(if hours > 99 { format!("{}h", hours) }
else { format!("{}h{:02}m", hours, mins) }))
}) })
} }