aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2016-04-27 03:49:48 -0400
committerJesse Luehrs <doy@tozt.net>2016-04-27 03:49:48 -0400
commitc50136709ec7940b616f0645191d84264c22fa7f (patch)
treeebe7106867db1cbc7d6d182d9281b1a2ee4e9fdb
parent06445fe6e42f44bbb14f00afee97865b58250a70 (diff)
downloadvt100-rust-c50136709ec7940b616f0645191d84264c22fa7f.tar.gz
vt100-rust-c50136709ec7940b616f0645191d84264c22fa7f.zip
allow the attr ffi wrappers to be used on more than just cells
-rw-r--r--src/cell.rs28
-rw-r--r--src/ffi.c16
-rw-r--r--src/ffi.rs8
3 files changed, 36 insertions, 16 deletions
diff --git a/src/cell.rs b/src/cell.rs
index e78f16c..abec58f 100644
--- a/src/cell.rs
+++ b/src/cell.rs
@@ -58,21 +58,41 @@ impl Cell {
pub fn bold(&self) -> bool {
let Cell(cell_impl) = *self;
- unsafe { ffi::vt100_wrapper_cell_bold(cell_impl) != 0 }
+ let prefix: *mut CellPrefix = unsafe {
+ std::mem::transmute(cell_impl)
+ };
+ unsafe {
+ ffi::vt100_wrapper_cell_attrs_bold(&mut (*prefix).attrs) != 0
+ }
}
pub fn italic(&self) -> bool {
let Cell(cell_impl) = *self;
- unsafe { ffi::vt100_wrapper_cell_italic(cell_impl) != 0 }
+ let prefix: *mut CellPrefix = unsafe {
+ std::mem::transmute(cell_impl)
+ };
+ unsafe {
+ ffi::vt100_wrapper_cell_attrs_italic(&mut (*prefix).attrs) != 0
+ }
}
pub fn underline(&self) -> bool {
let Cell(cell_impl) = *self;
- unsafe { ffi::vt100_wrapper_cell_underline(cell_impl) != 0 }
+ let prefix: *mut CellPrefix = unsafe {
+ std::mem::transmute(cell_impl)
+ };
+ unsafe {
+ ffi::vt100_wrapper_cell_attrs_underline(&mut (*prefix).attrs) != 0
+ }
}
pub fn inverse(&self) -> bool {
let Cell(cell_impl) = *self;
- unsafe { ffi::vt100_wrapper_cell_inverse(cell_impl) != 0 }
+ let prefix: *mut CellPrefix = unsafe {
+ std::mem::transmute(cell_impl)
+ };
+ unsafe {
+ ffi::vt100_wrapper_cell_attrs_inverse(&mut (*prefix).attrs) != 0
+ }
}
}
diff --git a/src/ffi.c b/src/ffi.c
index f3d1ecf..ac52f92 100644
--- a/src/ffi.c
+++ b/src/ffi.c
@@ -6,22 +6,22 @@ int vt100_wrapper_cell_is_wide(struct vt100_cell *cell)
return cell->is_wide;
}
-int vt100_wrapper_cell_bold(struct vt100_cell *cell)
+int vt100_wrapper_cell_attrs_bold(struct vt100_cell_attrs *attrs)
{
- return cell->attrs.bold;
+ return attrs->bold;
}
-int vt100_wrapper_cell_italic(struct vt100_cell *cell)
+int vt100_wrapper_cell_attrs_italic(struct vt100_cell_attrs *attrs)
{
- return cell->attrs.italic;
+ return attrs->italic;
}
-int vt100_wrapper_cell_underline(struct vt100_cell *cell)
+int vt100_wrapper_cell_attrs_underline(struct vt100_cell_attrs *attrs)
{
- return cell->attrs.underline;
+ return attrs->underline;
}
-int vt100_wrapper_cell_inverse(struct vt100_cell *cell)
+int vt100_wrapper_cell_attrs_inverse(struct vt100_cell_attrs *attrs)
{
- return cell->attrs.inverse;
+ return attrs->inverse;
}
diff --git a/src/ffi.rs b/src/ffi.rs
index 4586bcd..daab278 100644
--- a/src/ffi.rs
+++ b/src/ffi.rs
@@ -39,10 +39,10 @@ extern "C" {
) -> *mut types::CellImpl;
pub fn vt100_wrapper_cell_is_wide(cell: *mut types::CellImpl) -> libc::c_int;
- pub fn vt100_wrapper_cell_bold(cell: *mut types::CellImpl) -> libc::c_int;
- pub fn vt100_wrapper_cell_italic(cell: *mut types::CellImpl) -> libc::c_int;
- pub fn vt100_wrapper_cell_underline(cell: *mut types::CellImpl) -> libc::c_int;
- pub fn vt100_wrapper_cell_inverse(cell: *mut types::CellImpl) -> libc::c_int;
+ pub fn vt100_wrapper_cell_attrs_bold(cell: *mut types::CellAttrs) -> libc::c_int;
+ pub fn vt100_wrapper_cell_attrs_italic(cell: *mut types::CellAttrs) -> libc::c_int;
+ pub fn vt100_wrapper_cell_attrs_underline(cell: *mut types::CellAttrs) -> libc::c_int;
+ pub fn vt100_wrapper_cell_attrs_inverse(cell: *mut types::CellAttrs) -> libc::c_int;
}
#[cfg(test)]