aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-12-07 02:53:54 -0500
committerJesse Luehrs <doy@tozt.net>2019-12-07 02:55:43 -0500
commit7152bfd5772f64ec0fc7d7d204f5fd4986104823 (patch)
treee794694fd3817d7b5dd9e5909d442fcb06f494e2
parent1075c2888dffb261164d1f3c5a5d216c4a3f0d35 (diff)
downloadvt100-rust-7152bfd5772f64ec0fc7d7d204f5fd4986104823.tar.gz
vt100-rust-7152bfd5772f64ec0fc7d7d204f5fd4986104823.zip
one more try for leaving a cursor at the end of a row
-rw-r--r--src/grid.rs32
-rw-r--r--src/term.rs28
-rw-r--r--tests/data/fixtures/il_dl.in1
-rw-r--r--tests/data/fixtures/il_dl/18.json12
-rw-r--r--tests/data/fixtures/il_dl/18.typescript2
5 files changed, 52 insertions, 23 deletions
diff --git a/src/grid.rs b/src/grid.rs
index b12216c..88c33eb 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -274,18 +274,20 @@ impl Grid {
}
// this can happen if you get the cursor off the end of a row,
- // and then do something to clear the current row without
- // moving the cursor (IL, ED, EL, etc). i can't see any way
- // for this to happen without the entire current row being
- // cleared (not just the last cell), so this seems
- // prooooobably fine?
+ // and then do something to clear the end of the current row
+ // without moving the cursor (IL, DL, ED, EL, etc). we know
+ // there can't be something in the last column because we
+ // would have caught that above, so it should be safe to
+ // overwrite it.
if !found {
pos.row = orig_row;
crate::term::MoveFromTo::new(prev_pos, pos)
.write_buf(contents);
contents.push(b' ');
- crate::term::ClearRowBackward::default()
- .write_buf(contents);
+ crate::term::SaveCursor::default().write_buf(contents);
+ crate::term::Backspace::default().write_buf(contents);
+ crate::term::EraseChar::new(1).write_buf(contents);
+ crate::term::RestoreCursor::default().write_buf(contents);
}
}
} else {
@@ -374,18 +376,20 @@ impl Grid {
}
// this can happen if you get the cursor off the end of a row,
- // and then do something to clear the current row without
- // moving the cursor (IL, ED, EL, etc). i can't see any way
- // for this to happen without the entire current row being
- // cleared (not just the last cell), so this seems
- // prooooobably fine?
+ // and then do something to clear the end of the current row
+ // without moving the cursor (IL, DL, ED, EL, etc). we know
+ // there can't be something in the last column because we
+ // would have caught that above, so it should be safe to
+ // overwrite it.
if !found {
pos.row = orig_row;
crate::term::MoveFromTo::new(prev_pos, pos)
.write_buf(contents);
contents.push(b' ');
- crate::term::ClearRowBackward::default()
- .write_buf(contents);
+ crate::term::SaveCursor::default().write_buf(contents);
+ crate::term::Backspace::default().write_buf(contents);
+ crate::term::EraseChar::new(1).write_buf(contents);
+ crate::term::RestoreCursor::default().write_buf(contents);
}
}
} else {
diff --git a/src/term.rs b/src/term.rs
index 0a578c1..31e1f51 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -26,31 +26,41 @@ impl BufWrite for ClearRowForward {
#[derive(Default, Debug)]
#[must_use = "this struct does nothing unless you call write_buf"]
-pub struct ClearRowBackward;
+pub struct CRLF;
-impl BufWrite for ClearRowBackward {
+impl BufWrite for CRLF {
fn write_buf(&self, buf: &mut Vec<u8>) {
- buf.extend_from_slice(b"\x1b[1K");
+ buf.extend_from_slice(b"\r\n");
}
}
#[derive(Default, Debug)]
#[must_use = "this struct does nothing unless you call write_buf"]
-pub struct CRLF;
+pub struct Backspace;
-impl BufWrite for CRLF {
+impl BufWrite for Backspace {
fn write_buf(&self, buf: &mut Vec<u8>) {
- buf.extend_from_slice(b"\r\n");
+ buf.extend_from_slice(b"\x08");
}
}
#[derive(Default, Debug)]
#[must_use = "this struct does nothing unless you call write_buf"]
-pub struct Backspace;
+pub struct SaveCursor;
-impl BufWrite for Backspace {
+impl BufWrite for SaveCursor {
fn write_buf(&self, buf: &mut Vec<u8>) {
- buf.extend_from_slice(b"\x08");
+ buf.extend_from_slice(b"\x1b7");
+ }
+}
+
+#[derive(Default, Debug)]
+#[must_use = "this struct does nothing unless you call write_buf"]
+pub struct RestoreCursor;
+
+impl BufWrite for RestoreCursor {
+ fn write_buf(&self, buf: &mut Vec<u8>) {
+ buf.extend_from_slice(b"\x1b8");
}
}
diff --git a/tests/data/fixtures/il_dl.in b/tests/data/fixtures/il_dl.in
index 3e159aa..db55d5e 100644
--- a/tests/data/fixtures/il_dl.in
+++ b/tests/data/fixtures/il_dl.in
@@ -15,3 +15,4 @@ a
b
\x1b[L
cd
+\x1bc\na\x1b[1;80Hb\x1b[M
diff --git a/tests/data/fixtures/il_dl/18.json b/tests/data/fixtures/il_dl/18.json
new file mode 100644
index 0000000..131a334
--- /dev/null
+++ b/tests/data/fixtures/il_dl/18.json
@@ -0,0 +1,12 @@
+{
+ "contents": "a",
+ "cells": {
+ "0,0": {
+ "contents": "a"
+ }
+ },
+ "cursor_position": [
+ 0,
+ 80
+ ]
+} \ No newline at end of file
diff --git a/tests/data/fixtures/il_dl/18.typescript b/tests/data/fixtures/il_dl/18.typescript
new file mode 100644
index 0000000..607e0b1
--- /dev/null
+++ b/tests/data/fixtures/il_dl/18.typescript
@@ -0,0 +1,2 @@
+c
+ab \ No newline at end of file