Browse Source

Minor console refactor

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

37
src/console.rs

@ -1,11 +1,9 @@ @@ -1,11 +1,9 @@
use libctru::console::*;
use libctru::libc;
use std::default::Default;
use std::ptr;
use gfx::Screen;
use std::fmt::{self, Write};
use std::default::Default;
use std::ptr;
use libctru::console::*;
pub struct Console {
context: PrintConsole,
@ -13,8 +11,14 @@ pub struct Console { @@ -13,8 +11,14 @@ pub struct Console {
impl Console {
pub fn init(screen: Screen) -> Self {
let ret = unsafe { *(consoleInit(screen.into(), ptr::null_mut())) };
Console { context: ret }
unsafe {
let ret = *(consoleInit(screen.into(), ptr::null_mut()));
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) {
@ -28,23 +32,6 @@ impl Console { @@ -28,23 +32,6 @@ impl Console {
impl Default for Console {
fn default() -> Self {
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 {
// 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)
}
Console::init(Screen::Top)
}
}

Loading…
Cancel
Save