use crate::event::Event;
use crate::style;
use crate::Vec2;
pub trait Backend {
fn poll_event(&mut self) -> Option<Event>;
fn set_title(&mut self, title: String);
fn refresh(&mut self);
fn has_colors(&self) -> bool;
fn screen_size(&self) -> Vec2;
fn move_to(&self, pos: Vec2);
fn print(&self, text: &str);
fn clear(&self, color: style::Color);
fn set_color(&self, colors: style::ColorPair) -> style::ColorPair;
fn set_effect(&self, effect: style::Effect);
fn is_persistent(&self) -> bool {
false
}
fn unset_effect(&self, effect: style::Effect);
fn name(&self) -> &str {
"unknown"
}
}
pub struct Dummy;
impl Dummy {
pub fn init() -> Box<dyn Backend>
where
Self: Sized,
{
Box::new(Dummy)
}
}
impl Backend for Dummy {
fn name(&self) -> &str {
"dummy"
}
fn set_title(&mut self, _title: String) {}
fn refresh(&mut self) {}
fn has_colors(&self) -> bool {
false
}
fn screen_size(&self) -> Vec2 {
(1, 1).into()
}
fn poll_event(&mut self) -> Option<Event> {
Some(Event::Exit)
}
fn move_to(&self, _: Vec2) {}
fn print(&self, _: &str) {}
fn clear(&self, _: style::Color) {}
fn set_color(&self, colors: style::ColorPair) -> style::ColorPair {
colors
}
fn set_effect(&self, _: style::Effect) {}
fn unset_effect(&self, _: style::Effect) {}
}