cleanup
This commit is contained in:
+11
-6
@@ -10,6 +10,11 @@ use anyhow::{bail, Result};
|
|||||||
use tokio::sync::broadcast::channel;
|
use tokio::sync::broadcast::channel;
|
||||||
use tokio::task::JoinSet;
|
use tokio::task::JoinSet;
|
||||||
|
|
||||||
|
use message::Message;
|
||||||
|
use pid::Pid;
|
||||||
|
use pomodoro::Pomodoro;
|
||||||
|
use ui::{clear_terminal, Ui};
|
||||||
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn main() -> ExitCode {
|
async fn main() -> ExitCode {
|
||||||
match main2().await {
|
match main2().await {
|
||||||
@@ -22,25 +27,25 @@ async fn main() -> ExitCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn main2() -> Result<()> {
|
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)
|
bail!("already running (pid {})", pid.pid)
|
||||||
} else {
|
} else {
|
||||||
pid::Pid::create()?
|
Pid::create()?
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = run_all_tasks().await;
|
let result = run_all_tasks().await;
|
||||||
|
|
||||||
ui::clear_terminal()?;
|
clear_terminal()?;
|
||||||
pid.remove()?;
|
pid.remove()?;
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_all_tasks() -> 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 timer = Pomodoro::new(rx);
|
||||||
let ui = ui::Ui::new(tx);
|
let ui = Ui::new(tx);
|
||||||
|
|
||||||
let mut tasks = JoinSet::new();
|
let mut tasks = JoinSet::new();
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -122,8 +122,9 @@ impl Pomodoro {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn format(dur: Duration) -> String {
|
fn format(dur: Duration) -> String {
|
||||||
let min = dur.as_secs() / 60;
|
let secs = dur.as_secs();
|
||||||
let sec = dur.as_secs() % 60;
|
let min = secs / 60;
|
||||||
|
let sec = secs % 60;
|
||||||
|
|
||||||
format!("{min}:{sec:0>2}")
|
format!("{min}:{sec:0>2}")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user