From 7e3c6c45d8d3e759ec40bab26617cfb16c92ba60 Mon Sep 17 00:00:00 2001 From: imgurbot12 Date: Fri, 18 Aug 2023 19:58:19 -0700 Subject: [PATCH] feat: added options to pass from entries --- rmenu-plugin/src/bin/main.rs | 35 ++++++++++++++++++++++++----------- rmenu-plugin/src/lib.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/rmenu-plugin/src/bin/main.rs b/rmenu-plugin/src/bin/main.rs index 55c6bf0..7322f59 100644 --- a/rmenu-plugin/src/bin/main.rs +++ b/rmenu-plugin/src/bin/main.rs @@ -21,6 +21,12 @@ fn parse_action(action: &str) -> Result { enum Command { /// Generate Complete RMenu Entry Entry { + /// Set Name of Entry + #[arg(short, long, default_value_t=String::from("main"))] + name: String, + /// Set Comment of Entry + #[arg(short, long)] + comment: Option, /// Precomposed Action JSON Objects #[arg(short, long, value_parser=parse_action)] #[clap(required = true)] @@ -34,6 +40,12 @@ enum Command { }, /// Generate RMenu Entry Action Object Action { + /// Set Name of Action + #[arg(short, long, default_value_t=String::from("main"))] + name: String, + /// Set Comment of Action + #[arg(short, long)] + comment: Option, /// Arguments to run As Action Command #[clap(required = true, value_delimiter = ' ')] args: Vec, @@ -47,12 +59,6 @@ enum Command { #[command(author, version, about, long_about = None)] #[command(propagate_version = true)] struct Cli { - /// Set Name of Entry/Action - #[arg(short, long, default_value_t=String::from("main"))] - name: String, - /// Set Comment of Entry/Action - #[arg(short, long)] - comment: Option, /// Generate an Entry/Action Object #[clap(subcommand)] command: Command, @@ -62,20 +68,27 @@ fn main() { let cli = Cli::parse(); let result = match cli.command { Command::Entry { + name, + comment, actions, icon, icon_alt, } => serde_json::to_string(&Entry { - name: cli.name, - comment: cli.comment, + name, + comment, actions, icon, icon_alt, }), - Command::Action { args, terminal } => serde_json::to_string(&Action { - name: cli.name, + Command::Action { + name, + comment, + args, + terminal, + } => serde_json::to_string(&Action { + name, exec: Method::new(args.join(" "), terminal), - comment: cli.comment, + comment, }), }; println!("{}", result.expect("Serialization Failed")); diff --git a/rmenu-plugin/src/lib.rs b/rmenu-plugin/src/lib.rs index 0e41732..c7516f3 100644 --- a/rmenu-plugin/src/lib.rs +++ b/rmenu-plugin/src/lib.rs @@ -49,6 +49,7 @@ impl Action { /// RMenu Menu-Entry Implementation #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[serde(tag = "type", rename = "entry")] pub struct Entry { pub name: String, pub actions: Vec, @@ -80,6 +81,33 @@ impl Entry { } } +/// Additional Plugin Option Overrides +#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)] +#[serde(tag = "type", rename = "options")] +#[serde(default)] +pub struct Options { + // base settings + theme: Option, + // search settings + placeholder: Option, + search_restrict: Option, + search_min_length: Option, + search_max_length: Option, + // key settings + key_exec: Option>, + key_exit: Option>, + key_move_next: Option>, + key_move_prev: Option>, + key_open_menu: Option>, + key_close_menu: Option>, + // window settings + title: Option, + deocorate: Option, + fullscreen: Option, + window_width: Option, + window_height: Option, +} + /// Retrieve EXE of Self #[inline] pub fn self_exe() -> String {