use crate::poll_events::PollEvents;
use crate::terminal::{CrosstermTerminal, Terminal};
use crossbeam::channel::TryRecvError;
use std::fmt::{Debug, Formatter};
use std::io;
pub struct RunConfig<Event, Error>
where
Event: 'static + Send,
Error: 'static + Send,
{
pub(crate) term: Box<dyn Terminal<Error>>,
pub(crate) poll: Vec<Box<dyn PollEvents<Event, Error>>>,
}
impl<Event, Error> Debug for RunConfig<Event, Error>
where
Event: 'static + Send,
Error: 'static + Send,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("RunConfig")
.field("render", &"...")
.field("events", &"...")
.finish()
}
}
impl<Event, Error> RunConfig<Event, Error>
where
Event: 'static + Send,
Error: 'static + Send + From<io::Error> + From<TryRecvError>,
{
#[allow(clippy::should_implement_trait)]
pub fn default() -> Result<Self, Error> {
Ok(Self {
term: Box::new(CrosstermTerminal::new()?),
poll: Default::default(),
})
}
pub fn new(term: impl Terminal<Error> + 'static) -> Self {
Self {
term: Box::new(term),
poll: Default::default(),
}
}
pub fn poll(mut self, poll: impl PollEvents<Event, Error> + 'static) -> Self {
self.poll.push(Box::new(poll));
self
}
}