summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2020-09-22 18:12:36 -0400
committerGitHub <noreply@github.com>2020-09-22 18:12:36 -0400
commit6db76029e2419d53c81cb2111e487f83ee248a2f (patch)
tree356ff9a92b2d6024d581a6466f832080f2adccbd /src/app
parentb0b174eb9843e9af55f5c3f2d37cae96f1744a6b (diff)
feature: Beginnings of in-app config (#231)
Initial refactorings and additions to support in-app config. - Refactor our current options logic to support in-app configs. That is, we can write to a config file with our changes now. - The default action when creating a new config file is to leave it blank. (TBD and for now, not sure on this one) - Previously, we would set everything in a config file on startup; now we need to read from the config TOML struct whenever. - `C` keybind is now occupied for configs. - `no_write` option to never write to a config file.
Diffstat (limited to 'src/app')
-rw-r--r--src/app/query.rs6
-rw-r--r--src/app/states.rs41
2 files changed, 38 insertions, 9 deletions
diff --git a/src/app/query.rs b/src/app/query.rs
index 488749a4..4d693bb4 100644
--- a/src/app/query.rs
+++ b/src/app/query.rs
@@ -187,7 +187,11 @@ impl ProcessQuery for ProcWidgetState {
let initial_or = Or {
lhs: And {
lhs: Prefix {
- or: Some(Box::new(list_of_ors.pop_front().unwrap())),
+ or: if let Some(or) = list_of_ors.pop_front() {
+ Some(Box::new(or))
+ } else {
+ None
+ },
compare_prefix: None,
regex_prefix: None,
},
diff --git a/src/app/states.rs b/src/app/states.rs
index aaa25004..dea49b18 100644
--- a/src/app/states.rs
+++ b/src/app/states.rs
@@ -280,6 +280,7 @@ impl Default for ProcColumn {
}
}
+// TODO: [SORTING] Sort by clicking on column header (ie: click on cpu, sort/invert cpu sort)?
impl ProcColumn {
/// Returns its new status.
pub fn toggle(&mut self, column: &ProcessSorting) -> Option<bool> {
@@ -303,8 +304,12 @@ impl ProcColumn {
self.ordered_columns
.iter()
.filter_map(|column_type| {
- if self.column_mapping.get(&column_type).unwrap().enabled {
- Some(1)
+ if let Some(col_map) = self.column_mapping.get(&column_type) {
+ if col_map.enabled {
+ Some(1)
+ } else {
+ None
+ }
} else {
None
}
@@ -467,16 +472,20 @@ impl ProcWidgetState {
}
pub fn toggle_command_and_name(&mut self, is_using_command: bool) {
- self.columns
+ if let Some(pn) = self
+ .columns
.column_mapping
.get_mut(&ProcessSorting::ProcessName)
- .unwrap()
- .enabled = !is_using_command;
- self.columns
+ {
+ pn.enabled = !is_using_command;
+ }
+ if let Some(c) = self
+ .columns
.column_mapping
.get_mut(&ProcessSorting::Command)
- .unwrap()
- .enabled = is_using_command;
+ {
+ c.enabled = is_using_command;
+ }
}
pub fn get_cursor_position(&self) -> usize {
@@ -798,3 +807,19 @@ pub struct ParagraphScrollState {
pub current_scroll_index: u16,
pub max_scroll_index: u16,
}
+
+#[derive(Default)]
+pub struct ConfigState {
+ pub current_category_index: usize,
+ pub category_list: Vec<ConfigCategory>,
+}
+
+#[derive(Default)]
+pub struct ConfigCategory {
+ pub category_name: &'static str,
+ pub options_list: Vec<ConfigOption>,
+}
+
+pub struct ConfigOption {
+ pub set_function: Box<dyn Fn() -> anyhow::Result<()>>,
+}