Browse Source

Distinct behaviour for main and non-main threads

pull/28/head
Andrea Ciliberti 3 years ago
parent
commit
32d17e552a
  1. 9
      ctru-rs/src/lib.rs

9
ctru-rs/src/lib.rs

@ -11,11 +11,16 @@ pub fn init() { @@ -11,11 +11,16 @@ pub fn init() {
use std::panic::PanicInfo;
let main_thread = thread::current().id();
// Panic Hook setup
let default_hook = std::panic::take_hook();
let new_hook = Box::new(move |info: &PanicInfo| {
println!("\x1b[1;31m\n--------------------------------------------------");
println!("\x1b[1;31m\n--------------------------------------------------"); // Red ANSI Color Code
default_hook(info);
// Only for panics in the main thread
if main_thread == thread::current().id() {
println!("\nPress SELECT to exit the software");
let hid = services::hid::Hid::init().unwrap();
@ -25,6 +30,8 @@ pub fn init() { @@ -25,6 +30,8 @@ pub fn init() {
break;
}
}
}
println!("\x1b[1;37m\n"); // Get back to white
});
std::panic::set_hook(new_hook);
}

Loading…
Cancel
Save