aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-12-05 14:48:06 -0500
committerJesse Luehrs <doy@tozt.net>2019-12-06 21:26:07 -0500
commit532a9b9417f26c2d7011e4f1b79d556db717a650 (patch)
tree465e59a1cef826f7d08940bbd9f9932bda5a91ab
parent10b5fca013b4fa0839b60262164400e5a63f2fb4 (diff)
downloadvt100-rust-532a9b9417f26c2d7011e4f1b79d556db717a650.tar.gz
vt100-rust-532a9b9417f26c2d7011e4f1b79d556db717a650.zip
preserve wrapping state when possible
-rw-r--r--src/row.rs34
-rw-r--r--src/term.rs10
-rw-r--r--tests/data/fixtures/il_dl.in5
-rw-r--r--tests/data/fixtures/il_dl/13.json8
-rw-r--r--tests/data/fixtures/il_dl/13.typescript1
-rw-r--r--tests/data/fixtures/il_dl/14.json12
-rw-r--r--tests/data/fixtures/il_dl/14.typescript1
-rw-r--r--tests/data/fixtures/il_dl/15.json15
-rw-r--r--tests/data/fixtures/il_dl/15.typescript1
-rw-r--r--tests/data/fixtures/il_dl/16.json15
-rw-r--r--tests/data/fixtures/il_dl/16.typescript1
-rw-r--r--tests/data/fixtures/il_dl/17.json21
-rw-r--r--tests/data/fixtures/il_dl/17.typescript1
13 files changed, 125 insertions, 0 deletions
diff --git a/src/row.rs b/src/row.rs
index 36d7d34..8f96c27 100644
--- a/src/row.rs
+++ b/src/row.rs
@@ -127,6 +127,14 @@ impl Row {
let mut prev_was_wide = false;
let default_cell = crate::cell::Cell::default();
+ let first_cell = self.get(start).unwrap();
+ if wrapping && first_cell == &default_cell {
+ contents.push(b' ');
+ crate::term::Backspace::default().write_buf(contents);
+ crate::term::EraseChar::new(1).write_buf(contents);
+ prev_pos = crate::grid::Pos { row, col: 0 };
+ }
+
let mut erase: Option<(u16, &crate::attrs::Attrs)> = None;
for (col, cell) in self
.cells()
@@ -221,6 +229,32 @@ impl Row {
) -> (crate::grid::Pos, crate::attrs::Attrs) {
let mut prev_was_wide = false;
+ let first_cell = self.get(start).unwrap();
+ let prev_first_cell = prev.get(start).unwrap();
+ if wrapping
+ && first_cell == prev_first_cell
+ && prev_pos.row + 1 == row
+ && prev_pos.col
+ >= self.cols() - if prev_first_cell.is_wide() { 1 } else { 0 }
+ {
+ let mut cell_contents = prev_first_cell.contents();
+ let need_erase = if cell_contents == "" {
+ cell_contents = " ".to_string();
+ true
+ } else {
+ false
+ };
+ contents.extend(cell_contents.as_bytes());
+ crate::term::Backspace::default().write_buf(contents);
+ if prev_first_cell.is_wide() {
+ crate::term::Backspace::default().write_buf(contents);
+ }
+ if need_erase {
+ crate::term::EraseChar::new(1).write_buf(contents);
+ }
+ prev_pos = crate::grid::Pos { row, col: 0 };
+ }
+
let mut erase: Option<(u16, &crate::attrs::Attrs)> = None;
for (col, (cell, prev_cell)) in self
.cells()
diff --git a/src/term.rs b/src/term.rs
index 5a9fbd6..0a578c1 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -46,6 +46,16 @@ impl BufWrite for CRLF {
#[derive(Default, Debug)]
#[must_use = "this struct does nothing unless you call write_buf"]
+pub struct Backspace;
+
+impl BufWrite for Backspace {
+ fn write_buf(&self, buf: &mut Vec<u8>) {
+ buf.extend_from_slice(b"\x08");
+ }
+}
+
+#[derive(Default, Debug)]
+#[must_use = "this struct does nothing unless you call write_buf"]
pub struct MoveTo {
row: u16,
col: u16,
diff --git a/tests/data/fixtures/il_dl.in b/tests/data/fixtures/il_dl.in
index e0a564e..3e159aa 100644
--- a/tests/data/fixtures/il_dl.in
+++ b/tests/data/fixtures/il_dl.in
@@ -10,3 +10,8 @@
a
\x1b[L
bc
+\x1bc\x1b[1;80H
+a
+b
+\x1b[L
+cd
diff --git a/tests/data/fixtures/il_dl/13.json b/tests/data/fixtures/il_dl/13.json
new file mode 100644
index 0000000..5deb58b
--- /dev/null
+++ b/tests/data/fixtures/il_dl/13.json
@@ -0,0 +1,8 @@
+{
+ "contents": "",
+ "cells": {},
+ "cursor_position": [
+ 0,
+ 79
+ ]
+} \ No newline at end of file
diff --git a/tests/data/fixtures/il_dl/13.typescript b/tests/data/fixtures/il_dl/13.typescript
new file mode 100644
index 0000000..fc29e50
--- /dev/null
+++ b/tests/data/fixtures/il_dl/13.typescript
@@ -0,0 +1 @@
+c \ No newline at end of file
diff --git a/tests/data/fixtures/il_dl/14.json b/tests/data/fixtures/il_dl/14.json
new file mode 100644
index 0000000..59543cb
--- /dev/null
+++ b/tests/data/fixtures/il_dl/14.json
@@ -0,0 +1,12 @@
+{
+ "contents": " a",
+ "cells": {
+ "0,79": {
+ "contents": "a"
+ }
+ },
+ "cursor_position": [
+ 0,
+ 80
+ ]
+} \ No newline at end of file
diff --git a/tests/data/fixtures/il_dl/14.typescript b/tests/data/fixtures/il_dl/14.typescript
new file mode 100644
index 0000000..2e65efe
--- /dev/null
+++ b/tests/data/fixtures/il_dl/14.typescript
@@ -0,0 +1 @@
+a \ No newline at end of file
diff --git a/tests/data/fixtures/il_dl/15.json b/tests/data/fixtures/il_dl/15.json
new file mode 100644
index 0000000..a28d5bc
--- /dev/null
+++ b/tests/data/fixtures/il_dl/15.json
@@ -0,0 +1,15 @@
+{
+ "contents": " ab",
+ "cells": {
+ "0,79": {
+ "contents": "a"
+ },
+ "1,0": {
+ "contents": "b"
+ }
+ },
+ "cursor_position": [
+ 1,
+ 1
+ ]
+} \ No newline at end of file
diff --git a/tests/data/fixtures/il_dl/15.typescript b/tests/data/fixtures/il_dl/15.typescript
new file mode 100644
index 0000000..63d8dbd
--- /dev/null
+++ b/tests/data/fixtures/il_dl/15.typescript
@@ -0,0 +1 @@
+b \ No newline at end of file
diff --git a/tests/data/fixtures/il_dl/16.json b/tests/data/fixtures/il_dl/16.json
new file mode 100644
index 0000000..102c2f1
--- /dev/null
+++ b/tests/data/fixtures/il_dl/16.json
@@ -0,0 +1,15 @@
+{
+ "contents": " a\nb",
+ "cells": {
+ "0,79": {
+ "contents": "a"
+ },
+ "2,0": {
+ "contents": "b"
+ }
+ },
+ "cursor_position": [
+ 1,
+ 1
+ ]
+} \ No newline at end of file
diff --git a/tests/data/fixtures/il_dl/16.typescript b/tests/data/fixtures/il_dl/16.typescript
new file mode 100644
index 0000000..a330c08
--- /dev/null
+++ b/tests/data/fixtures/il_dl/16.typescript
@@ -0,0 +1 @@
+ \ No newline at end of file
diff --git a/tests/data/fixtures/il_dl/17.json b/tests/data/fixtures/il_dl/17.json
new file mode 100644
index 0000000..4b2e900
--- /dev/null
+++ b/tests/data/fixtures/il_dl/17.json
@@ -0,0 +1,21 @@
+{
+ "contents": " a cd\nb",
+ "cells": {
+ "0,79": {
+ "contents": "a"
+ },
+ "1,1": {
+ "contents": "c"
+ },
+ "1,2": {
+ "contents": "d"
+ },
+ "2,0": {
+ "contents": "b"
+ }
+ },
+ "cursor_position": [
+ 1,
+ 3
+ ]
+} \ No newline at end of file
diff --git a/tests/data/fixtures/il_dl/17.typescript b/tests/data/fixtures/il_dl/17.typescript
new file mode 100644
index 0000000..25038d7
--- /dev/null
+++ b/tests/data/fixtures/il_dl/17.typescript
@@ -0,0 +1 @@
+cd \ No newline at end of file