Browse Source

Removed ANSI formatting from panic hook

pull/28/head
Andrea Ciliberti 3 years ago
parent
commit
9ea0232902
  1. 1
      ctru-rs/examples/thread-basic.rs
  2. 25
      ctru-rs/src/console.rs
  3. 4
      ctru-rs/src/lib.rs

1
ctru-rs/examples/thread-basic.rs

@ -13,7 +13,6 @@ fn main() {
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let gfx = Gfx::default(); let gfx = Gfx::default();
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::init(gfx.top_screen.borrow_mut());
drop(_console);
let prio = thread::current().priority(); let prio = thread::current().priority();
println!("Main thread prio: {}\n", prio); println!("Main thread prio: {}\n", prio);

25
ctru-rs/src/console.rs

@ -7,18 +7,6 @@ use crate::gfx::Screen;
static mut EMPTY_CONSOLE: PrintConsole = unsafe { const_zero::const_zero!(PrintConsole) }; static mut EMPTY_CONSOLE: PrintConsole = unsafe { const_zero::const_zero!(PrintConsole) };
pub fn console_exists() -> bool {
unsafe {
let current_console = ctru_sys::consoleSelect(&mut EMPTY_CONSOLE);
let res = (*current_console).consoleInitialised;
ctru_sys::consoleSelect(current_console);
res
}
}
pub struct Console<'screen> { pub struct Console<'screen> {
context: Box<PrintConsole>, context: Box<PrintConsole>,
screen: RefMut<'screen, dyn Screen>, screen: RefMut<'screen, dyn Screen>,
@ -36,6 +24,19 @@ impl<'screen> Console<'screen> {
Console { context, screen } Console { context, screen }
} }
/// Returns true if a valid Console to print on is selected
pub fn exists() -> bool {
unsafe {
let current_console = ctru_sys::consoleSelect(&mut EMPTY_CONSOLE);
let res = (*current_console).consoleInitialised;
ctru_sys::consoleSelect(current_console);
res
}
}
/// Select this console as the current target for stdout /// Select this console as the current target for stdout
pub fn select(&self) { pub fn select(&self) {
unsafe { unsafe {

4
ctru-rs/src/lib.rs

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

Loading…
Cancel
Save