aboutsummaryrefslogtreecommitdiffstats
path: root/src/cell.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-10-29 13:42:00 -0400
committerJesse Luehrs <doy@tozt.net>2019-10-29 13:42:00 -0400
commitf84638fd816d2295c5d9f60c0ac8eb6df50d1aba (patch)
tree4562b26f23283710e454d257114813be1623ea1d /src/cell.rs
parente525fddb572614f4c6d6a7d71ed44e9dfe7af350 (diff)
downloadvt100-rust-f84638fd816d2295c5d9f60c0ac8eb6df50d1aba.tar.gz
vt100-rust-f84638fd816d2295c5d9f60c0ac8eb6df50d1aba.zip
start the rewrite
Diffstat (limited to 'src/cell.rs')
-rw-r--r--src/cell.rs94
1 files changed, 34 insertions, 60 deletions
diff --git a/src/cell.rs b/src/cell.rs
index 40b7fad..b1821c6 100644
--- a/src/cell.rs
+++ b/src/cell.rs
@@ -1,84 +1,58 @@
-use libc;
-use std;
-
-use color;
-use ffi;
-use types;
-
-pub struct Cell(*mut types::CellImpl);
-
-#[repr(C)]
-struct CellPrefix {
- pub contents: [libc::c_char; 8],
- pub len: libc::size_t,
- pub attrs: types::CellAttrs,
+#[derive(Clone, Debug)]
+pub struct Cell {
+ contents: String,
+ fgcolor: crate::color::Color,
+ bgcolor: crate::color::Color,
+ bold: bool,
+ italic: bool,
+ inverse: bool,
+ underline: bool,
}
impl Cell {
- pub fn new(cell_impl: *mut types::CellImpl) -> Cell {
- Cell(cell_impl)
+ pub fn new() -> Self {
+ Self::default()
}
pub fn contents(&self) -> &str {
- let Cell(cell_impl) = *self;
- let prefix: *mut CellPrefix = cell_impl as *mut CellPrefix;
- let contents: &[u8] = unsafe {
- std::slice::from_raw_parts(
- &(*prefix).contents as *const i8 as *const u8,
- (*prefix).len,
- )
- };
- std::str::from_utf8(contents).unwrap()
+ &self.contents
}
- pub fn fgcolor(&self) -> color::Color {
- let Cell(cell_impl) = *self;
- let prefix: *mut CellPrefix = cell_impl as *mut CellPrefix;
- let attrs = unsafe { &(*prefix).attrs };
- color::Color::new(&attrs.fgcolor)
+ pub fn fgcolor(&self) -> crate::color::Color {
+ self.fgcolor
}
- pub fn bgcolor(&self) -> color::Color {
- let Cell(cell_impl) = *self;
- let prefix: *mut CellPrefix = cell_impl as *mut CellPrefix;
- let attrs = unsafe { &(*prefix).attrs };
- color::Color::new(&attrs.bgcolor)
- }
-
- pub fn is_wide(&self) -> bool {
- let Cell(cell_impl) = *self;
- unsafe { ffi::vt100_wrapper_cell_is_wide(cell_impl) != 0 }
+ pub fn bgcolor(&self) -> crate::color::Color {
+ self.bgcolor
}
pub fn bold(&self) -> bool {
- let Cell(cell_impl) = *self;
- let prefix: *mut CellPrefix = cell_impl as *mut CellPrefix;
- unsafe {
- ffi::vt100_wrapper_cell_attrs_bold(&mut (*prefix).attrs) != 0
- }
+ self.bold
}
pub fn italic(&self) -> bool {
- let Cell(cell_impl) = *self;
- let prefix: *mut CellPrefix = cell_impl as *mut CellPrefix;
- unsafe {
- ffi::vt100_wrapper_cell_attrs_italic(&mut (*prefix).attrs) != 0
- }
+ self.italic
+ }
+
+ pub fn inverse(&self) -> bool {
+ self.inverse
}
pub fn underline(&self) -> bool {
- let Cell(cell_impl) = *self;
- let prefix: *mut CellPrefix = cell_impl as *mut CellPrefix;
- unsafe {
- ffi::vt100_wrapper_cell_attrs_underline(&mut (*prefix).attrs) != 0
- }
+ self.underline
}
+}
- pub fn inverse(&self) -> bool {
- let Cell(cell_impl) = *self;
- let prefix: *mut CellPrefix = cell_impl as *mut CellPrefix;
- unsafe {
- ffi::vt100_wrapper_cell_attrs_inverse(&mut (*prefix).attrs) != 0
+impl Default for Cell {
+ fn default() -> Self {
+ Self {
+ contents: String::new(),
+ fgcolor: crate::color::Color::Default,
+ bgcolor: crate::color::Color::Default,
+ bold: false,
+ italic: false,
+ inverse: false,
+ underline: false,
}
}
}