Browse Source

Minor console refactor

pull/10/head
Fenrir 8 years ago
parent
commit
d315ac82a1
  1. 35
      src/console.rs

35
src/console.rs

@ -1,11 +1,9 @@
use libctru::console::*; use std::default::Default;
use libctru::libc; use std::ptr;
use gfx::Screen; use gfx::Screen;
use std::fmt::{self, Write}; use libctru::console::*;
use std::default::Default;
use std::ptr;
pub struct Console { pub struct Console {
context: PrintConsole, context: PrintConsole,
@ -13,9 +11,15 @@ pub struct Console {
impl Console { impl Console {
pub fn init(screen: Screen) -> Self { pub fn init(screen: Screen) -> Self {
let ret = unsafe { *(consoleInit(screen.into(), ptr::null_mut())) }; unsafe {
let ret = *(consoleInit(screen.into(), ptr::null_mut()));
Console { context: ret } Console { context: ret }
} }
}
pub fn select(&mut self) {
unsafe { consoleSelect(&mut self.context); }
}
pub fn set_window(&mut self, x: i32, y: i32, width: i32, height: i32) { pub fn set_window(&mut self, x: i32, y: i32, width: i32, height: i32) {
unsafe { consoleSetWindow(&mut self.context, x, y, width, height) } unsafe { consoleSetWindow(&mut self.context, x, y, width, height) }
@ -28,23 +32,6 @@ impl Console {
impl Default for Console { impl Default for Console {
fn default() -> Self { fn default() -> Self {
let ret = unsafe { *(consoleInit(Screen::Top.into(), ptr::null_mut())) }; Console::init(Screen::Top)
Console { context: ret }
}
}
impl Write for Console {
fn write_str(&mut self, s: &str) -> fmt::Result {
// Writing 0 bytes to the console fails
if s.is_empty() {
return Ok(())
}
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(())
} else {
Err(fmt::Error)
}
} }
} }

Loading…
Cancel
Save