Add App core struct with event-handling and initialization logic for TUI.
This commit is contained in:
43
crates/owlen-tui/src/code_app.rs
Normal file
43
crates/owlen-tui/src/code_app.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use anyhow::Result;
|
||||
use owlen_core::session::SessionController;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::chat_app::{AppState, ChatApp, InputMode, SessionEvent};
|
||||
use crate::events::Event;
|
||||
|
||||
const DEFAULT_SYSTEM_PROMPT: &str =
|
||||
"You are OWLEN Code Assistant. Provide detailed, actionable programming help.";
|
||||
|
||||
pub struct CodeApp {
|
||||
inner: ChatApp,
|
||||
}
|
||||
|
||||
impl CodeApp {
|
||||
pub fn new(mut controller: SessionController) -> (Self, mpsc::UnboundedReceiver<SessionEvent>) {
|
||||
controller
|
||||
.conversation_mut()
|
||||
.push_system_message(DEFAULT_SYSTEM_PROMPT.to_string());
|
||||
let (inner, rx) = ChatApp::new(controller);
|
||||
(Self { inner }, rx)
|
||||
}
|
||||
|
||||
pub async fn handle_event(&mut self, event: Event) -> Result<AppState> {
|
||||
self.inner.handle_event(event).await
|
||||
}
|
||||
|
||||
pub fn handle_session_event(&mut self, event: SessionEvent) -> Result<()> {
|
||||
self.inner.handle_session_event(event)
|
||||
}
|
||||
|
||||
pub fn mode(&self) -> InputMode {
|
||||
self.inner.mode()
|
||||
}
|
||||
|
||||
pub fn inner(&self) -> &ChatApp {
|
||||
&self.inner
|
||||
}
|
||||
|
||||
pub fn inner_mut(&mut self) -> &mut ChatApp {
|
||||
&mut self.inner
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user