Skip to content

Commit

Permalink
Merge pull request cjbassi#78 from vojta7/proc_improvement
Browse files Browse the repository at this point in the history
Proc improvement
  • Loading branch information
cjbassi committed May 11, 2020
2 parents 4bfd2c6 + 9860b57 commit 664e634
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/widgets/proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub struct ProcWidget<'a> {
impl ProcWidget<'_> {
pub fn new(colorscheme: &Colorscheme) -> ProcWidget {
ProcWidget {
title: " Processes ".to_string(),
title: "Processes".to_string(),
update_interval: Ratio::from_integer(1),
colorscheme,

Expand Down Expand Up @@ -312,7 +312,7 @@ impl Widget for &mut ProcWidget<'_> {
}

let mut header = [
if self.grouping { "Count" } else { "PID" },
if self.grouping { " Count" } else { " PID" },
"Command",
"CPU%",
"Mem%",
Expand Down Expand Up @@ -358,33 +358,46 @@ impl Widget for &mut ProcWidget<'_> {
}
}

let procs_count = procs.len();
Table::new(
header.iter(),
procs.into_iter().skip(self.view_offset).map(|proc| {
Row::StyledData(
vec![
proc.num.to_string(),
format!(" {}", proc.num),
if self.grouping {
proc.name
} else {
proc.commandline
},
format!("{:2.1}", proc.cpu),
format!("{:2.1}", proc.mem),
format!("{:>5.1}", proc.cpu),
format!("{:>4.1}", proc.mem),
]
.into_iter(),
self.colorscheme.text,
)
}),
)
.block(block::new(self.colorscheme, &self.title))
.block(block::new(
self.colorscheme,
&format!(
" {} ({}-{} of {}) ",
self.title,
self.view_offset + 1,
self.view_offset + self.view_height,
procs_count
),
))
.header_style(self.colorscheme.text.modifier(Modifier::BOLD))
// TODO: this is only a temporary workaround until we fix the table column resizing
// https://github.com/cjbassi/ytop/issues/23
.widths(&[
Constraint::Length(6),
// max PID can be 4194304 (7 digits) + 1 for padding
Constraint::Length(8),
// Constraint::Min(5),
Constraint::Length(u16::max((area.width as i16 - 2 - 16 - 3) as u16, 5)),
// width - (left + right border) - (column1 + column3 + column4 width) - (spaces
// between colums)
Constraint::Length(u16::max((area.width as i16 - 2 - 18 - 3) as u16, 5)),
Constraint::Length(5),
Constraint::Length(5),
])
Expand Down

0 comments on commit 664e634

Please sign in to comment.