use crate::display::Display;
use pancurses::{
Window,
initscr,
endwin,
Input,
noecho,
curs_set
};
pub struct Curses {
pub width: i32,
pub height: i32,
pub name: String,
window: Window
}
impl Display for Curses {
fn new(width: i32, height: i32, name: String) -> Self {
let w = initscr();
noecho();
curs_set(0);
w.keypad(true);
w.timeout(-1);
Self {
width, height, name, window: w
}
}
fn draw(&mut self, ch: char, x: i32, y: i32) {
self.window.mvprintw(y, x, ch.to_string());
}
fn get_key(&mut self) -> String {
match self.window.getch() {
Some(v) => match v {
Input::Character(c) => c.to_string(),
_ => " ".to_string()
},
None => " ".to_string()
}
}
fn refresh(&mut self) {
self.window.refresh();
}
fn clear(&mut self) {
self.window.clear();
}
fn close(&mut self) {
endwin();
}
}