From b615e03beb20cb836fe643b57291657b9c2845d8 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 9 Mar 2023 01:45:05 -0500 Subject: stop implementing Default for Cell --- CHANGELOG.md | 1 + src/cell.rs | 10 +++++++++- src/grid.rs | 6 +++--- src/row.rs | 4 ++-- tests/helpers/fixtures.rs | 4 +++- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9fb38a..96e29d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * `Screen::bells_diff`, `Screen::audible_bell_count`, `Screen::visual_bell_count`, and `Screen::errors` have been removed in favor of the new callback api described above. +* `Cell` no longer implements `Default`. ### Changed diff --git a/src/cell.rs b/src/cell.rs index 240ddf9..b7ddd26 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -3,7 +3,7 @@ use unicode_width::UnicodeWidthChar as _; const CODEPOINTS_IN_CELL: usize = 6; /// Represents a single terminal cell. -#[derive(Clone, Debug, Default, Eq)] +#[derive(Clone, Debug, Eq)] pub struct Cell { contents: [char; CODEPOINTS_IN_CELL], len: u8, @@ -25,6 +25,14 @@ impl PartialEq for Cell { } impl Cell { + pub(crate) fn new() -> Self { + Self { + contents: Default::default(), + len: 0, + attrs: crate::attrs::Attrs::default(), + } + } + #[inline] fn len(&self) -> usize { usize::from(self.len & 0x0f) diff --git a/src/grid.rs b/src/grid.rs index dee4e10..a9ecfff 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -76,7 +76,7 @@ impl Grid { self.size = size; for row in &mut self.rows { - row.resize(size.cols, crate::Cell::default()); + row.resize(size.cols, crate::Cell::new()); } self.rows.resize(usize::from(size.rows), self.new_row()); @@ -496,7 +496,7 @@ impl Grid { if wide { row.get_mut(pos.col).unwrap().set_wide_continuation(false); } - row.insert(pos.col, crate::Cell::default()); + row.insert(pos.col, crate::Cell::new()); if wide { row.get_mut(pos.col).unwrap().set_wide_continuation(true); } @@ -511,7 +511,7 @@ impl Grid { for _ in 0..(count.min(size.cols - pos.col)) { row.remove(pos.col); } - row.resize(size.cols, crate::Cell::default()); + row.resize(size.cols, crate::Cell::new()); } pub fn erase_cells(&mut self, count: u16, attrs: crate::attrs::Attrs) { diff --git a/src/row.rs b/src/row.rs index def12f6..b52146c 100644 --- a/src/row.rs +++ b/src/row.rs @@ -9,7 +9,7 @@ pub struct Row { impl Row { pub fn new(cols: u16) -> Self { Self { - cells: vec![crate::Cell::default(); usize::from(cols)], + cells: vec![crate::Cell::new(); usize::from(cols)], wrapped: false, } } @@ -145,7 +145,7 @@ impl Row { prev_attrs: Option, ) -> (crate::grid::Pos, crate::attrs::Attrs) { let mut prev_was_wide = false; - let default_cell = crate::Cell::default(); + let default_cell = crate::Cell::new(); let mut prev_pos = prev_pos.unwrap_or_else(|| { if wrapping { diff --git a/tests/helpers/fixtures.rs b/tests/helpers/fixtures.rs index bc39926..44105ec 100644 --- a/tests/helpers/fixtures.rs +++ b/tests/helpers/fixtures.rs @@ -89,12 +89,14 @@ impl FixtureScreen { #[allow(dead_code)] pub fn from_screen(screen: &vt100::Screen) -> Self { + let empty_screen = vt100::Parser::default().screen().clone(); + let empty_cell = empty_screen.cell(0, 0).unwrap(); let mut cells = std::collections::BTreeMap::new(); let (rows, cols) = screen.size(); for row in 0..rows { for col in 0..cols { let cell = screen.cell(row, col).unwrap(); - if cell != &vt100::Cell::default() { + if cell != empty_cell { cells.insert( format!("{row},{col}"), FixtureCell::from_cell(cell), -- cgit v1.2.3-54-g00ecf