diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-11 13:07:08 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-11 13:07:08 -0500 |
commit | 28cb645786aa233b975975173cff5f66c9b629c8 (patch) | |
tree | dd440e8aededee708e7b323633e77253afcacb78 /src/term.rs | |
parent | 3ff771c00eee3028757f474b546e23ff2bcbc481 (diff) | |
download | vt100-rust-28cb645786aa233b975975173cff5f66c9b629c8.tar.gz vt100-rust-28cb645786aa233b975975173cff5f66c9b629c8.zip |
factor out cursor movement logic
Diffstat (limited to 'src/term.rs')
-rw-r--r-- | src/term.rs | 26 |
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); + } + } +} |