2026-04-03 17:25:59 -04:00
|
|
|
// subconscious_screen.rs — F3 subconscious agent overlay
|
|
|
|
|
|
|
|
|
|
use ratatui::{
|
|
|
|
|
layout::Rect,
|
|
|
|
|
style::{Color, Modifier, Style},
|
|
|
|
|
text::{Line, Span},
|
|
|
|
|
widgets::{Block, Borders, Paragraph, Wrap},
|
|
|
|
|
Frame,
|
2026-04-06 19:33:18 -04:00
|
|
|
crossterm::event::KeyCode,
|
2026-04-03 17:25:59 -04:00
|
|
|
};
|
|
|
|
|
|
2026-04-06 19:33:18 -04:00
|
|
|
use super::{App, ScreenView, screen_legend};
|
2026-04-03 17:25:59 -04:00
|
|
|
|
user: ScreenView trait, overlay screens extracted from App
Convert F2-F5 screens to ScreenView trait with tick() method.
Each screen owns its view state (scroll, selection, expanded).
State persists across screen switches.
- ThalamusScreen: owns sampling_selected, scroll
- ConsciousScreen: owns scroll, selected, expanded
- SubconsciousScreen: owns selected, log_view, scroll
- UnconsciousScreen: owns scroll
Removed from App: Screen enum, debug_scroll, debug_selected,
debug_expanded, agent_selected, agent_log_view, sampling_selected,
set_screen(), per-screen key handling, draw dispatch.
App now only draws the interact (F1) screen. Overlay screens are
drawn by the event loop via ScreenView::tick. F-key routing and
screen instantiation to be wired in event_loop next.
InteractScreen (state-driven, reading from agent entries) is the
next step — will eliminate the input display race condition.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-05 17:54:40 -04:00
|
|
|
pub(crate) struct SubconsciousScreen {
|
|
|
|
|
selected: usize,
|
|
|
|
|
scroll: u16,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl SubconsciousScreen {
|
|
|
|
|
pub fn new() -> Self {
|
2026-04-07 01:59:09 -04:00
|
|
|
Self { selected: 0, scroll: 0 }
|
user: ScreenView trait, overlay screens extracted from App
Convert F2-F5 screens to ScreenView trait with tick() method.
Each screen owns its view state (scroll, selection, expanded).
State persists across screen switches.
- ThalamusScreen: owns sampling_selected, scroll
- ConsciousScreen: owns scroll, selected, expanded
- SubconsciousScreen: owns selected, log_view, scroll
- UnconsciousScreen: owns scroll
Removed from App: Screen enum, debug_scroll, debug_selected,
debug_expanded, agent_selected, agent_log_view, sampling_selected,
set_screen(), per-screen key handling, draw dispatch.
App now only draws the interact (F1) screen. Overlay screens are
drawn by the event loop via ScreenView::tick. F-key routing and
screen instantiation to be wired in event_loop next.
InteractScreen (state-driven, reading from agent entries) is the
next step — will eliminate the input display race condition.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-05 17:54:40 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ScreenView for SubconsciousScreen {
|
|
|
|
|
fn label(&self) -> &'static str { "subconscious" }
|
|
|
|
|
|
|
|
|
|
fn tick(&mut self, frame: &mut Frame, area: Rect,
|
2026-04-05 23:04:10 -04:00
|
|
|
events: &[ratatui::crossterm::event::Event], app: &mut App) {
|
|
|
|
|
for event in events {
|
|
|
|
|
if let ratatui::crossterm::event::Event::Key(key) = event {
|
|
|
|
|
if key.kind != ratatui::crossterm::event::KeyEventKind::Press { continue; }
|
2026-04-07 01:59:09 -04:00
|
|
|
match key.code {
|
|
|
|
|
KeyCode::Up => {
|
|
|
|
|
self.selected = self.selected.saturating_sub(1);
|
|
|
|
|
}
|
|
|
|
|
KeyCode::Down => {
|
|
|
|
|
self.selected = (self.selected + 1)
|
|
|
|
|
.min(app.agent_state.len().saturating_sub(1));
|
|
|
|
|
}
|
|
|
|
|
KeyCode::PageUp => { self.scroll = self.scroll.saturating_sub(20); }
|
|
|
|
|
KeyCode::PageDown => { self.scroll += 20; }
|
|
|
|
|
_ => {}
|
user: ScreenView trait, overlay screens extracted from App
Convert F2-F5 screens to ScreenView trait with tick() method.
Each screen owns its view state (scroll, selection, expanded).
State persists across screen switches.
- ThalamusScreen: owns sampling_selected, scroll
- ConsciousScreen: owns scroll, selected, expanded
- SubconsciousScreen: owns selected, log_view, scroll
- UnconsciousScreen: owns scroll
Removed from App: Screen enum, debug_scroll, debug_selected,
debug_expanded, agent_selected, agent_log_view, sampling_selected,
set_screen(), per-screen key handling, draw dispatch.
App now only draws the interact (F1) screen. Overlay screens are
drawn by the event loop via ScreenView::tick. F-key routing and
screen instantiation to be wired in event_loop next.
InteractScreen (state-driven, reading from agent entries) is the
next step — will eliminate the input display race condition.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-05 17:54:40 -04:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-03 17:25:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut lines: Vec<Line> = Vec::new();
|
|
|
|
|
let section = Style::default().fg(Color::Yellow);
|
|
|
|
|
let hint = Style::default().fg(Color::DarkGray).add_modifier(Modifier::ITALIC);
|
|
|
|
|
|
|
|
|
|
lines.push(Line::raw(""));
|
|
|
|
|
lines.push(Line::styled("── Subconscious Agents ──", section));
|
2026-04-07 01:59:09 -04:00
|
|
|
lines.push(Line::styled(" (↑/↓ select)", hint));
|
2026-04-03 17:25:59 -04:00
|
|
|
lines.push(Line::raw(""));
|
|
|
|
|
|
2026-04-07 01:59:09 -04:00
|
|
|
if app.agent_state.is_empty() {
|
|
|
|
|
lines.push(Line::styled(" (no agents loaded)", hint));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i, snap) in app.agent_state.iter().enumerate() {
|
user: ScreenView trait, overlay screens extracted from App
Convert F2-F5 screens to ScreenView trait with tick() method.
Each screen owns its view state (scroll, selection, expanded).
State persists across screen switches.
- ThalamusScreen: owns sampling_selected, scroll
- ConsciousScreen: owns scroll, selected, expanded
- SubconsciousScreen: owns selected, log_view, scroll
- UnconsciousScreen: owns scroll
Removed from App: Screen enum, debug_scroll, debug_selected,
debug_expanded, agent_selected, agent_log_view, sampling_selected,
set_screen(), per-screen key handling, draw dispatch.
App now only draws the interact (F1) screen. Overlay screens are
drawn by the event loop via ScreenView::tick. F-key routing and
screen instantiation to be wired in event_loop next.
InteractScreen (state-driven, reading from agent entries) is the
next step — will eliminate the input display race condition.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-05 17:54:40 -04:00
|
|
|
let selected = i == self.selected;
|
2026-04-03 17:25:59 -04:00
|
|
|
let prefix = if selected { "▸ " } else { " " };
|
2026-04-07 01:59:09 -04:00
|
|
|
let bg = if selected {
|
|
|
|
|
Style::default().bg(Color::DarkGray)
|
|
|
|
|
} else {
|
|
|
|
|
Style::default()
|
|
|
|
|
};
|
2026-04-03 17:25:59 -04:00
|
|
|
|
2026-04-07 01:59:09 -04:00
|
|
|
let status_spans = if snap.running {
|
|
|
|
|
vec![
|
|
|
|
|
Span::styled(
|
|
|
|
|
format!("{}{:<30}", prefix, snap.name),
|
|
|
|
|
bg.fg(Color::Green),
|
|
|
|
|
),
|
user: ScreenView trait, overlay screens extracted from App
Convert F2-F5 screens to ScreenView trait with tick() method.
Each screen owns its view state (scroll, selection, expanded).
State persists across screen switches.
- ThalamusScreen: owns sampling_selected, scroll
- ConsciousScreen: owns scroll, selected, expanded
- SubconsciousScreen: owns selected, log_view, scroll
- UnconsciousScreen: owns scroll
Removed from App: Screen enum, debug_scroll, debug_selected,
debug_expanded, agent_selected, agent_log_view, sampling_selected,
set_screen(), per-screen key handling, draw dispatch.
App now only draws the interact (F1) screen. Overlay screens are
drawn by the event loop via ScreenView::tick. F-key routing and
screen instantiation to be wired in event_loop next.
InteractScreen (state-driven, reading from agent entries) is the
next step — will eliminate the input display race condition.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-05 17:54:40 -04:00
|
|
|
Span::styled("● ", bg.fg(Color::Green)),
|
2026-04-07 01:59:09 -04:00
|
|
|
Span::styled(
|
|
|
|
|
format!("phase: {} turn: {}", snap.current_phase, snap.turn),
|
|
|
|
|
bg,
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
} else {
|
|
|
|
|
let ago = snap.last_run_secs_ago
|
|
|
|
|
.map(|s| {
|
|
|
|
|
if s < 60.0 { format!("{:.0}s ago", s) }
|
|
|
|
|
else if s < 3600.0 { format!("{:.0}m ago", s / 60.0) }
|
|
|
|
|
else { format!("{:.1}h ago", s / 3600.0) }
|
|
|
|
|
})
|
|
|
|
|
.unwrap_or_else(|| "never".to_string());
|
|
|
|
|
vec![
|
|
|
|
|
Span::styled(
|
|
|
|
|
format!("{}{:<30}", prefix, snap.name),
|
|
|
|
|
bg.fg(Color::Gray),
|
|
|
|
|
),
|
|
|
|
|
Span::styled("○ ", bg.fg(Color::DarkGray)),
|
|
|
|
|
Span::styled(
|
|
|
|
|
format!("idle last: {} walked: {}", ago, snap.walked_count),
|
|
|
|
|
bg.fg(Color::DarkGray),
|
|
|
|
|
),
|
|
|
|
|
]
|
2026-04-04 04:23:29 -04:00
|
|
|
};
|
2026-04-07 01:59:09 -04:00
|
|
|
lines.push(Line::from(status_spans));
|
2026-04-03 17:25:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let block = Block::default()
|
user: ScreenView trait, overlay screens extracted from App
Convert F2-F5 screens to ScreenView trait with tick() method.
Each screen owns its view state (scroll, selection, expanded).
State persists across screen switches.
- ThalamusScreen: owns sampling_selected, scroll
- ConsciousScreen: owns scroll, selected, expanded
- SubconsciousScreen: owns selected, log_view, scroll
- UnconsciousScreen: owns scroll
Removed from App: Screen enum, debug_scroll, debug_selected,
debug_expanded, agent_selected, agent_log_view, sampling_selected,
set_screen(), per-screen key handling, draw dispatch.
App now only draws the interact (F1) screen. Overlay screens are
drawn by the event loop via ScreenView::tick. F-key routing and
screen instantiation to be wired in event_loop next.
InteractScreen (state-driven, reading from agent entries) is the
next step — will eliminate the input display race condition.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-05 17:54:40 -04:00
|
|
|
.title_top(Line::from(screen_legend()).left_aligned())
|
2026-04-03 17:25:59 -04:00
|
|
|
.title_top(Line::from(" subconscious ").right_aligned())
|
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
|
.border_style(Style::default().fg(Color::Cyan));
|
|
|
|
|
|
|
|
|
|
let para = Paragraph::new(lines)
|
|
|
|
|
.block(block)
|
|
|
|
|
.wrap(Wrap { trim: false })
|
user: ScreenView trait, overlay screens extracted from App
Convert F2-F5 screens to ScreenView trait with tick() method.
Each screen owns its view state (scroll, selection, expanded).
State persists across screen switches.
- ThalamusScreen: owns sampling_selected, scroll
- ConsciousScreen: owns scroll, selected, expanded
- SubconsciousScreen: owns selected, log_view, scroll
- UnconsciousScreen: owns scroll
Removed from App: Screen enum, debug_scroll, debug_selected,
debug_expanded, agent_selected, agent_log_view, sampling_selected,
set_screen(), per-screen key handling, draw dispatch.
App now only draws the interact (F1) screen. Overlay screens are
drawn by the event loop via ScreenView::tick. F-key routing and
screen instantiation to be wired in event_loop next.
InteractScreen (state-driven, reading from agent entries) is the
next step — will eliminate the input display race condition.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-05 17:54:40 -04:00
|
|
|
.scroll((self.scroll, 0));
|
|
|
|
|
frame.render_widget(para, area);
|
2026-04-03 17:25:59 -04:00
|
|
|
}
|
|
|
|
|
}
|