My personal-knowledge-system, with deeply integrated task tracking and long term goal planning capabilities.
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

at todo 88 lines 3.0 kB view raw
1use std::io::stdout; 2 3use crossterm::{ 4 cursor, 5 event::{DisableBracketedPaste, DisableMouseCapture}, 6 terminal::LeaveAlternateScreen, 7}; 8 9/// Sets the panic-hook to be customized color-eyre `panic_hook`. 10/// 11/// Additionally the panic handler prints different information 12/// based on debug / release builds. 13pub fn init() -> color_eyre::Result<()> { 14 let (_panic_hook, eyre_hook) = color_eyre::config::HookBuilder::default() 15 .panic_section(format!( 16 "This is a bug. Please report it at {}", 17 env!("CARGO_PKG_REPOSITORY") 18 )) 19 .capture_span_trace_by_default(false) 20 .display_location_section(false) 21 .display_env_section(false) 22 .into_hooks(); 23 24 eyre_hook.install()?; 25 std::panic::set_hook(Box::new(move |panic_info| { 26 // exit from terminal if the app is in a terminal 27 if crossterm::terminal::is_raw_mode_enabled().unwrap() { 28 let _ = crossterm::execute!(stdout(), DisableBracketedPaste); 29 let _ = crossterm::execute!(stdout(), DisableMouseCapture); 30 let _ = crossterm::execute!(stdout(), LeaveAlternateScreen, cursor::Show); 31 let _ = crossterm::terminal::disable_raw_mode(); 32 } 33 34 // in release mode, do human_panic printing 35 #[cfg(not(debug_assertions))] 36 { 37 use human_panic::{handle_dump, metadata, print_msg}; 38 let metadata = metadata!(); 39 let file_path = handle_dump(&metadata, panic_info); 40 print_msg(file_path, &metadata) 41 .expect("human-panic: printing error message to console failed"); 42 eprintln!("{}", _panic_hook.panic_report(panic_info)); 43 } 44 45 // in debug mode do better panic printing 46 #[cfg(debug_assertions)] 47 { 48 better_panic::Settings::auto() 49 .most_recent_first(false) 50 .lineno_suffix(true) 51 .verbosity(better_panic::Verbosity::Full) 52 .create_panic_handler()(panic_info); 53 } 54 55 // 1 = failure 56 std::process::exit(1) 57 })); 58 59 Ok(()) 60} 61 62/// Akin to `dbg!` macro, except that it generates `tracing::Event`s instead 63/// of printing to standard error. 64/// 65/// Can customize level by providing a `tracing::Level`, but its debug by default. 66#[macro_export] 67macro_rules! trace_dbg { 68 (target: $target:expr, level: $level:expr, $ex:expr) => { 69 { 70 match $ex { 71 value => { 72 tracing::event!(target: $target, $level, ?value, stringify!($ex)); 73 value 74 } 75 } 76 } 77 }; 78 (level: $level:expr, $ex:expr) => { 79 trace_dbg!(target: module_path!(), level: $level, $ex) 80 }; 81 82 (target: $target:expr, $ex:expr) => { 83 trace_dbg!(target: $target, level: tracing::Level::DEBUG, $ex) 84 }; 85 ($ex:expr) => { 86 trace_dbg!(level: tracing::Level::DEBUG, $ex) 87 }; 88}