aboutsummaryrefslogtreecommitdiffstats
path: root/src/cell.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2016-04-27 02:36:30 -0400
committerJesse Luehrs <doy@tozt.net>2016-04-27 03:03:46 -0400
commitdf328c13903d5a0e595d27b14f79e2a61f66f8fc (patch)
tree84812f3b90cd60a38a461e1b33e059365309492c /src/cell.rs
parent65b2ce10f83942a9dd2974ac19c694f1c6c9e617 (diff)
downloadvt100-rust-df328c13903d5a0e595d27b14f79e2a61f66f8fc.tar.gz
vt100-rust-df328c13903d5a0e595d27b14f79e2a61f66f8fc.zip
implement fgcolor and bgcolor for cells
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)
+ }
}