diff options
-rw-r--r-- | src/ios.rs | 14 | ||||
-rw-r--r-- | src/term.rs | 2 | ||||
-rw-r--r-- | src/util.rs | 15 | ||||
-rw-r--r-- | test/rl.rs | 2 | ||||
-rw-r--r-- | test/termios3.rs | 2 |
5 files changed, 16 insertions, 19 deletions
@@ -1,4 +1,4 @@ -use core::libc::{c_int,c_void}; +use core::libc::{c_int,c_uint,c_void}; use core::unstable::finally::Finally; /** @@ -53,6 +53,16 @@ pub fn preserve<T> (body: &fn () -> T) -> T { } } +/// Returns the size of the terminal, as `(columns, rows)`. +pub fn size() -> (uint, uint) { + let cols: c_uint = 0; + let rows: c_uint = 0; + unsafe { + c::size(&cols, &rows) + } + (cols as uint, rows as uint) +} + #[link_name = "termios_wrapper"] extern mod c { fn cooked () -> c_int; @@ -62,4 +72,6 @@ extern mod c { fn get() -> *c_void; fn set(t: *c_void); + + fn size(cols: *c_uint, rows: *c_uint); } diff --git a/src/term.rs b/src/term.rs index dfe6dce..0daa5ca 100644 --- a/src/term.rs +++ b/src/term.rs @@ -5,8 +5,6 @@ #[crate_type = "lib"]; -pub use util::size; - pub mod hexes; pub mod info; pub mod ios; diff --git a/src/util.rs b/src/util.rs index 09d8c11..149f425 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,4 +1,4 @@ -use core::libc::{c_int,c_uint}; +use core::libc::c_int; // XXX huge hack until there's a better built-in way to do this pub fn timed_read (timeout: int) -> Option<char> { @@ -24,16 +24,3 @@ pub fn timed_read (timeout: int) -> Option<char> { extern mod io_helper { fn timed_read (timeout: c_int) -> c_int; } - -pub fn size() -> (uint, uint) { - let cols: c_uint = 0; - let rows: c_uint = 0; - unsafe { - termios_wrapper::size(&cols, &rows) - } - (cols as uint, rows as uint) -} - -extern mod termios_wrapper { - fn size(cols: *c_uint, rows: *c_uint); -} @@ -37,7 +37,7 @@ fn draw_ground (term: &mut Term, color: Option<Color>, } fn main () { - let (cols, rows) = term::size(); + let (cols, rows) = term::ios::size(); { let mut term = Term(); diff --git a/test/termios3.rs b/test/termios3.rs index c387260..f02c324 100644 --- a/test/termios3.rs +++ b/test/termios3.rs @@ -3,7 +3,7 @@ extern mod term; fn main () { match io::stdout().get_type() { io::Screen => { - let (cols, rows) = term::size(); + let (cols, rows) = term::ios::size(); println(fmt!("tty: %d %d", cols as int, rows as int)); } io::File => { |