extern crate termion;
use ::backend;
use ::event::{Event, Key};
use std::io::Write;
use self::termion::input::TermRead;
use self::termion::raw::IntoRawMode;
use ::theme::{BaseColor, Color, ColorStyle, Effect};
pub struct Concrete {
terminal: termion::raw::RawTerminal<::std::io::Stdout>,
}
impl backend::Backend for Concrete {
fn init() -> Self {
print!("{}", termion::cursor::Hide);
let backend = Concrete {
terminal: ::std::io::stdout().into_raw_mode().unwrap(),
};
backend.clear();
backend
}
fn finish(&mut self) {
print!("{}{}", termion::cursor::Show, termion::cursor::Goto(1, 1));
self.clear();
}
fn init_color_style(&mut self, style: ColorStyle, foreground: &Color,
background: &Color) {
}
fn with_color<F: FnOnce()>(&self, color: ColorStyle, f: F) {
f();
}
fn with_effect<F: FnOnce()>(&self, effect: Effect, f: F) {
f();
}
fn has_colors(&self) -> bool {
true
}
fn screen_size(&self) -> (usize, usize) {
let (x, y) = termion::terminal_size().unwrap_or((1, 1));
(x as usize, y as usize)
}
fn clear(&self) {
print!("{}", termion::clear::All);
}
fn refresh(&mut self) {
self.terminal.flush().unwrap();
}
fn print_at(&self, (x, y): (usize, usize), text: &str) {
print!("{}{}", termion::cursor::Goto(x as u16, y as u16), text);
}
fn set_refresh_rate(&mut self, fps: u32) {
}
fn poll_event(&self) -> Event {
::std::io::stdin().keys().next();
Event::Key(Key::Enter)
}
}