use std::collections::HashMap;
use std::time::Instant;
struct AgentLane {
name: String,
status: String,
started: Instant,
}
pub struct LaneDisplay {
lanes: HashMap<String, AgentLane>,
}
impl LaneDisplay {
pub fn new() -> Self {
Self {
lanes: HashMap::new(),
}
}
pub fn add_lane(&mut self, name: &str) {
self.lanes.insert(
name.to_string(),
AgentLane {
name: name.to_string(),
status: "starting...".to_string(),
started: Instant::now(),
},
);
}
pub fn update_lane(&mut self, name: &str, status: &str) {
if let Some(lane) = self.lanes.get_mut(name) {
lane.status = status.to_string();
}
}
pub fn remove_lane(&mut self, name: &str) {
self.lanes.remove(name);
}
pub fn render(&self) {
let mut sorted: Vec<&AgentLane> = self.lanes.values().collect();
sorted.sort_by(|a, b| a.name.cmp(&b.name));
for lane in &sorted {
let elapsed = lane.started.elapsed().as_secs();
eprintln!(
" \x1b[36m[{elapsed:>3}s]\x1b[0m \x1b[1m{}\x1b[0m — {}",
lane.name, lane.status
);
}
}
pub fn is_empty(&self) -> bool {
self.lanes.is_empty()
}
pub fn len(&self) -> usize {
self.lanes.len()
}
}
impl Default for LaneDisplay {
fn default() -> Self {
Self::new()
}
}