split out src/mind
This commit is contained in:
parent
ce04568454
commit
79e384f005
21 changed files with 1865 additions and 2175 deletions
97
src/user/thalamus.rs
Normal file
97
src/user/thalamus.rs
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
// 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(""));
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue