aboutsummaryrefslogtreecommitdiffstats
path: root/src/row.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-10-29 16:20:40 -0400
committerJesse Luehrs <doy@tozt.net>2019-10-29 16:20:40 -0400
commit95d757f2643d7451973c121d775ff1bae4ee26e9 (patch)
tree26564a8414541ed64bfe23fb9e5516abfc8bbb83 /src/row.rs
parent1f7cb68522ceb57187bcc9353bc2be405a927015 (diff)
downloadvt100-rust-95d757f2643d7451973c121d775ff1bae4ee26e9.tar.gz
vt100-rust-95d757f2643d7451973c121d775ff1bae4ee26e9.zip
more passing tests
Diffstat (limited to 'src/row.rs')
-rw-r--r--src/row.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/row.rs b/src/row.rs
new file mode 100644
index 0000000..f9c4e77
--- /dev/null
+++ b/src/row.rs
@@ -0,0 +1,40 @@
+#[derive(Clone)]
+pub struct Row {
+ cells: Vec<crate::cell::Cell>,
+ wrapped: bool,
+}
+
+impl Row {
+ pub fn new(cols: u16) -> Self {
+ Self {
+ cells: vec![crate::cell::Cell::default(); cols as usize],
+ wrapped: false,
+ }
+ }
+
+ pub fn get(&self, col: u16) -> Option<&crate::cell::Cell> {
+ self.cells.get(col as usize)
+ }
+
+ pub fn get_mut(&mut self, col: u16) -> Option<&mut crate::cell::Cell> {
+ self.cells.get_mut(col as usize)
+ }
+
+ pub fn contents(&self, col_start: u16, col_end: u16) -> String {
+ // XXX very inefficient
+ let mut max_col = 0;
+ for (col, cell) in self.cells.iter().enumerate() {
+ if cell.has_contents() {
+ max_col = col;
+ }
+ }
+ let mut contents = String::new();
+ for col in col_start..=(col_end.min(max_col as u16)) {
+ contents += self.cells[col as usize].contents();
+ }
+ if !self.wrapped {
+ contents += "\n";
+ }
+ contents
+ }
+}