use super::*;
use Screen;
pub struct TerminalCursor<'stdout> {
screen: &'stdout Arc<TerminalOutput>,
terminal_cursor: Box<ITerminalCursor + Sync + Send>,
}
impl<'stdout> TerminalCursor<'stdout> {
pub fn new(screen: &'stdout Arc<TerminalOutput>) -> TerminalCursor<'stdout> {
#[cfg(target_os = "windows")]
let cursor =
functions::get_module::<Box<ITerminalCursor + Sync + Send>>(WinApiCursor::new(), AnsiCursor::new())
.unwrap();
#[cfg(not(target_os = "windows"))]
let cursor = AnsiCursor::new() as Box<ITerminalCursor + Sync + Send>;
TerminalCursor {
terminal_cursor: cursor,
screen: screen,
}
}
pub fn goto(&self, x: u16, y: u16) {
self.terminal_cursor.goto(x, y, &self.screen);
}
pub fn pos(&self) -> (u16, u16) {
self.terminal_cursor.pos(&self.screen)
}
pub fn move_up(&mut self, count: u16) -> &mut TerminalCursor<'stdout> {
self.terminal_cursor.move_up(count, &self.screen);
self
}
pub fn move_right(&mut self, count: u16) -> &mut TerminalCursor<'stdout> {
self.terminal_cursor.move_right(count, &self.screen);
self
}
pub fn move_down(&mut self, count: u16) -> &mut TerminalCursor<'stdout> {
self.terminal_cursor.move_down(count, &self.screen);
self
}
pub fn move_left(&mut self, count: u16) -> &mut TerminalCursor<'stdout> {
self.terminal_cursor.move_left(count, &self.screen);
self
}
pub fn save_position(&self) {
self.terminal_cursor.save_position(&self.screen);
}
pub fn reset_position(&self) {
self.terminal_cursor.reset_position(&self.screen);
}
pub fn hide(&self) {
self.terminal_cursor.hide(&self.screen);
}
pub fn show(&self) {
self.terminal_cursor.show(&self.screen);
}
pub fn blink(&self, blink: bool) {
self.terminal_cursor.blink(blink, &self.screen);
}
}
pub fn cursor<'stdout>(stdout: &'stdout Screen) -> TerminalCursor<'stdout> {
TerminalCursor::new(&stdout.stdout)
}