aboutsummaryrefslogtreecommitdiffstats
path: root/src/term.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-11 13:07:08 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-11 13:07:08 -0500
commit28cb645786aa233b975975173cff5f66c9b629c8 (patch)
treedd440e8aededee708e7b323633e77253afcacb78 /src/term.rs
parent3ff771c00eee3028757f474b546e23ff2bcbc481 (diff)
downloadvt100-rust-28cb645786aa233b975975173cff5f66c9b629c8.tar.gz
vt100-rust-28cb645786aa233b975975173cff5f66c9b629c8.zip
factor out cursor movement logic
Diffstat (limited to 'src/term.rs')
-rw-r--r--src/term.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/term.rs b/src/term.rs
index e1f1a22..5b99841 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -293,3 +293,29 @@ impl BufWrite for HideCursor {
}
}
}
+
+#[derive(Debug)]
+pub struct MoveFromTo {
+ from: crate::grid::Pos,
+ to: crate::grid::Pos,
+}
+
+impl MoveFromTo {
+ pub fn new(from: crate::grid::Pos, to: crate::grid::Pos) -> Self {
+ Self { from, to }
+ }
+}
+
+impl BufWrite for MoveFromTo {
+ fn write_buf(&self, buf: &mut Vec<u8>) {
+ if self.to.row == self.from.row + 1 && self.to.col == 0 {
+ crate::term::CRLF::default().write_buf(buf);
+ } else if self.from.row == self.to.row && self.from.col < self.to.col
+ {
+ crate::term::MoveRight::new(self.to.col - self.from.col)
+ .write_buf(buf);
+ } else {
+ crate::term::MoveTo::new(self.to).write_buf(buf);
+ }
+ }
+}