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

@ -268,10 +268,10 @@ Run using `btm`.
Note that the `and` operator takes precedence over the `or` operator.
| Keywords | Usage | Description |
| ---------- | ------------------------------------- | --------------------------------------------------- |
| `and, &&` | `<CONDITION 1> and/&&<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 |
| Keywords | Usage | Description |
| ------------------ | -------------------------------------------- | --------------------------------------------------- |
| `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 |
#### Supported units

View File

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

View File

@ -120,7 +120,7 @@ pub const SEARCH_HELP_TEXT: [&str; 43] = [
"<= ex: cpu <= 1\n",
"\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",
"\n",
"Supported units:\n",