2021-02-12 08:12:43 +00:00
|
|
|
#[macro_use]
|
2021-02-12 12:32:17 +00:00
|
|
|
extern crate anyhow;
|
|
|
|
#[macro_use]
|
2021-02-12 08:12:43 +00:00
|
|
|
extern crate crossterm;
|
2021-02-12 12:32:17 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2021-02-12 08:12:43 +00:00
|
|
|
|
2021-02-12 12:32:17 +00:00
|
|
|
mod mail;
|
2021-02-12 08:12:43 +00:00
|
|
|
mod ui;
|
|
|
|
|
|
|
|
use anyhow::Result;
|
2021-02-12 12:32:17 +00:00
|
|
|
use futures::future::TryFutureExt;
|
2021-02-12 08:54:19 +00:00
|
|
|
use tokio::sync::oneshot;
|
2021-02-12 08:12:43 +00:00
|
|
|
|
2021-02-12 08:54:19 +00:00
|
|
|
type ExitSender = oneshot::Sender<()>;
|
2021-02-12 08:12:43 +00:00
|
|
|
|
2021-02-12 08:54:19 +00:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<()> {
|
2021-02-12 12:32:17 +00:00
|
|
|
setup_logger()?;
|
2021-02-12 08:12:43 +00:00
|
|
|
|
2021-02-12 08:54:19 +00:00
|
|
|
let (exit_tx, exit_rx) = oneshot::channel::<()>();
|
2021-02-12 08:12:43 +00:00
|
|
|
|
2021-02-12 12:32:17 +00:00
|
|
|
tokio::spawn(mail::run_mail("mzhang.io", 143).unwrap_or_else(report_err));
|
2021-02-12 13:21:00 +00:00
|
|
|
let mut stdout = std::io::stdout();
|
2021-02-12 12:32:17 +00:00
|
|
|
tokio::spawn(ui::run_ui(stdout, exit_tx).unwrap_or_else(report_err));
|
2021-02-12 08:12:43 +00:00
|
|
|
|
2021-02-12 08:54:19 +00:00
|
|
|
exit_rx.await?;
|
2021-02-12 08:12:43 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2021-02-12 12:32:17 +00:00
|
|
|
|
|
|
|
fn report_err(err: anyhow::Error) {
|
|
|
|
error!("error: {:?}", err);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn setup_logger() -> Result<()> {
|
|
|
|
fern::Dispatch::new()
|
|
|
|
.format(|out, message, record| {
|
|
|
|
out.finish(format_args!(
|
|
|
|
"{}[{}][{}] {}",
|
|
|
|
chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"),
|
|
|
|
record.target(),
|
|
|
|
record.level(),
|
|
|
|
message
|
|
|
|
))
|
|
|
|
})
|
|
|
|
.level(log::LevelFilter::Debug)
|
|
|
|
.chain(fern::log_file("output.log")?)
|
|
|
|
.apply()?;
|
|
|
|
Ok(())
|
|
|
|
}
|