fix additional clippy warnings.

This commit is contained in:
jasonwitty 2025-08-11 14:34:45 -07:00
parent 0cbba6b290
commit 0105b29bfc
3 changed files with 15 additions and 15 deletions

View File

@ -135,7 +135,7 @@ pub fn per_core_handle_scrollbar_mouse(
if track == 0 { if track == 0 {
return; return;
} }
let thumb_len = ((track * view + total - 1) / total).max(1).min(track); let thumb_len = (track * view).div_ceil(total).max(1).min(track);
let top_for_offset = |off: usize| -> usize { let top_for_offset = |off: usize| -> usize {
if max_off == 0 { if max_off == 0 {
0 0
@ -340,7 +340,7 @@ pub fn draw_per_core_bars(
let spark = Sparkline::default().data(&hist).max(100).style(Style::default().fg(fg)); let spark = Sparkline::default().data(&hist).max(100).style(Style::default().fg(fg));
f.render_widget(spark, hchunks[0]); f.render_widget(spark, hchunks[0]);
let label = format!("cpu{:<2}{}{:>5.1}%", idx, trend, curr); let label = format!("cpu{idx:<2}{trend}{curr:>5.1}%");
let line = Line::from(Span::styled( let line = Line::from(Span::styled(
label, label,
Style::default().fg(fg).add_modifier(Modifier::BOLD), Style::default().fg(fg).add_modifier(Modifier::BOLD),
@ -361,7 +361,7 @@ pub fn draw_per_core_bars(
let view = viewport_rows.clamp(1, total); let view = viewport_rows.clamp(1, total);
let max_off = total.saturating_sub(view); let max_off = total.saturating_sub(view);
let thumb_len = ((track * view + total - 1) / total).max(1).min(track); let thumb_len = (track * view).div_ceil(total).max(1).min(track);
let thumb_top = if max_off == 0 { let thumb_top = if max_off == 0 {
0 0
} else { } else {

View File

@ -15,7 +15,7 @@ fn fmt_bytes(b: u64) -> String {
if fb >= GB { format!("{:.1}G", fb / GB) } if fb >= GB { format!("{:.1}G", fb / GB) }
else if fb >= MB { format!("{:.1}M", fb / MB) } else if fb >= MB { format!("{:.1}M", fb / MB) }
else if fb >= KB { format!("{:.1}K", fb / KB) } else if fb >= KB { format!("{:.1}K", fb / KB) }
else { format!("{}B", b) } else { format!("{b}B") }
} }
pub fn draw_gpu(f: &mut ratatui::Frame<'_>, area: Rect, m: Option<&Metrics>) { pub fn draw_gpu(f: &mut ratatui::Frame<'_>, area: Rect, m: Option<&Metrics>) {
@ -52,9 +52,7 @@ pub fn draw_gpu(f: &mut ratatui::Frame<'_>, area: Rect, m: Option<&Metrics>) {
let max_gpus = (area.height / per_gpu_rows) as usize; let max_gpus = (area.height / per_gpu_rows) as usize;
let count = gpus.len().min(max_gpus); let count = gpus.len().min(max_gpus);
let constraints = std::iter::repeat(Constraint::Length(1)) let constraints = vec![Constraint::Length(1); count * per_gpu_rows as usize];
.take(count * per_gpu_rows as usize)
.collect::<Vec<_>>();
let rows = Layout::default() let rows = Layout::default()
.direction(Direction::Vertical) .direction(Direction::Vertical)
.constraints(constraints) .constraints(constraints)
@ -74,7 +72,7 @@ pub fn draw_gpu(f: &mut ratatui::Frame<'_>, area: Rect, m: Option<&Metrics>) {
for i in 0..count { for i in 0..count {
let g = &gpus[i]; let g = &gpus[i];
// Row 1: GPU name (and temp can be appended later) // Row 1: GPU name
let name_text = g.name.clone(); let name_text = g.name.clone();
f.render_widget( f.render_widget(
Paragraph::new(Span::raw(name_text)).style(Style::default().fg(Color::Gray)), Paragraph::new(Span::raw(name_text)).style(Style::default().fg(Color::Gray)),
@ -106,8 +104,11 @@ pub fn draw_gpu(f: &mut ratatui::Frame<'_>, area: Rect, m: Option<&Metrics>) {
.label(Span::raw("")) .label(Span::raw(""))
.ratio(mem_ratio); .ratio(mem_ratio);
f.render_widget(mem_gauge, mem_cols[0]); f.render_widget(mem_gauge, mem_cols[0]);
// Prepare strings to enable captured identifiers in format!
let used_s = fmt_bytes(used);
let total_s = fmt_bytes(total);
f.render_widget( f.render_widget(
Paragraph::new(Span::raw(format!("vram: {}/{} ({mem_pct}%)", fmt_bytes(used), fmt_bytes(total)))) Paragraph::new(Span::raw(format!("vram: {used_s}/{total_s} ({mem_pct}%)")))
.style(Style::default().fg(Color::Gray)), .style(Style::default().fg(Color::Gray)),
mem_cols[1], mem_cols[1],
); );

View File

@ -79,8 +79,8 @@ async fn main() {
let addr = SocketAddr::from(([0, 0, 0, 0], port)); let addr = SocketAddr::from(([0, 0, 0, 0], port));
//output to console //output to console
println!("Remote agent running at http://{}", addr); println!("Remote agent running at http://{addr}");
println!("WebSocket endpoint: ws://{}/ws", addr); println!("WebSocket endpoint: ws://{addr}/ws");
//trace logging //trace logging
tracing::info!("Remote agent running at http://{} (ws at /ws)", addr); tracing::info!("Remote agent running at http://{} (ws at /ws)", addr);
@ -103,8 +103,7 @@ fn resolve_port() -> u16 {
} }
} }
eprintln!( eprintln!(
"Warning: invalid SOCKTOP_PORT='{}'; using default {}", "Warning: invalid SOCKTOP_PORT='{s}'; using default {DEFAULT}"
s, DEFAULT
); );
} }
@ -116,12 +115,12 @@ fn resolve_port() -> u16 {
match v.parse::<u16>() { match v.parse::<u16>() {
Ok(p) if p != 0 => return p, Ok(p) if p != 0 => return p,
_ => { _ => {
eprintln!("Invalid port '{}'; using default {}", v, DEFAULT); eprintln!("Invalid port '{v}'; using default {DEFAULT}");
return DEFAULT; return DEFAULT;
} }
} }
} else { } else {
eprintln!("Missing value for {} ; using default {}", arg, DEFAULT); eprintln!("Missing value for {arg} ; using default {DEFAULT}");
return DEFAULT; return DEFAULT;
} }
} }