use crossterm::event::KeyEvent;
use std::time::Duration;
use crate::Result;
pub trait ScreenDataProvider: Send + shaku::Interface {
fn provide(&self) -> Result<Box<dyn std::any::Any>>;
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ScreenType {
Title,
Loading,
Typing,
StageSummary,
SessionSummary,
TotalSummary,
TotalSummaryShare,
SessionFailure,
Records,
Analytics,
SessionDetail,
SessionSharing,
Animation,
VersionCheck,
InfoDialog,
Help,
DetailsDialog,
Settings,
Panic,
RepoList,
RepoPlay,
TrendingLanguageSelection,
TrendingRepositorySelection,
}
#[derive(Debug, Clone)]
pub enum UpdateStrategy {
InputOnly,
TimeBased(Duration),
Hybrid {
interval: Duration,
input_priority: bool,
},
}
#[derive(Debug, Clone)]
pub enum ScreenTransition {
None,
Push(ScreenType),
Pop,
Replace(ScreenType),
PopTo(ScreenType),
Exit,
}
impl crate::domain::events::Event for ScreenTransition {
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
pub trait Screen: Send + Sync + shaku::Interface {
fn get_type(&self) -> ScreenType;
fn default_provider() -> Box<dyn ScreenDataProvider>
where
Self: Sized;
fn init_with_data(&self, data: Box<dyn std::any::Any>) -> Result<()>;
fn on_pushed_from(&self, _source_screen: &dyn Screen) -> Result<()> {
Ok(())
}
fn handle_key_event(&self, key_event: KeyEvent) -> Result<()>;
fn render_ratatui(&self, frame: &mut ratatui::Frame) -> Result<()>;
fn cleanup(&self) -> Result<()> {
Ok(())
}
fn get_update_strategy(&self) -> UpdateStrategy {
UpdateStrategy::InputOnly
}
fn update(&self) -> Result<bool> {
Ok(false)
}
fn is_exitable(&self) -> bool {
false
}
fn as_any(&self) -> &dyn std::any::Any;
}