user: hook up screen_legend from ScreenView::label()

Build legend string from actual screen labels instead of hardcoded
constant. Computed once at startup via OnceLock, accessible from
all screen draw methods.

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2026-04-05 19:03:06 -04:00
parent 68f115b880
commit 6f000bd0f6
3 changed files with 80 additions and 67 deletions

View file

@ -28,10 +28,24 @@ use std::io;
use crate::user::ui_channel::{ContextInfo, SharedContextState, StatusInfo};
/// Build the screen legend from the screen table.
/// Build the screen legend from screen labels.
pub(crate) fn screen_legend_from(interact: &dyn ScreenView, screens: &[Box<dyn ScreenView>]) -> String {
let mut parts = vec![format!("F1={}", interact.label())];
for (i, s) in screens.iter().enumerate() {
parts.push(format!("F{}={}", i + 2, s.label()));
}
format!(" {} ", parts.join(" "))
}
// Cached legend — set once at startup by event_loop
static SCREEN_LEGEND: std::sync::OnceLock<String> = std::sync::OnceLock::new();
pub(crate) fn set_screen_legend(legend: String) {
let _ = SCREEN_LEGEND.set(legend);
}
pub(crate) fn screen_legend() -> String {
// Built from the SCREENS table in event_loop
" F1=interact F2=conscious F3=subconscious F4=unconscious F5=thalamus ".to_string()
SCREEN_LEGEND.get().cloned().unwrap_or_default()
}
pub(crate) fn strip_ansi(text: &str) -> String {