diff options
author | Jesse Luehrs <doy@tozt.net> | 2016-04-27 03:40:06 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2016-04-27 03:40:06 -0400 |
commit | 06445fe6e42f44bbb14f00afee97865b58250a70 (patch) | |
tree | e0d5d7382c91b5902a3042cded6a548a29c50750 | |
parent | de82973a9e4a5d50547587b7f3aa092223240826 (diff) | |
download | vt100-rust-06445fe6e42f44bbb14f00afee97865b58250a70.tar.gz vt100-rust-06445fe6e42f44bbb14f00afee97865b58250a70.zip |
fgcolor and bgcolor for the screen
-rw-r--r-- | src/cell.rs | 9 | ||||
-rw-r--r-- | src/screen.rs | 21 | ||||
-rw-r--r-- | src/types.rs | 7 |
3 files changed, 29 insertions, 8 deletions
diff --git a/src/cell.rs b/src/cell.rs index ef12756..e78f16c 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -8,17 +8,10 @@ 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, + pub attrs: types::CellAttrs, } impl Cell { diff --git a/src/screen.rs b/src/screen.rs index 212da51..7b6e2a2 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -2,6 +2,7 @@ use libc; use std; use cell; +use color; use ffi; use types; @@ -22,6 +23,8 @@ struct ScreenPrefix { title_len: libc::size_t, icon_name: *mut libc::c_char, icon_name_len: libc::size_t, + + attrs: types::CellAttrs, } impl Screen { @@ -174,6 +177,24 @@ impl Screen { Some(std::str::from_utf8(slice).unwrap()) } } + + pub fn fgcolor(&self) -> color::Color { + let Screen(screen_impl) = *self; + let prefix: *mut ScreenPrefix = unsafe { + std::mem::transmute(screen_impl) + }; + let attrs = unsafe { &(*prefix).attrs }; + color::Color::new(&attrs.fgcolor) + } + + pub fn bgcolor(&self) -> color::Color { + let Screen(screen_impl) = *self; + let prefix: *mut ScreenPrefix = unsafe { + std::mem::transmute(screen_impl) + }; + let attrs = unsafe { &(*prefix).attrs }; + color::Color::new(&attrs.bgcolor) + } } impl Drop for Screen { diff --git a/src/types.rs b/src/types.rs index 6e82779..04806d8 100644 --- a/src/types.rs +++ b/src/types.rs @@ -5,6 +5,13 @@ pub enum CellImpl {} pub struct ColorImpl(pub libc::uint32_t); #[repr(C)] +pub struct CellAttrs { + pub fgcolor: ColorImpl, + pub bgcolor: ColorImpl, + pub attrs: libc::c_uchar, +} + +#[repr(C)] pub struct Loc { pub row: libc::c_int, pub col: libc::c_int, |