Fenrir
9 years ago
2 changed files with 40 additions and 24 deletions
@ -1,31 +1,42 @@ |
|||||||
use libctru::console::{PrintConsole, consoleInit, consoleClear}; |
use libctru::console::{consoleInit, consoleClear}; |
||||||
use libctru::gfx; |
use libctru::gfx; |
||||||
|
|
||||||
|
use core::default::Default; |
||||||
|
use core::marker::PhantomData; |
||||||
use core::ptr; |
use core::ptr; |
||||||
|
|
||||||
extern "C" { |
extern "C" { |
||||||
fn putchar(ch: u8) -> i32; |
fn putchar(ch: u8) -> i32; |
||||||
} |
} |
||||||
|
|
||||||
pub fn console_default_init() -> *mut PrintConsole { |
pub struct Console { |
||||||
unsafe { consoleInit(gfx::gfxScreen_t::GFX_TOP, ptr::null_mut()) } |
pd: PhantomData<i32>, |
||||||
} |
} |
||||||
|
|
||||||
pub fn console_write<'a>(s: &'a str) { |
impl Console { |
||||||
|
pub fn write<'a>(&mut self, s: &'a str) { |
||||||
unsafe { |
unsafe { |
||||||
for c in s.as_bytes().iter() { |
for ch in s.as_bytes().iter() { |
||||||
putchar(*c); |
putchar(*ch); |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
pub fn console_writeln<'a>(s: &'a str) { |
pub fn writeln<'a>(&mut self, s: &'a str) { |
||||||
unsafe { |
unsafe { |
||||||
console_write(s); |
self.write(s); |
||||||
putchar('\n' as u8); |
putchar('\n' as u8); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
pub fn console_clear() { |
pub fn clear(&mut self) { |
||||||
unsafe { consoleClear() } |
unsafe { consoleClear() } |
||||||
} |
} |
||||||
|
} |
||||||
|
|
||||||
|
impl Default for Console { |
||||||
|
fn default() -> Self { |
||||||
|
unsafe { consoleInit(gfx::gfxScreen_t::GFX_TOP, ptr::null_mut()); } |
||||||
|
Console { pd: PhantomData } |
||||||
|
} |
||||||
|
} |
||||||
|
Loading…
Reference in new issue