From 51d59739a3558d83926e824bc4ddec2c8779d255 Mon Sep 17 00:00:00 2001 From: Fenrir Date: Tue, 7 Jun 2016 16:51:40 -0700 Subject: [PATCH] Multiple console support --- src/console.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/console.rs b/src/console.rs index 0d0535a..123c067 100644 --- a/src/console.rs +++ b/src/console.rs @@ -1,17 +1,26 @@ -use libctru::console::{consoleInit, consoleClear}; -use libctru::gfx; +use libctru::console::*; use libctru::libc; +use gfx::Screen; + use core::fmt::{self, Write}; use core::default::Default; -use core::marker::PhantomData; use core::ptr; pub struct Console { - pd: PhantomData<()>, + context: PrintConsole, } impl Console { + pub fn init(screen: Screen) -> Self { + let ret = unsafe { *(consoleInit(screen.into(), ptr::null_mut())) }; + Console { context: ret } + } + + pub fn set_window(&mut self, x: i32, y: i32, width: i32, height: i32) { + unsafe { consoleSetWindow(&mut self.context, x, y, width, height) } + } + pub fn clear(&mut self) { unsafe { consoleClear() } } @@ -19,15 +28,14 @@ impl Console { impl Default for Console { fn default() -> Self { - unsafe { - consoleInit(gfx::gfxScreen_t::GFX_TOP, ptr::null_mut()); - } - Console { pd: PhantomData } + let ret = unsafe { *(consoleInit(Screen::Top.into(), ptr::null_mut())) }; + Console { context: ret } } } impl Write for Console { fn write_str(&mut self, s: &str) -> fmt::Result { + unsafe { consoleSelect(&mut self.context); } let ret = unsafe { libc::write(libc::STDOUT_FILENO, s.as_ptr() as *const _, s.len()) }; if ret == s.len() as isize { Ok(())