aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-10-31 12:57:43 -0400
committerJesse Luehrs <doy@tozt.net>2019-10-31 12:57:43 -0400
commitd808c39162273da61fec4d3273550149097726de (patch)
treed48a9b47148206d0ee33394d12ef3c2b1f31e9fb
parent3b072193b24fbad264548144142fcc448263284e (diff)
downloadvt100-rust-d808c39162273da61fec4d3273550149097726de.tar.gz
vt100-rust-d808c39162273da61fec4d3273550149097726de.zip
implement ascii text wrapping
-rw-r--r--src/grid.rs42
-rw-r--r--src/row.rs4
-rw-r--r--src/screen.rs3
3 files changed, 33 insertions, 16 deletions
diff --git a/src/grid.rs b/src/grid.rs
index 91fde39..7d6d487 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -46,14 +46,24 @@ impl Grid {
self.pos = self.saved_pos;
}
+ pub fn row(&self, pos: Pos) -> Option<&crate::row::Row> {
+ self.rows.get(pos.row as usize)
+ }
+
+ pub fn row_mut(&mut self, pos: Pos) -> Option<&mut crate::row::Row> {
+ self.rows.get_mut(pos.row as usize)
+ }
+
+ pub fn current_row_mut(&mut self) -> Option<&mut crate::row::Row> {
+ self.row_mut(self.pos)
+ }
+
pub fn cell(&self, pos: Pos) -> Option<&crate::cell::Cell> {
- self.rows.get(pos.row as usize).and_then(|r| r.get(pos.col))
+ self.row(pos).and_then(|r| r.get(pos.col))
}
pub fn cell_mut(&mut self, pos: Pos) -> Option<&mut crate::cell::Cell> {
- self.rows
- .get_mut(pos.row as usize)
- .and_then(|v| v.get_mut(pos.col))
+ self.row_mut(pos).and_then(|r| r.get_mut(pos.col))
}
pub fn current_cell_mut(&mut self) -> Option<&mut crate::cell::Cell> {
@@ -96,6 +106,7 @@ impl Grid {
self.rows[i as usize] = crate::row::Row::new(self.size.cols);
}
let row = &mut self.rows[pos.row as usize];
+ row.wrap(false);
for i in pos.col..self.size.cols {
*row.get_mut(i).unwrap() = crate::cell::Cell::default();
}
@@ -117,6 +128,7 @@ impl Grid {
pub fn erase_row_forward(&mut self, pos: Pos) {
let row = &mut self.rows[pos.row as usize];
+ row.wrap(false);
for i in pos.col..self.size.cols {
*row.get_mut(i).unwrap() = crate::cell::Cell::default();
}
@@ -240,14 +252,13 @@ impl Grid {
self.row_clamp_bottom();
}
- pub fn col_inc_clamp(&mut self, count: u16) {
+ pub fn col_inc(&mut self, count: u16) {
self.pos.col = self.pos.col.saturating_add(count);
- self.col_clamp();
}
- pub fn col_inc_wrap(&mut self, count: u16) {
+ pub fn col_inc_clamp(&mut self, count: u16) {
self.pos.col = self.pos.col.saturating_add(count);
- self.col_wrap();
+ self.col_clamp();
}
pub fn col_dec(&mut self, count: u16) {
@@ -265,6 +276,14 @@ impl Grid {
self.col_clamp();
}
+ pub fn col_wrap(&mut self) {
+ if self.pos.col > self.size.cols - 1 {
+ self.current_row_mut().unwrap().wrap(true);
+ self.pos.col = 0;
+ self.row_inc_scroll(1);
+ }
+ }
+
fn row_clamp_top(&mut self) -> u16 {
if self.pos.row < self.scroll_top {
let rows = self.scroll_top - self.pos.row;
@@ -290,13 +309,6 @@ impl Grid {
self.pos.col = self.size.cols - 1;
}
}
-
- fn col_wrap(&mut self) {
- if self.pos.col > self.size.cols - 1 {
- self.pos.col = 0;
- self.row_inc_scroll(1);
- }
- }
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
diff --git a/src/row.rs b/src/row.rs
index 878529e..65f3cd2 100644
--- a/src/row.rs
+++ b/src/row.rs
@@ -36,6 +36,10 @@ impl Row {
self.cells.resize(len, cell);
}
+ pub fn wrap(&mut self, wrap: bool) {
+ self.wrapped = wrap;
+ }
+
pub fn contents(&self, col_start: u16, col_end: u16) -> String {
// XXX very inefficient
let mut max_col = None;
diff --git a/src/screen.rs b/src/screen.rs
index 9f35546..f26d8a7 100644
--- a/src/screen.rs
+++ b/src/screen.rs
@@ -90,9 +90,10 @@ impl State {
fn text(&mut self, c: char) {
let attrs = self.attrs;
+ self.grid_mut().col_wrap();
if let Some(cell) = self.current_cell_mut() {
cell.set(c.to_string(), attrs);
- self.grid_mut().col_inc_wrap(1);
+ self.grid_mut().col_inc(1);
} else {
panic!("couldn't find current cell")
}