aboutsummaryrefslogtreecommitdiffstats
path: root/src/grid.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-05 12:53:25 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-05 13:26:49 -0500
commit2e7f1686d719497d9b2d2d2c8ffba20e6c8214bd (patch)
tree8f31cb37faaec73bdf4a5253f0c34bceb3cc6d6f /src/grid.rs
parente12f9d9ee4e6b902436d0282e4a1e47ed7d54d6c (diff)
downloadvt100-rust-2e7f1686d719497d9b2d2d2c8ffba20e6c8214bd.tar.gz
vt100-rust-2e7f1686d719497d9b2d2d2c8ffba20e6c8214bd.zip
adjust the way window contents are reported
contents and contents_formatted now only allow getting the entire terminal contents, and for any other uses we now provide rows and rows_formatted. the reasoning here is that it wasn't particularly useful to return newline (or crlf) separated lines when not drawing the full terminal, since it's not like you can send those to the terminal in any meaningful way anyway (like, if you wanted to draw a subset of the terminal state, you'll almost certainly need to be doing explicit positioning on your own, since crlf is only actually correct if you're drawing the screen subset in the upper left hand corner of the screen). with this, you can draw each (subset of a) line individually, and reposition the cursor in whatever way makes sense in between drawing the lines.
Diffstat (limited to 'src/grid.rs')
-rw-r--r--src/grid.rs43
1 files changed, 14 insertions, 29 deletions
diff --git a/src/grid.rs b/src/grid.rs
index d7abbad..14a3eae 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -123,48 +123,33 @@ impl Grid {
.expect("cursor not pointing to a cell")
}
- pub fn contents(
- &self,
- row_start: u16,
- col_start: u16,
- row_end: u16,
- col_end: u16,
- ) -> String {
+ pub fn contents(&self) -> String {
let mut contents = String::new();
- let row_start = row_start as usize;
- let row_end = row_end as usize;
- for row in self.rows().skip(row_start).take(row_end - row_start + 1) {
- contents += &row.contents(col_start, col_end);
+ for row in self.rows() {
+ contents += &row.contents(0, self.size.cols);
+ if !row.wrapped() {
+ contents += "\n";
+ }
}
contents.trim_end().to_string()
}
- pub fn contents_formatted(
- &self,
- row_start: u16,
- col_start: u16,
- row_end: u16,
- col_end: u16,
- ) -> Vec<u8> {
+ pub fn contents_formatted(&self) -> Vec<u8> {
let mut contents = vec![];
let mut prev_attrs = crate::attrs::Attrs::default();
- let row_start = row_start as usize;
- let row_end = row_end as usize;
- for row in self.rows().skip(row_start).take(row_end - row_start + 1) {
+ for row in self.rows() {
let (mut new_contents, new_attrs) =
- row.contents_formatted(col_start, col_end, prev_attrs);
+ row.contents_formatted(0, self.size.cols, prev_attrs);
contents.append(&mut new_contents);
+ if !row.wrapped() {
+ contents.extend(b"\r\n");
+ }
prev_attrs = new_attrs;
}
- let mut idx = None;
- for (i, b) in contents.iter().enumerate().rev() {
- if !(*b as char).is_whitespace() {
- idx = Some(i + 1);
- break;
- }
+ while contents.ends_with(b"\r\n") {
+ contents.truncate(contents.len() - 2);
}
- contents.truncate(idx.unwrap_or(0));
contents
}