From d1b3cf663372d3cb28030f80609aff8a8df8a930 Mon Sep 17 00:00:00 2001 From: MovingtoMars Date: Sat, 11 Jun 2016 11:23:30 +1200 Subject: [PATCH 1/2] add move_cursor_{left,right} to TermWrite --- src/control.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/control.rs b/src/control.rs index 24a68d2..1899b1d 100644 --- a/src/control.rs +++ b/src/control.rs @@ -43,6 +43,32 @@ pub trait TermWrite { fn hide_cursor(&mut self) -> io::Result { self.csi(b"?25l") } + /// Move the cursor `num` spaces to the left. + fn move_cursor_left(&mut self, num: u32) -> io::Result { + if num > 0 { + self.csi(&[b'0' + (num / 10000) as u8, + b'0' + (num / 1000) as u8 % 10, + b'0' + (num / 100) as u8 % 10, + b'0' + (num / 10) as u8 % 10, + b'0' + num as u8 % 10, + b'C']) + } else { + Ok(0) + } + } + /// Move the cursor `num` spaces to the right. + fn move_cursor_right(&mut self, num: u32) -> io::Result { + if num > 0 { + self.csi(&[b'0' + (num / 10000) as u8, + b'0' + (num / 1000) as u8 % 10, + b'0' + (num / 100) as u8 % 10, + b'0' + (num / 10) as u8 % 10, + b'0' + num as u8 % 10, + b'D']) + } else { + Ok(0) + } + } // TODO // fn mode From aaeeb06d429de39c3c001e71541a0ec6319c4d19 Mon Sep 17 00:00:00 2001 From: MovingtoMars Date: Sat, 11 Jun 2016 22:29:04 +1200 Subject: [PATCH 2/2] fix cursor moving --- src/control.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/control.rs b/src/control.rs index 1899b1d..56f1e0a 100644 --- a/src/control.rs +++ b/src/control.rs @@ -51,7 +51,7 @@ pub trait TermWrite { b'0' + (num / 100) as u8 % 10, b'0' + (num / 10) as u8 % 10, b'0' + num as u8 % 10, - b'C']) + b'D']) } else { Ok(0) } @@ -64,7 +64,7 @@ pub trait TermWrite { b'0' + (num / 100) as u8 % 10, b'0' + (num / 10) as u8 % 10, b'0' + num as u8 % 10, - b'D']) + b'C']) } else { Ok(0) }