From 9ea0232902373e817b43506c77b9ad12347a82c0 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Fri, 28 Jan 2022 14:28:56 +0100 Subject: [PATCH] Removed ANSI formatting from panic hook --- ctru-rs/examples/thread-basic.rs | 1 - ctru-rs/src/console.rs | 25 +++++++++++++------------ ctru-rs/src/lib.rs | 4 +--- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/ctru-rs/examples/thread-basic.rs b/ctru-rs/examples/thread-basic.rs index 6b400f5..7657718 100644 --- a/ctru-rs/examples/thread-basic.rs +++ b/ctru-rs/examples/thread-basic.rs @@ -13,7 +13,6 @@ fn main() { let hid = Hid::init().unwrap(); let gfx = Gfx::default(); let _console = Console::init(gfx.top_screen.borrow_mut()); - drop(_console); let prio = thread::current().priority(); println!("Main thread prio: {}\n", prio); diff --git a/ctru-rs/src/console.rs b/ctru-rs/src/console.rs index bc96dd0..ec03a3d 100644 --- a/ctru-rs/src/console.rs +++ b/ctru-rs/src/console.rs @@ -7,18 +7,6 @@ use crate::gfx::Screen; 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> { context: Box, screen: RefMut<'screen, dyn Screen>, @@ -36,6 +24,19 @@ impl<'screen> Console<'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 pub fn select(&self) { unsafe { diff --git a/ctru-rs/src/lib.rs b/ctru-rs/src/lib.rs index 4f6558a..5f487a9 100644 --- a/ctru-rs/src/lib.rs +++ b/ctru-rs/src/lib.rs @@ -16,11 +16,10 @@ pub fn init() { // Panic Hook setup let default_hook = std::panic::take_hook(); let new_hook = Box::new(move |info: &PanicInfo| { - 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() && console::console_exists() { + if main_thread == thread::current().id() && console::Console::exists() { println!("\nPress SELECT to exit the software"); 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); }