Feat: CPU meter in top bar
This commit is contained in:
@@ -407,28 +407,36 @@ fn render_header(
|
|||||||
pattern_area,
|
pattern_area,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Stats block
|
// Stats block — CPU bar filling the area, text overlaid
|
||||||
let cpu_pct = (app.metrics.cpu_load * 100.0).min(100.0);
|
let cpu_pct = (app.metrics.cpu_load * 100.0).min(100.0);
|
||||||
let peers = link.peers();
|
|
||||||
let voices = app.metrics.active_voices;
|
let voices = app.metrics.active_voices;
|
||||||
let cpu_color = if cpu_pct >= 80.0 {
|
let cpu_bar_color = if cpu_pct >= 80.0 {
|
||||||
theme.flash.error_fg
|
theme.flash.error_fg
|
||||||
} else if cpu_pct >= 50.0 {
|
} else if cpu_pct >= 50.0 {
|
||||||
theme.ui.accent
|
theme.ui.accent
|
||||||
} else {
|
} else {
|
||||||
theme.header.stats_fg
|
theme.meter.low
|
||||||
};
|
};
|
||||||
let dim = Style::new()
|
|
||||||
.bg(theme.header.stats_bg)
|
|
||||||
.fg(theme.header.stats_fg);
|
|
||||||
let stats_line = Line::from(vec![
|
|
||||||
Span::styled(format!(" CPU {cpu_pct:.0}%"), dim.fg(cpu_color)),
|
|
||||||
Span::styled(format!(" V:{voices} L:{peers} "), dim),
|
|
||||||
]);
|
|
||||||
let block_style = Style::new().bg(theme.header.stats_bg);
|
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
Paragraph::new(stats_line)
|
Block::default().style(Style::new().bg(theme.header.stats_bg)),
|
||||||
.block(Block::default().padding(pad).style(block_style))
|
stats_area,
|
||||||
|
);
|
||||||
|
let filled_w = (cpu_pct / 100.0 * stats_area.width as f32).round() as u16;
|
||||||
|
if filled_w > 0 {
|
||||||
|
frame.render_widget(
|
||||||
|
Block::default().style(Style::new().bg(cpu_bar_color)),
|
||||||
|
Rect {
|
||||||
|
width: filled_w.min(stats_area.width),
|
||||||
|
..stats_area
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let stats_text = format!("CPU {cpu_pct:.0}% V:{voices}");
|
||||||
|
frame.render_widget(
|
||||||
|
Paragraph::new(stats_text)
|
||||||
|
.block(Block::default().padding(pad))
|
||||||
|
.style(Style::new().fg(theme.ui.text_primary))
|
||||||
.alignment(Alignment::Center),
|
.alignment(Alignment::Center),
|
||||||
stats_area,
|
stats_area,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user