use super::*;
use Screen;
pub struct TerminalCursor<'stdout> {
terminal_cursor: Box<ITerminalCursor + Sync + Send>,
stdout: Option<&'stdout Arc<TerminalOutput>>,
}
impl<'stdout> TerminalCursor<'stdout> {
pub fn new() -> 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,
stdout: None,
}
}
pub fn from_output(stdout: &'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,
stdout: Some(stdout),
}
}
pub fn goto(&self, x: u16, y: u16) {
self.terminal_cursor.goto(x, y, &self.stdout);
}
pub fn pos(&self) -> (u16, u16) {
self.terminal_cursor.pos()
}
pub fn move_up(&mut self, count: u16) -> &mut TerminalCursor<'stdout> {
self.terminal_cursor.move_up(count, &self.stdout);
self
}
pub fn move_right(&mut self, count: u16) -> &mut TerminalCursor<'stdout> {
self.terminal_cursor.move_right(count, &self.stdout);
self
}
pub fn move_down(&mut self, count: u16) -> &mut TerminalCursor<'stdout> {
self.terminal_cursor.move_down(count, &self.stdout);
self
}
pub fn move_left(&mut self, count: u16) -> &mut TerminalCursor<'stdout> {
self.terminal_cursor.move_left(count, &self.stdout);
self
}
pub fn save_position(&self) {
self.terminal_cursor.save_position(&self.stdout);
}
pub fn reset_position(&self) {
self.terminal_cursor.reset_position(&self.stdout);
}
pub fn hide(&self) {
self.terminal_cursor.hide(&self.stdout);
}
pub fn show(&self) {
self.terminal_cursor.show(&self.stdout);
}
pub fn blink(&self, blink: bool) {
self.terminal_cursor.blink(blink, &self.stdout);
}
}
pub fn cursor() -> TerminalCursor<'static> {
TerminalCursor::new()
}
pub fn from_screen(screen: &Screen) -> TerminalCursor {
TerminalCursor::from_output(&screen.stdout)
}