#![warn(missing_docs, unused_crate_dependencies)]
pub use cai_core::Result;
mod app;
mod event;
mod ui;
pub use app::{App, AppState, Column, Mode, SortOrder};
pub use event::{Event, EventHandler};
use cai_storage::Storage;
use std::sync::Arc;
use tokio::sync::RwLock;
pub async fn run<S>(storage: Arc<S>) -> Result<()>
where
S: Storage + 'static,
{
let mut terminal = ui::init_terminal()?;
let app = App::new(storage);
let mut app = Arc::new(RwLock::new(app));
let event_handler = EventHandler::new(100);
let res = ui::run_app(&mut terminal, &mut app, event_handler).await;
ui::restore_terminal(terminal)?;
res.map_err(|e| cai_core::Error::Message(e.to_string()))
}