top: tui impl I (irix or solaris)

This commit is contained in:
Bluemangoo
2025-10-04 11:00:41 +08:00
parent 1b9452779e
commit 82c1641b82
3 changed files with 19 additions and 2 deletions
+8 -2
View File
@@ -223,13 +223,19 @@ fn todo(_pid: u32, _stat: Stat) -> Box<dyn Column> {
Box::new("TODO".to_string())
}
fn cpu(pid: u32, _stat: Stat) -> Box<dyn Column> {
fn cpu(pid: u32, stat: Stat) -> Box<dyn Column> {
let binding = sysinfo().read().unwrap();
let Some(proc) = binding.process(Pid::from_u32(pid)) else {
return PercentValue::new_boxed(0.0);
};
PercentValue::new_boxed(proc.cpu_usage())
let cpu_usage = if stat.1.irix_mode {
proc.cpu_usage()
} else {
proc.cpu_usage() / binding.cpus().len() as f32
};
PercentValue::new_boxed(cpu_usage)
}
fn pid(pid: u32, _stat: Stat) -> Box<dyn Column> {
+9
View File
@@ -74,6 +74,15 @@ pub fn handle_input(
data.write().unwrap().1 = ProcList::new(settings, &tui_stat.read().unwrap());
should_update.store(true, Ordering::Relaxed);
}
char!('I') => {
{
let mut stat = tui_stat.write().unwrap();
stat.irix_mode = !stat.irix_mode;
}
data.write().unwrap().1 = ProcList::new(settings, &tui_stat.read().unwrap());
should_update.store(true, Ordering::Relaxed);
}
char!('l') => {
let mut stat = tui_stat.write().unwrap();
stat.show_load_avg = !stat.show_load_avg;
+2
View File
@@ -30,6 +30,7 @@ pub(crate) struct TuiStat {
pub highlight_bold: bool,
pub show_coordinates: bool,
pub show_zeros: bool,
pub irix_mode: bool,
pub filter: Option<crate::Filter>,
}
@@ -66,6 +67,7 @@ impl TuiStat {
highlight_bold: false,
show_coordinates: false,
show_zeros: true,
irix_mode: true,
filter: None,
}