pub mod headless;
pub use headless::Headless;
use crate::event::Event;
use crate::grid::{Pos, Size};
use crate::tile::Tile;
use core::time::Duration;
pub trait BackendError: core::fmt::Display + core::fmt::Debug {}
impl BackendError for core::convert::Infallible {}
#[cfg(feature = "std")]
impl BackendError for std::io::Error {}
pub trait Output {
type Error: BackendError;
fn draw<'a, I>(&mut self, content: I) -> Result<(), Self::Error>
where
I: Iterator<Item = (Pos, &'a Tile, Option<&'a str>)>;
fn draw_layers<'a, I>(&mut self, content: I) -> Result<(), Self::Error>
where
I: Iterator<Item = (u8, Pos, &'a Tile, Option<&'a str>)>,
{
self.draw(content.filter_map(|(layer, pos, tile, extra)| {
if layer == 0 {
Some((pos, tile, extra))
} else {
None
}
}))
}
fn needs_full_frame(&self) -> bool {
false
}
fn composites_layers(&self) -> bool {
false
}
fn flush(&mut self) -> Result<(), Self::Error>;
#[must_use]
fn size(&self) -> Size;
fn clear(&mut self) -> Result<(), Self::Error>;
fn resize(&mut self, size: Size) {
let _ = size;
}
}
pub trait Input {
fn poll_event(&mut self, timeout: Duration) -> Option<Event>;
fn push_event(&mut self, _event: Event) {}
}
pub trait Cursor {
fn set_cursor_visible(&mut self, _visible: bool) {}
fn set_cursor_position(&mut self, _position: Pos) {}
}
pub trait Backend: Output + Input + Cursor {}
impl<T: Output + Input + Cursor> Backend for T {}