bug/change: removed space as and for now

This commit is contained in:
ClementTsang 2020-05-04 23:44:33 -04:00
parent 9932ad34c1
commit 38f4967a8a
5 changed files with 73 additions and 59 deletions

View File

@ -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): 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 ### Bug Fixes
- Fixed `dd` not working on non-first entries. - Fixed `dd` not working on non-first entries.

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, &&, <Space>` | `<CONDITION 1> and/&&/<Space> <CONDITION 2>` | Requires both conditions to be true to match | | `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 | | `or, \|\|` | `<CONDITION 1> or/\|\| <CONDITION 2>` | Requires at least one condition to be true to match |
#### Supported units #### Supported units

View File

@ -40,25 +40,37 @@ pub trait ProcessQuery {
impl ProcessQuery for ProcWidgetState { impl ProcessQuery for ProcWidgetState {
fn parse_query(&self) -> Result<Query> { fn parse_query(&self) -> Result<Query> {
fn process_string_to_filter(query: &mut VecDeque<String>) -> 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 {
while query.front().is_some() {
let rhs = Some(Box::new(process_and(query)?));
lhs = Or {
lhs: And {
lhs: Prefix { lhs: Prefix {
or: Some(Box::from(lhs)), or: Some(Box::from(lhs)),
compare_prefix: None, compare_prefix: None,
regex_prefix: None, regex_prefix: None,
}, },
rhs: None, rhs: None,
},
rhs,
}; };
while query.front().is_some() {
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: 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> { 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> { fn process_prefix(query: &mut VecDeque<String>, inside_quotations: bool) -> Result<Prefix> {
if let Some(queue_top) = query.pop_front() { if let Some(queue_top) = query.pop_front() {
// debug!("QT: {:?}", queue_top);
if !inside_quotations && queue_top == "(" { if !inside_quotations && queue_top == "(" {
if query.front().is_none() { if query.front().is_none() {
return Err(QueryError("Missing closing parentheses".into())); return Err(QueryError("Missing closing parentheses".into()));
@ -302,40 +315,40 @@ impl ProcessQuery for ProcWidgetState {
| PrefixType::TRead | PrefixType::TRead
| PrefixType::TWrite => { | PrefixType::TWrite => {
if let Some(potential_unit) = query.front() { if let Some(potential_unit) = query.front() {
match potential_unit.as_str() { match potential_unit.to_lowercase().as_str() {
"TB" => { "tb" => {
value *= 1_000_000_000_000.0; value *= 1_000_000_000_000.0;
query.pop_front(); query.pop_front();
} }
"TiB" => { "tib" => {
value *= 1_099_511_627_776.0; value *= 1_099_511_627_776.0;
query.pop_front(); query.pop_front();
} }
"GB" => { "gb" => {
value *= 1_000_000_000.0; value *= 1_000_000_000.0;
query.pop_front(); query.pop_front();
} }
"GiB" => { "gib" => {
value *= 1_073_741_824.0; value *= 1_073_741_824.0;
query.pop_front(); query.pop_front();
} }
"MB" => { "mb" => {
value *= 1_000_000.0; value *= 1_000_000.0;
query.pop_front(); query.pop_front();
} }
"MiB" => { "mib" => {
value *= 1_048_576.0; value *= 1_048_576.0;
query.pop_front(); query.pop_front();
} }
"KB" => { "kb" => {
value *= 1000.0; value *= 1000.0;
query.pop_front(); query.pop_front();
} }
"KiB" => { "kib" => {
value *= 1024.0; value *= 1024.0;
query.pop_front(); query.pop_front();
} }
"B" => { "b" => {
// Just gotta pop. // Just gotta pop.
query.pop_front(); query.pop_front();
} }
@ -400,7 +413,7 @@ impl ProcessQuery for ProcWidgetState {
#[derive(Debug)] #[derive(Debug)]
pub struct Query { pub struct Query {
/// Remember, AND > OR, but and must come after or then. /// Remember, AND > OR, but and must come after or then.
pub query: Or, pub query: And,
} }
impl Query { impl Query {

View File

@ -205,7 +205,7 @@ impl ProcWidgetState {
self.process_search_state.search_state.error_message = None; self.process_search_state.search_state.error_message = None;
} else { } else {
let parsed_query = self.parse_query(); let parsed_query = self.parse_query();
// debug!("PQ: {:#?}", parsed_query); debug!("PQ: {:#?}", parsed_query);
if let Ok(parsed_query) = parsed_query { if let Ok(parsed_query) = parsed_query {
self.process_search_state.search_state.query = Some(parsed_query); self.process_search_state.search_state.query = Some(parsed_query);

View File

@ -88,7 +88,7 @@ pub const PROCESS_HELP_TEXT: [&str; 8] = [
"Ctrl-f, / Open process search widget", "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", "4 - Process search widget\n",
"Tab Toggle between searching for PID and name\n", "Tab Toggle between searching for PID and name\n",
"Esc Close the search widget (retains the filter)\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", "Alt-r/F3 Toggle using regex\n",
"Left, Alt-h Move cursor left\n", "Left, Alt-h Move cursor left\n",
"Right, Alt-l Move cursor right\n", "Right, Alt-l Move cursor right\n",
"Search keywords\n", "\n",
"pid\n", "Search keywords:\n",
"cpu\n", "pid ex: pid 825\n",
"mem\n", "cpu ex: cpu > 4.2\n",
"pid\n", "mem ex: mem < 4.2\n",
"read\n", "read ex: read >= 1 b\n",
"write\n", "write ex: write <= 1 tb\n",
"tread\n", "tread ex: tread = 1\n",
"twrite\n\n", "twrite ex: twrite = 1\n",
"\nComparison operators\n", "\n",
"=\n", "Comparison operators:\n",
">\n", "= ex: cpu = 1\n",
"<\n", "> ex: cpu > 1\n",
">=\n", "< ex: cpu < 1\n",
"<=\n", ">= ex: cpu >= 1\n",
"\nLogical operators\n", "<= ex: cpu <= 1\n",
"and/&&\n", "\n",
"or/||\n", "Logical operators:\n",
"\nSupported units\n", "and/&& ex: btm and cpu > 1 and mem > 1\n",
"B\n", "or/|| ex: btm or firefox\n",
"KB\n", "\n",
"MB\n", "Supported units:\n",
"TB\n", "B ex: read > 1 b\n",
"KiB\n", "KB ex: read > 1 kb\n",
"MiB\n", "MB ex: read > 1 mb\n",
"GiB\n", "TB ex: read > 1 tb\n",
"TiB\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] = [ pub const BATTERY_HELP_TEXT: [&str; 3] = [