aboutsummaryrefslogtreecommitdiffstats
path: root/src/cell.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/cell.rs')
-rw-r--r--src/cell.rs31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/cell.rs b/src/cell.rs
index 7590e98..4c0d6fb 100644
--- a/src/cell.rs
+++ b/src/cell.rs
@@ -1,14 +1,23 @@
use libc;
use std;
+use color;
use types;
pub struct Cell(*mut types::CellImpl);
#[repr(C)]
+struct CellAttrs {
+ fgcolor: types::ColorImpl,
+ bgcolor: types::ColorImpl,
+ attrs: libc::c_uchar,
+}
+
+#[repr(C)]
struct CellPrefix {
pub contents: [libc::c_char; 8],
pub len: libc::size_t,
+ pub attrs: CellAttrs,
}
impl Cell {
@@ -18,8 +27,10 @@ impl Cell {
pub fn contents(&self) -> &str {
let Cell(cell_impl) = *self;
+ let prefix: *mut CellPrefix = unsafe {
+ std::mem::transmute(cell_impl)
+ };
let contents: &[u8] = unsafe {
- let prefix: *mut CellPrefix = std::mem::transmute(cell_impl);
std::slice::from_raw_parts(
&(*prefix).contents as *const i8 as *const u8,
(*prefix).len
@@ -27,4 +38,22 @@ impl Cell {
};
std::str::from_utf8(contents).unwrap()
}
+
+ pub fn fgcolor(&self) -> color::Color {
+ let Cell(cell_impl) = *self;
+ let prefix: *mut CellPrefix = unsafe {
+ std::mem::transmute(cell_impl)
+ };
+ let attrs = unsafe { &(*prefix).attrs };
+ color::Color::new(&attrs.fgcolor)
+ }
+
+ pub fn bgcolor(&self) -> color::Color {
+ let Cell(cell_impl) = *self;
+ let prefix: *mut CellPrefix = unsafe {
+ std::mem::transmute(cell_impl)
+ };
+ let attrs = unsafe { &(*prefix).attrs };
+ color::Color::new(&attrs.bgcolor)
+ }
}