- Added `chat.rs` for rendering chat messages with timestamps and roles. - Introduced `markdown.rs` for rendering markdown content with styling. - Created `status.rs` to display the application status bar with session and message counts. - Developed `workflow.rs` to show the current workflow status, including tool calls and active jobs. - Established a `theme.rs` for centralized color management across the UI. - Updated `mod.rs` to include new modules and manage rendering logic.
43 lines
1.1 KiB
Rust
43 lines
1.1 KiB
Rust
use std::net::TcpListener;
|
|
use std::thread;
|
|
use anyhow::Result;
|
|
use super::conn::Connection;
|
|
|
|
pub struct IpcServer {
|
|
listener: TcpListener,
|
|
}
|
|
|
|
impl IpcServer {
|
|
pub fn bind(addr: &str) -> Result<Self> {
|
|
let listener = TcpListener::bind(addr)?;
|
|
Ok(IpcServer { listener })
|
|
}
|
|
|
|
pub fn accept(&self) -> Result<Connection> {
|
|
let (stream, _addr) = self.listener.accept()?;
|
|
stream.set_nodelay(true)?;
|
|
Ok(Connection::Tcp(stream))
|
|
}
|
|
|
|
pub fn accept_with_handler<F>(self, handler: F) -> thread::JoinHandle<()>
|
|
where
|
|
F: Fn(Connection) -> Result<()> + Send + 'static,
|
|
{
|
|
thread::spawn(move || {
|
|
for stream in self.listener.incoming() {
|
|
match stream {
|
|
Ok(stream) => {
|
|
if let Err(e) = handler(Connection::Tcp(stream)) {
|
|
eprintln!("ipc handler error: {}", e);
|
|
}
|
|
}
|
|
Err(e) => {
|
|
eprintln!("ipc accept error: {}", e);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|