Skip to content

Commit

Permalink
Fixed search failure with only option #117
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Oct 19, 2021
1 parent e4c3027 commit 6f347f4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
* [Added] pgid/session column [#150](https://github.com/dalance/procs/pull/150)
* [Added] floating point watch interval support [#157](https://github.com/dalance/procs/pull/157)
* [Added] MultiSlot column [#180](https://github.com/dalance/procs/issue/180)
* [Fixed] Search failure with only option [#117](https://github.com/dalance/procs/issue/117)

## [v0.11.9](https://github.com/dalance/procs/compare/v0.11.8...v0.11.9) - 2021-06-22

Expand Down
1 change: 1 addition & 0 deletions src/config.rs
Expand Up @@ -89,6 +89,7 @@ pub struct ColumnInfo {
pub align: ConfigColumnAlign,
pub max_width: Option<usize>,
pub min_width: Option<usize>,
pub visible: bool,
}

// ---------------------------------------------------------------------------------------------------------------------
Expand Down
89 changes: 50 additions & 39 deletions src/view.rs
Expand Up @@ -50,6 +50,7 @@ impl View {
align: ConfigColumnAlign::Left,
max_width: None,
min_width: None,
visible: true,
});
}
}
Expand Down Expand Up @@ -81,14 +82,17 @@ impl View {
};

for kind in kinds {
if let Some(ref only) = opt.only {
let visible = if let Some(ref only) = opt.only {
let kind_name = KIND_LIST[&kind].0.to_lowercase();
if kind_name.find(&only.to_lowercase()).is_none() {
continue;
false
} else {
only_kind_found = true;
true
}
}
} else {
true
};

let column = gen_column(
&kind,
Expand All @@ -108,6 +112,7 @@ impl View {
align: c.align.clone(),
max_width: c.max_width,
min_width: c.min_width,
visible,
});
}
}
Expand Down Expand Up @@ -372,21 +377,23 @@ impl View {
fn display_header(&self, config: &Config, theme: &ConfigTheme) -> Result<(), Error> {
let mut row = String::from("");
for (i, c) in self.columns.iter().enumerate() {
let order = if i == self.sort_info.idx {
Some(self.sort_info.order.clone())
} else {
None
};
row = format!(
"{} {}",
row,
apply_color(
c.column.display_header(&c.align, order, config),
&config.style.header,
theme,
false
)
);
if c.visible {
let order = if i == self.sort_info.idx {
Some(self.sort_info.order.clone())
} else {
None
};
row = format!(
"{} {}",
row,
apply_color(
c.column.display_header(&c.align, order, config),
&config.style.header,
theme,
false
)
);
}
}
row = row.trim_end().to_string();
row = truncate(&row, self.term_info.width).to_string();
Expand All @@ -397,16 +404,18 @@ impl View {
fn display_unit(&self, config: &Config, theme: &ConfigTheme) -> Result<(), Error> {
let mut row = String::from("");
for c in &self.columns {
row = format!(
"{} {}",
row,
apply_color(
c.column.display_unit(&c.align),
&config.style.unit,
theme,
false
)
);
if c.visible {
row = format!(
"{} {}",
row,
apply_color(
c.column.display_unit(&c.align),
&config.style.unit,
theme,
false
)
);
}
}
row = row.trim_end().to_string();
row = truncate(&row, self.term_info.width).to_string();
Expand All @@ -423,17 +432,19 @@ impl View {
) -> Result<(), Error> {
let mut row = String::from("");
for c in &self.columns {
row = format!(
"{} {}",
row,
apply_style(
c.column.display_content(pid, &c.align).unwrap(),
&c.style,
&config.style,
theme,
auxiliary
)
);
if c.visible {
row = format!(
"{} {}",
row,
apply_style(
c.column.display_content(pid, &c.align).unwrap(),
&c.style,
&config.style,
theme,
auxiliary
)
);
}
}
row = row.trim_end().to_string();
row = truncate(&row, self.term_info.width).to_string();
Expand Down

0 comments on commit 6f347f4

Please sign in to comment.