From df328c13903d5a0e595d27b14f79e2a61f66f8fc Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 27 Apr 2016 02:36:30 -0400 Subject: implement fgcolor and bgcolor for cells --- src/cell.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/cell.rs') 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) + } } -- cgit v1.2.3-54-g00ecf