aboutsummaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorDaniel Jankowski <daniel.jankowski@rub.de>2024-06-02 12:32:23 +0200
committerDaniel Jankowski <daniel.jankowski@rub.de>2024-06-02 12:32:23 +0200
commitd669610cae0051b60dfb9564a52582611968dfad (patch)
treedfa1909c86f5612139d679f6f1747310a7aa71bf /src/widgets
parentchore: update cargo deps (diff)
downloadsl0pstatus-d669610cae0051b60dfb9564a52582611968dfad.tar.gz
sl0pstatus-d669610cae0051b60dfb9564a52582611968dfad.tar.xz
sl0pstatus-d669610cae0051b60dfb9564a52582611968dfad.zip
feat: implement click action for command widget
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/command.rs35
-rw-r--r--src/widgets/datetime.rs2
-rw-r--r--src/widgets/mode.rs2
-rw-r--r--src/widgets/notification.rs2
-rw-r--r--src/widgets/session.rs2
-rw-r--r--src/widgets/swap_layout.rs2
-rw-r--r--src/widgets/tabs.rs2
-rw-r--r--src/widgets/widget.rs2
8 files changed, 40 insertions, 9 deletions
diff --git a/src/widgets/command.rs b/src/widgets/command.rs
index 83609c4..184d354 100644
--- a/src/widgets/command.rs
+++ b/src/widgets/command.rs
@@ -37,6 +37,7 @@ struct CommandConfig {
cwd: Option<PathBuf>,
interval: i64,
render_mode: RenderMode,
+ click_action: String,
}
#[derive(Clone, Debug, Default)]
@@ -113,7 +114,29 @@ impl Widget for CommandWidget {
}
}
- fn process_click(&self, _state: &ZellijState, _pos: usize) {}
+ fn process_click(&self, name: &str, _state: &ZellijState, _pos: usize) {
+ let command_config = match self.config.get(name) {
+ Some(cc) => cc,
+ None => {
+ return;
+ }
+ };
+
+ if command_config.click_action.is_empty() {
+ return;
+ }
+
+ let command = commandline_parser(&command_config.click_action);
+ let context: BTreeMap<String, String> = BTreeMap::new();
+
+ tracing::debug!("Running command {:?} {:?}", command, context);
+
+ #[cfg(all(not(feature = "bench"), not(test)))]
+ run_command(
+ &command.iter().map(|x| x.as_str()).collect::<Vec<&str>>(),
+ context,
+ );
+ }
}
fn render_dynamic_formatted_content(content: &str) -> String {
@@ -190,6 +213,7 @@ fn parse_config(zj_conf: &BTreeMap<String, String>) -> BTreeMap<String, CommandC
env: None,
interval: 1,
render_mode: RenderMode::Static,
+ click_action: "".to_owned(),
};
if let Some(existing_conf) = config.get(command_name.as_str()) {
@@ -199,7 +223,13 @@ fn parse_config(zj_conf: &BTreeMap<String, String>) -> BTreeMap<String, CommandC
if key.ends_with("command") {
command_conf
.command
- .clone_from(&zj_conf.get(&key).unwrap().to_owned())
+ .clone_from(&zj_conf.get(&key).unwrap().to_owned());
+ }
+
+ if key.ends_with("clickaction") {
+ command_conf
+ .click_action
+ .clone_from(&zj_conf.get(&key).unwrap().to_owned());
}
if key.ends_with("env") {
@@ -437,6 +467,7 @@ mod test {
cwd: None,
interval,
render_mode: RenderMode::Static,
+ click_action: "".to_owned(),
},
"test",
state,
diff --git a/src/widgets/datetime.rs b/src/widgets/datetime.rs
index 18390f2..3cf4721 100644
--- a/src/widgets/datetime.rs
+++ b/src/widgets/datetime.rs
@@ -63,5 +63,5 @@ impl Widget for DateTimeWidget {
self.color_format.format_string(&output)
}
- fn process_click(&self, _state: &ZellijState, _pos: usize) {}
+ fn process_click(&self, _name: &str, _state: &ZellijState, _pos: usize) {}
}
diff --git a/src/widgets/mode.rs b/src/widgets/mode.rs
index a452c53..68c9bfa 100644
--- a/src/widgets/mode.rs
+++ b/src/widgets/mode.rs
@@ -139,7 +139,7 @@ impl Widget for ModeWidget {
})
}
- fn process_click(&self, _state: &ZellijState, _pos: usize) {}
+ fn process_click(&self, _name: &str, _state: &ZellijState, _pos: usize) {}
}
impl ModeWidget {
diff --git a/src/widgets/notification.rs b/src/widgets/notification.rs
index 5023fa7..1b8cfcd 100644
--- a/src/widgets/notification.rs
+++ b/src/widgets/notification.rs
@@ -74,5 +74,5 @@ impl Widget for NotificationWidget {
output.to_owned()
}
- fn process_click(&self, _state: &ZellijState, _pos: usize) {}
+ fn process_click(&self, _name: &str, _state: &ZellijState, _pos: usize) {}
}
diff --git a/src/widgets/session.rs b/src/widgets/session.rs
index 4916a65..9e27f6d 100644
--- a/src/widgets/session.rs
+++ b/src/widgets/session.rs
@@ -18,5 +18,5 @@ impl Widget for SessionWidget {
}
}
- fn process_click(&self, _state: &ZellijState, _pos: usize) {}
+ fn process_click(&self, _name: &str, _state: &ZellijState, _pos: usize) {}
}
diff --git a/src/widgets/swap_layout.rs b/src/widgets/swap_layout.rs
index 7d36b14..d8f9ffb 100644
--- a/src/widgets/swap_layout.rs
+++ b/src/widgets/swap_layout.rs
@@ -66,7 +66,7 @@ impl Widget for SwapLayoutWidget {
output
}
- fn process_click(&self, _state: &ZellijState, _pos: usize) {
+ fn process_click(&self, _name: &str, _state: &ZellijState, _pos: usize) {
next_swap_layout()
}
}
diff --git a/src/widgets/tabs.rs b/src/widgets/tabs.rs
index b0e9ce4..6853465 100644
--- a/src/widgets/tabs.rs
+++ b/src/widgets/tabs.rs
@@ -101,7 +101,7 @@ impl Widget for TabsWidget {
output
}
- fn process_click(&self, state: &ZellijState, pos: usize) {
+ fn process_click(&self, _name: &str, state: &ZellijState, pos: usize) {
let mut offset = 0;
let mut index = 1;
let mut counter = 0;
diff --git a/src/widgets/widget.rs b/src/widgets/widget.rs
index ff4a784..7087cba 100644
--- a/src/widgets/widget.rs
+++ b/src/widgets/widget.rs
@@ -2,5 +2,5 @@ use crate::config::ZellijState;
pub trait Widget {
fn process(&self, name: &str, state: &ZellijState) -> String;
- fn process_click(&self, state: &ZellijState, pos: usize);
+ fn process_click(&self, name: &str, state: &ZellijState, pos: usize);
}