mirror of
https://github.com/MalteT/mensa.git
synced 2024-10-22 21:59:17 +02:00
Fix #10, don't highlight everything
Only highlight, if a highlighting rule exists. This will of course still highlight everything, if the user so desires.
This commit is contained in:
parent
354bb2976c
commit
5e7314d0f4
|
@ -54,6 +54,10 @@ impl Rule {
|
|||
(all_adds_empty || any_add) && !any_sub
|
||||
}
|
||||
|
||||
pub fn is_non_empty_match(&self, meal: &MealComplete) -> bool {
|
||||
!self.is_empty() && self.is_match(meal)
|
||||
}
|
||||
|
||||
pub fn joined(self, other: Self) -> Self {
|
||||
Self {
|
||||
name: self.name.joined(other.name),
|
||||
|
@ -61,9 +65,17 @@ impl Rule {
|
|||
category: self.category.joined(other.category),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.name.is_empty() && self.tag.is_empty() && self.category.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl TagRule {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.add.is_empty() && self.sub.is_empty()
|
||||
}
|
||||
|
||||
fn is_match_add(&self, meal: &MealComplete) -> bool {
|
||||
self.add.iter().any(|tag| meal.meta.tags.contains(tag))
|
||||
}
|
||||
|
@ -101,6 +113,10 @@ impl RegexRule {
|
|||
Self { add, sub }
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.add.is_none() && self.sub.is_none()
|
||||
}
|
||||
|
||||
fn is_match_add(&self, meal: &MealComplete) -> bool {
|
||||
match self.add {
|
||||
Some(ref rset) => rset.is_match(&meal.meta.category),
|
||||
|
|
|
@ -103,7 +103,7 @@ impl Meal {
|
|||
for meal in meals {
|
||||
let complete = meal.complete()?;
|
||||
if filter.is_match(&complete) {
|
||||
let is_fav = favs.is_match(&complete);
|
||||
let is_fav = favs.is_non_empty_match(&complete);
|
||||
println!("{}", *PRE);
|
||||
complete.print(is_fav);
|
||||
printed_at_least_one_meal = true;
|
||||
|
|
Loading…
Reference in a new issue