consciousness/src/user/thalamus.rs

117 lines
4.3 KiB
Rust
Raw Normal View History

// thalamus_screen.rs — F5: presence, idle state, and channel status
//
// Shows idle state from the in-process thalamus (no subprocess spawn),
// then channel daemon status from cached data.
use ratatui::{
layout::Rect,
style::{Color, Style},
text::{Line, Span},
widgets::{Block, Borders, Paragraph, Wrap},
Frame,
};
use super::{App, SCREEN_LEGEND};
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 / idle state from in-process thalamus
lines.push(Line::styled("── Presence ──", section));
lines.push(Line::raw(""));
if let Some(ref idle) = self.idle_info {
let presence = if idle.user_present {
Span::styled("present", Style::default().fg(Color::Green))
} else {
Span::styled("away", Style::default().fg(Color::DarkGray))
};
lines.push(Line::from(vec![
Span::raw(" User: "),
presence,
Span::raw(format!(" (last {:.0}s ago)", idle.since_activity)),
]));
lines.push(Line::raw(format!(" Activity: {:.1}%", idle.activity_ewma * 100.0)));
lines.push(Line::raw(format!(" Idle state: {}", idle.block_reason)));
if idle.dreaming {
lines.push(Line::styled(" ◆ dreaming", Style::default().fg(Color::Magenta)));
}
if idle.sleeping {
lines.push(Line::styled(" ◆ sleeping", Style::default().fg(Color::Blue)));
}
} else {
lines.push(Line::styled(" not initialized", dim));
}
lines.push(Line::raw(""));
// Sampling parameters (↑/↓ select, ←/→ adjust)
lines.push(Line::styled("── Sampling (←/→ adjust) ──", section));
lines.push(Line::raw(""));
let params = [
format!("temperature: {:.2}", self.temperature),
format!("top_p: {:.2}", self.top_p),
format!("top_k: {}", self.top_k),
];
for (i, label) in params.iter().enumerate() {
let prefix = if i == self.sampling_selected { "" } else { " " };
let style = if i == self.sampling_selected {
Style::default().fg(Color::Cyan)
} else {
Style::default()
};
lines.push(Line::styled(format!("{}{}", prefix, label), style));
}
lines.push(Line::raw(""));
// Channel status from cached data
lines.push(Line::styled("── Channels ──", section));
lines.push(Line::raw(""));
if self.channel_status.is_empty() {
lines.push(Line::styled(" no channels configured", dim));
} else {
for ch in &self.channel_status {
let (symbol, color) = if ch.connected {
("", Color::Green)
} else {
("", Color::Red)
};
let unread_str = if ch.unread > 0 {
format!(" ({} unread)", ch.unread)
} else {
String::new()
};
lines.push(Line::from(vec![
Span::raw(" "),
Span::styled(symbol, Style::default().fg(color)),
Span::raw(format!(" {:<24}", ch.name)),
Span::styled(
if ch.connected { "connected" } else { "disconnected" },
Style::default().fg(color),
),
Span::styled(unread_str, Style::default().fg(Color::Yellow)),
]));
}
}
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);
}
}