use std::{fmt::{Debug, Display},
pin::Pin};
use super::{main_event_loop_impl, BoxedSafeApp, GlobalData};
use crate::{get_size, CommonResult, FlexBoxId, InputDevice, InputEvent, OutputDevice};
#[derive(Debug)]
pub struct TerminalWindow;
pub type MainEventLoopFuture<'a, S, AS> = Pin<
Box<
dyn Future<
Output = CommonResult<(
/* global_data */ GlobalData<S, AS>,
/* event stream */ InputDevice,
/* stdout */ OutputDevice,
)>,
> + 'a,
>,
>;
#[derive(Debug)]
pub enum TerminalWindowMainThreadSignal<AS>
where
AS: Debug + Default + Clone + Sync + Send,
{
Exit,
Render(Option<FlexBoxId>),
ApplyAppSignal(AS),
}
impl TerminalWindow {
pub fn main_event_loop<'a, S, AS>(
app: BoxedSafeApp<S, AS>,
exit_keys: &'a [InputEvent],
state: S,
) -> miette::Result<MainEventLoopFuture<'a, S, AS>>
where
S: Display + Debug + Default + Clone + Sync + Send + 'a,
AS: Debug + Default + Clone + Sync + Send + 'static,
{
let initial_size = get_size()?;
let input_device = InputDevice::new_event_stream();
let output_device = OutputDevice::new_stdout();
Ok(main_event_loop_impl(
app,
exit_keys,
state,
initial_size,
input_device,
output_device,
))
}
}