mirror of
https://github.com/imgurbot12/rmenu.git
synced 2025-01-26 12:58:08 +01:00
feat: added options to pass from entries
This commit is contained in:
parent
7ff9412a67
commit
7e3c6c45d8
2 changed files with 52 additions and 11 deletions
|
@ -21,6 +21,12 @@ fn parse_action(action: &str) -> Result<Action, serde_json::Error> {
|
|||
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<String>,
|
||||
/// 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<String>,
|
||||
/// Arguments to run As Action Command
|
||||
#[clap(required = true, value_delimiter = ' ')]
|
||||
args: Vec<String>,
|
||||
|
@ -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<String>,
|
||||
/// 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"));
|
||||
|
|
|
@ -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<Action>,
|
||||
|
@ -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<String>,
|
||||
// search settings
|
||||
placeholder: Option<String>,
|
||||
search_restrict: Option<String>,
|
||||
search_min_length: Option<usize>,
|
||||
search_max_length: Option<usize>,
|
||||
// key settings
|
||||
key_exec: Option<Vec<String>>,
|
||||
key_exit: Option<Vec<String>>,
|
||||
key_move_next: Option<Vec<String>>,
|
||||
key_move_prev: Option<Vec<String>>,
|
||||
key_open_menu: Option<Vec<String>>,
|
||||
key_close_menu: Option<Vec<String>>,
|
||||
// window settings
|
||||
title: Option<String>,
|
||||
deocorate: Option<bool>,
|
||||
fullscreen: Option<bool>,
|
||||
window_width: Option<usize>,
|
||||
window_height: Option<usize>,
|
||||
}
|
||||
|
||||
/// Retrieve EXE of Self
|
||||
#[inline]
|
||||
pub fn self_exe() -> String {
|
||||
|
|
Loading…
Reference in a new issue