mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-10 14:44:18 +00:00
bug/change: removed space as and for now
This commit is contained in:
parent
9932ad34c1
commit
38f4967a8a
5 changed files with 73 additions and 59 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)?));
|
||||
let rhs = process_or(query)?;
|
||||
|
||||
lhs = Or {
|
||||
lhs: And {
|
||||
lhs: Prefix {
|
||||
or: Some(Box::from(lhs)),
|
||||
compare_prefix: None,
|
||||
regex_prefix: None,
|
||||
},
|
||||
rhs: None,
|
||||
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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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] = [
|
||||
|
|
Loading…
Reference in a new issue