diff options
author | ClementTsang <cjhtsang@uwaterloo.ca> | 2020-05-04 23:44:33 -0400 |
---|---|---|
committer | ClementTsang <cjhtsang@uwaterloo.ca> | 2020-05-04 23:44:33 -0400 |
commit | 38f4967a8a9b15e255caf7078f09f7eb4850f169 (patch) | |
tree | 8afe0823245db8cd301e929d0dcad4e5c884e1c8 /src | |
parent | 9932ad34c1d790df721a6cc204d0fb9150a1cfbe (diff) |
bug/change: removed space as and for now0.4.0
Diffstat (limited to 'src')
-rw-r--r-- | src/app/query.rs | 63 | ||||
-rw-r--r-- | src/app/states.rs | 2 | ||||
-rw-r--r-- | src/constants.rs | 59 |
3 files changed, 70 insertions, 54 deletions
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] = [ |