Browse Source

Redesigned console API

pull/10/head
Fenrir 9 years ago
parent
commit
7b2483622d
  1. 7
      ctru-sys/src/console.rs
  2. 33
      src/console.rs

7
ctru-sys/src/console.rs

@ -54,7 +54,12 @@ pub enum debugDevice { @@ -54,7 +54,12 @@ pub enum debugDevice {
extern "C" {
pub fn consoleSetFont(console: *mut PrintConsole, font: *mut ConsoleFont) -> ();
pub fn consoleSetWindow(console: *mut PrintConsole, x: i32, y: i32, width: i32, height: i32) -> ();
pub fn consoleSetWindow(console: *mut PrintConsole,
x: i32,
y: i32,
width: i32,
height: i32)
-> ();
pub fn consoleGetDefault() -> *mut PrintConsole;
pub fn consoleSelect(console: *mut PrintConsole) -> *mut PrintConsole;
pub fn consoleInit(screen: gfxScreen_t, console: *mut PrintConsole) -> *mut PrintConsole;

33
src/console.rs

@ -1,31 +1,42 @@ @@ -1,31 +1,42 @@
use libctru::console::{PrintConsole, consoleInit, consoleClear};
use libctru::console::{consoleInit, consoleClear};
use libctru::gfx;
use core::default::Default;
use core::marker::PhantomData;
use core::ptr;
extern "C" {
fn putchar(ch: u8) -> i32;
}
pub fn console_default_init() -> *mut PrintConsole {
unsafe { consoleInit(gfx::gfxScreen_t::GFX_TOP, ptr::null_mut()) }
pub struct Console {
pd: PhantomData<i32>,
}
pub fn console_write<'a>(s: &'a str) {
impl Console {
pub fn write<'a>(&mut self, s: &'a str) {
unsafe {
for c in s.as_bytes().iter() {
putchar(*c);
for ch in s.as_bytes().iter() {
putchar(*ch);
}
}
}
}
pub fn console_writeln<'a>(s: &'a str) {
pub fn writeln<'a>(&mut self, s: &'a str) {
unsafe {
console_write(s);
self.write(s);
putchar('\n' as u8);
}
}
}
pub fn console_clear() {
pub fn clear(&mut self) {
unsafe { consoleClear() }
}
}
impl Default for Console {
fn default() -> Self {
unsafe { consoleInit(gfx::gfxScreen_t::GFX_TOP, ptr::null_mut()); }
Console { pd: PhantomData }
}
}

Loading…
Cancel
Save