summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClementTsang <cjhtsang@uwaterloo.ca>2020-05-04 23:44:33 -0400
committerClementTsang <cjhtsang@uwaterloo.ca>2020-05-04 23:44:33 -0400
commit38f4967a8a9b15e255caf7078f09f7eb4850f169 (patch)
tree8afe0823245db8cd301e929d0dcad4e5c884e1c8
parent9932ad34c1d790df721a6cc204d0fb9150a1cfbe (diff)
bug/change: removed space as and for now0.4.0
-rw-r--r--CHANGELOG.md2
-rw-r--r--README.md8
-rw-r--r--src/app/query.rs63
-rw-r--r--src/app/states.rs2
-rw-r--r--src/constants.rs59
5 files changed, 74 insertions, 60 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ec1d20ad..dbd6d4bc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -54,8 +54,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#59](https://github.com/ClementTsang/bottom/issues/59): Moved maximization key to `e`, renamed feature to _expanding_ the widget. Done to allow for the `<Enter>` key to be used later for a more intuitive usage.
-- [#59](https://github.com/ClementTsang/bottom/issues/59): Redesigned search menu and query.
-
### Bug Fixes
- Fixed `dd` not working on non-first entries.
diff --git a/README.md b/README.md
index e7337710..148d8660 100644
--- a/README.md
+++ b/README.md
@@ -268,10 +268,10 @@ Run using `btm`.
Note that the `and` operator takes precedence over the `or` operator.
-| 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 |
+| 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 |
#### Supported units
diff --git a/src/app/query.rs b/src/app/query.rs
index b0263730..863298db 100644
--- a/src/app/query.rs
+++ b/src/app/query.rs
@@ -40,25 +40,37 @@ pub trait ProcessQuery {
impl ProcessQuery for ProcWidgetState {
fn parse_query(&self) -> Result<Query> {
fn process_string_to_filter(query: &mut VecDeque<String>) -> Result<Query> {
- let mut lhs: Or = process_or(query)?;
+ let lhs = process_or(query)?;
+ let mut and_query = And {
+ lhs: Prefix {
+ or: Some(Box::from(lhs)),
+ compare_prefix: None,
+ regex_prefix: None,
+ },
+ rhs: None,
+ };
while query.front().is_some() {
- let rhs = Some(Box::new(process_and(query)?));
-
- lhs = Or {
- lhs: And {
- lhs: Prefix {
- or: Some(Box::from(lhs)),
- compare_prefix: None,
- regex_prefix: None,
- },
- rhs: None,
+ let rhs = process_or(query)?;
+
+ and_query = And {
+ lhs: Prefix {
+ or: Some(Box::from(Or {
+ lhs: and_query,
+ rhs: None,
+ })),
+ compare_prefix: None,
+ regex_prefix: None,
},
- rhs,
- };
+ rhs: Some(Box::from(Prefix {
+ or: Some(Box::from(rhs)),
+ compare_prefix: None,
+ regex_prefix: None,
+ })),
+ }
}
- Ok(Query { query: lhs })
+ Ok(Query { query: and_query })
}
fn process_or(query: &mut VecDeque<String>) -> Result<Or> {
@@ -129,6 +141,7 @@ impl ProcessQuery for ProcWidgetState {
fn process_prefix(query: &mut VecDeque<String>, inside_quotations: bool) -> Result<Prefix> {
if let Some(queue_top) = query.pop_front() {
+ // debug!("QT: {:?}", queue_top);
if !inside_quotations && queue_top == "(" {
if query.front().is_none() {
return Err(QueryError("Missing closing parentheses".into()));
@@ -302,40 +315,40 @@ impl ProcessQuery for ProcWidgetState {
| PrefixType::TRead
| PrefixType::TWrite => {
if let Some(potential_unit) = query.front() {
- match potential_unit.as_str() {
- "TB" => {
+ match potential_unit.to_lowercase().as_str() {
+ "tb" => {
value *= 1_000_000_000_000.0;
query.pop_front();
}
- "TiB" => {
+ "tib" => {
value *= 1_099_511_627_776.0;
query.pop_front();
}
- "GB" => {
+ "gb" => {
value *= 1_000_000_000.0;
query.pop_front();
}
- "GiB" => {
+ "gib" => {
value *= 1_073_741_824.0;
query.pop_front();
}
- "MB" => {
+ "mb" => {
value *= 1_000_000.0;
query.pop_front();
}
- "MiB" => {
+ "mib" => {
value *= 1_048_576.0;
query.pop_front();
}
- "KB" => {
+ "kb" => {
value *= 1000.0;
query.pop_front();
}
- "KiB" => {
+ "kib" => {
value *= 1024.0;
query.pop_front();
}
- "B" => {
+ "b" => {
// Just gotta pop.
query.pop_front();
}
@@ -400,7 +413,7 @@ impl ProcessQuery for ProcWidgetState {
#[derive(Debug)]
pub struct Query {
/// Remember, AND > OR, but and must come after or then.
- pub query: Or,
+ pub query: And,
}
impl Query {
diff --git a/src/app/states.rs b/src/app/states.rs
index 98913e61..67ab5a5f 100644
--- a/src/app/states.rs
+++ b/src/app/states.rs
@@ -205,7 +205,7 @@ impl ProcWidgetState {
self.process_search_state.search_state.error_message = None;
} else {
let parsed_query = self.parse_query();
- // debug!("PQ: {:#?}", parsed_query);
+ debug!("PQ: {:#?}", parsed_query);
if let Ok(parsed_query) = parsed_query {
self.process_search_state.search_state.query = Some(parsed_query);
diff --git a/src/constants.rs b/src/constants.rs
index 09d20d60..0a228a80 100644
--- a/src/constants.rs
+++ b/src/constants.rs
@@ -88,7 +88,7 @@ pub const PROCESS_HELP_TEXT: [&str; 8] = [
"Ctrl-f, / Open process search widget",
];
-pub const SEARCH_HELP_TEXT: [&str; 40] = [
+pub const SEARCH_HELP_TEXT: [&str; 43] = [
"4 - Process search widget\n",
"Tab Toggle between searching for PID and name\n",
"Esc Close the search widget (retains the filter)\n",
@@ -102,33 +102,36 @@ pub const SEARCH_HELP_TEXT: [&str; 40] = [
"Alt-r/F3 Toggle using regex\n",
"Left, Alt-h Move cursor left\n",
"Right, Alt-l Move cursor right\n",
- "Search keywords\n",
- "pid\n",
- "cpu\n",
- "mem\n",
- "pid\n",
- "read\n",
- "write\n",
- "tread\n",
- "twrite\n\n",
- "\nComparison operators\n",
- "=\n",
- ">\n",
- "<\n",
- ">=\n",
- "<=\n",
- "\nLogical operators\n",
- "and/&&\n",
- "or/||\n",
- "\nSupported units\n",
- "B\n",
- "KB\n",
- "MB\n",
- "TB\n",
- "KiB\n",
- "MiB\n",
- "GiB\n",
- "TiB\n",
+ "\n",
+ "Search keywords:\n",
+ "pid ex: pid 825\n",
+ "cpu ex: cpu > 4.2\n",
+ "mem ex: mem < 4.2\n",
+ "read ex: read >= 1 b\n",
+ "write ex: write <= 1 tb\n",
+ "tread ex: tread = 1\n",
+ "twrite ex: twrite = 1\n",
+ "\n",
+ "Comparison operators:\n",
+ "= ex: cpu = 1\n",
+ "> ex: cpu > 1\n",
+ "< ex: cpu < 1\n",
+ ">= ex: cpu >= 1\n",
+ "<= ex: cpu <= 1\n",
+ "\n",
+ "Logical operators:\n",
+ "and/&& ex: btm and cpu > 1 and mem > 1\n",
+ "or/|| ex: btm or firefox\n",
+ "\n",
+ "Supported units:\n",
+ "B ex: read > 1 b\n",
+ "KB ex: read > 1 kb\n",
+ "MB ex: read > 1 mb\n",
+ "TB ex: read > 1 tb\n",
+ "KiB ex: read > 1 kib\n",
+ "MiB ex: read > 1 mib\n",
+ "GiB ex: read > 1 gib\n",
+ "TiB ex: read > 1 tib",
];
pub const BATTERY_HELP_TEXT: [&str; 3] = [