summaryrefslogtreecommitdiffstats
path: root/src/options.rs
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2021-01-01 18:09:28 -0500
committerGitHub <noreply@github.com>2021-01-01 18:09:28 -0500
commit90be9730a62e2a935ccf01cdd6e320c65624722a (patch)
treeb22a66210a2af97f0ced92dc27d89a6ad2137f63 /src/options.rs
parentd8d72d060d4bd4473bfe769673a2227bda948c97 (diff)
feature: Add network interface filtering (#381)
Adds a new option in the config file to filter out network interfaces. Also add the option to filter by whole words. Interface follows that of the existing ones: ```toml [net_filter] is_list_ignored = false list = ["virbr0.*"] regex = true case_sensitive = false whole_word = false ```
Diffstat (limited to 'src/options.rs')
-rw-r--r--src/options.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/options.rs b/src/options.rs
index 8301094a..999a8cf1 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -30,6 +30,7 @@ pub struct Config {
pub row: Option<Vec<Row>>,
pub disk_filter: Option<IgnoreList>,
pub temp_filter: Option<IgnoreList>,
+ pub net_filter: Option<IgnoreList>,
}
impl Config {
@@ -216,6 +217,7 @@ pub struct IgnoreList {
pub list: Vec<String>,
pub regex: Option<bool>,
pub case_sensitive: Option<bool>,
+ pub whole_word: Option<bool>,
}
pub fn build_app(
@@ -413,6 +415,8 @@ pub fn build_app(
get_ignore_list(&config.disk_filter).context("Update 'disk_filter' in your config file")?;
let temp_filter =
get_ignore_list(&config.temp_filter).context("Update 'temp_filter' in your config file")?;
+ let net_filter =
+ get_ignore_list(&config.net_filter).context("Update 'net_filter' in your config file")?;
// One more thing - we have to update the search settings of our proc_state_map, and create the hashmaps if needed!
// Note that if you change your layout, this might not actually match properly... not sure if/where we should deal with that...
@@ -472,6 +476,7 @@ pub fn build_app(
.filters(DataFilters {
disk_filter,
temp_filter,
+ net_filter,
})
.config(config.clone())
.config_path(config_path)
@@ -907,17 +912,24 @@ fn get_ignore_list(ignore_list: &Option<IgnoreList>) -> error::Result<Option<Fil
} else {
false
};
+ let whole_word = if let Some(whole_word) = ignore_list.whole_word {
+ whole_word
+ } else {
+ false
+ };
let escaped_string: String;
let res = format!(
- "{}{}",
+ "{}{}{}{}",
+ if whole_word { "^" } else { "" },
if use_cs { "" } else { "(?i)" },
if use_regex {
name
} else {
escaped_string = regex::escape(name);
&escaped_string
- }
+ },
+ if whole_word { "$" } else { "" },
);
Regex::new(&res)