From 06445fe6e42f44bbb14f00afee97865b58250a70 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 27 Apr 2016 03:40:06 -0400 Subject: fgcolor and bgcolor for the screen --- src/cell.rs | 9 +-------- src/screen.rs | 21 +++++++++++++++++++++ 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 @@ -7,18 +7,11 @@ 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 @@ -4,6 +4,13 @@ pub enum ScreenImpl {} 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, -- cgit v1.2.3-54-g00ecf