aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2016-04-26 03:50:40 -0400
committerJesse Luehrs <doy@tozt.net>2016-04-26 03:50:40 -0400
commitd83869a86b1832974018c51dcfac5b93e501256d (patch)
tree3797ee3bd4beb21167406bcefd87bee77a54d44b
parentfdf0992b76aa267df76246bdc95eb5650a757d74 (diff)
downloadvt100-rust-d83869a86b1832974018c51dcfac5b93e501256d.tar.gz
vt100-rust-d83869a86b1832974018c51dcfac5b93e501256d.zip
split things out into more modules
-rw-r--r--src/ffi.rs34
-rw-r--r--src/lib.rs2
-rw-r--r--src/screen.rs58
-rw-r--r--src/types.rs9
4 files changed, 56 insertions, 47 deletions
diff --git a/src/ffi.rs b/src/ffi.rs
new file mode 100644
index 0000000..ceb8f35
--- /dev/null
+++ b/src/ffi.rs
@@ -0,0 +1,34 @@
+use libc;
+
+use types;
+
+extern "C" {
+ pub fn vt100_screen_new(
+ rows: libc::c_int,
+ cols: libc::c_int
+ ) -> *mut types::ScreenImpl;
+ pub fn vt100_screen_delete(screen: *mut types::ScreenImpl);
+
+ pub fn vt100_screen_process_string(
+ screen: *mut types::ScreenImpl,
+ buf: *const libc::c_char,
+ len: libc::size_t,
+ ) -> libc::c_int;
+ pub fn vt100_screen_get_string_plaintext(
+ screen: *mut types::ScreenImpl,
+ start: *const types::Loc,
+ end: *const types::Loc,
+ outp: *mut *mut libc::c_char,
+ outlen: *mut libc::size_t,
+ );
+}
+
+#[cfg(test)]
+mod tests {
+ #[test]
+ fn ffi() {
+ let ptr = unsafe { super::vt100_screen_new(24, 80) };
+ assert!(!ptr.is_null());
+ unsafe { super::vt100_screen_delete(ptr) };
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index 92267a1..71fc540 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,7 @@
extern crate libc;
+mod ffi;
mod screen;
+mod types;
pub use screen::Screen;
diff --git a/src/screen.rs b/src/screen.rs
index c8b5b8d..698a6af 100644
--- a/src/screen.rs
+++ b/src/screen.rs
@@ -1,25 +1,20 @@
use libc;
use std;
-enum ScreenImpl {}
-
-#[repr(C)]
-struct Loc {
- pub row: libc::c_int,
- pub col: libc::c_int,
-}
+use ffi;
+use types;
pub struct Screen {
pub rows: i32,
pub cols: i32,
- screen_impl: *mut ScreenImpl,
+ screen_impl: *mut types::ScreenImpl,
}
impl Screen {
pub fn new(rows: i32, cols: i32) -> Screen {
let screen_impl = unsafe {
- vt100_screen_new(rows as libc::c_int, cols as libc::c_int)
+ ffi::vt100_screen_new(rows as libc::c_int, cols as libc::c_int)
};
Screen {
rows: rows,
@@ -30,7 +25,7 @@ impl Screen {
pub fn process(&mut self, s: &str) -> u64 {
unsafe {
- vt100_screen_process_string(
+ ffi::vt100_screen_process_string(
self.screen_impl,
s.as_ptr() as *const libc::c_char,
s.len()
@@ -49,16 +44,16 @@ impl Screen {
let row_end = std::cmp::min(std::cmp::max(row_end, 0), self.rows - 1);
let col_end = std::cmp::min(std::cmp::max(col_end, 0), self.cols - 1);
- let start_loc = Loc { row: row_start, col: col_start };
- let end_loc = Loc { row: row_end, col: col_end };
+ let start_loc = types::Loc { row: row_start, col: col_start };
+ let end_loc = types::Loc { row: row_end, col: col_end };
let mut plaintext: *mut libc::c_char = unsafe { std::mem::uninitialized() };
let mut len: libc::size_t = unsafe { std::mem::uninitialized() };
unsafe {
- vt100_screen_get_string_plaintext(
+ ffi::vt100_screen_get_string_plaintext(
self.screen_impl,
- &start_loc as *const Loc,
- &end_loc as *const Loc,
+ &start_loc as *const types::Loc,
+ &end_loc as *const types::Loc,
&mut plaintext as *mut *mut libc::c_char,
&mut len as *mut libc::size_t,
)
@@ -75,37 +70,6 @@ impl Screen {
impl Drop for Screen {
fn drop(&mut self) {
- unsafe { vt100_screen_delete(self.screen_impl) };
- }
-}
-
-extern "C" {
- fn vt100_screen_new(
- rows: libc::c_int,
- cols: libc::c_int
- ) -> *mut ScreenImpl;
- fn vt100_screen_delete(screen: *mut ScreenImpl);
-
- fn vt100_screen_process_string(
- screen: *mut ScreenImpl,
- buf: *const libc::c_char,
- len: libc::size_t,
- ) -> libc::c_int;
- fn vt100_screen_get_string_plaintext(
- screen: *mut ScreenImpl,
- start: *const Loc,
- end: *const Loc,
- outp: *mut *mut libc::c_char,
- outlen: *mut libc::size_t,
- );
-}
-
-#[cfg(test)]
-mod tests {
- #[test]
- fn ffi() {
- let ptr = unsafe { super::vt100_screen_new(24, 80) };
- assert!(!ptr.is_null());
- unsafe { super::vt100_screen_delete(ptr) };
+ unsafe { ffi::vt100_screen_delete(self.screen_impl) };
}
}
diff --git a/src/types.rs b/src/types.rs
new file mode 100644
index 0000000..a5ac590
--- /dev/null
+++ b/src/types.rs
@@ -0,0 +1,9 @@
+use libc;
+
+pub enum ScreenImpl {}
+
+#[repr(C)]
+pub struct Loc {
+ pub row: libc::c_int,
+ pub col: libc::c_int,
+}