2026-04-03 18:46:14 -04:00
|
|
|
// thalamus_screen.rs — F5: attention routing and channel status
|
2026-04-03 17:25:59 -04:00
|
|
|
//
|
2026-04-03 18:46:14 -04:00
|
|
|
// Shows presence/idle/activity status, then channel daemon status.
|
2026-04-03 17:25:59 -04:00
|
|
|
|
|
|
|
|
use ratatui::{
|
|
|
|
|
layout::Rect,
|
|
|
|
|
style::{Color, Style},
|
2026-04-03 18:46:14 -04:00
|
|
|
text::{Line, Span},
|
2026-04-03 17:25:59 -04:00
|
|
|
widgets::{Block, Borders, Paragraph, Wrap},
|
|
|
|
|
Frame,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use super::{App, SCREEN_LEGEND};
|
2026-04-03 18:46:14 -04:00
|
|
|
use crate::thalamus::supervisor::Supervisor;
|
2026-04-03 17:25:59 -04:00
|
|
|
|
|
|
|
|
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())
|
2026-04-03 18:46:14 -04:00
|
|
|
.unwrap_or_default()
|
2026-04-03 17:25:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl App {
|
|
|
|
|
pub(crate) fn draw_thalamus(&self, frame: &mut Frame, size: Rect) {
|
|
|
|
|
let section = Style::default().fg(Color::Yellow);
|
2026-04-03 18:46:14 -04:00
|
|
|
let dim = Style::default().fg(Color::DarkGray);
|
2026-04-03 17:25:59 -04:00
|
|
|
let mut lines: Vec<Line> = Vec::new();
|
2026-04-03 18:46:14 -04:00
|
|
|
|
|
|
|
|
// 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));
|
2026-04-03 17:25:59 -04:00
|
|
|
lines.push(Line::raw(""));
|
|
|
|
|
|
2026-04-03 18:46:14 -04:00
|
|
|
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)),
|
|
|
|
|
]));
|
|
|
|
|
}
|
2026-04-03 17:25:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|