conf/shortcuts: implement a key to command mapping
Run cargo lints / Lint on ${{ matrix.build }} (linux-amd64, ubuntu-latest, stable, x86_64-unknown-linux-gnu) (pull_request) Successful in 13m15s Details
Run Tests / Test on ${{ matrix.build }} (linux-amd64, ubuntu-latest, stable, x86_64-unknown-linux-gnu) (pull_request) Successful in 20m58s Details

Permits users to map keys in their configuration file to an array of meli commands

e.g:
[shortcuts.listing]
commands = [ { command = [ "tag remove trash", "flag unset trash" ], shortcut = "D" },
             { command = [ "tag add trash", "flag set trash" ], shortcut = "d" } ]

Signed-off-by: Guillaume Ranquet <granquet@baylibre.com>
pull/344/head
Guillaume Ranquet 2024-01-05 11:31:48 +01:00
parent 60f26f9dae
commit a37d5fc1d1
9 changed files with 140 additions and 0 deletions

View File

@ -1013,6 +1013,23 @@ exit_entry = 'i'
.\"
.sp
.Pp
.Em commands
.sp
In addition, each shortcuts section supports a TOML array of commands to associate a key to an array of meli
.Em COMMAND
.sp
.\"
.\"
.\"
.Bd -literal
[shortcuts.listing]
commands = [ { command = [ "tag remove trash", "flag unset trash" ], shortcut = "D" },
{ command = [ "tag add trash", "flag set trash" ], shortcut = "d" } ]
.Ed
.\"
.\"
.\"
.Pp
.Em general
.Bl -tag -width 36n
.It Ic toggle_help

View File

@ -88,6 +88,12 @@ impl DotAddressable for Shortcuts {
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommandShortcut {
pub shortcut: Key,
pub command: Vec<String>,
}
/// Create a struct holding all of a Component's shortcuts.
#[macro_export]
macro_rules! shortcut_key_values {
@ -100,6 +106,7 @@ macro_rules! shortcut_key_values {
#[serde(default)]
#[serde(rename = $cname)]
pub struct $name {
pub commands: Vec<CommandShortcut>,
$(pub $fname : Key),*
}
@ -122,6 +129,7 @@ macro_rules! shortcut_key_values {
impl Default for $name {
fn default() -> Self {
Self {
commands : vec![],
$($fname: $default),*
}
}

View File

@ -838,6 +838,23 @@ impl Component for ContactList {
self.movement = Some(PageMovement::End);
return true;
}
UIEvent::Input(ref key) => {
return context
.settings
.shortcuts
.contact_list
.commands
.iter()
.any(|cmd| {
if cmd.shortcut == *key {
for cmd in &cmd.command {
context.replies.push_back(UIEvent::Command(cmd.to_string()));
}
return true;
}
false
})
}
_ => {}
}
}

View File

@ -1132,6 +1132,23 @@ impl Component for Composer {
};
return true;
}
UIEvent::Input(ref key) => {
return context
.settings
.shortcuts
.composing
.commands
.iter()
.any(|cmd| {
if cmd.shortcut == *key {
for cmd in &cmd.command {
context.replies.push_back(UIEvent::Command(cmd.to_string()));
}
return true;
}
false
})
}
_ => {}
}
if self.cursor == Cursor::Headers

View File

@ -1960,6 +1960,25 @@ impl Component for Listing {
)));
return true;
}
UIEvent::Input(ref key) => {
return context
.settings
.shortcuts
.listing
.commands
.iter()
.any(|cmd| {
if cmd.shortcut == *key {
for cmd in &cmd.command {
context
.replies
.push_back(UIEvent::Command(cmd.to_string()));
}
return true;
}
false
});
}
_ => {}
}
}

View File

@ -1415,6 +1415,23 @@ impl Component for ConversationsListing {
}
_ => {}
},
UIEvent::Input(ref key) => {
return context
.settings
.shortcuts
.listing
.commands
.iter()
.any(|cmd| {
if cmd.shortcut == *key {
for cmd in &cmd.command {
context.replies.push_back(UIEvent::Command(cmd.to_string()));
}
return true;
}
false
})
}
_ => {}
}
}

View File

@ -789,6 +789,23 @@ impl Component for MailView {
.push_back(UIEvent::Action(Tab(New(Some(Box::new(new_tab))))));
return true;
}
UIEvent::Input(ref key) => {
return context
.settings
.shortcuts
.envelope_view
.commands
.iter()
.any(|cmd| {
if cmd.shortcut == *key {
for cmd in &cmd.command {
context.replies.push_back(UIEvent::Command(cmd.to_string()));
}
return true;
}
false
})
}
_ => {}
}
false

View File

@ -1103,6 +1103,23 @@ impl Component for ThreadView {
}
false
}
UIEvent::Input(ref key) => {
return context
.settings
.shortcuts
.thread_view
.commands
.iter()
.any(|cmd| {
if cmd.shortcut == *key {
for cmd in &cmd.command {
context.replies.push_back(UIEvent::Command(cmd.to_string()));
}
return true;
}
false
})
}
_ => {
if self
.entries

View File

@ -835,6 +835,17 @@ impl Component for Pager {
String::new(),
)));
}
UIEvent::Input(ref key) => {
return context.settings.shortcuts.pager.commands.iter().any(|cmd| {
if cmd.shortcut == *key {
for cmd in &cmd.command {
context.replies.push_back(UIEvent::Command(cmd.to_string()));
}
return true;
}
false
})
}
_ => {}
}
false