Add more controls

Add support for scrolling up and down, and moving the cursor up and
down.
This commit is contained in:
Philip Munksgaard 2016-07-13 23:43:37 +02:00
parent 3996d24f12
commit 7a723b0ef5
1 changed files with 60 additions and 0 deletions

View File

@ -91,6 +91,66 @@ pub trait TermWrite {
}
}
/// Move the cursor `num` spaces up.
#[inline]
fn move_cursor_up(&mut self, num: u32) -> io::Result<usize> {
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<usize> {
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<usize> {
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<usize> {
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.