change: reallow spaces to represent "and"

This commit is contained in:
ClementTsang 2020-05-08 15:00:40 -04:00
parent a71d991695
commit b253d0153b
3 changed files with 21 additions and 24 deletions

View File

@ -269,8 +269,8 @@ Run using `btm`.
Note that the `and` operator takes precedence over the `or` operator. Note that the `and` operator takes precedence over the `or` operator.
| Keywords | Usage | Description | | Keywords | Usage | Description |
| ---------- | ------------------------------------- | --------------------------------------------------- | | ------------------ | -------------------------------------------- | --------------------------------------------------- |
| `and, &&` | `<CONDITION 1> and/&&<CONDITION 2>` | Requires both conditions to be true to match | | `and, &&, <Space>` | `<CONDITION 1> and/&&/<Space> <CONDITION 2>` | Requires both conditions to be true to match |
| `or, \|\|` | `<CONDITION 1> or/\|\| <CONDITION 2>` | Requires at least one condition to be true to match | | `or, \|\|` | `<CONDITION 1> or/\|\| <CONDITION 2>` | Requires at least one condition to be true to match |
#### Supported units #### Supported units

View File

@ -9,7 +9,6 @@ use crate::{
use std::collections::VecDeque; use std::collections::VecDeque;
const DELIMITER_LIST: [char; 6] = ['=', '>', '<', '(', ')', '\"']; const DELIMITER_LIST: [char; 6] = ['=', '>', '<', '(', ')', '\"'];
const OR_LIST: [&str; 2] = ["or", "||"]; const OR_LIST: [&str; 2] = ["or", "||"];
const AND_LIST: [&str; 2] = ["and", "&&"]; const AND_LIST: [&str; 2] = ["and", "&&"];
@ -111,12 +110,14 @@ impl ProcessQuery for ProcWidgetState {
let mut rhs: Option<Box<Prefix>> = None; let mut rhs: Option<Box<Prefix>> = None;
while let Some(queue_top) = query.front() { while let Some(queue_top) = query.front() {
if AND_LIST.contains(&queue_top.to_lowercase().as_str()) { if queue_top == ")" {
break;
} else if AND_LIST.contains(&queue_top.to_lowercase().as_str()) {
query.pop_front(); query.pop_front();
}
rhs = Some(Box::new(process_prefix(query, false)?)); rhs = Some(Box::new(process_prefix(query, false)?));
if let Some(queue_next) = query.front() { if query.front().is_some() {
if AND_LIST.contains(&queue_next.to_lowercase().as_str()) {
// Must merge LHS and RHS // Must merge LHS and RHS
lhs = Prefix { lhs = Prefix {
or: Some(Box::new(Or { or: Some(Box::new(Or {
@ -127,10 +128,6 @@ impl ProcessQuery for ProcWidgetState {
compare_prefix: None, compare_prefix: None,
}; };
rhs = None; rhs = None;
}
} else {
break;
}
} else { } else {
break; break;
} }

View File

@ -120,7 +120,7 @@ pub const SEARCH_HELP_TEXT: [&str; 43] = [
"<= ex: cpu <= 1\n", "<= ex: cpu <= 1\n",
"\n", "\n",
"Logical operators:\n", "Logical operators:\n",
"and/&& ex: btm and cpu > 1 and mem > 1\n", "and/&&/<Space> ex: btm and cpu > 1 and mem > 1\n",
"or/|| ex: btm or firefox\n", "or/|| ex: btm or firefox\n",
"\n", "\n",
"Supported units:\n", "Supported units:\n",