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); }