This commit is contained in:
Dr. Matthias Ratajczak
2023-03-03 12:31:12 +01:00
parent 7956077085
commit a36858a327
2 changed files with 14 additions and 8 deletions
+11 -6
View File
@@ -10,6 +10,11 @@ use anyhow::{bail, Result};
use tokio::sync::broadcast::channel;
use tokio::task::JoinSet;
use message::Message;
use pid::Pid;
use pomodoro::Pomodoro;
use ui::{clear_terminal, Ui};
#[tokio::main(flavor = "current_thread")]
async fn main() -> ExitCode {
match main2().await {
@@ -22,25 +27,25 @@ async fn main() -> ExitCode {
}
async fn main2() -> Result<()> {
let pid = if let Some(pid) = pid::Pid::check_already_running() {
let pid = if let Some(pid) = Pid::check_already_running() {
bail!("already running (pid {})", pid.pid)
} else {
pid::Pid::create()?
Pid::create()?
};
let result = run_all_tasks().await;
ui::clear_terminal()?;
clear_terminal()?;
pid.remove()?;
result
}
async fn run_all_tasks() -> Result<()> {
let (tx, rx) = channel::<message::Message>(10);
let (tx, rx) = channel::<Message>(10);
let timer = pomodoro::Pomodoro::new(rx);
let ui = ui::Ui::new(tx);
let timer = Pomodoro::new(rx);
let ui = Ui::new(tx);
let mut tasks = JoinSet::new();
+3 -2
View File
@@ -122,8 +122,9 @@ impl Pomodoro {
}
fn format(dur: Duration) -> String {
let min = dur.as_secs() / 60;
let sec = dur.as_secs() % 60;
let secs = dur.as_secs();
let min = secs / 60;
let sec = secs % 60;
format!("{min}:{sec:0>2}")
}