consciousness/src/user/tui/thalamus_screen.rs

97 lines
3 KiB
Rust
Raw Normal View History

// thalamus_screen.rs — F5: attention routing and channel status
//
// Shows presence/idle/activity status, then channel daemon status.
use ratatui::{
layout::Rect,
style::{Color, Style},
text::{Line, Span},
widgets::{Block, Borders, Paragraph, Wrap},
Frame,
};
use super::{App, SCREEN_LEGEND};
use crate::thalamus::supervisor::Supervisor;
fn fetch_daemon_status() -> Vec<String> {
std::process::Command::new("poc-daemon")
.arg("status")
.output()
.ok()
.and_then(|o| {
if o.status.success() {
String::from_utf8(o.stdout).ok()
} else {
None
}
})
.map(|s| s.lines().map(String::from).collect())
.unwrap_or_default()
}
impl App {
pub(crate) fn draw_thalamus(&self, frame: &mut Frame, size: Rect) {
let section = Style::default().fg(Color::Yellow);
let dim = Style::default().fg(Color::DarkGray);
let mut lines: Vec<Line> = Vec::new();
// Presence status first
let daemon_status = fetch_daemon_status();
if !daemon_status.is_empty() {
lines.push(Line::styled("── Presence ──", section));
lines.push(Line::raw(""));
for line in &daemon_status {
lines.push(Line::raw(format!(" {}", line)));
}
lines.push(Line::raw(""));
}
// Channel status
lines.push(Line::styled("── Channels ──", section));
lines.push(Line::raw(""));
let mut sup = Supervisor::new();
sup.load_config();
let status = sup.status();
if status.is_empty() {
lines.push(Line::styled(" no channels configured", dim));
} else {
for (name, enabled, alive) in &status {
let (symbol, color) = if *alive {
("", Color::Green)
} else if *enabled {
("", Color::Red)
} else {
("", Color::DarkGray)
};
let state = if *alive {
"running"
} else if *enabled {
"stopped"
} else {
"disabled"
};
lines.push(Line::from(vec![
Span::raw(" "),
Span::styled(symbol, Style::default().fg(color)),
Span::raw(format!(" {:<20} {}", name, state)),
]));
}
}
let block = Block::default()
.title_top(Line::from(SCREEN_LEGEND).left_aligned())
.title_top(Line::from(" thalamus ").right_aligned())
.borders(Borders::ALL)
.border_style(Style::default().fg(Color::Cyan));
let para = Paragraph::new(lines)
.block(block)
.wrap(Wrap { trim: false })
.scroll((self.debug_scroll, 0));
frame.render_widget(para, size);
}
}