From 7a723b0ef53db242b95fd73739f8b18a4343e2bf Mon Sep 17 00:00:00 2001 From: Philip Munksgaard Date: Wed, 13 Jul 2016 23:43:37 +0200 Subject: [PATCH 1/2] Add more controls Add support for scrolling up and down, and moving the cursor up and down. --- src/control.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/control.rs b/src/control.rs index 810a087..7d0bd74 100644 --- a/src/control.rs +++ b/src/control.rs @@ -91,6 +91,66 @@ pub trait TermWrite { } } + /// Move the cursor `num` spaces up. + #[inline] + fn move_cursor_up(&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'A']) + } else { + Ok(0) + } + } + + /// Move the cursor `num` spaces down. + #[inline] + fn move_cursor_down(&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'B']) + } else { + Ok(0) + } + } + + /// Scroll the window up. + #[inline] + fn scroll_up(&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'S']) + } else { + Ok(0) + } + } + + /// Scroll the window down. + #[inline] + fn scroll_down(&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'T']) + } else { + Ok(0) + } + } + /// Reset the rendition mode. /// /// This will reset both the current style and color. From fa75b334d0efd13184d8b71fcd5738b924f15601 Mon Sep 17 00:00:00 2001 From: Philip Munksgaard Date: Thu, 14 Jul 2016 21:51:00 +0200 Subject: [PATCH 2/2] Improve function documentation --- src/control.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/control.rs b/src/control.rs index 7d0bd74..3d61109 100644 --- a/src/control.rs +++ b/src/control.rs @@ -121,7 +121,7 @@ pub trait TermWrite { } } - /// Scroll the window up. + /// Scroll the window `num` spaces up. #[inline] fn scroll_up(&mut self, num: u32) -> io::Result { if num > 0 { @@ -136,7 +136,7 @@ pub trait TermWrite { } } - /// Scroll the window down. + /// Scroll the window `num` spaces down. #[inline] fn scroll_down(&mut self, num: u32) -> io::Result { if num > 0 {