use crate::sink::UiEvent;
use crate::tui_context::TuiContext;
use anyhow::Result;
use koda_core::config::KodaConfig;
use koda_core::db::Database;
use koda_core::engine::EngineCommand;
use ratatui::{
style::{Color, Style},
text::Line,
};
use std::path::PathBuf;
use tokio::sync::mpsc;
pub async fn run(
project_root: PathBuf,
config: KodaConfig,
db: Database,
session_id: String,
version_check: tokio::task::JoinHandle<Option<String>>,
first_run: bool,
) -> Result<()> {
let mut ctx = TuiContext::new(
project_root,
config,
db,
session_id,
version_check,
first_run,
)
.await?;
if first_run {
ctx.emit(Line::styled(
" \u{1f43b} Welcome to Koda! Let's pick your LLM provider.",
Style::default().fg(Color::Cyan),
));
}
let (ui_tx, mut ui_rx) = mpsc::unbounded_channel::<UiEvent>();
let (cmd_tx, mut cmd_rx) = mpsc::channel::<EngineCommand>(32);
ctx.draw()?;
ctx.run_event_loop(&ui_tx, &mut ui_rx, &cmd_tx, &mut cmd_rx)
.await?;
ctx.cleanup().await;
Ok(())
}