redbear-power: show refresh interval in keybar (e.g. [/]:500ms)

Track current poll_ms in App, update it on all three poll-change paths
([ / ] /Enter), and display it persistently in the keybar between
governor and tab hints.
This commit is contained in:
2026-07-07 02:19:49 +03:00
parent babffee80e
commit 91b58cfacc
3 changed files with 8 additions and 0 deletions
@@ -146,6 +146,7 @@ pub struct App {
/// file read. Fields degrade to `None` when unavailable.
pub sched_stats: crate::sched::SchedStats,
pub load_avg: Option<(f64, f64, f64)>,
pub poll_ms: u64,
/// When true, render the Process tab as a tree (parents above
/// children, prefixed with `├─ ` / `└─ ` connector characters).
/// Toggled by the `T` hotkey. Sort modes are honored within
@@ -456,6 +457,7 @@ impl App {
None
}
}),
poll_ms: crate::app::POLL_MS,
process_tree: false,
show_full_cmdline: false,
folded: std::collections::BTreeSet::new(),
@@ -319,6 +319,7 @@ fn main() -> io::Result<()> {
} else {
POLL_MS
});
app.poll_ms = poll.as_millis() as u64;
let mut show_help = false;
// Tab/BackTab cycles keyboard focus between header / table / controls.
let mut focused_panel: usize = 1;
@@ -1029,6 +1030,7 @@ fn main() -> io::Result<()> {
if poll_idx > 0 {
poll_idx -= 1;
poll = Duration::from_millis(POLL_STEPS_MS[poll_idx]);
app.poll_ms = poll.as_millis() as u64;
app.flash_status(format!("refresh → {} ms", poll.as_millis()));
} else {
app.flash_status("refresh already at minimum (250 ms)");
@@ -1038,6 +1040,7 @@ fn main() -> io::Result<()> {
if poll_idx + 1 < POLL_STEPS_MS.len() {
poll_idx += 1;
poll = Duration::from_millis(POLL_STEPS_MS[poll_idx]);
app.poll_ms = poll.as_millis() as u64;
app.flash_status(format!("refresh → {} ms", poll.as_millis()));
} else {
app.flash_status("refresh already at maximum (2000 ms)");
@@ -1064,6 +1067,7 @@ fn main() -> io::Result<()> {
if let Ok(ms) = raw.parse::<u64>() {
if (50..=60_000).contains(&ms) {
poll = Duration::from_millis(ms);
app.poll_ms = ms;
poll_idx = POLL_STEPS_MS
.iter()
.position(|&v| v == ms)
@@ -2042,6 +2042,7 @@ pub fn render_cpu_table<'a>(
pub fn render_keybar<'a>(app: &'a App) -> Paragraph<'a> {
let gov = format!(" g:{}", app.cpufreq.active.as_str());
let interval = format!(" [/]:{}ms", app.poll_ms);
let tab_hints: &str = if app.current_tab == crate::app::TabId::Process {
" ↑↓:sel k:kill N:nice l:files C:cmd o:sort i:invert F:filter y:tree Enter:detail"
} else {
@@ -2049,6 +2050,7 @@ pub fn render_keybar<'a>(app: &'a App) -> Paragraph<'a> {
};
let mut parts = vec![
gov,
interval,
tab_hints.to_string(),
" T:tab ?:help e:expand f:freeze q:quit".to_string(),
];