summaryrefslogtreecommitdiffstats
path: root/src/options.rs
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2021-04-22 23:43:12 -0400
committerGitHub <noreply@github.com>2021-04-22 23:43:12 -0400
commitf33bb42c5b234183117fa30d87b1fe6d9ab94d69 (patch)
tree8fc79336c49b39f412e3f2c6e5a46c53aa920943 /src/options.rs
parentd9fd6be2ccad9d2eec888bd761cefc9ecbc16298 (diff)
feature: Add mount filtering, rework filter priority logic (#455)
This PR accomplishes two things: 1. This PR aims to add mount_filter to the config file. This allows a user to filter their disk widget entries by the mount name as well; this was particularly a problem in trying to address #431. 2. A slight rework of how the filter system works due to the need of being able to manage two potentially conflicting filter sources, since the disk widget will now potentially filter on both the disk name and the mount name. In regards to the second point, the new behaviour is as such: 1. Is the entry allowed through any filter? That is, does it match an entry in a filter where is_list_ignored is false? If so, we always keep this entry. 2. Is the entry denied through any filter? That is, does it match an entry in a filter where is_list_ignored is true? If so, we always deny this entry. 3. Anything else is allowed. This main (breaking) change is really the third point. This would mean that temp_filter and net_filter, when set to allow listed entries with is_list_ignored = false, are kinda... useless, as a whitelist in the scenario of being the only filter is kinda pointless. But hopefully this shouldn't be a problem...?
Diffstat (limited to 'src/options.rs')
-rw-r--r--src/options.rs49
1 files changed, 26 insertions, 23 deletions
diff --git a/src/options.rs b/src/options.rs
index 7855a8da..9dcd8123 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -30,6 +30,7 @@ pub struct Config {
pub colors: Option<ConfigColours>,
pub row: Option<Vec<Row>>,
pub disk_filter: Option<IgnoreList>,
+ pub mount_filter: Option<IgnoreList>,
pub temp_filter: Option<IgnoreList>,
pub net_filter: Option<IgnoreList>,
}
@@ -224,13 +225,24 @@ impl ConfigColours {
}
}
+/// Workaround as per https://github.com/serde-rs/serde/issues/1030
+fn default_as_true() -> bool {
+ true
+}
+
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct IgnoreList {
+ #[serde(default = "default_as_true")]
+ // TODO: Deprecate and/or rename, current name sounds awful.
+ // Maybe to something like "deny_entries"? Currently it defaults to a denylist anyways, so maybe "allow_entries"?
pub is_list_ignored: bool,
pub list: Vec<String>,
- pub regex: Option<bool>,
- pub case_sensitive: Option<bool>,
- pub whole_word: Option<bool>,
+ #[serde(default = "bool::default")]
+ pub regex: bool,
+ #[serde(default = "bool::default")]
+ pub case_sensitive: bool,
+ #[serde(default = "bool::default")]
+ pub whole_word: bool,
}
pub fn build_app(
@@ -440,6 +452,8 @@ pub fn build_app(
let disk_filter =
get_ignore_list(&config.disk_filter).context("Update 'disk_filter' in your config file")?;
+ let mount_filter = get_ignore_list(&config.mount_filter)
+ .context("Update 'mount_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 =
@@ -502,6 +516,7 @@ pub fn build_app(
.used_widgets(used_widgets)
.filters(DataFilters {
disk_filter,
+ mount_filter,
temp_filter,
net_filter,
})
@@ -927,34 +942,22 @@ fn get_ignore_list(ignore_list: &Option<IgnoreList>) -> error::Result<Option<Fil
.list
.iter()
.map(|name| {
- let use_regex = if let Some(use_regex) = ignore_list.regex {
- use_regex
- } else {
- false
- };
- let use_cs = if let Some(use_cs) = ignore_list.case_sensitive {
- use_cs
- } 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 {
+ if ignore_list.whole_word { "^" } else { "" },
+ if ignore_list.case_sensitive {
+ ""
+ } else {
+ "(?i)"
+ },
+ if ignore_list.regex {
name
} else {
escaped_string = regex::escape(name);
&escaped_string
},
- if whole_word { "$" } else { "" },
+ if ignore_list.whole_word { "$" } else { "" },
);
Regex::new(&res)