clippy clean up multiple files
This commit is contained in:
parent
7cd6a6e0a1
commit
1e248306a6
@ -26,8 +26,8 @@ use crate::ui::cpu::{
|
||||
per_core_handle_key, per_core_handle_mouse, per_core_handle_scrollbar_mouse, PerCoreScrollDrag,
|
||||
};
|
||||
use crate::ui::{
|
||||
disks::draw_disks, header::draw_header, mem::draw_mem, net::draw_net_spark,
|
||||
processes::draw_top_processes, swap::draw_swap, gpu::draw_gpu,
|
||||
disks::draw_disks, gpu::draw_gpu, header::draw_header, mem::draw_mem, net::draw_net_spark,
|
||||
processes::draw_top_processes, swap::draw_swap,
|
||||
};
|
||||
use crate::ws::{connect, request_metrics};
|
||||
|
||||
@ -106,7 +106,10 @@ impl App {
|
||||
while event::poll(Duration::from_millis(10))? {
|
||||
match event::read()? {
|
||||
Event::Key(k) => {
|
||||
if matches!(k.code, KeyCode::Char('q') | KeyCode::Char('Q') | KeyCode::Esc) {
|
||||
if matches!(
|
||||
k.code,
|
||||
KeyCode::Char('q') | KeyCode::Char('Q') | KeyCode::Esc
|
||||
) {
|
||||
self.should_quit = true;
|
||||
}
|
||||
// Per-core scroll via keys (Up/Down/PageUp/PageDown/Home/End)
|
||||
@ -135,7 +138,11 @@ impl App {
|
||||
.as_ref()
|
||||
.map(|mm| mm.cpu_per_core.len())
|
||||
.unwrap_or(0);
|
||||
per_core_clamp(&mut self.per_core_scroll, total_rows, content.height as usize);
|
||||
per_core_clamp(
|
||||
&mut self.per_core_scroll,
|
||||
total_rows,
|
||||
content.height as usize,
|
||||
);
|
||||
}
|
||||
Event::Mouse(m) => {
|
||||
// Layout to get areas
|
||||
@ -305,9 +312,9 @@ impl App {
|
||||
let left_stack = ratatui::layout::Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
Constraint::Min(7), // Disks grow
|
||||
Constraint::Length(3), // Download
|
||||
Constraint::Length(3), // Upload
|
||||
Constraint::Min(7), // Disks grow
|
||||
Constraint::Length(3), // Download
|
||||
Constraint::Length(3), // Upload
|
||||
])
|
||||
.split(bottom_lr[0]);
|
||||
|
||||
|
||||
@ -30,7 +30,6 @@ pub struct GpuMetrics {
|
||||
pub utilization_gpu_pct: u32,
|
||||
pub mem_used_bytes: u64,
|
||||
pub mem_total_bytes: u64,
|
||||
// pub vendor: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
//! CPU average sparkline + per-core mini bars.
|
||||
|
||||
use crossterm::event::{KeyCode, KeyEvent, MouseButton, MouseEvent, MouseEventKind};
|
||||
use ratatui::style::Modifier;
|
||||
use ratatui::{
|
||||
layout::{Constraint, Direction, Layout, Rect},
|
||||
@ -7,15 +8,14 @@ use ratatui::{
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Borders, Paragraph, Sparkline},
|
||||
};
|
||||
use crossterm::event::{KeyCode, KeyEvent, MouseButton, MouseEvent, MouseEventKind}; // + MouseButton
|
||||
|
||||
use crate::history::PerCoreHistory;
|
||||
use crate::types::Metrics;
|
||||
|
||||
/// Subtle grey theme for the custom scrollbar
|
||||
const SB_ARROW: Color = Color::Rgb(170,170,180);
|
||||
const SB_TRACK: Color = Color::Rgb(170,170,180);
|
||||
const SB_THUMB: Color = Color::Rgb(170,170,180);
|
||||
const SB_ARROW: Color = Color::Rgb(170, 170, 180);
|
||||
const SB_TRACK: Color = Color::Rgb(170, 170, 180);
|
||||
const SB_THUMB: Color = Color::Rgb(170, 170, 180);
|
||||
|
||||
/// State for dragging the scrollbar thumb
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
@ -100,7 +100,7 @@ pub fn per_core_handle_scrollbar_mouse(
|
||||
drag: &mut Option<PerCoreScrollDrag>,
|
||||
mouse: MouseEvent,
|
||||
per_core_area: Rect,
|
||||
total_rows: usize
|
||||
total_rows: usize,
|
||||
) {
|
||||
// Geometry
|
||||
let inner = Rect {
|
||||
@ -188,7 +188,8 @@ pub fn per_core_handle_scrollbar_mouse(
|
||||
if d.active {
|
||||
let dy = (mouse.row as i32) - (d.start_y as i32);
|
||||
let new_top = (d.start_top as i32 + dy)
|
||||
.clamp(0, (track.saturating_sub(thumb_len)) as i32) as usize;
|
||||
.clamp(0, (track.saturating_sub(thumb_len)) as i32)
|
||||
as usize;
|
||||
// Inverse mapping top -> offset
|
||||
if track > thumb_len {
|
||||
let denom = track - thumb_len;
|
||||
@ -322,11 +323,11 @@ pub fn draw_per_core_bars(
|
||||
|
||||
let trend = if curr > older + 0.2 {
|
||||
"↑"
|
||||
} else if curr + 0.2 < older {
|
||||
"↓"
|
||||
} else {
|
||||
"╌"
|
||||
};
|
||||
} else if curr + 0.2 < older {
|
||||
"↓"
|
||||
} else {
|
||||
"╌"
|
||||
};
|
||||
|
||||
let fg = match curr {
|
||||
x if x < 25.0 => Color::Green,
|
||||
@ -347,8 +348,7 @@ pub fn draw_per_core_bars(
|
||||
let spark = Sparkline::default()
|
||||
.data(&hist)
|
||||
.max(100)
|
||||
.style(Style::default()
|
||||
.fg(fg));
|
||||
.style(Style::default().fg(fg));
|
||||
|
||||
f.render_widget(spark, hchunks[0]);
|
||||
|
||||
|
||||
@ -97,8 +97,8 @@ pub fn draw_gpu(f: &mut ratatui::Frame<'_>, area: Rect, m: Option<&Metrics>) {
|
||||
.ratio(util as f64 / 100.0);
|
||||
f.render_widget(util_gauge, util_cols[0]);
|
||||
f.render_widget(
|
||||
Paragraph::new(Span::raw(format!("util: {util}%")))
|
||||
.style(Style::default().fg(Color::Gray)),
|
||||
Paragraph::new(Span::raw(format!("util: {util}%")))
|
||||
.style(Style::default().fg(Color::Gray)),
|
||||
util_cols[1],
|
||||
);
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
use ratatui::{
|
||||
layout::Rect,
|
||||
style::{Color, Style},
|
||||
widgets::{Block, Borders, Sparkline}
|
||||
widgets::{Block, Borders, Sparkline},
|
||||
};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
@ -12,7 +12,7 @@ pub fn draw_net_spark(
|
||||
area: Rect,
|
||||
title: &str,
|
||||
hist: &VecDeque<u64>,
|
||||
color: Color
|
||||
color: Color,
|
||||
) {
|
||||
let max_points = area.width.saturating_sub(2) as usize;
|
||||
let start = hist.len().saturating_sub(max_points);
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
//! socktop agent entrypoint: sets up sysinfo handles, launches a sampler,
|
||||
//! and serves a WebSocket endpoint at /ws.
|
||||
|
||||
mod gpu;
|
||||
mod metrics;
|
||||
mod sampler;
|
||||
mod state;
|
||||
mod types;
|
||||
mod ws;
|
||||
mod gpu;
|
||||
|
||||
use axum::{routing::get, Router};
|
||||
use std::{ net::SocketAddr, sync::atomic::AtomicUsize, sync::Arc, time::Duration,
|
||||
};
|
||||
use std::{net::SocketAddr, sync::atomic::AtomicUsize, sync::Arc, time::Duration};
|
||||
|
||||
use sysinfo::{
|
||||
Components, CpuRefreshKind, Disks, MemoryRefreshKind, Networks, ProcessRefreshKind,
|
||||
RefreshKind, System,
|
||||
|
||||
@ -41,7 +41,11 @@ pub async fn collect_metrics(state: &AppState) -> Metrics {
|
||||
components.refresh(true);
|
||||
components.iter().find_map(|c| {
|
||||
let l = c.label().to_ascii_lowercase();
|
||||
if l.contains("cpu") || l.contains("package") || l.contains("tctl") || l.contains("tdie") {
|
||||
if l.contains("cpu")
|
||||
|| l.contains("package")
|
||||
|| l.contains("tctl")
|
||||
|| l.contains("tdie")
|
||||
{
|
||||
c.temperature()
|
||||
} else {
|
||||
None
|
||||
|
||||
@ -45,7 +45,9 @@ impl AppState {
|
||||
last_json: Arc::new(RwLock::new(String::new())),
|
||||
client_count: Arc::new(AtomicUsize::new(0)),
|
||||
wake_sampler: Arc::new(Notify::new()),
|
||||
auth_token: std::env::var("SOCKTOP_TOKEN").ok().filter(|s| !s.is_empty()),
|
||||
auth_token: std::env::var("SOCKTOP_TOKEN")
|
||||
.ok()
|
||||
.filter(|s| !s.is_empty()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user