Added some better theming to the UI, enabled clippy to warn on 2018 idioms, and added human_panic hook to report bugs

This commit is contained in:
2023-08-08 10:50:05 -06:00
parent 652dc0f2c4
commit f92042fb21
6 changed files with 141 additions and 57 deletions
+51 -2
View File
@@ -1,7 +1,8 @@
extern crate core;
#![warn(rust_2018_idioms)]
use std::io;
use std::panic::PanicInfo;
use std::sync::Arc;
use std::{io, panic};
use anyhow::Result;
use clap::Parser;
@@ -36,6 +37,9 @@ struct Cli {}
#[tokio::main]
async fn main() -> Result<()> {
log4rs::init_config(utils::init_logging_config())?;
panic::set_hook(Box::new(|info| {
panic_hook(info);
}));
Cli::parse();
let config = confy::load("managarr", "config")?;
@@ -105,3 +109,48 @@ async fn start_ui(app: &Arc<Mutex<App>>) -> Result<()> {
Ok(())
}
#[cfg(debug_assertions)]
fn panic_hook(info: &PanicInfo<'_>) {
use backtrace::Backtrace;
use crossterm::style::Print;
let location = info.location().unwrap();
let msg = match info.payload().downcast_ref::<&'static str>() {
Some(s) => *s,
None => match info.payload().downcast_ref::<String>() {
Some(s) => &s[..],
None => "Box<Any>",
},
};
let stacktrace: String = format!("{:?}", Backtrace::new()).replace('\n', "\n\r");
disable_raw_mode().unwrap();
execute!(
io::stdout(),
LeaveAlternateScreen,
Print(format!(
"thread '<unnamed>' panicked at '{}', {}\n\r{}",
msg, location, stacktrace
)),
)
.unwrap();
}
#[cfg(not(debug_assertions))]
fn panic_hook(info: &PanicInfo<'_>) {
use human_panic::{handle_dump, print_msg, Metadata};
let meta = Metadata {
version: env!("CARGO_PKG_VERSION").into(),
name: env!("CARGO_PKG_NAME").into(),
authors: env!("CARGO_PKG_AUTHORS").replace(":", ", ").into(),
homepage: env!("CARGO_PKG_HOMEPAGE").into(),
};
let file_path = handle_dump(&meta, info);
disable_raw_mode().unwrap();
execute!(io::stdout(), LeaveAlternateScreen).unwrap();
print_msg(file_path, &meta).expect("human-panic: printing error message to console failed");
}