aboutsummaryrefslogtreecommitdiffstats
path: root/src/widgets/command.rs
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/command.rs
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/command.rs')
-rw-r--r--src/widgets/command.rs35
1 files changed, 33 insertions, 2 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,